Skip to content

Commit 05ca639

Browse files
committed
Merge branch 'develop'
2 parents 7219417 + 3ddbed5 commit 05ca639

File tree

60 files changed

+366
-259
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+366
-259
lines changed

changes.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@
2323
xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 https://maven.apache.org/plugins/maven-changes-plugin/xsd/changes-1.0.0.xsd">
2424
<body>
2525

26+
<release version="2.20.0" date="not released">
27+
<action type="add" dev="sseifert" issue="86"><![CDATA[
28+
ContentPackageOsgiConfigPostProcessor: Accept both <a href="https://devops.wcm.io/conga/plugins/sling//osgi-config-combined-json.html">Combined JSON files</a>
29+
and Sling Provisioning File Format as input for generating OSGi configurations.
30+
]]></action>
31+
<action type="update" dev="sseifert" issue="85">
32+
ContentPackageOsgiConfigPostProcessor: Write OSGi configurations as .cfg.json files instead of .config files.
33+
</action>
34+
<action type="update" dev="sseifert">
35+
Update to AEM Content Package Builder 1.7.4 to ensure folder path ZIP file entries are created.
36+
</action>
37+
</release>
38+
2639
<release version="2.19.10" date="2023-12-18">
2740
<action type="fix" dev="sseifert">
2841
Update to latest io.wcm.tooling.commons.content-package-builder to fix potential problem with element ordering content packages generated from JSON files.

conga-aem-plugin/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
<parent>
2626
<groupId>io.wcm.devops.conga.plugins</groupId>
2727
<artifactId>io.wcm.devops.conga.plugins.aem.parent</artifactId>
28-
<version>2.19.10</version>
28+
<version>2.20.0</version>
2929
<relativePath>../parent/pom.xml</relativePath>
3030
</parent>
3131

3232
<groupId>io.wcm.devops.conga.plugins</groupId>
3333
<artifactId>io.wcm.devops.conga.plugins.aem</artifactId>
34-
<version>2.19.10</version>
34+
<version>2.20.0</version>
3535
<packaging>jar</packaging>
3636

3737
<name>CONGA AEM Plugin</name>

conga-aem-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/crypto/impl/AesCryptoSupport.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
/**
3838
* AES crypto support implementation with the same algorithms as used by AEM 6.3 and up.
3939
*/
40+
@SuppressWarnings("java:S5542") // cannot use a more secure cipher mode, we have to be compatible with AEM
4041
public class AesCryptoSupport extends CryptoSupport {
4142

4243
private static final String AES_KEY_ALGORITHM = "AES";
@@ -54,7 +55,7 @@ private static Random initRandom() {
5455
return SecureRandom.getInstance(SECURE_RANDOM_ALGORITHM);
5556
}
5657
catch (NoSuchAlgorithmException ex) {
57-
throw new RuntimeException(ex);
58+
throw new IllegalStateException(ex);
5859
}
5960
}
6061

conga-aem-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/handlebars/escaping/AnyEscapingStrategy.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
*/
2020
package io.wcm.devops.conga.plugins.aem.handlebars.escaping;
2121

22+
import java.util.Map;
23+
2224
import org.apache.commons.text.translate.CharSequenceTranslator;
2325
import org.apache.commons.text.translate.LookupTranslator;
2426

