Skip to content

Commit c98fa9b

Browse files
committed
conga-aem-maven-plugin: Add 'cloudmanager-dispatcher-config' goal to build ZIP file with dispatcher configuration for deployment with Adobe Cloud Manager.
rename goal "all-package" to "cloudmanager-all-package"
1 parent 17c623f commit c98fa9b

8 files changed

Lines changed: 391 additions & 76 deletions

File tree

changes.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@
3434
Add new config parameter 'cryptoSkip' that allows to skip crypto encryption in aemCryptoEncrypt expression.
3535
</action>
3636
<action type="add" dev="sseifert">
37-
conga-aem-maven-plugin: Add 'all-package' goal to build combined container package for deployment with Adobe Cloud Manager.
37+
conga-aem-maven-plugin: Add 'cloudmanager-all-package' goal to build combined container package for deployment with Adobe Cloud Manager.
38+
</action>
39+
<action type="add" dev="sseifert">
40+
conga-aem-maven-plugin: Add 'cloudmanager-dispatcher-config' goal to build ZIP file with dispatcher configuration for deployment with Adobe Cloud Manager.
3841
</action>
3942
<action type="update" dev="sseifert">
4043
aem-contentpackage-osgiconfig post processor: Include only generated *.config files in AEM content package, no other .content files (exception the package is empty otherwise).

tooling/conga-aem-maven-plugin/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@
9191
<version>${maven.version}</version>
9292
<scope>compile</scope>
9393
</dependency>
94+
<dependency>
95+
<groupId>org.apache.maven</groupId>
96+
<artifactId>maven-archiver</artifactId>
97+
<version>3.4.0</version>
98+
<scope>compile</scope>
99+
</dependency>
94100
<dependency>
95101
<groupId>org.apache.maven.plugin-tools</groupId>
96102
<artifactId>maven-plugin-annotations</artifactId>

tooling/conga-aem-maven-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/maven/AllPackageMojo.java renamed to tooling/conga-aem-maven-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/maven/AbstractCloudManagerMojo.java

Lines changed: 8 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import static io.wcm.devops.conga.generator.util.FileUtil.getCanonicalPath;
2323

2424
import java.io.File;
25-
import java.io.IOException;
2625
import java.util.Arrays;
2726
import java.util.Collections;
2827
import java.util.List;
@@ -31,40 +30,14 @@
3130

3231
import org.apache.maven.plugin.AbstractMojo;
3332
import org.apache.maven.plugin.MojoExecutionException;
34-
import org.apache.maven.plugin.MojoFailureException;
35-
import org.apache.maven.plugins.annotations.Mojo;
3633
import org.apache.maven.plugins.annotations.Parameter;
3734

3835
import com.google.common.collect.ImmutableSet;
3936

