fixed due to unpredictable dependency ordering

This commit is contained in:
2021-10-29 09:56:52 -04:00
parent f116e493a2
commit 80521c89a1

View File

@@ -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,16 @@ 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 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;
@@ -60,25 +65,44 @@ public class AmpDependencyFilter implements DependencyFilter {
return true;
}
if (this.isOrIsInAlfrescoModule(moduleId, 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;
}
return true;
}
private boolean isOrIsInAlfrescoModule(String moduleId, DependencyNode moduleNode, Iterator<DependencyNode> parents) {
Artifact artifact = moduleNode.getArtifact();
if (this.moduleIds.contains(moduleId)) {
if (this.log.isDebugEnabled())
this.log.debug("Not packaging library; detected as Alfresco Module: " + node.getArtifact().getArtifactId());
this.log.debug("Detected as Alfresco Module: " + artifact.getArtifactId());
return true;
} else if (this.notModuleIds.contains(moduleId)) {
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;
}
} else if (parents != null && parents.hasNext()) {
DependencyNode parentNode = parents.next();
String parentModuleId = this.getModuleId(parentNode.getArtifact());
if (this.isOrIsInAlfrescoModule(parentModuleId, parentNode, parents)) {
if (this.log.isDebugEnabled())
this.log.debug("Detected as dependency to other Alfresco Module: " + artifact.getArtifactId());
return true;
}
}
if ("amp".equalsIgnoreCase(artifact.getExtension())) {
// never seen this artifact or its parents
return this.isAlfrescoModule(moduleId, moduleNode);
}
private boolean isAlfrescoModule(String moduleId, DependencyNode moduleNode) {
Artifact artifact = moduleNode.getArtifact();
if (this.moduleExtension.equalsIgnoreCase(artifact.getExtension())) {
if (this.log.isDebugEnabled())
this.log.debug("Not packaging library; detected as Alfresco Module: " + node.getArtifact().getArtifactId());
this.log.debug("Not packaging library; detected as Alfresco Module: " + artifact.getArtifactId());
this.moduleIds.add(moduleId);
return false;
}
@@ -88,7 +112,7 @@ public class AmpDependencyFilter implements DependencyFilter {
if (file == null) {
if (this.log.isDebugEnabled())
this.log.debug("Resolving dependency: " + artifact.getArtifactId());
ArtifactResult result = this.callback.resolveArtifact(new ArtifactRequest(node));
ArtifactResult result = this.callback.resolveArtifact(new ArtifactRequest(moduleNode));
if (result.isMissing() || !result.isResolved())
throw new ArtifactResolutionException(Arrays.asList(result));
artifact = result.getArtifact();
@@ -97,13 +121,14 @@ public class AmpDependencyFilter implements DependencyFilter {
if (this.log.isDebugEnabled())
this.log.debug("Checking dependency file: " + file);
if (this.isAlfrescoModule(file)) {
if (this.isAlfrescoModuleJar(file)) {
this.moduleIds.add(moduleId);
if (this.log.isInfoEnabled())
this.log.info("Not packaging library; detected as Alfresco Module: " + node.getArtifact().getArtifactId());
this.log.info("Not packaging library; detected as Alfresco Module: " + artifact.getArtifactId());
return false;
}
this.notModuleIds.add(moduleId);
return true;
} catch (ArtifactResolutionException are) {
this.log.warn("An artifact could not be resolved; assuming it is not an Alfresco module and continuing");
@@ -112,9 +137,9 @@ public class AmpDependencyFilter implements DependencyFilter {
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;
}
}
}
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);