Skip to content

Commit 2b4da23

Browse files
committed
conga-aem-maven-plugin:cloudmanager-all-package: Also process package names and dependencies in embedded sub packages.
1 parent a9cde6f commit 2b4da23

3 files changed

Lines changed: 106 additions & 18 deletions

File tree

changes.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
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="1.14.6" date="not released">
27+
<action type="fix" dev="sseifert">
28+
conga-aem-maven-plugin:cloudmanager-all-package: Also process package names and dependencies in embedded sub packages.
29+
</action>
30+
</release>
31+
2632
<release version="1.14.4" date="2021-06-08">
2733
<action type="update" dev="sseifert">
2834
Update to latest AEM Content Package Builder.

tooling/conga-aem-maven-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/maven/allpackage/AllPackageBuilder.java

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import static org.apache.jackrabbit.vault.packaging.PackageProperties.NAME_NAME;
2727

2828
import java.io.File;
29+
import java.io.FileInputStream;
2930
import java.io.FileOutputStream;
3031
import java.io.IOException;
3132
import java.io.InputStream;
@@ -231,7 +232,15 @@ public boolean build(Map<String, String> properties) throws IOException {
231232
}
232233

233234
// set package name, wire previous package in package dependency
234-
addFileWithDependency(contentPackage, path, pkg, previousPkg, environmentRunMode, allPackagesFromFileSets);
235+
File tempPackageFile = processContentPackage(pkg.getFile(), pkg, previousPkg, environmentRunMode, allPackagesFromFileSets);
236+
237+
// add temp zip file to "all" content package
238+
try {
239+
contentPackage.addFile(path, tempPackageFile);
240+
}
241+
finally {
242+
FileUtils.deleteQuietly(tempPackageFile);
243+
}
235244

