Skip to content

Commit 3374534

Browse files
Add version suffix to release version packages (configurable) (#17)
1 parent 50640f2 commit 3374534

6 files changed

Lines changed: 423 additions & 8 deletions

File tree

tooling/conga-aem-maven-plugin/src/it/wcmio-archetype-aem65/config-definition/pom.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,28 @@
9494
</executions>
9595
</plugin>
9696

97+
<plugin>
98+
<groupId>io.wcm.devops.conga.plugins</groupId>
99+
<artifactId>conga-aem-maven-plugin</artifactId>
100+
<executions>
101+
102+
<!-- Generate "all" packages including all packages from CONGA configuration for deployment via Adobe Cloud Manager -->
103+
<execution>
104+
<id>cloudmanager-all-package</id>
105+
<phase>generate-resources</phase>
106+
<goals>
107+
<goal>cloudmanager-all-package</goal>
108+
</goals>
109+
<configuration>
110+
<group>it</group>
111+
<packageTypeValidation>WARN</packageTypeValidation>
112+
<packageVersionMode>RELEASE_SUFFIX_VERSION</packageVersionMode>
113+
</configuration>
114+
</execution>
115+
116+
</executions>
117+
</plugin>
118+
97119
<!-- Do not generate eclipse project files -->
98120
<plugin>
99121
<groupId>io.wcm.devops.maven.plugins</groupId>

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ public final class CloudManagerAllPackageMojo extends AbstractCloudManagerMojo {
113113
@Parameter(property = "conga.cloudManager.allPackage.packageTypeValidation", defaultValue = "STRICT")
114114
private PackageTypeValidation packageTypeValidation;
115115

116+
/**
117+
* How to handle versions of packages and sub-packages inside "all" package.
118+
* <p>
119+
* Possible options see
120+
* <a href="apidocs/io/wcm/devops/conga/plugins/aem/maven/PackageVersionMode.html">PackageVersionMode</a>.
121+
* </p>
122+
*/
123+
@Parameter(property = "conga.cloudManager.allPackage.packageVersionMode", defaultValue = "DEFAULT")
124+
private PackageVersionMode packageVersionMode;
125+
116126
/**
117127
* Automatically generate dependencies between content packages based on file order in CONGA configuration.
118128
* @deprecated Please use autoDependenciesMode instead.
@@ -250,6 +260,7 @@ private AllPackageBuilder createBuilder(String packageName) {
250260
.autoDependenciesMode(this.autoDependenciesMode)
251261
.runModeOptimization(this.runModeOptimization)
252262
.packageTypeValidation(this.packageTypeValidation)
263+
.packageVersionMode(this.packageVersionMode)
253264
.logger(getLog())
254265
.buildOutputTimestamp(new BuildOutputTimestamp(outputTimestamp));
255266
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* #%L
3+
* wcm.io
4+
* %%
5+
* Copyright (C) 2022 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+
/**
23+
* How to handle versions of packages and sub-packages inside "all" package.
24+
*/
25+
public enum PackageVersionMode {
26+
27+
/**
28+
* Keep original versions.
29+
*/
30+
DEFAULT,
31+
32+
/**
33+
* Suffix the version number of all packages with a release version with the version of the POM the Mojo runs in.
34+
* Within the version suffix, dots are replaced with underlines to avoid convision with the main version number.
35+
* This is useful when deploying to AMS with Cloud Manager.
36+
* <p>
37+
* Example:
38+
* </p>
39+
* <ul>
40+
* <li>Original package version: 2.5.0</li>
41+
* <li>POM version: 2022.1103.152749.0000000571</li>
42+
* <li>Resulting package version: 2.5.0-2022_1103_152749_0000000571</li>
43+
* </ul>
44+
*/
45+
RELEASE_SUFFIX_VERSION
46+
47+
}

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

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import static org.apache.jackrabbit.vault.packaging.PackageProperties.NAME_DEPENDENCIES;
3030
import static org.apache.jackrabbit.vault.packaging.PackageProperties.NAME_NAME;
3131
import static org.apache.jackrabbit.vault.packaging.PackageProperties.NAME_PACKAGE_TYPE;
32+
import static org.apache.jackrabbit.vault.packaging.PackageProperties.NAME_VERSION;
3233

3334
import java.io.File;
3435
import java.io.FileOutputStream;
@@ -57,6 +58,7 @@
5758
import org.apache.jackrabbit.vault.packaging.DependencyUtil;
5859
import org.apache.jackrabbit.vault.packaging.PackageType;
5960
import org.apache.jackrabbit.vault.packaging.VersionRange;
61+
import org.apache.maven.artifact.ArtifactUtils;
6062
import org.apache.maven.plugin.logging.Log;
6163
import org.apache.maven.plugin.logging.SystemStreamLog;
6264
import org.jetbrains.annotations.NotNull;
@@ -67,6 +69,7 @@
6769
import io.wcm.devops.conga.plugins.aem.maven.AutoDependenciesMode;
6870
import io.wcm.devops.conga.plugins.aem.maven.BuildOutputTimestamp;
6971
import io.wcm.devops.conga.plugins.aem.maven.PackageTypeValidation;
72+
import io.wcm.devops.conga.plugins.aem.maven.PackageVersionMode;
7073
import io.wcm.devops.conga.plugins.aem.maven.RunModeOptimization;
7174
import io.wcm.devops.conga.plugins.aem.maven.model.BundleFile;
7275
import io.wcm.devops.conga.plugins.aem.maven.model.ContentPackageFile;
@@ -105,6 +108,7 @@ public final class AllPackageBuilder {
105108
private AutoDependenciesMode autoDependenciesMode = AutoDependenciesMode.OFF;
106109
private RunModeOptimization runModeOptimization = RunModeOptimization.OFF;
107110
private PackageTypeValidation packageTypeValidation = PackageTypeValidation.STRICT;
111+
private PackageVersionMode packageVersionMode = PackageVersionMode.DEFAULT;
108112
private Log log;
109113
private BuildOutputTimestamp buildOutputTimestamp;
110114

@@ -113,6 +117,7 @@ public final class AllPackageBuilder {
113117
PackageType.APPLICATION.name().toLowerCase(),
114118
PackageType.CONTAINER.name().toLowerCase(),
115119
PackageType.CONTENT.name().toLowerCase());
120+
private static final String VERSION_SUFFIX_SEPARATOR = "-";
116121

117122
private final List<ContentPackageFileSet> contentPackageFileSets = new ArrayList<>();
118123
private final List<BundleFileSet> bundleFileSets = new ArrayList<>();
@@ -156,6 +161,15 @@ public AllPackageBuilder packageTypeValidation(PackageTypeValidation value) {
156161
return this;
157162
}
158163

164+
/**
165+
* @param value How to handle versions of packages and sub-packages inside "all" package.
166+
* @return this
167+
*/
168+
public AllPackageBuilder packageVersionMode(PackageVersionMode value) {
169+
this.packageVersionMode = value;
170+
return this;
171+
}
172+
159173
/**
160174
* @param value Maven logger
161175
* @return this
@@ -457,8 +471,8 @@ private static String buildRootPath(String groupName, String packageName) {
457471

458472
/**
459473
* Generate suffix for instance and environment run modes.
460-
* @param file Content package
461-
* @return Package path
474+
* @param file File
475+
* @return Suffix string
462476
*/
463477
private static String buildRunModeSuffix(InstallableFile file, String environmentRunMode) {
464478
StringBuilder runModeSuffix = new StringBuilder();
@@ -474,6 +488,26 @@ else if (isOnlyPublish(file)) {
474488
return runModeSuffix.toString();
475489
}
476490

491+
/**
492+
* Generate suffix for versions of content packages.
493+
* @param pkg Content package
494+
* @param ignoreSnapshot Do not build version suffix for SNAPSHOT versions
495+
* @return Suffix string
496+
*/
497+
private String buildVersionSuffix(ContentPackageFile pkg, boolean ignoreSnapshot) {
498+
StringBuilder versionSuffix = new StringBuilder();
499+
500+
if (this.packageVersionMode == PackageVersionMode.RELEASE_SUFFIX_VERSION
501+
&& (!ArtifactUtils.isSnapshot(pkg.getVersion()) || !ignoreSnapshot)
502+
&& this.version != null) {
503+
versionSuffix.append(VERSION_SUFFIX_SEPARATOR)
504+
// replace dots with underlines in version suffix to avoid confusion with main version number
505+
.append(StringUtils.replace(this.version, ".", "_"));
506+
}
507+
508+
return versionSuffix.toString();
509+
}
510+
477511
/**
478512
* Build path to be used for embedded package.
479513
* @param pkg Package
@@ -492,7 +526,11 @@ private String buildPackagePath(ContentPackageFile pkg, String rootPath, String
492526

493527
String versionSuffix = "";
494528
String packageVersion = pkg.getVersion();
495-
if (packageVersion != null && pkg.getFile().getName().contains(packageVersion)) {
529+
String packageVersionWithoutSuffix = packageVersion;
530+
if (this.packageVersionMode == PackageVersionMode.RELEASE_SUFFIX_VERSION && this.version != null) {
531+
packageVersionWithoutSuffix = StringUtils.removeEnd(packageVersion, buildVersionSuffix(pkg, false));
532+
}
533+
if (packageVersion != null && pkg.getFile().getName().contains(packageVersionWithoutSuffix)) {
496534
versionSuffix = "-" + packageVersion;
497535
}
498536
String fileName = pkg.getName() + versionSuffix
@@ -554,6 +592,7 @@ private List<TemporaryContentPackageFile> processContentPackage(ContentPackageFi
554592
FileVaultProperties fileVaultProps = new FileVaultProperties(is);
555593
Properties props = fileVaultProps.getProperties();
556594
addSuffixToPackageName(props, pkg, environmentRunMode);
595+
addSuffixToVersion(props, pkg);
557596

558597
// update package dependencies
559598
ContentPackageFile dependencyFile = previousPkg;
@@ -562,7 +601,7 @@ private List<TemporaryContentPackageFile> processContentPackage(ContentPackageFi
562601
}
563602
updateDependencies(props, dependencyFile, environmentRunMode, allPackagesFromFileSets);
564603

565-
// if package type is missing package properties, put in the type defined in model
604+
// if package type is missing in package properties, put in the type defined in model
566605
String packageType = pkg.getPackageType();
567606
if (props.get(NAME_PACKAGE_TYPE) == null && packageType != null) {
568607
props.put(NAME_PACKAGE_TYPE, packageType);
@@ -583,7 +622,7 @@ else if (StringUtils.equals(FilenameUtils.getExtension(zipInEntry.getName()), "z
583622
}
584623

585624
// check if contained ZIP file is really a content package
586-
// then process it as well, remove if from the content package is was contained it
625+
// then process it as well, remove if from the content package is was contained in
587626
// and add it as "1st level package" to the all package
588627
TemporaryContentPackageFile tempSubPackage = new TemporaryContentPackageFile(tempSubPackageFile, pkg.getVariants());
589628
if (packageTypeValidation == PackageTypeValidation.STRICT && !isValidPackageType(tempSubPackage)) {
@@ -644,7 +683,7 @@ else if (in.getLastModifiedTime() != null) {
644683
* @param dependencyFile Dependency package
645684
* @param allPackagesFromFileSets Set with all packages from all file sets as dependency instances
646685
*/
647-
private static void updateDependencies(Properties props, ContentPackageFile dependencyFile, String environmentRunMode,
686+
private void updateDependencies(Properties props, ContentPackageFile dependencyFile, String environmentRunMode,
648687
Set<Dependency> allPackagesFromFileSets) {
649688
String[] existingDepsStrings = StringUtils.split(props.getProperty(NAME_DEPENDENCIES), ",");
650689
Dependency[] existingDeps = null;
@@ -658,9 +697,10 @@ private static void updateDependencies(Properties props, ContentPackageFile depe
658697
Dependency[] deps;
659698
if (dependencyFile != null) {
660699
String runModeSuffix = buildRunModeSuffix(dependencyFile, environmentRunMode);
700+
String dependencyVersion = dependencyFile.getVersion() + buildVersionSuffix(dependencyFile, true);
661701
Dependency newDependency = new Dependency(dependencyFile.getGroup(),
662702
dependencyFile.getName() + runModeSuffix,
663-
VersionRange.fromString(dependencyFile.getVersion()));
703+
VersionRange.fromString(dependencyVersion));
664704
deps = addDependency(existingDeps, newDependency);
665705
}
666706
else {
@@ -688,6 +728,15 @@ private static void addSuffixToPackageName(Properties props, ContentPackageFile
688728
props.put(NAME_NAME, packageName);
689729
}
690730

731+
private void addSuffixToVersion(Properties props, ContentPackageFile pkg) {
732+
// package version
733+
if (StringUtils.isEmpty(pkg.getVersion())) {
734+
return;
735+
}
736+
String suffixedVersion = pkg.getVersion() + buildVersionSuffix(pkg, true);
737+
props.put(NAME_VERSION, suffixedVersion);
738+
}
739+
691740
/**
692741
* Removes existing references to packages contained in the list of packages to manage by this builder because
693742
* they are added new (and probably with a different package name) during processing.

0 commit comments

Comments
 (0)