Skip to content

Commit bf1c868

Browse files
committed
ensure only allowed packageTypes are included in cloud manager "all" package
1 parent a3d466d commit bf1c868

4 files changed

Lines changed: 119 additions & 4 deletions

File tree

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
import org.apache.maven.plugin.logging.Log;
4848
import org.apache.maven.plugin.logging.SystemStreamLog;
4949

50+
import com.google.common.collect.ImmutableSet;
51+
5052
import io.wcm.devops.conga.plugins.aem.maven.model.ContentPackageFile;
5153
import io.wcm.tooling.commons.contentpackagebuilder.ContentPackage;
5254
import io.wcm.tooling.commons.contentpackagebuilder.ContentPackageBuilder;
@@ -65,6 +67,7 @@ public final class AllPackageBuilder {
6567
private Log log;
6668

6769
private static final String RUNMODE_DEFAULT = "$default$";
70+
private static final Set<String> ALLOWED_PACKAGE_TYPES = ImmutableSet.of("application", "container", "content");
6871

6972
/**
7073
* @param targetFile Target file
@@ -132,12 +135,24 @@ public boolean build(List<ContentPackageFile> contentPackages, Set<String> cloud
132135

133136
// generate warnings for each invalid content packages that is skipped
134137
contentPackages.stream()
135-
.filter(pkg -> !isValid(pkg))
138+
.filter(pkg -> !hasPackageType(pkg))
136139
.forEach(pkg -> getLog().warn("Skipping content package without package type: " + getCanonicalPath(pkg.getFile())));
137140

141+
// fail build if content packages with non-allowed package types exist
142+
List<ContentPackageFile> invalidPackageTypeContentPackages = contentPackages.stream()
143+
.filter(AllPackageBuilder::hasPackageType)
144+
.filter(pkg -> !isValidPackageType(pkg))
145+
.collect(Collectors.toList());
146+
if (!invalidPackageTypeContentPackages.isEmpty()) {
147+
throw new IOException("Content packages found with unsupported package types: " +
148+
invalidPackageTypeContentPackages.stream()
149+
.map(pkg -> pkg.getName() + " -> " + pkg.getPackageType())
150+
.collect(Collectors.joining(", ")));
151+
}
152+
138153
// collect AEM content packages for this node
139154
List<ContentPackageFile> validContentPackages = contentPackages.stream()
140-
.filter(pkg -> isValid(pkg))
155+
.filter(AllPackageBuilder::hasPackageType)
141156
.collect(Collectors.toList());
142157
if (validContentPackages.isEmpty()) {
143158
return false;
@@ -184,11 +199,16 @@ public boolean build(List<ContentPackageFile> contentPackages, Set<String> cloud
184199
return true;
185200
}
186201

187-
private static boolean isValid(ContentPackageFile pkg) {
188-
// accept only content packages with package type
202+
private static boolean hasPackageType(ContentPackageFile pkg) {
203+
// accept only content packages with a package type set
189204
return pkg.getPackageType() != null;
190205
}
191206

207+
private static boolean isValidPackageType(ContentPackageFile pkg) {
208+
// check if the package type is an allowed package type
209+
return ALLOWED_PACKAGE_TYPES.contains(pkg.getPackageType());
210+
}
211+
192212
private static boolean isMutable(ContentPackageFile pkg) {
193213
return StringUtils.equals("content", pkg.getPackageType());
194214
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 static org.junit.jupiter.api.Assertions.assertThrows;
23+
24+
import java.io.File;
25+
import java.io.IOException;
26+
import java.util.List;
27+
28+
import org.apache.commons.io.FileUtils;
29+
import org.junit.jupiter.api.BeforeEach;
30+
import org.junit.jupiter.api.Test;
31+
import org.junit.jupiter.api.TestInfo;
32+
33+
import com.google.common.collect.ImmutableSet;
34+
35+
import io.wcm.devops.conga.plugins.aem.maven.model.ContentPackageFile;
36+
import io.wcm.devops.conga.plugins.aem.maven.model.ModelParser;
37+
38+
class AllPackageBuilderMixedPackageTypeTest {
39+
40+
private File nodeDir;
41+
private File targetDir;
42+
private File targetUnpackDir;
43+
44+
@BeforeEach
45+
void setUp(TestInfo testInfo) throws IOException {
46+
nodeDir = new File("src/test/resources/node-mixed-package");
47+
targetDir = new File("target/test-" + getClass().getSimpleName() + "_" + testInfo.getDisplayName());
48+
targetUnpackDir = new File(targetDir, "unpack");
49+
FileUtils.deleteDirectory(targetDir);
50+
targetDir.mkdirs();
51+
targetUnpackDir.mkdirs();
52+
}
53+
54+
@Test
55+
void testBuild() throws Exception {
56+
List<ContentPackageFile> contentPackages = new ModelParser().getContentPackagesForNode(nodeDir);
57+
File targetFile = new File(targetDir, "all.zip");
58+
59+
AllPackageBuilder builder = new AllPackageBuilder(targetFile, "test-group", "test-pkg");
60+
61+
// should fail to to "mixed" packageType
62+
assertThrows(IOException.class, () -> {
63+
builder.build(contentPackages, ImmutableSet.of());
64+
});
65+
}
66+
67+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
roles:
2+
- role: aem-cms
3+
variant: aem-author
4+
variants: [aem-author]
5+
files:
6+
- path: packages/aem-cms-system-config.zip
7+
postProcessors: [aem-contentpackage-osgiconfig, aem-contentpackage-properties]
8+
aemContentPackageProperties:
9+
allowIndexDefinitions: false
10+
created: '2020-04-07T10:36:38.606+02:00'
11+
createdBy: admin
12+
description: |-
13+
This file is AUTO-GENERATED by CONGA. Please do not change it manually.
14+
15+
Version 1.3.1-SNAPSHOT
16+
Environment: development
17+
Role: aem-cms
18+
Variant: aem-author
19+
Template: aem-cms-system-config.provisioning.hbs
20+
21+
Dependencies:
22+
io.wcm.devops.conga.definitions/io.wcm.devops.conga.definitions.aem/1.6.2
23+
group: wcm-io-samples
24+
name: aem-cms-system-config
25+
packageType: mixed
26+
requiresRoot: false
27+
version: 1.3.1-SNAPSHOT
28+
force: true

0 commit comments

Comments
 (0)