Skip to content

Commit 0448d8b

Browse files
committed
conga-aem-maven-plugin: Add "singlePackage" flag for "cloudmanager-all-package" goal to alternatively build single "all" content package for all environments and nodes.
1 parent 270960b commit 0448d8b

6 files changed

Lines changed: 182 additions & 54 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.0" date="not released">
27+
<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.
29+
</action>
30+
</release>
31+
2632
<release version="1.13.0" date="2020-07-10">
2733
<action type="add" dev="sseifert">
2834
aem-contentpackage post processor: Add "fileMatch" property to include a list of binary files matching the pattern into a content package.

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

Lines changed: 76 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ public final class CloudManagerAllPackageMojo extends AbstractCloudManagerMojo {
6565
@Parameter(property = "conga.cloudManager.allPackage.group", required = true)
6666
private String group;
6767

68+
/**
69+
* Build one single content package for all environments and nodes.
70+
*/
71+
@Parameter(property = "conga.cloudManager.allPackage.singlePackage", defaultValue = "true")
72+
private boolean singlePackage;
73+
6874
/**
6975
* Automatically generate dependencies between content packages based on file order in CONGA configuration.
7076
* <p>
@@ -132,42 +138,91 @@ public void execute() throws MojoExecutionException, MojoFailureException {
132138
}
133139
}
134140

135-
List<File> environmentDirs = getEnvironmentDir();
136-
for (File environmentDir : environmentDirs) {
137-
List<File> nodeDirs = getNodeDirs(environmentDir);
138-
ModelParser modelParser = new ModelParser();
139-
for (File nodeDir : nodeDirs) {
140-
Set<String> cloudManagerTarget = modelParser.getCloudManagerTarget(nodeDir);
141-
if (!cloudManagerTarget.contains(CLOUDMANAGER_TARGET_NONE)) {
142-
buildAllPackage(environmentDir, nodeDir, cloudManagerTarget, modelParser);
143-
}
144-
}
141+
if (singlePackage) {
142+
buildSingleAllPackage();
143+
}
144+
else {
145+
buildAllPackagesPerEnvironmentNode();
145146
}
146147
}
147148

148-
private void buildAllPackage(File environmentDir, File nodeDir, Set<String> cloudManagerTarget,
149-
ModelParser modelParser) throws MojoExecutionException {
150-
String groupName = this.group;
151-
String packageName = environmentDir.getName() + "." + nodeDir.getName() + "." + this.name;
149+
/**
150+
* Build an "all" package for each environment and node.
151+
*/
152+
private void buildAllPackagesPerEnvironmentNode() throws MojoExecutionException, MojoFailureException {
153+
visitEnvironmentsNodes((environmentDir, nodeDir, cloudManagerTarget, contentPackages) -> {
154+
String packageName = environmentDir.getName() + "." + nodeDir.getName() + "." + this.name;
155+
AllPackageBuilder builder = createBuilder(packageName);
152156

153-
List<ContentPackageFile> contentPackages = modelParser.getContentPackagesForNode(nodeDir);
154-
File targetFile = new File(getTargetDir(), packageName + ".zip");
157+
try {
158+
builder.add(contentPackages, cloudManagerTarget);
159+
}
160+
catch (IllegalArgumentException ex) {
161+
throw new MojoFailureException(ex.getMessage(), ex);
162+
}
163+
164+
buildAllPackage(builder);
165+
});
166+
}
167+
168+
/**
169+
* Build a single "all" package containing packages from all environments and nodes.
170+
*/
171+
private void buildSingleAllPackage() throws MojoExecutionException, MojoFailureException {
172+
String packageName = this.name;
173+
AllPackageBuilder builder = createBuilder(packageName);
174+
175+
visitEnvironmentsNodes((environmentDir, nodeDir, cloudManagerTarget, contentPackages) -> {
176+
try {
177+
builder.add(contentPackages, cloudManagerTarget);
178+
}
179+
catch (IllegalArgumentException ex) {
180+
throw new MojoFailureException(ex.getMessage(), ex);
181+
}
182+
});
183+
184+
buildAllPackage(builder);
185+
}
155186

156-
AllPackageBuilder builder = new AllPackageBuilder(targetFile, groupName, packageName)
187+
private AllPackageBuilder createBuilder(String packageName) {
188+
File targetFile = new File(getTargetDir(), packageName + ".zip");
189+
return new AllPackageBuilder(targetFile, this.group, packageName)
157190
.autoDependenciesMode(this.autoDependenciesMode)
158191
.logger(getLog());
192+
}
159193

194+
private void buildAllPackage(AllPackageBuilder builder) throws MojoExecutionException {
160195
try {
161-
if (builder.build(contentPackages, cloudManagerTarget, properties)) {
162-
getLog().info("Generated " + getCanonicalPath(targetFile));
196+
if (builder.build(properties)) {
197+
getLog().info("Generated " + getCanonicalPath(builder.getTargetFile()));
163198
}
164199
else {
165-
getLog().debug("Skipped " + getCanonicalPath(targetFile) + " - no valid package.");
200+
getLog().debug("Skipped " + getCanonicalPath(builder.getTargetFile()) + " - no valid package.");
166201
}
167202
}
168203
catch (IOException ex) {
169-
throw new MojoExecutionException("Unable to generate " + getCanonicalPath(targetFile), ex);
204+
throw new MojoExecutionException("Unable to generate " + getCanonicalPath(builder.getTargetFile()), ex);
170205
}
171206
}
172207

208+
private void visitEnvironmentsNodes(EnvironmentNodeVisitor visitor) throws MojoExecutionException, MojoFailureException {
209+
ModelParser modelParser = new ModelParser();
210+
List<File> environmentDirs = getEnvironmentDir();
211+
for (File environmentDir : environmentDirs) {
212+
List<File> nodeDirs = getNodeDirs(environmentDir);
213+
for (File nodeDir : nodeDirs) {
214+
Set<String> cloudManagerTarget = modelParser.getCloudManagerTarget(nodeDir);
215+
if (!cloudManagerTarget.contains(CLOUDMANAGER_TARGET_NONE)) {
216+
List<ContentPackageFile> contentPackages = modelParser.getContentPackagesForNode(nodeDir);
217+
visitor.visit(environmentDir, nodeDir, cloudManagerTarget, contentPackages);
218+
}
219+
}
220+
}
221+
}
222+
223+
interface EnvironmentNodeVisitor {
224+
void visit(File environmentDir, File nodeDir, Set<String> cloudManagerTarget,
225+
List<ContentPackageFile> contentPackages) throws MojoExecutionException, MojoFailureException;
226+
}
227+
173228
}

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

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public final class AllPackageBuilder {
7272
private static final String RUNMODE_DEFAULT = "$default$";
7373
private static final Set<String> ALLOWED_PACKAGE_TYPES = ImmutableSet.of("application", "container", "content");
7474

75+
private final List<ContentPackageFileSet> fileSets = new ArrayList<>();
76+
7577
/**
7678
* @param targetFile Target file
7779
* @param groupName Group name
@@ -110,15 +112,12 @@ private Log getLog() {
110112
}
111113

112114
/**
113-
* Build "all" content package.
115+
* Add content packages to be contained in "all" content package.
114116
* @param contentPackages Content packages (invalid will be filtered out)
115117
* @param cloudManagerTarget Target environments/run modes the packages should be attached to
116-
* @param properties Specifies additional properties to be set in the properties.xml file.
117-
* @return true if "all" package was generated, false if not valid package was found.
118-
* @throws IOException I/O exception
118+
* @throws IllegalArgumentException If and invalid package type is detected
119119
*/
120-
public boolean build(List<ContentPackageFile> contentPackages,
121-
Set<String> cloudManagerTarget, Map<String, String> properties) throws IOException {
120+
public void add(List<ContentPackageFile> contentPackages, Set<String> cloudManagerTarget) {
122121

123122
// collect list of cloud manager environment run modes
124123
List<String> environmentRunModes = new ArrayList<>();
@@ -140,7 +139,7 @@ public boolean build(List<ContentPackageFile> contentPackages,
140139
.filter(pkg -> !isValidPackageType(pkg))
141140
.collect(Collectors.toList());
142141
if (!invalidPackageTypeContentPackages.isEmpty()) {
143-
throw new IOException("Content packages found with unsupported package types: " +
142+
throw new IllegalArgumentException("Content packages found with unsupported package types: " +
144143
invalidPackageTypeContentPackages.stream()
145144
.map(pkg -> pkg.getName() + " -> " + pkg.getPackageType())
146145
.collect(Collectors.joining(", ")));
@@ -150,7 +149,21 @@ public boolean build(List<ContentPackageFile> contentPackages,
150149
List<ContentPackageFile> validContentPackages = contentPackages.stream()
151150
.filter(AllPackageBuilder::hasPackageType)
152151
.collect(Collectors.toList());
153-
if (validContentPackages.isEmpty()) {
152+
153+
if (!validContentPackages.isEmpty()) {
154+
fileSets.add(new ContentPackageFileSet(validContentPackages, environmentRunModes));
155+
}
156+
}
157+
158+
/**
159+
* Build "all" content package.
160+
* @param properties Specifies additional properties to be set in the properties.xml file.
161+
* @return true if "all" package was generated, false if no valid package was found.
162+
* @throws IOException I/O exception
163+
*/
164+
public boolean build(Map<String, String> properties) throws IOException {
165+
166+
if (fileSets.isEmpty()) {
154167
return false;
155168
}
156169

@@ -172,27 +185,29 @@ public boolean build(List<ContentPackageFile> contentPackages,
172185
// build content package
173186
// if auto dependencies is active: build separate "dependency chains" between mutable and immutable packages
174187
try (ContentPackage contentPackage = builder.build(targetFile)) {
175-
for (String environmentRunMode : environmentRunModes) {
176-
List<ContentPackageFile> previousPackages = new ArrayList<>();
177-
for (ContentPackageFile pkg : validContentPackages) {
178-
String path = buildPackagePath(pkg, rootPath, environmentRunMode);
179-
180-
ContentPackageFile previousPkg = null;
181-
182-
if (autoDependenciesMode != AutoDependenciesMode.OFF
183-
&& (autoDependenciesMode != AutoDependenciesMode.IMMUTABLE_ONLY || !isMutable(pkg))) {
184-
// get last previous package
185-
// if not IMMUTABLE_MUTABLE_COMBINED active only that of the same mutability type
186-
previousPkg = previousPackages.stream()
187-
.filter(item -> (autoDependenciesMode == AutoDependenciesMode.IMMUTABLE_MUTABLE_COMBINED) || mutableMatches(item, pkg))
188-
.reduce((first, second) -> second)
189-
.orElse(null);
190-
}
188+
for (ContentPackageFileSet fileSet : fileSets) {
189+
for (String environmentRunMode : fileSet.getEnvironmentRunModes()) {
190+
List<ContentPackageFile> previousPackages = new ArrayList<>();
191+
for (ContentPackageFile pkg : fileSet.getContentPackages()) {
192+
String path = buildPackagePath(pkg, rootPath, environmentRunMode);
193+
194+
ContentPackageFile previousPkg = null;
195+
196+
if (autoDependenciesMode != AutoDependenciesMode.OFF
197+
&& (autoDependenciesMode != AutoDependenciesMode.IMMUTABLE_ONLY || !isMutable(pkg))) {
198+
// get last previous package
199+
// if not IMMUTABLE_MUTABLE_COMBINED active only that of the same mutability type
200+
previousPkg = previousPackages.stream()
201+
.filter(item -> (autoDependenciesMode == AutoDependenciesMode.IMMUTABLE_MUTABLE_COMBINED) || mutableMatches(item, pkg))
202+
.reduce((first, second) -> second)
203+
.orElse(null);
204+
}
191205

192-
// set package name, wire previous package in package dependency
193-
addFileWithDependency(contentPackage, path, pkg, previousPkg, environmentRunMode);
206+
// set package name, wire previous package in package dependency
207+
addFileWithDependency(contentPackage, path, pkg, previousPkg, environmentRunMode);
194208

195-
previousPackages.add(pkg);
209+
previousPackages.add(pkg);
210+
}
196211
}
197212
}
198213
}
@@ -363,4 +378,8 @@ private static void addSuffixToPackageName(Properties props, ContentPackageFile
363378
props.put(NAME_NAME, packageName);
364379
}
365380

381+
public File getTargetFile() {
382+
return this.targetFile;
383+
}
384+
366385
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* #%L
3+
* wcm.io
4+
* %%
5+
* Copyright (C) 2020 wcm.io
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package io.wcm.devops.conga.plugins.aem.maven.allpackage;
21+
22+
import java.util.List;
23+
24+
import io.wcm.devops.conga.plugins.aem.maven.model.ContentPackageFile;
25+
26+
class ContentPackageFileSet {
27+
28+
private final List<ContentPackageFile> contentPackages;
29+
private final List<String> environmentRunModes;
30+
31+
ContentPackageFileSet(List<ContentPackageFile> contentPackages, List<String> environmentRunModes) {
32+
this.contentPackages = contentPackages;
33+
this.environmentRunModes = environmentRunModes;
34+
}
35+
36+
public List<ContentPackageFile> getContentPackages() {
37+
return this.contentPackages;
38+
}
39+
40+
public List<String> getEnvironmentRunModes() {
41+
return this.environmentRunModes;
42+
}
43+
44+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ void testBuild() throws Exception {
5959
AllPackageBuilder builder = new AllPackageBuilder(targetFile, "test-group", "test-pkg");
6060

6161
// should fail to to "mixed" packageType
62-
assertThrows(IOException.class, () -> {
63-
builder.build(contentPackages, ImmutableSet.of(), null);
62+
assertThrows(IllegalArgumentException.class, () -> {
63+
builder.add(contentPackages, ImmutableSet.of());
6464
});
6565
}
6666

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ void testBuild(Set<String> cloudManagerTarget, List<String> runmodeSuffixes) thr
8181
File targetFile = new File(targetDir, "all.zip");
8282

8383
AllPackageBuilder builder = new AllPackageBuilder(targetFile, "test-group", "test-pkg");
84-
assertTrue(builder.build(contentPackages, cloudManagerTarget, ImmutableMap.of("prop1", "value1")));
84+
builder.add(contentPackages, cloudManagerTarget);
85+
assertTrue(builder.build(ImmutableMap.of("prop1", "value1")));
8586

8687
ZipUtil.unpack(targetFile, targetUnpackDir);
8788

@@ -135,7 +136,8 @@ void testBuil_IMMUTABLE_MUTABLE_COMBINED(Set<String> cloudManagerTarget, List<St
135136

136137
AllPackageBuilder builder = new AllPackageBuilder(targetFile, "test-group", "test-pkg")
137138
.autoDependenciesMode(AutoDependenciesMode.IMMUTABLE_MUTABLE_COMBINED);
138-
assertTrue(builder.build(contentPackages, cloudManagerTarget, null));
139+
builder.add(contentPackages, cloudManagerTarget);
140+
assertTrue(builder.build(null));
139141

140142
ZipUtil.unpack(targetFile, targetUnpackDir);
141143

@@ -193,7 +195,8 @@ void testBuild_IMMUTABLE_MUTABLE_SEPARATE(Set<String> cloudManagerTarget, List<S
193195

194196
AllPackageBuilder builder = new AllPackageBuilder(targetFile, "test-group", "test-pkg")
195197
.autoDependenciesMode(AutoDependenciesMode.IMMUTABLE_MUTABLE_SEPARATE);
196-
assertTrue(builder.build(contentPackages, cloudManagerTarget, null));
198+
builder.add(contentPackages, cloudManagerTarget);
199+
assertTrue(builder.build(null));
197200

198201
ZipUtil.unpack(targetFile, targetUnpackDir);
199202

@@ -250,7 +253,8 @@ void testBuild_IMMUTABLE_ONLY(Set<String> cloudManagerTarget, List<String> runmo
250253

251254
AllPackageBuilder builder = new AllPackageBuilder(targetFile, "test-group", "test-pkg")
252255
.autoDependenciesMode(AutoDependenciesMode.IMMUTABLE_ONLY);
253-
assertTrue(builder.build(contentPackages, cloudManagerTarget, null));
256+
builder.add(contentPackages, cloudManagerTarget);
257+
assertTrue(builder.build(null));
254258

255259
ZipUtil.unpack(targetFile, targetUnpackDir);
256260

0 commit comments

Comments
 (0)