Skip to content

Commit 505922e

Browse files
committed
conga-aem-maven-plugin:cloudmanager-all-package: Fix auto dependency generation for package that already contain dependencies.
1 parent af86fde commit 505922e

7 files changed

Lines changed: 132 additions & 39 deletions

File tree

changes.xml

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

2626
<release version="1.14.0" date="not released">
2727
<action type="add" dev="sseifert">
28-
conga-aem-maven-plugin: Add "singlePackage" flag for "cloudmanager-all-package" goal to alternatively build single "all" content package for all environments and nodes.
28+
conga-aem-maven-plugin:cloudmanager-all-package: Add "singlePackage" flag to alternatively build single "all" content package for all environments and nodes.
29+
</action>
30+
<action type="add" dev="sseifert">
31+
conga-aem-maven-plugin:cloudmanager-all-package: Fix auto dependency generation for package that already contain dependencies.
2932
</action>
3033
</release>
3134

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

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
import java.io.IOException;
3131
import java.io.InputStream;
3232
import java.util.ArrayList;
33+
import java.util.Arrays;
3334
import java.util.Enumeration;
35+
import java.util.HashSet;
3436
import java.util.List;
3537
import java.util.Map;
3638
import java.util.Properties;
@@ -182,6 +184,14 @@ public boolean build(Map<String, String> properties) throws IOException {
182184
properties.entrySet().forEach(entry -> builder.property(entry.getKey(), entry.getValue()));
183185
}
184186

