Skip to content

Commit 0d66886

Browse files
Omit CONGA file header in generated content packages and use single creation date (#178)
1 parent 7259109 commit 0d66886

File tree

6 files changed

+18
-77
lines changed

6 files changed

+18
-77
lines changed

changes.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
<body>
2626

2727
<release version="2.20.4" date="not released">
28-
<action type="update" dev="sseifert">
28+
<action type="update" dev="sseifert" issue="178">
29+
Omit CONGA file header in generated content packages and use single creation date.
30+
</action>
31+
<action type="update" dev="sseifert" issue="177">
2932
CONGA AEM Maven Plugin: Switch to JSR-330 annotations.
3033
</action>
3134
</release>

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

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.io.IOException;
2929
import java.io.InputStream;
3030
import java.io.OutputStream;
31-
import java.nio.charset.StandardCharsets;
3231
import java.nio.file.Files;
3332
import java.util.Dictionary;
3433
import java.util.HashMap;
@@ -43,7 +42,6 @@
4342
import io.wcm.devops.conga.generator.GeneratorException;
4443
import io.wcm.devops.conga.generator.plugins.postprocessor.AbstractPostProcessor;
4544
import io.wcm.devops.conga.generator.spi.context.FileContext;
46-
import io.wcm.devops.conga.generator.spi.context.FileHeaderContext;
4745
import io.wcm.devops.conga.generator.spi.context.PostProcessorContext;
4846
import io.wcm.devops.conga.plugins.aem.util.ContentPackageUtil;
4947
import io.wcm.devops.conga.plugins.sling.postprocessor.JsonOsgiConfigPostProcessor;
@@ -83,9 +81,6 @@ public List<FileContext> apply(FileContext fileContext, PostProcessorContext con
8381
Map<String, Object> options = context.getOptions();
8482

8583
try {
86-
// extract file header
87-
FileHeaderContext fileHeader = extractFileHeader(fileContext, context);
88-
8984
// generate OSGi configurations
9085
Model model;
9186
if (ProvisioningUtil.isProvisioningFile(fileContext)) {
@@ -105,15 +100,15 @@ public List<FileContext> apply(FileContext fileContext, PostProcessorContext con
105100

106101
String rootPath = ContentPackageUtil.getMandatoryProp(options, PROPERTY_PACKAGE_ROOT_PATH);
107102

108-
ContentPackageBuilder builder = ContentPackageUtil.getContentPackageBuilder(options, context.getUrlFileManager(), fileHeader);
103+
ContentPackageBuilder builder = ContentPackageUtil.getContentPackageBuilder(options, context.getUrlFileManager());
109104

110105
// set package type depending on if config is present or not
111106
builder.packageType(hasAnyConfig ? "container" : "application");
112107

113108
try (ContentPackage contentPackage = builder.build(zipFile)) {
114109
if (hasAnyConfig) {
115110
// generate OSGI config files
116-
generateOsgiConfigurations(model, contentPackage, rootPath, fileHeader, context);
111+
generateOsgiConfigurations(model, contentPackage, rootPath, context);
117112
}
118113
else {
119114
// create folder for root path if package is empty otherwise
@@ -142,12 +137,11 @@ public List<FileContext> apply(FileContext fileContext, PostProcessorContext con
142137
* @param model Provisioning Model
143138
* @param contentPackage Content package
144139
* @param rootPath Root path
145-
* @param fileHeader File header
146140
* @param context Post processor context
147141
* @return true if any config file was added
148142
*/
149143
private boolean generateOsgiConfigurations(Model model, ContentPackage contentPackage,
150-
String rootPath, FileHeaderContext fileHeader, PostProcessorContext context) throws IOException {
144+
String rootPath, PostProcessorContext context) throws IOException {
151145
List<Void> result = ProvisioningUtil.visitOsgiConfigurations(model, new ConfigConsumer<Void>() {
152146
@Override
153147
@SuppressWarnings("java:S3457") // log placeholders
@@ -161,11 +155,6 @@ public Void accept(String path, Dictionary<String, Object> properties) throws IO
161155
OsgiConfigUtil.write(os, properties);
162156
}
163157
try {
164-
FileContext tempFileContext = new FileContext().file(tempFile).charset(StandardCharsets.UTF_8);
165-
166-
// apply file header
167-
applyFileHeader(tempFileContext, fileHeader, context);
168-
169158
// write configuration to content package
170159
try (InputStream is = new BufferedInputStream(new FileInputStream(tempFile))) {
171160
contentPackage.addFile(contentPath, is);

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import io.wcm.devops.conga.generator.GeneratorException;
3636
import io.wcm.devops.conga.generator.plugins.postprocessor.AbstractPostProcessor;
3737
import io.wcm.devops.conga.generator.spi.context.FileContext;
38-
import io.wcm.devops.conga.generator.spi.context.FileHeaderContext;
3938
import io.wcm.devops.conga.generator.spi.context.PostProcessorContext;
4039
import io.wcm.devops.conga.generator.util.FileUtil;
4140
import io.wcm.devops.conga.plugins.aem.util.ContentPackageBinaryFile;
@@ -77,16 +76,13 @@ public List<FileContext> apply(FileContext fileContext, PostProcessorContext con
7776
Map<String, Object> options = context.getOptions();
7877

7978
try {
80-
// extract file header
81-
FileHeaderContext fileHeader = extractFileHeader(fileContext, context);
82-
8379
// create AEM content package with configurations
8480
File zipFile = new File(file.getParentFile(), FilenameUtils.getBaseName(file.getName()) + ".zip");
8581
logger.info("Generate {}", zipFile.getCanonicalPath());
8682

8783
String rootPath = ContentPackageUtil.getMandatoryProp(options, PROPERTY_PACKAGE_ROOT_PATH);
8884

89-
ContentPackageBuilder builder = ContentPackageUtil.getContentPackageBuilder(options, context.getUrlFileManager(), fileHeader);
85+
ContentPackageBuilder builder = ContentPackageUtil.getContentPackageBuilder(options, context.getUrlFileManager());
9086
try (ContentPackage contentPackage = builder.build(zipFile)) {
9187

9288
// add content from JSON file

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

Lines changed: 8 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.nio.file.Path;
4242
import java.nio.file.Paths;
4343
import java.util.ArrayList;
44+
import java.util.Date;
4445
import java.util.List;
4546
import java.util.Map;
4647
import java.util.Objects;
@@ -54,7 +55,6 @@
5455

5556
import io.wcm.devops.conga.generator.GeneratorException;
5657
import io.wcm.devops.conga.generator.UrlFileManager;
57-
import io.wcm.devops.conga.generator.spi.context.FileHeaderContext;
5858
import io.wcm.devops.conga.model.util.MapExpander;
5959
import io.wcm.devops.conga.plugins.aem.postprocessor.ContentPackageOsgiConfigPostProcessor;
6060
import io.wcm.devops.conga.plugins.aem.postprocessor.ContentPackagePostProcessor;
@@ -70,6 +70,11 @@ public final class ContentPackageUtil {
7070

7171
private static final String THUMBNAIL_IMAGE_DEFAULT = "/default-package-thumbnail.png";
7272

73+
/*
74+
* Use a single date for all content packages build in a single run.
75+
*/
76+
private static final Date CURRENT_DATE = new Date();
77+
7378
private ContentPackageUtil() {
7479
// constants only
7580
}
@@ -81,19 +86,8 @@ private ContentPackageUtil() {
8186
* @return Content package builder
8287
*/
8388
public static ContentPackageBuilder getContentPackageBuilder(Map<String, Object> options, UrlFileManager urlFileManager) {
84-
return getContentPackageBuilder(options, urlFileManager, null);
85-
}
86-
87-
/**
88-
* Builds content package builder populated with options from options map.
89-
* @param options Options
90-
* @param urlFileManager URL file manager
91-
* @param fileHeader File header
92-
* @return Content package builder
93-
*/
94-
public static ContentPackageBuilder getContentPackageBuilder(Map<String, Object> options, UrlFileManager urlFileManager,
95-
FileHeaderContext fileHeader) {
9689
ContentPackageBuilder builder = new ContentPackageBuilder()
90+
.created(CURRENT_DATE)
9791
.group(getMandatoryProp(options, PROPERTY_PACKAGE_GROUP))
9892
.name(getMandatoryProp(options, PROPERTY_PACKAGE_NAME))
9993
.version(getOptionalProp(options, PROPERTY_PACKAGE_VERSION))
@@ -103,12 +97,7 @@ public static ContentPackageBuilder getContentPackageBuilder(Map<String, Object>
10397
.allowIndexDefinitions(getOptionalPropBoolean(options, PROPERTY_PACKAGE_ALLOW_INDEX_DEFINITIONS));
10498

10599
// description
106-
if (fileHeader != null) {
107-
builder.description(mergeDescriptionFileHeader(getOptionalProp(options, PROPERTY_PACKAGE_DESCRIPTION), fileHeader));
108-
}
109-
else {
110-
builder.description(getOptionalProp(options, PROPERTY_PACKAGE_DESCRIPTION));
111-
}
100+
builder.description(getOptionalProp(options, PROPERTY_PACKAGE_DESCRIPTION));
112101

113102
// AC handling
114103
AcHandling acHandling = getAcHandling(options);
@@ -144,42 +133,6 @@ public static ContentPackageBuilder getContentPackageBuilder(Map<String, Object>
144133
return builder;
145134
}
146135

147-
/**
148-
* Merges description and file header to a single string.
149-
* @param description Description from configuration - may be null
150-
* @param fileHeader File header from file - may be null
151-
* @return Merged description or null if all input is null
152-
*/
153-
private static String mergeDescriptionFileHeader(String description, FileHeaderContext fileHeader) {
154-
boolean hasDescription = StringUtils.isNotBlank(description);
155-
boolean hasFileHeader = fileHeader != null && !fileHeader.getCommentLines().isEmpty();
156-
157-
if (!hasDescription && !hasFileHeader) {
158-
return null;
159-
}
160-
161-
StringBuilder result = new StringBuilder();
162-
163-
if (hasDescription) {
164-
result.append(description);
165-
}
166-
167-
if (hasDescription && hasFileHeader) {
168-
result.append("\n---\n");
169-
}
170-
171-
if (hasFileHeader) {
172-
@SuppressWarnings("null")
173-
String fileHeaderString = StringUtils.trim(fileHeader.getCommentLines().stream()
174-
.filter(line -> !StringUtils.contains(line, "*****"))
175-
.map(StringUtils::trim)
176-
.collect(Collectors.joining("\n")));
177-
result.append(fileHeaderString);
178-
}
179-
180-
return result.toString();
181-
}
182-
183136
/**
184137
* Get filter definitions either from contentPackageRootPath or from contentPackageFilters property.
185138
* @param options Options

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void testPostProcess_Provisioning() throws Exception {
8181
File contentPackageFile = new File(target, "test.txt");
8282
FileUtils.copyFile(new File(getClass().getResource("/provisioning/provisioning.txt").toURI()), contentPackageFile);
8383

84-
postProcess_assertResult(target, contentPackageFile, "myDesc\n---\nSample comment in provisioning.txt");
84+
postProcess_assertResult(target, contentPackageFile, "myDesc");
8585
}
8686

8787
@Test

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ void testPostProcess() throws Exception {
147147
Document propertiesXml = getXmlFromZip(zipFile, "META-INF/vault/properties.xml");
148148
assertXpathEvaluatesTo("ignore", "/properties/entry[@key='acHandling']", propertiesXml);
149149
assertXpathEvaluatesTo("content", "/properties/entry[@key='packageType']", propertiesXml);
150-
assertXpathEvaluatesTo("Sample comment in content.json", "/properties/entry[@key='description']", propertiesXml);
150+
assertXpathEvaluatesTo("", "/properties/entry[@key='description']", propertiesXml);
151151
assertXpathEvaluatesTo("value1", "/properties/entry[@key='prop1']", propertiesXml);
152152
assertXpathEvaluatesTo("123", "/properties/entry[@key='my.custom.prop2']", propertiesXml);
153153

0 commit comments

Comments
 (0)