12 Commits
Author SHA1 Message Date
brian.long f1f3362f00 v1.0.7 pom 2022-04-04 17:52:48 -04:00
brian.long 846e02a439 Merge branch 'develop' into stable 2022-04-04 17:52:32 -04:00
brian.long de45b98652 added classifier support 2022-04-04 17:52:24 -04:00
brian.long 52aac1f24b v1.0.6 pom 2021-10-29 11:18:56 -04:00
brian.long 6f1e386a63 Merge branch 'develop' into stable 2021-10-29 11:18:51 -04:00
brian.long b25646c45e fixed NPE 2021-10-29 11:18:25 -04:00
brian.long 141a22941b excluding deps that are children of provided deps 2021-10-29 11:11:04 -04:00
brian.long 4ba804039d fixed true/false flip 2021-10-29 10:09:59 -04:00
brian.long 41d8067d09 fixed exclusion of all due to self ref 2021-10-29 10:06:16 -04:00
brian.long f2c4b0b3a7 https repo 2021-10-29 10:00:00 -04:00
brian.long 80521c89a1 fixed due to unpredictable dependency ordering 2021-10-29 09:56:52 -04:00
brian.long f116e493a2 ignoring AMPs from AMP packing 2021-10-29 09:10:03 -04:00
4 changed files with 131 additions and 29 deletions
+2 -3
View File
@@ -8,7 +8,7 @@
<groupId>com.inteligr8.alfresco</groupId>
<artifactId>amp-plugin</artifactId>
<version>1.0.5</version>
<version>1.0.7</version>
<packaging>maven-plugin</packaging>
<name>A Maven plugin to generate AMP files</name>
@@ -117,9 +117,8 @@
<repository>
<id>inteligr8-releases</id>
<name>Inteligr8 Releases</name>
<url>http://repos.inteligr8.com/nexus/repository/inteligr8-public</url>
<url>https://repos.inteligr8.com/nexus/repository/inteligr8-public</url>
</repository>
</distributionManagement>
</project>
@@ -7,6 +7,7 @@ import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
@@ -25,12 +26,17 @@ import org.eclipse.aether.resolution.ArtifactResult;
public class AmpDependencyFilter implements DependencyFilter {
private final Pattern modulePropertiesPattern = Pattern.compile("^alfresco/module/[^/]+/module\\.properties$");
private final String moduleExtension = "amp";
private final Set<String> ignoreDependenciesOfParentScopes = new HashSet<>(Arrays.asList("provided", "system"));
private final int streamBufferSize = 16 * 1024;
private final Log log;
private final Charset charset;
private final ArtifactResolutionCallback callback;
private final String projectModuleId;
private Set<String> moduleIds = new HashSet<String>();
private Set<String> notModuleIds = new HashSet<String>();
public AmpDependencyFilter(Log log, String charsetName, ArtifactResolutionCallback callback) {
this.log = log;
@@ -54,34 +60,73 @@ public class AmpDependencyFilter implements DependencyFilter {
if (this.log.isDebugEnabled())
this.log.debug("Checking dependency: " + artifact.getArtifactId());
String moduleId = this.getModuleId(artifact);
if (this.projectModuleId.equals(moduleId)) {
String possibleModuleId = this.getModuleId(artifact);
if (this.projectModuleId.equals(possibleModuleId)) {
// always include project itself, even if it is a module
return true;
}
if (this.moduleIds.contains(moduleId)) {
if (this.log.isDebugEnabled())
this.log.debug("Not packaging library; detected as Alfresco Module: " + node.getArtifact().getArtifactId());
return false;
} else if (parents != null) {
for (DependencyNode parent : parents) {
String parentModuleId = this.getModuleId(parent.getArtifact());
if (this.moduleIds.contains(parentModuleId)) {
this.moduleIds.add(moduleId);
if (this.log.isDebugEnabled())
this.log.debug("Not packaging library; detected as dependency to other Alfresco Module: " + node.getArtifact().getArtifactId());
return false;
}
try {
if (this.isOrIsInAlfrescoModule(possibleModuleId, node, parents.iterator())) {
if (this.log.isDebugEnabled())
this.log.debug("Not packaging library; detected as Alfresco Module or as dependency to other Alfresco Module: " + artifact.getArtifactId());
return false;
}
} catch (NotInScopeException nise) {
if (this.log.isDebugEnabled())
this.log.debug("Not packaging library; detected as provided by another dependency [" + nise.getNotInScopeParentArtifact() + "]: " + artifact.getArtifactId());
return false;
}
return true;
}
private boolean isOrIsInAlfrescoModule(String possibleModuleId, DependencyNode depNode, Iterator<DependencyNode> parents) throws NotInScopeException {
Artifact artifact = depNode.getArtifact();
if (this.projectModuleId.equals(possibleModuleId)) {
return false;
} else if (depNode.getDependency() != null && this.ignoreDependenciesOfParentScopes.contains(depNode.getDependency().getScope())) {
throw new NotInScopeException(artifact);
} else if (this.moduleIds.contains(possibleModuleId)) {
if (this.log.isDebugEnabled())
this.log.debug("Detected as Alfresco Module: " + artifact.getArtifactId());
return true;
} else if (this.notModuleIds.contains(possibleModuleId)) {
return false;
} else if (parents != null && parents.hasNext()) {
DependencyNode parentNode = parents.next();
String parentModuleId = this.getModuleId(parentNode.getArtifact());
if (this.log.isDebugEnabled())
this.log.debug("Checking parent dependency: " + artifact.getArtifactId());
if (this.isOrIsInAlfrescoModule(parentModuleId, parentNode, parents)) {
if (this.log.isDebugEnabled())
this.log.debug("Detected as dependency to other Alfresco Module: " + artifact.getArtifactId());
return true;
}
}
// never seen this artifact or its parents
return this.isAlfrescoModule(possibleModuleId, depNode);
}
private boolean isAlfrescoModule(String possibleModuleId, DependencyNode depNode) {
Artifact artifact = depNode.getArtifact();
if (this.moduleExtension.equalsIgnoreCase(artifact.getExtension())) {
if (this.log.isDebugEnabled())
this.log.debug("Detected as Alfresco Module: " + artifact.getArtifactId());
this.moduleIds.add(possibleModuleId);
return true;
}
File file = artifact.getFile();
try {
if (file == null) {
if (this.log.isDebugEnabled())
this.log.debug("Resolving dependency: " + artifact.getArtifactId());
ArtifactResult result = this.callback.resolveArtifact(new ArtifactRequest(node));
this.log.debug("Resolving dependency to get file: " + artifact.getArtifactId());
ArtifactResult result = this.callback.resolveArtifact(new ArtifactRequest(depNode));
if (result.isMissing() || !result.isResolved())
throw new ArtifactResolutionException(Arrays.asList(result));
artifact = result.getArtifact();
@@ -90,24 +135,25 @@ public class AmpDependencyFilter implements DependencyFilter {
if (this.log.isDebugEnabled())
this.log.debug("Checking dependency file: " + file);
if (this.isAlfrescoModule(file)) {
this.moduleIds.add(moduleId);
if (this.isAlfrescoModuleJar(file)) {
this.moduleIds.add(possibleModuleId);
if (this.log.isInfoEnabled())
this.log.info("Not packaging library; detected as Alfresco Module: " + node.getArtifact().getArtifactId());
return false;
this.log.info("Detected as Alfresco Module: " + artifact.getArtifactId());
return true;
}
return true;
this.notModuleIds.add(possibleModuleId);
return false;
} catch (ArtifactResolutionException are) {
this.log.warn("An artifact could not be resolved; assuming it is not an Alfresco module and continuing");
return true;
return false;
} catch (IOException ie) {
this.log.warn("An I/O issue occurred while inspecting a JAR to see if it is an Alfresco module; assuming it isn't and continuing");
return true;
return false;
}
}
}
private boolean isAlfrescoModule(File file) throws IOException {
public boolean isAlfrescoModuleJar(File file) throws IOException {
FileInputStream fistream = new FileInputStream(file);
BufferedInputStream bistream = new BufferedInputStream(fistream, this.streamBufferSize);
ZipInputStream zstream = new ZipInputStream(bistream, this.charset);
@@ -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);
@@ -0,0 +1,31 @@
package com.inteligr8.alfresco.amp;
import org.eclipse.aether.artifact.Artifact;
public class NotInScopeException extends Exception {
private static final long serialVersionUID = 8055701654626788700L;
private final Artifact notInScopeParentArtifact;
private Artifact impactedChildArtifact;
public NotInScopeException(Artifact notInScopeParentArtifact) {
super("The '" + notInScopeParentArtifact.getArtifactId() + "' artifact is not scope");
this.notInScopeParentArtifact = notInScopeParentArtifact;
}
public NotInScopeException(Artifact notInScopeParentArtifact, Artifact impactedChildArtifact) {
super("The '" + notInScopeParentArtifact.getArtifactId() + "' artifact is not scope, impacting the '" + impactedChildArtifact.getArtifactId() + "' artifact");
this.notInScopeParentArtifact = notInScopeParentArtifact;
this.impactedChildArtifact = impactedChildArtifact;
}
public Artifact getNotInScopeParentArtifact() {
return this.notInScopeParentArtifact;
}
public Artifact getImpactedChildArtifact() {
return this.impactedChildArtifact;
}
}