187+
// build set with dependencies instances for each package contained in all filesets
188+
Set<Dependency> allPackagesFromFileSets = new HashSet<>();
189+
for (ContentPackageFileSet fileSet : fileSets) {
190+
for (ContentPackageFile pkg : fileSet.getContentPackages()) {
191+
allPackagesFromFileSets.add(new Dependency(pkg.getGroup(), pkg.getName(), VersionRange.fromString(pkg.getVersion())));
192+
}
193+
}
194+
185195
// build content package
186196
// if auto dependencies is active: build separate "dependency chains" between mutable and immutable packages
187197
try (ContentPackage contentPackage = builder.build(targetFile)) {
@@ -204,7 +214,7 @@ public boolean build(Map<String, String> properties) throws IOException {
204214
}
205215

206216
// set package name, wire previous package in package dependency
207-
addFileWithDependency(contentPackage, path, pkg, previousPkg, environmentRunMode);
217+
addFileWithDependency(contentPackage, path, pkg, previousPkg, environmentRunMode, allPackagesFromFileSets);
208218

209219
previousPackages.add(pkg);
210220
}
@@ -292,12 +302,15 @@ private static String buildPackagePath(ContentPackageFile pkg, String rootPath,
292302
* @param contentPackage Target content page
293303
* @param path Path in target content package
294304
* @param pkg Package to add
295-
* @param previousPkg Previous package to get dependency information from
305+
* @param previousPkg Previous package to get dependency information from.
306+
* Is null if no previous package exists or auto dependency mode is switched off.
296307
* @param environmentRunMode Environment run mode
308+
* @param allPackagesFromFileSets Set with all packages from all file sets as dependency instances
297309
* @throws IOException I/O error
298310
*/
299-
private static void addFileWithDependency(ContentPackage contentPackage, String path,
300-
ContentPackageFile pkg, ContentPackageFile previousPkg, String environmentRunMode) throws IOException {
311+
private void addFileWithDependency(ContentPackage contentPackage, String path,
312+
ContentPackageFile pkg, ContentPackageFile previousPkg, String environmentRunMode,
313+
Set<Dependency> allPackagesFromFileSets) throws IOException {
301314

302315
// create temp zip file to create rewritten copy of package
303316
File tempFile = File.createTempFile("pkg", ".zip");
@@ -320,8 +333,8 @@ private static void addFileWithDependency(ContentPackage contentPackage, String
320333
Properties props = new Properties();
321334
props.loadFromXML(is);
322335
addSuffixToPackageName(props, pkg, environmentRunMode);
323-
if (previousPkg != null) {
324-
updateDependencies(props, previousPkg, environmentRunMode);
336+
if (autoDependenciesMode != AutoDependenciesMode.OFF) {
337+
updateDependencies(props, previousPkg, environmentRunMode, allPackagesFromFileSets);
325338
}
326339
props.storeToXML(zipOut, null);
327340
}
@@ -349,27 +362,39 @@ private static void addFileWithDependency(ContentPackage contentPackage, String
349362
* Add dependency information to dependencies string in properties (if it does not exist already).
350363
* @param props Properties
351364
* @param dependencyFile Dependency package
365+
* @param allPackagesFromFileSets Set with all packages from all file sets as dependency instances
352366
*/
353-
private static void updateDependencies(Properties props, ContentPackageFile dependencyFile, String environmentRunMode) {
367+
private static void updateDependencies(Properties props, ContentPackageFile dependencyFile, String environmentRunMode,
368+
Set<Dependency> allPackagesFromFileSets) {
354369
String[] existingDepsStrings = StringUtils.split(props.getProperty(NAME_DEPENDENCIES), ",");
355370
Dependency[] existingDeps = null;
356371
if (existingDepsStrings != null && existingDepsStrings.length > 0) {
357372
existingDeps = Dependency.fromString(existingDepsStrings);
358373
}
374+
if (existingDeps != null) {
375+
existingDeps = removeReferencesToManagedPackages(existingDeps, allPackagesFromFileSets);
376+
}
359377

360-
String runModeSuffix = buildRunModeSuffix(dependencyFile, environmentRunMode);
361-
Dependency newDependency = new Dependency(dependencyFile.getGroup(),
362-
dependencyFile.getName() + runModeSuffix,
363-
VersionRange.fromString(dependencyFile.getVersion()));
364378
Dependency[] deps;
365-
if (existingDeps != null) {
366-
deps = DependencyUtil.add(existingDeps, newDependency);
379+
if (dependencyFile != null) {
380+
String runModeSuffix = buildRunModeSuffix(dependencyFile, environmentRunMode);
381+
Dependency newDependency = new Dependency(dependencyFile.getGroup(),
382+
dependencyFile.getName() + runModeSuffix,
383+
VersionRange.fromString(dependencyFile.getVersion()));
384+
if (existingDeps != null) {
385+
deps = DependencyUtil.add(existingDeps, newDependency);
386+
}
387+
else {
388+
deps = new Dependency[] { newDependency };
389+
}
367390
}
368391
else {
369-
deps = new Dependency[] { newDependency };
392+
deps = existingDeps;
370393
}
371394

372-
props.put(NAME_DEPENDENCIES, Dependency.toString(deps));
395+
if (deps != null) {
396+
props.put(NAME_DEPENDENCIES, Dependency.toString(deps));
397+
}
373398
}
374399

375400
private static void addSuffixToPackageName(Properties props, ContentPackageFile pkg, String environmentRunMode) {
@@ -378,6 +403,19 @@ private static void addSuffixToPackageName(Properties props, ContentPackageFile
378403
props.put(NAME_NAME, packageName);
379404
}
380405

406+
/**
407+
* Removes existing references to packages contained in the list of packages to manage by this builder because
408+
* they are added new (and probably with a different package name) during processing.
409+
* @param deps Dependencies list
410+
* @param allPackagesFromFileSets Set with all packages from all file sets as dependency instances
411+
* @return Dependencies list
412+
*/
413+
private static Dependency[] removeReferencesToManagedPackages(Dependency[] deps, Set<Dependency> allPackagesFromFileSets) {
414+
return Arrays.stream(deps)
415+
.filter(dep -> !allPackagesFromFileSets.contains(dep))
416+
.toArray(size -> new Dependency[size]);
417+
}
418+
381419
public File getTargetFile() {
382420
return this.targetFile;
383421
}

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

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@ void testBuild(Set<String> cloudManagerTarget, List<String> runmodeSuffixes) thr
9494

9595
for (String runmodeSuffix : runmodeSuffixes) {
9696
File applicationInstallDir = new File(applicationDir, "install" + runmodeSuffix);
97-
assertFiles(applicationInstallDir, "aem-cms-system-config" + runmodeSuffix + ".zip");
97+
assertFiles(applicationInstallDir, "acs-aem-commons-ui.apps" + runmodeSuffix + "-4.10.0.zip",
98+
"aem-cms-system-config" + runmodeSuffix + ".zip");
99+
assertNameDependencies(applicationInstallDir, "acs-aem-commons-ui.apps" + runmodeSuffix + "-4.10.0.zip",
100+
"acs-aem-commons-ui.apps" + runmodeSuffix,
101+
"day/cq60/product:cq-content:6.3.64");
98102
assertNameDependencies(applicationInstallDir, "aem-cms-system-config" + runmodeSuffix + ".zip",
99103
"aem-cms-system-config" + runmodeSuffix,
100104
"day/cq60/product:cq-ui-wcm-editor-content:1.1.224",
@@ -106,8 +110,12 @@ void testBuild(Set<String> cloudManagerTarget, List<String> runmodeSuffixes) thr
106110

107111
for (String runmodeSuffix : runmodeSuffixes) {
108112
File contentInstallDir = new File(contentDir, "install" + runmodeSuffix);
109-
assertFiles(contentInstallDir, "aem-cms-author-replicationagents" + runmodeSuffix + ".zip",
113+
assertFiles(contentInstallDir, "acs-aem-commons-ui.content" + runmodeSuffix + "-4.10.0.zip",
114+
"aem-cms-author-replicationagents" + runmodeSuffix + ".zip",
110115
"wcm-io-samples-sample-content" + runmodeSuffix + "-1.3.1-SNAPSHOT.zip");
116+
assertNameDependencies(contentInstallDir, "acs-aem-commons-ui.content" + runmodeSuffix + "-4.10.0.zip",
117+
"acs-aem-commons-ui.content" + runmodeSuffix,
118+
"adobe/consulting:acs-aem-commons-ui.apps:4.10.0");
111119
assertNameDependencies(contentInstallDir, "aem-cms-author-replicationagents" + runmodeSuffix + ".zip",
112120
"aem-cms-author-replicationagents" + runmodeSuffix);
113121
assertNameDependencies(contentInstallDir, "wcm-io-samples-sample-content" + runmodeSuffix + "-1.3.1-SNAPSHOT.zip",
@@ -130,7 +138,7 @@ void testBuild(Set<String> cloudManagerTarget, List<String> runmodeSuffixes) thr
130138

131139
@ParameterizedTest
132140
@MethodSource("cloudManagerTargetVariants")
133-
void testBuil_IMMUTABLE_MUTABLE_COMBINED(Set<String> cloudManagerTarget, List<String> runmodeSuffixes) throws Exception {
141+
void testBuild_IMMUTABLE_MUTABLE_COMBINED(Set<String> cloudManagerTarget, List<String> runmodeSuffixes) throws Exception {
134142
List<ContentPackageFile> contentPackages = new ModelParser().getContentPackagesForNode(nodeDir);
135143
File targetFile = new File(targetDir, "all.zip");
136144

@@ -149,7 +157,11 @@ void testBuil_IMMUTABLE_MUTABLE_COMBINED(Set<String> cloudManagerTarget, List<St
149157

150158
for (String runmodeSuffix : runmodeSuffixes) {
151159
File applicationInstallDir = new File(applicationDir, "install" + runmodeSuffix);
152-
assertFiles(applicationInstallDir, "aem-cms-system-config" + runmodeSuffix + ".zip");
160+
assertFiles(applicationInstallDir, "acs-aem-commons-ui.apps" + runmodeSuffix + "-4.10.0.zip",
161+
"aem-cms-system-config" + runmodeSuffix + ".zip");
162+
assertNameDependencies(applicationInstallDir, "acs-aem-commons-ui.apps" + runmodeSuffix + "-4.10.0.zip",
163+
"acs-aem-commons-ui.apps" + runmodeSuffix,
164+
"day/cq60/product:cq-content:6.3.64");
153165
assertNameDependencies(applicationInstallDir, "aem-cms-system-config" + runmodeSuffix + ".zip",
154166
"aem-cms-system-config" + runmodeSuffix,
155167
"day/cq60/product:cq-ui-wcm-editor-content:1.1.224",
@@ -162,10 +174,15 @@ void testBuil_IMMUTABLE_MUTABLE_COMBINED(Set<String> cloudManagerTarget, List<St
162174

163175
for (String runmodeSuffix : runmodeSuffixes) {
164176
File contentInstallDir = new File(contentDir, "install" + runmodeSuffix);
165-
assertFiles(contentInstallDir, "aem-cms-author-replicationagents" + runmodeSuffix + ".zip",
177+
assertFiles(contentInstallDir, "acs-aem-commons-ui.content" + runmodeSuffix + "-4.10.0.zip",
178+
"aem-cms-author-replicationagents" + runmodeSuffix + ".zip",
166179
"wcm-io-samples-sample-content" + runmodeSuffix + "-1.3.1-SNAPSHOT.zip");
180+
assertNameDependencies(contentInstallDir, "acs-aem-commons-ui.content" + runmodeSuffix + "-4.10.0.zip",
181+
"acs-aem-commons-ui.content" + runmodeSuffix,
182+
"adobe/consulting:acs-aem-commons-ui.apps" + runmodeSuffix + ":4.10.0");
167183
assertNameDependencies(contentInstallDir, "aem-cms-author-replicationagents" + runmodeSuffix + ".zip",
168-
"aem-cms-author-replicationagents" + runmodeSuffix);
184+
"aem-cms-author-replicationagents" + runmodeSuffix,
185+
"adobe/consulting:acs-aem-commons-ui.content" + runmodeSuffix + ":4.10.0");
169186
assertNameDependencies(contentInstallDir, "wcm-io-samples-sample-content" + runmodeSuffix + "-1.3.1-SNAPSHOT.zip",
170187
"wcm-io-samples-sample-content" + runmodeSuffix,
171188
"wcm-io-samples:wcm-io-samples-complete" + runmodeSuffix + ":1.3.1-SNAPSHOT");
@@ -208,22 +225,31 @@ void testBuild_IMMUTABLE_MUTABLE_SEPARATE(Set<String> cloudManagerTarget, List<S
208225

209226
for (String runmodeSuffix : runmodeSuffixes) {
210227
File applicationInstallDir = new File(applicationDir, "install" + runmodeSuffix);
211-
assertFiles(applicationInstallDir, "aem-cms-system-config" + runmodeSuffix + ".zip");
228+
assertFiles(applicationInstallDir, "acs-aem-commons-ui.apps" + runmodeSuffix + "-4.10.0.zip",
229+
"aem-cms-system-config" + runmodeSuffix + ".zip");
230+
assertNameDependencies(applicationInstallDir, "acs-aem-commons-ui.apps" + runmodeSuffix + "-4.10.0.zip",
231+
"acs-aem-commons-ui.apps" + runmodeSuffix,
232+
"day/cq60/product:cq-content:6.3.64");
212233
assertNameDependencies(applicationInstallDir, "aem-cms-system-config" + runmodeSuffix + ".zip",
213234
"aem-cms-system-config" + runmodeSuffix,
214235
"day/cq60/product:cq-ui-wcm-editor-content:1.1.224",
215-
"adobe/cq/product:cq-remotedam-client-ui-components:1.1.6");
236+
"adobe/cq/product:cq-remotedam-client-ui-components:1.1.6",
237+
"adobe/consulting:acs-aem-commons-ui.apps" + runmodeSuffix + ":4.10.0");
216238
}
217239

218240
File contentDir = new File(appsDir, "content");
219241
assertFiles(contentDir, toInstallFolderNames("install", runmodeSuffixes));
220242

221243
for (String runmodeSuffix : runmodeSuffixes) {
222244
File contentInstallDir = new File(contentDir, "install" + runmodeSuffix);
223-
assertFiles(contentInstallDir, "aem-cms-author-replicationagents" + runmodeSuffix + ".zip",
245+
assertFiles(contentInstallDir, "acs-aem-commons-ui.content" + runmodeSuffix + "-4.10.0.zip",
246+
"aem-cms-author-replicationagents" + runmodeSuffix + ".zip",
224247
"wcm-io-samples-sample-content" + runmodeSuffix + "-1.3.1-SNAPSHOT.zip");
248+
assertNameDependencies(contentInstallDir, "acs-aem-commons-ui.content" + runmodeSuffix + "-4.10.0.zip",
249+
"acs-aem-commons-ui.content" + runmodeSuffix);
225250
assertNameDependencies(contentInstallDir, "aem-cms-author-replicationagents" + runmodeSuffix + ".zip",
226-
"aem-cms-author-replicationagents" + runmodeSuffix);
251+
"aem-cms-author-replicationagents" + runmodeSuffix,
252+
"adobe/consulting:acs-aem-commons-ui.content" + runmodeSuffix + ":4.10.0");
227253
assertNameDependencies(contentInstallDir, "wcm-io-samples-sample-content" + runmodeSuffix + "-1.3.1-SNAPSHOT.zip",
228254
"wcm-io-samples-sample-content" + runmodeSuffix,
229255
"wcm-io-samples:aem-cms-author-replicationagents" + runmodeSuffix + ":1.3.1-SNAPSHOT");
@@ -266,20 +292,28 @@ void testBuild_IMMUTABLE_ONLY(Set<String> cloudManagerTarget, List<String> runmo
266292

267293
for (String runmodeSuffix : runmodeSuffixes) {
268294
File applicationInstallDir = new File(applicationDir, "install" + runmodeSuffix);
269-
assertFiles(applicationInstallDir, "aem-cms-system-config" + runmodeSuffix + ".zip");
295+
assertFiles(applicationInstallDir, "acs-aem-commons-ui.apps" + runmodeSuffix + "-4.10.0.zip",
296+
"aem-cms-system-config" + runmodeSuffix + ".zip");
297+
assertNameDependencies(applicationInstallDir, "acs-aem-commons-ui.apps" + runmodeSuffix + "-4.10.0.zip",
298+
"acs-aem-commons-ui.apps" + runmodeSuffix,
299+
"day/cq60/product:cq-content:6.3.64");
270300
assertNameDependencies(applicationInstallDir, "aem-cms-system-config" + runmodeSuffix + ".zip",
271301
"aem-cms-system-config" + runmodeSuffix,
272302
"day/cq60/product:cq-ui-wcm-editor-content:1.1.224",
273-
"adobe/cq/product:cq-remotedam-client-ui-components:1.1.6");
303+
"adobe/cq/product:cq-remotedam-client-ui-components:1.1.6",
304+
"adobe/consulting:acs-aem-commons-ui.apps" + runmodeSuffix + ":4.10.0");
274305
}
275306

276307
File contentDir = new File(appsDir, "content");
277308
assertFiles(contentDir, toInstallFolderNames("install", runmodeSuffixes));
278309

279310
for (String runmodeSuffix : runmodeSuffixes) {
280311
File contentInstallDir = new File(contentDir, "install" + runmodeSuffix);
281-
assertFiles(contentInstallDir, "aem-cms-author-replicationagents" + runmodeSuffix + ".zip",
312+
assertFiles(contentInstallDir, "acs-aem-commons-ui.content" + runmodeSuffix + "-4.10.0.zip",
313+
"aem-cms-author-replicationagents" + runmodeSuffix + ".zip",
282314
"wcm-io-samples-sample-content" + runmodeSuffix + "-1.3.1-SNAPSHOT.zip");
315+
assertNameDependencies(contentInstallDir, "acs-aem-commons-ui.content" + runmodeSuffix + "-4.10.0.zip",
316+
"acs-aem-commons-ui.content" + runmodeSuffix);
283317
assertNameDependencies(contentInstallDir, "aem-cms-author-replicationagents" + runmodeSuffix + ".zip",
284318
"aem-cms-author-replicationagents" + runmodeSuffix);
285319
assertNameDependencies(contentInstallDir, "wcm-io-samples-sample-content" + runmodeSuffix + "-1.3.1-SNAPSHOT.zip",

tooling/conga-aem-maven-plugin/src/test/java/io/wcm/devops/conga/plugins/aem/maven/model/ModelParserTest.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,18 @@ void setUp() {
5151
void testGetContentPackagesForNode() {
5252
List<ContentPackageFile> contentPackages = underTest.getContentPackagesForNode(nodeDir);
5353

54-
assertEquals(6, contentPackages.size());
55-
56-
assertPackage(contentPackages.get(0), "packages/aem-cms-author-replicationagents.zip", "content", true);
57-
assertPackage(contentPackages.get(1), "packages/aem-cms-system-config.zip", "application", true);
58-
assertPackage(contentPackages.get(2), "packages/wcm-io-samples-aem-cms-config.zip", "container", true);
59-
assertPackage(contentPackages.get(3), "packages/wcm-io-samples-aem-cms-author-systemusers.zip", null, true);
60-
assertPackage(contentPackages.get(4), "packages/wcm-io-samples-complete-1.3.1-SNAPSHOT.zip", "container", null);
61-
assertPackage(contentPackages.get(5), "packages/wcm-io-samples-sample-content-1.3.1-SNAPSHOT.zip", "content", null);
62-
63-
ContentPackageFile pkg1 = contentPackages.get(0);
54+
assertEquals(8, contentPackages.size());
55+
56+
assertPackage(contentPackages.get(0), "packages/acs-aem-commons-ui.apps-4.10.0-min.zip", "application", null);
57+
assertPackage(contentPackages.get(1), "packages/acs-aem-commons-ui.content-4.10.0-min.zip", "content", null);
58+
assertPackage(contentPackages.get(2), "packages/aem-cms-author-replicationagents.zip", "content", true);
59+
assertPackage(contentPackages.get(3), "packages/aem-cms-system-config.zip", "application", true);
60+
assertPackage(contentPackages.get(4), "packages/wcm-io-samples-aem-cms-config.zip", "container", true);
61+
assertPackage(contentPackages.get(5), "packages/wcm-io-samples-aem-cms-author-systemusers.zip", null, true);
62+
assertPackage(contentPackages.get(6), "packages/wcm-io-samples-complete-1.3.1-SNAPSHOT.zip", "container", null);
63+
assertPackage(contentPackages.get(7), "packages/wcm-io-samples-sample-content-1.3.1-SNAPSHOT.zip", "content", null);
64+
65+
ContentPackageFile pkg1 = contentPackages.get(2);
6466
assertEquals(ImmutableList.of("aem-author"), pkg1.getVariants());
6567
assertEquals(false, pkg1.getInstall());
6668
assertEquals(true, pkg1.getRecursive());

0 commit comments

Comments
 (0)