Skip to content

Commit 5a46804

Browse files
committed
add switch to use separate dependency chains for mutable and immutable packages
1 parent e8317e4 commit 5a46804

4 files changed

Lines changed: 85 additions & 4 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ public final class CloudManagerAllPackageMojo extends AbstractCloudManagerMojo {
5959
@Parameter(property = "conga.cloudManager.allPackage.autoDependencies", defaultValue = "true")
6060
private boolean autoDependencies;
6161

62+
/**
63+
* Use separate dependency chains for mutable and immutable packages.
64+
*/
65+
@Parameter(property = "conga.cloudManager.allPackage.autoDependenciesSeparateMutable", defaultValue = "false")
66+
private boolean autoDependenciesSeparateMutable;
67+
6268
/**
6369
* Set this to "true" to skip installing packages to CRX although configured in the POM.
6470
*/
@@ -88,6 +94,7 @@ private void buildAllPackage(File nodeDir, ModelParser modelParser) throws MojoF
8894

8995
AllPackageBuilder builder = new AllPackageBuilder(targetFile, groupName, packageName)
9096
.autoDependencies(this.autoDependencies)
97+
.autoDependenciesSeparateMutable(this.autoDependenciesSeparateMutable)
9198
.logger(getLog());
9299

93100
try {

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.io.FileOutputStream;
2929
import java.io.IOException;
3030
import java.io.InputStream;
31+
import java.util.ArrayList;
3132
import java.util.Enumeration;
3233
import java.util.List;
3334
import java.util.Properties;
@@ -59,6 +60,7 @@ public final class AllPackageBuilder {
5960
private final String groupName;
6061
private final String packageName;
6162
private boolean autoDependencies;
63+
private boolean autoDependenciesSeparateMutable;
6264
private Log log;
6365

6466
/**
@@ -82,6 +84,15 @@ public AllPackageBuilder autoDependencies(boolean value) {
8284
return this;
8385
}
8486

87+
/**
88+
* @param value Use separate dependency chains for mutable and immutable packages.
89+
* @return this
90+
*/
91+
public AllPackageBuilder autoDependenciesSeparateMutable(boolean value) {
92+
this.autoDependenciesSeparateMutable = value;
93+
return this;
94+
}
95+
8596
/**
8697
* @param value Maven logger
8798
* @return this
@@ -130,10 +141,19 @@ public boolean build(List<ContentPackageFile> contentPackages) throws IOExceptio
130141
builder.filter(new PackageFilter(rootPath));
131142

132143
// build content package
133-
ContentPackageFile previousPkg = null;
144+
// if auto dependencies is active: build separate "dependency chains" between mutable and immutable packages
145+
List<ContentPackageFile> previousPackages = new ArrayList<>();
134146
try (ContentPackage contentPackage = builder.build(targetFile)) {
135147
for (ContentPackageFile pkg : validContentPackages) {
136148
String path = buildPackagePath(pkg, rootPath);
149+
150+
// get last previous package
151+
// if autoDependenciesSeparateMutable active only that of the same mutability type
152+
ContentPackageFile previousPkg = previousPackages.stream()
153+
.filter(item -> !autoDependenciesSeparateMutable || mutableMatches(item, pkg))
154+
.reduce((first, second) -> second)
155+
.orElse(null);
156+
137157
if (autoDependencies && previousPkg != null) {
138158
// wire previous package in package dependency
139159
addFileWithDependency(contentPackage, path, pkg, previousPkg);
@@ -142,7 +162,7 @@ public boolean build(List<ContentPackageFile> contentPackages) throws IOExceptio
142162
// add package file directly
143163
contentPackage.addFile(path, pkg.getFile());
144164
}
145-
previousPkg = pkg;
165+
previousPackages.add(pkg);
146166
}
147167
}
148168

@@ -154,6 +174,17 @@ private static boolean isValid(ContentPackageFile pkg) {
154174
return pkg.getPackageType() != null;
155175
}
156176

177+
private static boolean isMutable(ContentPackageFile pkg) {
178+
return StringUtils.equals("content", pkg.getPackageType());
179+
}
180+
181+
private static boolean mutableMatches(ContentPackageFile pkg1, ContentPackageFile pkg2) {
182+
if (pkg1 == null || pkg2 == null) {
183+
return false;
184+
}
185+
return isMutable(pkg1) == isMutable(pkg2);
186+
}
187+
157188
/**
158189
* Build root path to be used for embedded package.
159190
* @param groupName Group name

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

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ void testBuild() throws Exception {
8686
File contentInstallDir = new File(contentDir, "install.author");
8787
assertFiles(contentInstallDir, "aem-cms-author-replicationagents.zip", "wcm-io-samples-sample-content-1.3.1-SNAPSHOT.zip");
8888
assertDependencies(contentInstallDir, "aem-cms-author-replicationagents.zip");
89-
assertDependencies(contentInstallDir, "wcm-io-samples-sample-content-1.3.1-SNAPSHOT.zip",
90-
"wcm-io-samples:wcm-io-samples-complete:1.3.1-SNAPSHOT");
89+
assertDependencies(contentInstallDir, "wcm-io-samples-sample-content-1.3.1-SNAPSHOT.zip");
9190

9291
File containerDir = new File(appsDir, "container");
9392
assertFiles(containerDir, "install.author");
@@ -142,6 +141,50 @@ void testBuildWithAutoDependencies() throws Exception {
142141
"wcm-io-samples:wcm-io-samples-aem-cms-config:1.3.1-SNAPSHOT");
143142
}
144143

144+
@Test
145+
void testBuildWithAutoDependenciesSeparateMutable() throws Exception {
146+
List<ContentPackageFile> contentPackages = new ModelParser().getContentPackagesForNode(nodeDir);
147+
File targetFile = new File(targetDir, "all.zip");
148+
149+
AllPackageBuilder builder = new AllPackageBuilder(targetFile, "test-group", "test-pkg")
150+
.autoDependencies(true)
151+
.autoDependenciesSeparateMutable(true);
152+
assertTrue(builder.build(contentPackages));
153+
154+
ZipUtil.unpack(targetFile, targetUnpackDir);
155+
156+
File appsDir = new File(targetUnpackDir, "jcr_root/apps/test-group-test-pkg-packages");
157+
assertFiles(appsDir, "application", "content", "container");
158+
159+
File applicationDir = new File(appsDir, "application");
160+
assertFiles(applicationDir, "install.author");
161+
162+
File applicationInstallDir = new File(applicationDir, "install.author");
163+
assertFiles(applicationInstallDir, "aem-cms-system-config.zip");
164+
assertDependencies(applicationInstallDir, "aem-cms-system-config.zip",
165+
"day/cq60/product:cq-ui-wcm-editor-content:1.1.224",
166+
"adobe/cq/product:cq-remotedam-client-ui-components:1.1.6");
167+
168+
File contentDir = new File(appsDir, "content");
169+
assertFiles(contentDir, "install.author");
170+
171+
File contentInstallDir = new File(contentDir, "install.author");
172+
assertFiles(contentInstallDir, "aem-cms-author-replicationagents.zip", "wcm-io-samples-sample-content-1.3.1-SNAPSHOT.zip");
173+
assertDependencies(contentInstallDir, "aem-cms-author-replicationagents.zip");
174+
assertDependencies(contentInstallDir, "wcm-io-samples-sample-content-1.3.1-SNAPSHOT.zip",
175+
"wcm-io-samples:aem-cms-author-replicationagents:1.3.1-SNAPSHOT");
176+
177+
File containerDir = new File(appsDir, "container");
178+
assertFiles(containerDir, "install.author");
179+
180+
File containerInstallDir = new File(containerDir, "install.author");
181+
assertFiles(containerInstallDir, "wcm-io-samples-aem-cms-config.zip", "wcm-io-samples-complete-1.3.1-SNAPSHOT.zip");
182+
assertDependencies(containerInstallDir, "wcm-io-samples-aem-cms-config.zip",
183+
"wcm-io-samples:aem-cms-system-config:1.3.1-SNAPSHOT");
184+
assertDependencies(containerInstallDir, "wcm-io-samples-complete-1.3.1-SNAPSHOT.zip",
185+
"wcm-io-samples:wcm-io-samples-aem-cms-config:1.3.1-SNAPSHOT");
186+
}
187+
145188
private void assertFiles(File dir, String... fileNames) {
146189
assertTrue(dir.exists(), "file exists: " + dir.getPath());
147190
assertTrue(dir.isDirectory(), "is directory: " + dir.getPath());

0 commit comments

Comments
 (0)