From de45b986526240e7abaabcca66aabec7d3d31dda Mon Sep 17 00:00:00 2001 From: "Brian M. Long" Date: Mon, 4 Apr 2022 17:52:24 -0400 Subject: [PATCH] added classifier support --- .../com/inteligr8/alfresco/amp/AmpMojo.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main/java/com/inteligr8/alfresco/amp/AmpMojo.java b/src/main/java/com/inteligr8/alfresco/amp/AmpMojo.java index 278e254..e2a1257 100644 --- a/src/main/java/com/inteligr8/alfresco/amp/AmpMojo.java +++ b/src/main/java/com/inteligr8/alfresco/amp/AmpMojo.java @@ -63,6 +63,9 @@ public class AmpMojo extends AbstractMojo implements ArtifactResolutionCallback @Requirement private ArtifactResolver artifactResolver; + + @Parameter( property = "classifier", required = false ) + protected String classifier; @Parameter( property = "outputFile", required = true, defaultValue = "${project.build.directory}/${project.artifactId}-${project.version}.amp" ) protected String outputAmpFile; @@ -103,6 +106,13 @@ public class AmpMojo extends AbstractMojo implements ArtifactResolutionCallback } this.getLog().debug("Executing AMP packaging"); + this.classifier = StringUtils.trimToNull(this.classifier); + if (this.classifier != null) { + this.getLog().info("A classifier was specified; injecting classifier into module and output artifact names"); + this.outputAmpFile = this.injectClassifier(this.outputAmpFile); + this.moduleJarFile = this.injectClassifier(this.moduleJarFile); + } + this.normalize(); File ampFile = this.getOutputFile(); @@ -134,6 +144,22 @@ public class AmpMojo extends AbstractMojo implements ArtifactResolutionCallback } } + private String injectClassifier(String filename) { + int lastDot = filename.lastIndexOf('.'); + if (lastDot < 0) + throw new IllegalArgumentException(); + + int lastDash = filename.lastIndexOf('-', lastDot-1); + if (lastDash > 0) { + // see if the classifier was already specified + String possibleClassifier = filename.substring(lastDash+1, lastDot); + if (this.classifier.equals(possibleClassifier)) + return filename; + } + + return filename.substring(0, lastDot) + '-' + this.classifier + filename.substring(lastDot); + } + private void normalize() { this.outputAmpFile = StringUtils.trimToNull(this.outputAmpFile); this.moduleJarFile = StringUtils.trimToNull(this.moduleJarFile);