25-
import com.google.common.collect.ImmutableMap;
26-
2727
import io.wcm.devops.conga.generator.spi.handlebars.EscapingStrategyPlugin;
2828
import io.wcm.devops.conga.generator.spi.handlebars.context.EscapingStrategyContext;
2929
import io.wcm.devops.conga.generator.util.FileUtil;
@@ -44,7 +44,7 @@ public class AnyEscapingStrategy implements EscapingStrategyPlugin {
4444
* Defines translations for strings in ANY files.
4545
*/
4646
private static final CharSequenceTranslator ESCAPE_ANY =
47-
new LookupTranslator(ImmutableMap.of(
47+
new LookupTranslator(Map.of(
4848
"\"", "\\\"",
4949
"\\", "\\\\"));
5050

conga-aem-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/handlebars/helper/AbstractCloudManagerConditionalHelper.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
import com.github.jknack.handlebars.Context;
3030
import com.github.jknack.handlebars.Options;
3131
import com.github.jknack.handlebars.Options.Buffer;
32-
import com.google.common.collect.ImmutableList;
33-
import com.google.common.collect.ImmutableMap;
3432

3533
import io.wcm.devops.conga.generator.spi.handlebars.HelperPlugin;
3634
import io.wcm.devops.conga.generator.spi.handlebars.context.HelperContext;
@@ -45,7 +43,7 @@ abstract class AbstractCloudManagerConditionalHelper implements HelperPlugin<Obj
4543

4644
static final String HTTPD_KEY = "httpd";
4745
static final String CLOUD_MANAGER_CONDITIONAL_KEY = "cloudManagerConditional";
48-
static final List<String> ENVIRONMENTS = ImmutableList.of("dev", "stage", "prod");
46+
static final List<String> ENVIRONMENTS = List.of("dev", "stage", "prod");
4947

5048
@Override
5149
@SuppressWarnings("unchecked")
@@ -70,7 +68,7 @@ public final Object apply(Object context, Options options, HelperContext pluginC
7068
for (CloudManagerConditional item : items) {
7169

7270
// config inside httpd.cloudManagerConditional is considered to be prefixed with "httpd.", so wrap it around here for merging
73-
Map<String, Object> httpdWrapper = ImmutableMap.of(HTTPD_KEY, item.getConfig());
71+
Map<String, Object> httpdWrapper = Map.of(HTTPD_KEY, item.getConfig());
7472
Map<String, Object> mergedModel = MapMerger.merge(httpdWrapper, (Map<String, Object>)currentContext.model());
7573

7674
// remove cloudManagerConditional after merging the models
@@ -96,7 +94,7 @@ protected abstract void renderBodyContent(Buffer buffer, CharSequence bodyConten
9694

9795
private List<CloudManagerConditional> getCloudManagerConditional(Map<String, Object> cloudManagerConditional) {
9896
return ENVIRONMENTS.stream()
99-
.map(env -> new CloudManagerConditional(env, cloudManagerConditional.getOrDefault(env, ImmutableMap.of())))
97+
.map(env -> new CloudManagerConditional(env, cloudManagerConditional.getOrDefault(env, Map.of())))
10098
.collect(Collectors.toList());
10199
}
102100

@@ -115,7 +113,7 @@ private static class CloudManagerConditional {
115113
this.config = (Map<String, Object>)value;
116114
}
117115
else {
118-
this.config = ImmutableMap.of();
116+
this.config = Map.of();
119117
}
120118
}
121119

conga-aem-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/handlebars/helper/AemCryptoEncryptHelper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public String getName() {
6363
}
6464

6565
@Override
66+
@SuppressWarnings({ "java:S3776", "java:S5411" }) // ignore complexity
6667
public Object apply(Object context, Options options, HelperContext pluginContext) throws IOException {
6768
if (context == null) {
6869
return null;

conga-aem-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/handlebars/helper/AemHttpdFilterHelper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ protected String generateFilter(Map<String, Object> filterMap, Options options)
7373
allowFrom, allowFromHost);
7474
}
7575

76+
@SuppressWarnings({ "java:S3776", "java:S1192" }) // ignore complexity
7677
private String generateRule(String ruleType, String ruleExpression, HttpdFilterType filterType,
7778
String allowFrom, String allowFromHost) {
7879
StringBuilder sb = new StringBuilder();

conga-aem-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/handlebars/helper/DispatcherFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* Java bean that describes a AEM dispatcher filter rule as defined in
2727
* https://docs.adobe.com/docs/en/dispatcher/disp-config.html#par_134_32_0009
2828
*/
29-
class DispatcherFilter extends AbstractFilter {
29+
final class DispatcherFilter extends AbstractFilter {
3030

3131
/*
3232
* The /type indicates whether to allow or deny access for the requests that match the pattern.

conga-aem-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/handlebars/helper/HttpdFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/**
2626
* Java bean that describes a simple HTTPd filter rule.
2727
*/
28-
class HttpdFilter extends AbstractFilter {
28+
final class HttpdFilter extends AbstractFilter {
2929

3030
private final HttpdFilterType type;
3131

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

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.io.InputStream;
3030
import java.io.OutputStream;
3131
import java.nio.charset.StandardCharsets;
32+
import java.nio.file.Files;
3233
import java.util.Dictionary;
3334
import java.util.HashMap;
3435
import java.util.List;
@@ -39,25 +40,24 @@
3940
import org.apache.sling.provisioning.model.Model;
4041
import org.slf4j.Logger;
4142

42-
import com.google.common.collect.ImmutableList;
43-
import com.google.common.collect.ImmutableMap;
44-
4543
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
4644
import io.wcm.devops.conga.generator.GeneratorException;
4745
import io.wcm.devops.conga.generator.plugins.postprocessor.AbstractPostProcessor;
4846
import io.wcm.devops.conga.generator.spi.context.FileContext;
4947
import io.wcm.devops.conga.generator.spi.context.FileHeaderContext;
5048
import io.wcm.devops.conga.generator.spi.context.PostProcessorContext;
5149
import io.wcm.devops.conga.plugins.aem.util.ContentPackageUtil;
50+
import io.wcm.devops.conga.plugins.sling.postprocessor.JsonOsgiConfigPostProcessor;
5251
import io.wcm.devops.conga.plugins.sling.util.ConfigConsumer;
52+
import io.wcm.devops.conga.plugins.sling.util.JsonOsgiConfigUtil;
5353
import io.wcm.devops.conga.plugins.sling.util.OsgiConfigUtil;
5454
import io.wcm.devops.conga.plugins.sling.util.ProvisioningUtil;
5555
import io.wcm.tooling.commons.contentpackagebuilder.ContentPackage;
5656
import io.wcm.tooling.commons.contentpackagebuilder.ContentPackageBuilder;
5757

5858
/**
59-
* Transforms a Sling Provisioning file into OSGi configurations (ignoring all other provisioning contents)
60-
* and then packages them up in an AEM content package to be deployed via CRX package manager.
59+
* Transforms a Sling Provisioning file or Combined JSON file as used by CONGA Sling Plugin
60+
* into OSGi configurations and then packages them up in an AEM content package to be deployed via CRX package manager.
6161
*/
6262
public class ContentPackageOsgiConfigPostProcessor extends AbstractPostProcessor {
6363

@@ -73,7 +73,8 @@ public String getName() {
7373

7474
@Override
7575
public boolean accepts(FileContext file, PostProcessorContext context) {
76-
return ProvisioningUtil.isProvisioningFile(file);
76+
return ProvisioningUtil.isProvisioningFile(file)
77+
|| StringUtils.endsWith(file.getFile().getName(), JsonOsgiConfigPostProcessor.FILE_EXTENSION);
7778
}
7879

7980
@Override
@@ -88,14 +89,20 @@ public List<FileContext> apply(FileContext fileContext, PostProcessorContext con
8889
FileHeaderContext fileHeader = extractFileHeader(fileContext, context);
8990

9091
// generate OSGi configurations
91-
Model model = ProvisioningUtil.getModel(fileContext);
92+
Model model;
93+
if (ProvisioningUtil.isProvisioningFile(fileContext)) {
94+
model = ProvisioningUtil.getModel(fileContext);
95+
}
96+
else {
97+
model = JsonOsgiConfigUtil.readToProvisioningModel(file);
98+
}
9299

93100
// check if any osgi configuration is present
94101
boolean hasAnyConfig = !ProvisioningUtil.visitOsgiConfigurations(model,
95102
(ConfigConsumer<Boolean>)(path, properties) -> true).isEmpty();
96103

97104
// create AEM content package with configurations
98-
File zipFile = new File(file.getParentFile(), FilenameUtils.getBaseName(file.getName()) + ".zip");
105+
File zipFile = new File(file.getParentFile(), getBaseFileName(file.getName()) + ".zip");
99106
logger.info("Generate {}", zipFile.getCanonicalPath());
100107

101108
String rootPath = ContentPackageUtil.getMandatoryProp(options, PROPERTY_PACKAGE_ROOT_PATH);
@@ -113,19 +120,19 @@ public List<FileContext> apply(FileContext fileContext, PostProcessorContext con
113120
else {
114121
// create folder for root path if package is empty otherwise
115122
// (to make sure probably already existing config is overridden/cleaned)
116-
contentPackage.addContent(rootPath, ImmutableMap.of("jcr:primaryType", "nt:folder"));
123+
contentPackage.addContent(rootPath, Map.of("jcr:primaryType", "nt:folder"));
117124
}
118125
}
119126

120127
// delete provisioning file after transformation
121-
file.delete();
128+
Files.delete(file.toPath());
122129

123130
// set force to true by default for CONGA-generated packages (but allow override from role definition)
124131
Map<String, Object> modelOptions = new HashMap<>();
125132
modelOptions.put("force", true);
126133
modelOptions.putAll(fileContext.getModelOptions());
127134

128-
return ImmutableList.of(new FileContext().file(zipFile).modelOptions(modelOptions));
135+
return List.of(new FileContext().file(zipFile).modelOptions(modelOptions));
129136
}
130137
catch (IOException ex) {
131138
throw new GeneratorException("Unable to post-process sling provisioning OSGi configurations.", ex);
@@ -146,12 +153,13 @@ private boolean generateOsgiConfigurations(Model model, ContentPackage contentPa
146153
List<Void> result = ProvisioningUtil.visitOsgiConfigurations(model, new ConfigConsumer<Void>() {
147154
@Override
148155
@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE")
156+
@SuppressWarnings("java:S3457") // log placeholders
149157
public Void accept(String path, Dictionary<String, Object> properties) throws IOException {
150158
String contentPath = rootPath + (StringUtils.contains(path, "/") ? "." : "/") + path;
151159
context.getLogger().info(" Include " + contentPath);
152160

153161
// write configuration to temporary file
154-
File tempFile = File.createTempFile(NAME, ".config");
162+
File tempFile = File.createTempFile(NAME, ".cfg.json");
155163
try (OutputStream os = new FileOutputStream(tempFile)) {
156164
OsgiConfigUtil.write(os, properties);
157165
}
@@ -168,12 +176,21 @@ public Void accept(String path, Dictionary<String, Object> properties) throws IO
168176
}
169177
finally {
170178
// remove temporary file
171-
tempFile.delete();
179+
Files.delete(tempFile.toPath());
172180
}
173181
return null;
174182
}
175183
});
176184
return !result.isEmpty();
177185
}
178186

187+
private String getBaseFileName(String fileName) {
188+
if (StringUtils.endsWith(fileName, JsonOsgiConfigPostProcessor.FILE_EXTENSION)) {
189+
return StringUtils.substringBeforeLast(fileName, JsonOsgiConfigPostProcessor.FILE_EXTENSION);
190+
}
191+
else {
192+
return FilenameUtils.getBaseName(fileName);
193+
}
194+
}
195+
179196
}

0 commit comments

Comments
 (0)