Skip to content

Commit d46b5d8

Browse files
committed
conga-aem-maven-plugin:cloudmanager-all-package: Add "attachArtifact" flag to attach "all" content package(s) as artifacts to maven build lifecycle.
1 parent 505922e commit d46b5d8

3 files changed

Lines changed: 51 additions & 1 deletion

File tree

changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
conga-aem-maven-plugin:cloudmanager-all-package: Add "singlePackage" flag to alternatively build single "all" content package for all environments and nodes.
2929
</action>
3030
<action type="add" dev="sseifert">
31+
conga-aem-maven-plugin:cloudmanager-all-package: Add "attachArtifact" flag to attach "all" content package(s) as artifacts to maven build lifecycle.
32+
</action>
33+
<action type="fix" dev="sseifert">
3134
conga-aem-maven-plugin:cloudmanager-all-package: Fix auto dependency generation for package that already contain dependencies.
3235
</action>
3336
</release>

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@
2929

3030
import org.apache.maven.plugin.MojoExecutionException;
3131
import org.apache.maven.plugin.MojoFailureException;
32+
import org.apache.maven.plugins.annotations.Component;
3233
import org.apache.maven.plugins.annotations.Mojo;
3334
import org.apache.maven.plugins.annotations.Parameter;
35+
import org.apache.maven.project.MavenProject;
36+
import org.apache.maven.project.MavenProjectHelper;
3437

3538
import io.wcm.devops.conga.plugins.aem.maven.allpackage.AllPackageBuilder;
3639
import io.wcm.devops.conga.plugins.aem.maven.model.ContentPackageFile;
@@ -71,6 +74,13 @@ public final class CloudManagerAllPackageMojo extends AbstractCloudManagerMojo {
7174
@Parameter(property = "conga.cloudManager.allPackage.singlePackage", defaultValue = "false")
7275
private boolean singlePackage;
7376

77+
/**
78+
* Attach "all" content package(s) as artifacts to maven build lifecycle.
79+
* The given package name will be used as classifier.
80+
*/
81+
@Parameter(property = "conga.cloudManager.allPackage.attachArtifact", defaultValue = "false")
82+
private boolean attachArtifact;
83+
7484
/**
7585
* Automatically generate dependencies between content packages based on file order in CONGA configuration.
7686
* <p>
@@ -116,6 +126,11 @@ public final class CloudManagerAllPackageMojo extends AbstractCloudManagerMojo {
116126
@Parameter(property = "conga.cloudManager.allPackage.skip", defaultValue = "false")
117127
private boolean skip;
118128

129+
@Parameter(readonly = true, defaultValue = "${project}")
130+
private MavenProject project;
131+
@Component
132+
private MavenProjectHelper projectHelper;
133+
119134
private static final String CLOUDMANAGER_TARGET_NONE = "none";
120135

121136
@Override
@@ -185,8 +200,16 @@ private void buildSingleAllPackage() throws MojoExecutionException, MojoFailureE
185200
}
186201

187202
private AllPackageBuilder createBuilder(String packageName) {
188-
File targetFile = new File(getTargetDir(), packageName + ".zip");
203+
String fileName;
204+
if (attachArtifact) {
205+
fileName = project.getArtifactId() + "." + packageName + "-" + project.getVersion() + ".zip";
206+
}
207+
else {
208+
fileName = packageName + ".zip";
209+
}
210+
File targetFile = new File(getTargetDir(), fileName);
189211
return new AllPackageBuilder(targetFile, this.group, packageName)
212+
.version(project.getVersion())
190213
.autoDependenciesMode(this.autoDependenciesMode)
191214
.logger(getLog());
192215
}
@@ -195,6 +218,9 @@ private void buildAllPackage(AllPackageBuilder builder) throws MojoExecutionExce
195218
try {
196219
if (builder.build(properties)) {
197220
getLog().info("Generated " + getCanonicalPath(builder.getTargetFile()));
221+
if (attachArtifact) {
222+
projectHelper.attachArtifact(this.project, "zip", builder.getPackageName(), builder.getTargetFile());
223+
}
198224
}
199225
else {
200226
getLog().debug("Skipped " + getCanonicalPath(builder.getTargetFile()) + " - no valid package.");

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public final class AllPackageBuilder {
6868
private final File targetFile;
6969
private final String groupName;
7070
private final String packageName;
71+
private String version;
7172
private AutoDependenciesMode autoDependenciesMode = AutoDependenciesMode.OFF;
7273
private Log log;
7374

@@ -106,6 +107,15 @@ public AllPackageBuilder logger(Log value) {
106107
return this;
107108
}
108109

110+
/**
111+
* @param value Package version
112+
* @return this
113+
*/
114+
public AllPackageBuilder version(String value) {
115+
this.version = value;
116+
return this;
117+
}
118+
109119
private Log getLog() {
110120
if (this.log == null) {
111121
this.log = new SystemStreamLog();
@@ -174,6 +184,9 @@ public boolean build(Map<String, String> properties) throws IOException {
174184
.group(groupName)
175185
.name(packageName)
176186
.packageType("container");
187+
if (version != null) {
188+
builder.version(version);
189+
}
177190

178191
// define root path for "all" package
179192
String rootPath = buildRootPath(groupName, packageName);
@@ -416,6 +429,14 @@ private static Dependency[] removeReferencesToManagedPackages(Dependency[] deps,
416429
.toArray(size -> new Dependency[size]);
417430
}
418431

432+
public String getGroupName() {
433+
return this.groupName;
434+
}
435+
436+
public String getPackageName() {
437+
return this.packageName;
438+
}
439+
419440
public File getTargetFile() {
420441
return this.targetFile;
421442
}

0 commit comments

Comments
 (0)