236245
previousPackages.add(pkg);
237246
}
@@ -316,24 +325,24 @@ private static String buildPackagePath(ContentPackageFile pkg, String rootPath,
316325
/**
317326
* Rewrite content package ZIP file while adding to "all" package:
318327
* Add dependency to previous package in CONGA configuration file oder.
319-
* @param contentPackage Target content page
320-
* @param path Path in target content package
321-
* @param pkg Package to add
328+
* @param contentPackageFile The actual content package file to process
329+
* @param pkg Package to process (can be parent packe of the actual file)
322330
* @param previousPkg Previous package to get dependency information from.
323331
* Is null if no previous package exists or auto dependency mode is switched off.
324332
* @param environmentRunMode Environment run mode
325333
* @param allPackagesFromFileSets Set with all packages from all file sets as dependency instances
334+
* @return Returns a *temporary* file - has to be deleted when processing the result is completed.
326335
* @throws IOException I/O error
327336
*/
328-
private void addFileWithDependency(ContentPackage contentPackage, String path,
329-
ContentPackageFile pkg, ContentPackageFile previousPkg, String environmentRunMode,
337+
private File processContentPackage(File contentPackageFile, ContentPackageFile pkg,
338+
ContentPackageFile previousPkg, String environmentRunMode,
330339
Set<Dependency> allPackagesFromFileSets) throws IOException {
331340

332341
// create temp zip file to create rewritten copy of package
333342
File tempFile = File.createTempFile("pkg", ".zip");
334343

335344
// open original content package
336-
try (ZipFile zipFileIn = new ZipFile(pkg.getFile())) {
345+
try (ZipFile zipFileIn = new ZipFile(contentPackageFile)) {
337346
String dependenciesString = null;
338347

339348
// iterate through entries and write them to the temp. zip file
@@ -345,9 +354,10 @@ private void addFileWithDependency(ContentPackage contentPackage, String path,
345354
ZipEntry zipOutEntry = new ZipEntry(zipInEntry.getName());
346355
if (!zipInEntry.isDirectory()) {
347356
zipOut.putNextEntry(zipOutEntry);
348-
if (StringUtils.equals(zipInEntry.getName(), "META-INF/vault/properties.xml")) {
357+
try (InputStream is = zipFileIn.getInputStream(zipInEntry)) {
358+
349359
// if entry is properties.xml, update dependency information
350-
try (InputStream is = zipFileIn.getInputStream(zipInEntry)) {
360+
if (StringUtils.equals(zipInEntry.getName(), "META-INF/vault/properties.xml")) {
351361
Properties props = new Properties();
352362
props.loadFromXML(is);
353363
addSuffixToPackageName(props, pkg, environmentRunMode);
@@ -356,28 +366,39 @@ private void addFileWithDependency(ContentPackage contentPackage, String path,
356366
}
357367
props.storeToXML(zipOut, null);
358368
}
359-
}
360-
else {
369+
370+
// process sub-packages as well: add runmode suffix and update dependencies
371+
else if (StringUtils.equals(FilenameUtils.getExtension(zipInEntry.getName()), "zip")) {
372+
File tempSubPackageFile = File.createTempFile("subpkg", ".zip");
373+
try (FileOutputStream subPackageFos = new FileOutputStream(tempSubPackageFile)) {
374+
IOUtils.copy(is, subPackageFos);
375+
}
376+
File resultSubPackageFile = processContentPackage(tempSubPackageFile, pkg, previousPkg, environmentRunMode, allPackagesFromFileSets);
377+
try (FileInputStream subPackageFis = new FileInputStream(resultSubPackageFile)) {
378+
IOUtils.copy(subPackageFis, zipOut);
379+
}
380+
finally {
381+
FileUtils.deleteQuietly(resultSubPackageFile);
382+
}
383+
}
384+
361385
// otherwise transfer the binary data 1:1
362-
try (InputStream is = zipFileIn.getInputStream(zipInEntry)) {
386+
else {
363387
IOUtils.copy(is, zipOut);
364388
}
365389
}
390+
366391
zipOut.closeEntry();
367392
}
368393
}
369394

370395
if (log.isDebugEnabled()) {
371-
log.debug("Adding package " + getCanonicalPath(pkg.getFile())
396+
log.debug("Processed " + getCanonicalPath(contentPackageFile)
372397
+ (dependenciesString != null ? " with dependencies: " + dependenciesString : ""));
373398
}
374399
}
375400

376-
// add temp zip file to "all" content package
377-
contentPackage.addFile(path, tempFile);
378-
}
379-
finally {
380-
FileUtils.deleteQuietly(tempFile);
401+
return tempFile;
381402
}
382403
}
383404

tooling/conga-aem-maven-plugin/src/test/java/io/wcm/devops/conga/plugins/aem/maven/allpackage/AllPackageBuilderTest.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,21 @@
2020
package io.wcm.devops.conga.plugins.aem.maven.allpackage;
2121

2222
import static io.wcm.devops.conga.plugins.aem.maven.allpackage.ContentPackageTestUtil.assertXpathEvaluatesTo;
23+
import static io.wcm.devops.conga.plugins.aem.maven.allpackage.ContentPackageTestUtil.getDataFromZip;
2324
import static io.wcm.devops.conga.plugins.aem.maven.allpackage.ContentPackageTestUtil.getXmlFromZip;
2425
import static org.junit.jupiter.api.Assertions.assertEquals;
2526
import static org.junit.jupiter.api.Assertions.assertTrue;
2627

28+
import java.io.ByteArrayInputStream;
2729
import java.io.File;
30+
import java.io.FileOutputStream;
2831
import java.io.IOException;
2932
import java.util.List;
3033
import java.util.Set;
3134
import java.util.stream.Stream;
3235

3336
import org.apache.commons.io.FileUtils;
37+
import org.apache.commons.io.IOUtils;
3438
import org.apache.commons.lang3.StringUtils;
3539
import org.junit.jupiter.api.BeforeEach;
3640
import org.junit.jupiter.api.TestInfo;
@@ -131,6 +135,11 @@ void testBuild(Set<String> cloudManagerTarget, List<String> runmodeSuffixes) thr
131135
assertFiles(containerInstallDir, "accesscontroltool-package" + runmodeSuffix + "-3.0.0.zip",
132136
"wcm-io-samples-aem-cms-config" + runmodeSuffix + ".zip",
133137
"wcm-io-samples-complete" + runmodeSuffix + "-1.3.1-SNAPSHOT.zip");
138+
assertNameDependencies(containerInstallDir, "accesscontroltool-package" + runmodeSuffix + "-3.0.0.zip",
139+
"accesscontroltool-package" + runmodeSuffix);
140+
assertNameDependenciesSubPackage(containerInstallDir, "accesscontroltool-package" + runmodeSuffix + "-3.0.0.zip",
141+
"jcr_root/apps/netcentric/actool/install/accesscontroltool-apps-package-3.0.0.zip",
142+
"accesscontroltool-apps-package" + runmodeSuffix);
134143
assertNameDependencies(containerInstallDir, "wcm-io-samples-aem-cms-config" + runmodeSuffix + ".zip",
135144
"wcm-io-samples-aem-cms-config" + runmodeSuffix);
136145
assertNameDependencies(containerInstallDir, "wcm-io-samples-complete" + runmodeSuffix + "-1.3.1-SNAPSHOT.zip",
@@ -205,6 +214,10 @@ void testBuild_IMMUTABLE_MUTABLE_COMBINED(Set<String> cloudManagerTarget, List<S
205214
assertNameDependencies(containerInstallDir, "accesscontroltool-package" + runmodeSuffix + "-3.0.0.zip",
206215
"accesscontroltool-package" + runmodeSuffix,
207216
"adobe/consulting:acs-aem-commons-ui.content" + runmodeSuffix + ":4.10.0");
217+
assertNameDependenciesSubPackage(containerInstallDir, "accesscontroltool-package" + runmodeSuffix + "-3.0.0.zip",
218+
"jcr_root/apps/netcentric/actool/install/accesscontroltool-apps-package-3.0.0.zip",
219+
"accesscontroltool-apps-package" + runmodeSuffix,
220+
"adobe/consulting:acs-aem-commons-ui.content" + runmodeSuffix + ":4.10.0");
208221
assertNameDependencies(containerInstallDir, "wcm-io-samples-aem-cms-config" + runmodeSuffix + ".zip",
209222
"wcm-io-samples-aem-cms-config" + runmodeSuffix,
210223
"wcm-io-samples:aem-cms-system-config" + runmodeSuffix + ":1.3.1-SNAPSHOT");
@@ -280,6 +293,10 @@ void testBuild_IMMUTABLE_MUTABLE_SEPARATE(Set<String> cloudManagerTarget, List<S
280293
assertNameDependencies(containerInstallDir, "accesscontroltool-package" + runmodeSuffix + "-3.0.0.zip",
281294
"accesscontroltool-package" + runmodeSuffix,
282295
"adobe/consulting:acs-aem-commons-ui.apps" + runmodeSuffix + ":4.10.0");
296+
assertNameDependenciesSubPackage(containerInstallDir, "accesscontroltool-package" + runmodeSuffix + "-3.0.0.zip",
297+
"jcr_root/apps/netcentric/actool/install/accesscontroltool-apps-package-3.0.0.zip",
298+
"accesscontroltool-apps-package" + runmodeSuffix,
299+
"adobe/consulting:acs-aem-commons-ui.apps" + runmodeSuffix + ":4.10.0");
283300
assertNameDependencies(containerInstallDir, "wcm-io-samples-aem-cms-config" + runmodeSuffix + ".zip",
284301
"wcm-io-samples-aem-cms-config" + runmodeSuffix,
285302
"wcm-io-samples:aem-cms-system-config" + runmodeSuffix + ":1.3.1-SNAPSHOT");
@@ -353,6 +370,10 @@ void testBuild_IMMUTABLE_ONLY(Set<String> cloudManagerTarget, List<String> runmo
353370
assertNameDependencies(containerInstallDir, "accesscontroltool-package" + runmodeSuffix + "-3.0.0.zip",
354371
"accesscontroltool-package" + runmodeSuffix,
355372
"adobe/consulting:acs-aem-commons-ui.apps" + runmodeSuffix + ":4.10.0");
373+
assertNameDependenciesSubPackage(containerInstallDir, "accesscontroltool-package" + runmodeSuffix + "-3.0.0.zip",
374+
"jcr_root/apps/netcentric/actool/install/accesscontroltool-apps-package-3.0.0.zip",
375+
"accesscontroltool-apps-package" + runmodeSuffix,
376+
"adobe/consulting:acs-aem-commons-ui.apps" + runmodeSuffix + ":4.10.0");
356377
assertNameDependencies(containerInstallDir, "wcm-io-samples-aem-cms-config" + runmodeSuffix + ".zip",
357378
"wcm-io-samples-aem-cms-config" + runmodeSuffix,
358379
"wcm-io-samples:aem-cms-system-config" + runmodeSuffix + ":1.3.1-SNAPSHOT");
@@ -362,6 +383,11 @@ void testBuild_IMMUTABLE_ONLY(Set<String> cloudManagerTarget, List<String> runmo
362383
}
363384
}
364385

386+
/**
387+
* Assert existence of given files.
388+
* @param dir Directory
389+
* @param fileNames Expected file names in directory
390+
*/
365391
private void assertFiles(File dir, String... fileNames) {
366392
assertTrue(dir.exists(), "file exists: " + dir.getPath());
367393
assertTrue(dir.isDirectory(), "is directory: " + dir.getPath());
@@ -371,6 +397,14 @@ private void assertFiles(File dir, String... fileNames) {
371397
assertEquals(expectedFileNames, actualFileNames, "files in " + dir.getPath());
372398
}
373399

400+
/**
401+
* Assert content package name and list of package dependencies.
402+
* @param dir Directory
403+
* @param fileName Content package file name
404+
* @param packageName Expected content package name
405+
* @param dependencies Expected dependencies
406+
* @throws Exception Exception
407+
*/
374408
private void assertNameDependencies(File dir, String fileName, String packageName,
375409
String... dependencies) throws Exception {
376410
File zipFile = new File(dir, fileName);
@@ -385,6 +419,33 @@ private void assertNameDependencies(File dir, String fileName, String packageNam
385419
assertXpathEvaluatesTo(expecedDependencies, "/properties/entry[@key='dependencies']", filterXml);
386420
}
387421

422+
/**
423+
* Assert content package name and list of package dependencies.
424+
* @param dir Directory
425+
* @param fileName Content package file name
426+
* @param subPackageFileName Path and file name of sub package inside main package.
427+
* @param packageName Expected content package name
428+
* @param dependencies Expected dependencies
429+
* @throws Exception Exception
430+
*/
431+
private void assertNameDependenciesSubPackage(File dir, String fileName, String subPackageFileName,
432+
String packageName, String... dependencies) throws Exception {
433+
File zipFile = new File(dir, fileName);
434+
byte[] subPackageData = getDataFromZip(zipFile, subPackageFileName);
435+
File tempPackageFile = File.createTempFile("testpkg", ".zip");
436+
try (ByteArrayInputStream is = new ByteArrayInputStream(subPackageData);
437+
FileOutputStream fos = new FileOutputStream(tempPackageFile)) {
438+
IOUtils.copy(is, fos);
439+
}
440+
try {
441+
assertNameDependencies(tempPackageFile.getParentFile(), tempPackageFile.getName(),
442+
packageName, dependencies);
443+
}
444+
finally {
445+
FileUtils.deleteQuietly(tempPackageFile);
446+
}
447+
}
448+
388449
private String[] toInstallFolderNames(String baseName, List<String> runmodeSuffixes) {
389450
return runmodeSuffixes.stream()
390451
.map(suffix -> baseName + suffix)

0 commit comments

Comments
 (0)