40-
import io.wcm.devops.conga.plugins.aem.maven.allpackage.AllPackageBuilder;
41-
import io.wcm.devops.conga.plugins.aem.maven.model.ContentPackageFile;
42-
import io.wcm.devops.conga.plugins.aem.maven.model.ModelParser;
43-
4437
/**
45-
* Builds an "all" content package dedicated for deployment via Adobe Cloud Manager
46-
* for the given environment and node(s).
38+
* Common functionality for mojos that generate configuration ZIP files for Adobe Cloud Manager.
4739
*/
48-
@Mojo(name = "all-package", threadSafe = true, requiresProject = false)
49-
public final class AllPackageMojo extends AbstractMojo {
50-
51-
/**
52-
* Package name for the "all" content package.
53-
*/
54-
@Parameter(property = "conga.allPackage.name", defaultValue = "all")
55-
private String name;
56-
57-
/**
58-
* Group name for the "all" content package.
59-
*/
60-
@Parameter(property = "conga.allPackage.group", required = true)
61-
private String group;
62-
63-
/**
64-
* Automatically generate dependencies between content packages based on file order in CONGA configuration.
65-
*/
66-
@Parameter(property = "conga.allPackage.autoDependencies", defaultValue = "true")
67-
private boolean autoDependencies;
40+
abstract class AbstractCloudManagerMojo extends AbstractMojo {
6841

6942
/**
7043
* Selected environments to generate. It's only allowed to define a single environment for this mojo,
@@ -93,31 +66,18 @@ public final class AllPackageMojo extends AbstractMojo {
9366
private File target;
9467

9568
/**
96-
* Set this to "true" to skip installing packages to CRX although configured in the POM.
69+
* @return Target directory
9770
*/
98-
@Parameter(property = "conga.allPackage.skip", defaultValue = "false")
99-
private boolean skip;
100-
101-
@Override
102-
public void execute() throws MojoExecutionException, MojoFailureException {
103-
if (skip) {
104-
return;
105-
}
106-
107-
File environmentDir = getEnvironmentDir();
108-
List<File> nodeDirs = getNodeDirs(environmentDir);
109-
ModelParser modelParser = new ModelParser();
110-
for (File nodeDir : nodeDirs) {
111-
buildAllPackage(nodeDir, modelParser);
112-
}
71+
protected File getTargetDir() {
72+
return target;
11373
}
11474

11575
/**
11676
* Get directory of the selected environment. It has to be exactly one matching environment.
11777
* @return Environment directory
118-
* @throw MojoExecutionException if no or multiple directories found
78+
* @throws MojoExecutionException if no or multiple directories found
11979
*/
120-
private File getEnvironmentDir() throws MojoExecutionException {
80+
protected File getEnvironmentDir() throws MojoExecutionException {
12181
List<File> directories = null;
12282
Set<String> selectedEnvironments = toSet(this.environments);
12383
if (configurationDir.exists() && configurationDir.isDirectory()) {
@@ -144,7 +104,7 @@ private File getEnvironmentDir() throws MojoExecutionException {
144104
* @param environmentDir Environment directory
145105
* @return List of directories
146106
*/
147-
private List<File> getNodeDirs(File environmentDir) {
107+
protected List<File> getNodeDirs(File environmentDir) {
148108
Set<String> selectedNodes = toSet(this.nodes);
149109
File[] files = environmentDir.listFiles();
150110
if (files != null) {
@@ -158,30 +118,6 @@ private List<File> getNodeDirs(File environmentDir) {
158118
}
159119
}
160120

161-
private void buildAllPackage(File nodeDir, ModelParser modelParser) throws MojoFailureException {
162-
String groupName = this.group;
163-
String packageName = nodeDir.getName() + "-" + this.name;
164-
165-
List<ContentPackageFile> contentPackages = modelParser.getContentPackagesForNode(nodeDir);
166-
File targetFile = new File(target, packageName + ".zip");
167-
168-
AllPackageBuilder builder = new AllPackageBuilder(targetFile, groupName, packageName)
169-
.autoDependencies(this.autoDependencies)
170-
.logger(getLog());
171-
172-
try {
173-
if (builder.build(contentPackages)) {
174-
getLog().info("Generated " + getCanonicalPath(targetFile));
175-
}
176-
else {
177-
getLog().debug("Skipped " + getCanonicalPath(targetFile) + " - no valid package.");
178-
}
179-
}
180-
catch (IOException ex) {
181-
throw new MojoFailureException("Unable to generate " + getCanonicalPath(targetFile), ex);
182-
}
183-
}
184-
185121
private static Set<String> toSet(String[] values) {
186122
if (values != null) {
187123
return ImmutableSet.copyOf(values);
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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;
21+
22+
import static io.wcm.devops.conga.generator.util.FileUtil.getCanonicalPath;
23+
24+
import java.io.File;
25+
import java.io.IOException;
26+
import java.util.List;
27+
28+
import org.apache.maven.plugin.MojoExecutionException;
29+
import org.apache.maven.plugin.MojoFailureException;
30+
import org.apache.maven.plugins.annotations.Mojo;
31+
import org.apache.maven.plugins.annotations.Parameter;
32+
33+
import io.wcm.devops.conga.plugins.aem.maven.allpackage.AllPackageBuilder;
34+
import io.wcm.devops.conga.plugins.aem.maven.model.ContentPackageFile;
35+
import io.wcm.devops.conga.plugins.aem.maven.model.ModelParser;
36+
37+
/**
38+
* Builds an "all" content package dedicated for deployment via Adobe Cloud Manager
39+
* for the given environment and node(s).
40+
*/
41+
@Mojo(name = "cloudmanager-all-package", threadSafe = true)
42+
public final class CloudManagerAllPackageMojo extends AbstractCloudManagerMojo {
43+
44+
/**
45+
* Package name for the "all" content package.
46+
*/
47+
@Parameter(property = "conga.cloudManager.allPackage.name", defaultValue = "all")
48+
private String name;
49+
50+
/**
51+
* Group name for the "all" content package.
52+
*/
53+
@Parameter(property = "conga.cloudManager.allPackage.group", required = true)
54+
private String group;
55+
56+
/**
57+
* Automatically generate dependencies between content packages based on file order in CONGA configuration.
58+
*/
59+
@Parameter(property = "conga.cloudManager.allPackage.autoDependencies", defaultValue = "true")
60+
private boolean autoDependencies;
61+
62+
/**
63+
* Set this to "true" to skip installing packages to CRX although configured in the POM.
64+
*/
65+
@Parameter(property = "conga.cloudManager.allPackage.skip", defaultValue = "false")
66+
private boolean skip;
67+
68+
@Override
69+
public void execute() throws MojoExecutionException, MojoFailureException {
70+
if (skip) {
71+
return;
72+
}
73+
74+
File environmentDir = getEnvironmentDir();
75+
List<File> nodeDirs = getNodeDirs(environmentDir);
76+
ModelParser modelParser = new ModelParser();
77+
for (File nodeDir : nodeDirs) {
78+
buildAllPackage(nodeDir, modelParser);
79+
}
80+
}
81+
82+
private void buildAllPackage(File nodeDir, ModelParser modelParser) throws MojoFailureException {
83+
String groupName = this.group;
84+
String packageName = nodeDir.getName() + "-" + this.name;
85+
86+
List<ContentPackageFile> contentPackages = modelParser.getContentPackagesForNode(nodeDir);
87+
File targetFile = new File(getTargetDir(), packageName + ".zip");
88+
89+
AllPackageBuilder builder = new AllPackageBuilder(targetFile, groupName, packageName)
90+
.autoDependencies(this.autoDependencies)
91+
.logger(getLog());
92+
93+
try {
94+
if (builder.build(contentPackages)) {
95+
getLog().info("Generated " + getCanonicalPath(targetFile));
96+
}
97+
else {
98+
getLog().debug("Skipped " + getCanonicalPath(targetFile) + " - no valid package.");
99+
}
100+
}
101+
catch (IOException ex) {
102+
throw new MojoFailureException("Unable to generate " + getCanonicalPath(targetFile), ex);
103+
}
104+
}
105+
106+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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;
21+
22+
import java.io.File;
23+
import java.io.IOException;
24+
import java.util.List;
25+
26+
import org.apache.maven.plugin.MojoExecutionException;
27+
import org.apache.maven.plugin.MojoFailureException;
28+
import org.apache.maven.plugins.annotations.Component;
29+
import org.apache.maven.plugins.annotations.Mojo;
30+
import org.apache.maven.plugins.annotations.Parameter;
31+
import org.codehaus.plexus.archiver.Archiver;
32+
import org.codehaus.plexus.archiver.ArchiverException;
33+
import org.codehaus.plexus.archiver.zip.ZipArchiver;
34+
35+
import io.wcm.devops.conga.plugins.aem.maven.model.ModelParser;
36+
37+
/**
38+
* Builds an Dispatcher configuration ZIP file dedicated for deployment via Adobe Cloud Manager
39+
* for the given environment and node(s).
40+
* Only nodes with role <code>aem-dispatcher-cloud</code> are respected.
41+
*/
42+
@Mojo(name = "cloudmanager-dispatcher-config", threadSafe = true)
43+
public final class CloudManagerDispatcherConfigMojo extends AbstractCloudManagerMojo {
44+
45+
private static final String ROLE_AEM_DISPATCHER_CLOUD = "aem-dispatcher-cloud";
46+
47+
/**
48+
* Set this to "true" to skip installing packages to CRX although configured in the POM.
49+
*/
50+
@Parameter(property = "conga.cloudManager.dispatcherConfig.skip", defaultValue = "false")
51+
private boolean skip;
52+
53+
@Component(role = Archiver.class, hint = "zip")
54+
private ZipArchiver zipArchiver;
55+
56+
@Override
57+
public void execute() throws MojoExecutionException, MojoFailureException {
58+
if (skip) {
59+
return;
60+
}
61+
62+
File environmentDir = getEnvironmentDir();
63+
List<File> nodeDirs = getNodeDirs(environmentDir);
64+
ModelParser modelParser = new ModelParser();
65+
for (File nodeDir : nodeDirs) {
66+
if (modelParser.hasRole(nodeDir, ROLE_AEM_DISPATCHER_CLOUD)) {
67+
buildDispatcherConfig(nodeDir);
68+
}
69+
}
70+
}
71+
72+
private void buildDispatcherConfig(File nodeDir) throws MojoFailureException {
73+
File targetFile = new File(getTargetDir(), nodeDir.getName() + ".dispatcher-config.zip");
74+
75+
zipArchiver.setDestFile(targetFile);
76+
String[] includes = new String[] { "**/*" };
77+
String[] excludes = new String[] { ModelParser.MODEL_FILE };
78+
zipArchiver.addDirectory(nodeDir, includes, excludes);
79+
try {
80+
zipArchiver.createArchive();
81+
}
82+
catch (ArchiverException | IOException ex) {
83+
throw new MojoFailureException("Unable to build file " + targetFile.getPath() + ": " + ex.getMessage(), ex);
84+
}
85+
}
86+
87+
}

0 commit comments

Comments
 (0)