Skip to content

Commit a3d466d

Browse files
committed
aem-contentpackage-properties post processor: Allow to override package type with contentPackage.packageType option (useful for 3rdparty packages that have no package type defined).
1 parent d86742d commit a3d466d

4 files changed

Lines changed: 44 additions & 9 deletions

File tree

changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
aem-contentpackage-osgiconfig post processor: Include only generated *.config files in AEM content package, no other .content files (exception the package is empty otherwise).
4444
Automatically set 'packageType' for packages created by this post processor.
4545
</action>
46+
<action type="update" dev="sseifert">
47+
aem-contentpackage-properties post processor: Allow to override package type with contentPackage.packageType option (useful for 3rdparty packages that have no package type defined).
48+
</action>
4649
</release>
4750

4851
<release version="1.10.0" date="2020-01-30">

conga-aem-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/postprocessor/ContentPackagePropertiesPostProcessor.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@
1919
*/
2020
package io.wcm.devops.conga.plugins.aem.postprocessor;
2121

22+
import static io.wcm.devops.conga.plugins.aem.postprocessor.ContentPackageOptions.PROPERTY_PACKAGE_PACKAGE_TYPE;
23+
import static org.apache.jackrabbit.vault.packaging.PackageProperties.NAME_PACKAGE_TYPE;
24+
2225
import java.io.IOException;
2326
import java.util.List;
2427
import java.util.Map;
2528

29+
import org.apache.commons.lang3.StringUtils;
2630
import org.slf4j.Logger;
2731

2832
import com.google.common.collect.ImmutableList;
@@ -33,6 +37,7 @@
3337
import io.wcm.devops.conga.generator.spi.context.FileContext;
3438
import io.wcm.devops.conga.generator.spi.context.PostProcessorContext;
3539
import io.wcm.devops.conga.generator.util.FileUtil;
40+
import io.wcm.devops.conga.plugins.aem.util.ContentPackageUtil;
3641
import io.wcm.tooling.commons.packmgr.util.ContentPackageProperties;
3742

3843
/**
@@ -82,6 +87,14 @@ public List<FileContext> apply(FileContext fileContext, PostProcessorContext con
8287
try {
8388
Map<String, Object> properties = ContentPackageProperties.get(fileContext.getFile());
8489
if (!properties.isEmpty()) {
90+
91+
// allow to redefine the packageType content package property via post processor options
92+
// this is useful when 3rdparty packages do not define a package type
93+
String packageType = ContentPackageUtil.getOptionalProp(context.getOptions(), PROPERTY_PACKAGE_PACKAGE_TYPE);
94+
if (StringUtils.isNotBlank(packageType)) {
95+
properties.put(NAME_PACKAGE_TYPE, packageType);
96+
}
97+
8598
fileContext.getModelOptions().put(MODEL_OPTIONS_PROPERTY, properties);
8699
logger.info("Extracted properties from AEM content package.");
87100
}

conga-aem-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/util/ContentPackageUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ else if (value != null) {
287287
* @param key Key
288288
* @return Option value or null
289289
*/
290-
private static String getOptionalProp(Map<String, Object> options, String key) {
290+
public static String getOptionalProp(Map<String, Object> options, String key) {
291291
Object value = MapExpander.getDeep(options, key);
292292
if (value instanceof String) {
293293
return (String)value;

conga-aem-plugin/src/test/java/io/wcm/devops/conga/plugins/aem/postprocessor/ContentPackagePropertiesPostProcessorTest.java

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,58 +30,77 @@
3030
import org.junit.jupiter.api.Test;
3131
import org.slf4j.LoggerFactory;
3232

33+
import com.google.common.collect.ImmutableMap;
34+
3335
import io.wcm.devops.conga.generator.spi.PostProcessorPlugin;
3436
import io.wcm.devops.conga.generator.spi.context.FileContext;
3537
import io.wcm.devops.conga.generator.spi.context.PluginContextOptions;
3638
import io.wcm.devops.conga.generator.spi.context.PostProcessorContext;
3739
import io.wcm.devops.conga.generator.util.PluginManagerImpl;
3840
import io.wcm.devops.conga.plugins.sling.postprocessor.ProvisioningOsgiConfigPostProcessor;
3941

40-
public class ContentPackagePropertiesPostProcessorTest {
42+
class ContentPackagePropertiesPostProcessorTest {
4143

4244
private PostProcessorPlugin underTest;
4345

4446
@BeforeEach
45-
public void setUp() {
47+
void setUp() {
4648
underTest = new PluginManagerImpl().get(ContentPackagePropertiesPostProcessor.NAME, PostProcessorPlugin.class);
4749
}
4850

4951
@SuppressWarnings("unchecked")
5052
@Test
51-
public void testContentPackage() throws Exception {
53+
void testContentPackage() throws Exception {
5254

5355
FileContext fileContext = new FileContext()
5456
.file(new File("src/test/resources/package/example.zip"));
5557

5658
// post-process
57-
applyPlugin(fileContext);
59+
applyPlugin(fileContext, ImmutableMap.of());
5860

5961
// validate
6062
Map<String, Object> props = (Map<String, Object>)fileContext.getModelOptions().get(ContentPackagePropertiesPostProcessor.MODEL_OPTIONS_PROPERTY);
6163
assertEquals("mapping-sample", props.get("name"));
6264
assertEquals(false, props.get("requiresRoot"));
6365
assertEquals(2, props.get("packageFormatVersion"));
66+
assertNull(props.get("packageType"));
67+
}
68+
69+
@SuppressWarnings("unchecked")
70+
@Test
71+
void testContentPackageOverridePackageType() throws Exception {
72+
73+
FileContext fileContext = new FileContext()
74+
.file(new File("src/test/resources/package/example.zip"));
75+
76+
// post-process
77+
applyPlugin(fileContext, ImmutableMap.of("contentPackage", ImmutableMap.of("packageType", "mytype")));
78+
79+
// validate
80+
Map<String, Object> props = (Map<String, Object>)fileContext.getModelOptions().get(ContentPackagePropertiesPostProcessor.MODEL_OPTIONS_PROPERTY);
81+
assertEquals("mytype", props.get("packageType"));
6482
}
6583

6684
@Test
67-
public void testNonContentPackage() throws Exception {
85+
void testNonContentPackage() throws Exception {
6886

6987
FileContext fileContext = new FileContext()
7088
.file(new File("src/test/resources/package/no-content-package.zip"));
7189

7290
// post-process
73-
applyPlugin(fileContext);
91+
applyPlugin(fileContext, ImmutableMap.of());
7492

7593
// validate
7694
assertNull(fileContext.getModelOptions().get(ContentPackagePropertiesPostProcessor.MODEL_OPTIONS_PROPERTY));
7795
}
7896

79-
private void applyPlugin(FileContext fileContext) {
97+
private void applyPlugin(FileContext fileContext, Map<String, Object> options) {
8098
PluginContextOptions pluginContextOptions = new PluginContextOptions()
8199
.pluginManager(new PluginManagerImpl())
82100
.logger(LoggerFactory.getLogger(ProvisioningOsgiConfigPostProcessor.class));
83101
PostProcessorContext context = new PostProcessorContext()
84-
.pluginContextOptions(pluginContextOptions);
102+
.pluginContextOptions(pluginContextOptions)
103+
.options(options);
85104

86105
assertTrue(underTest.accepts(fileContext, context));
87106
underTest.apply(fileContext, context);

0 commit comments

Comments
 (0)