Commit 141a2294 authored by Brian Long's avatar Brian Long
Browse files

excluding deps that are children of provided deps

parent 4ba80403
Loading
Loading
Loading
Loading
+16 −3
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ 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;
@@ -65,16 +66,22 @@ public class AmpDependencyFilter implements DependencyFilter {
			return true;
		}
		
		try {
			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;
			}
		} 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 moduleId, DependencyNode moduleNode, Iterator<DependencyNode> parents) {
	private boolean isOrIsInAlfrescoModule(String moduleId, DependencyNode moduleNode, Iterator<DependencyNode> parents) throws NotInScopeException {
    	Artifact artifact = moduleNode.getArtifact();
    	
    	if (this.projectModuleId.equals(moduleId)) {
@@ -87,7 +94,13 @@ public class AmpDependencyFilter implements DependencyFilter {
			return false;
		} else if (parents != null && parents.hasNext()) {
			DependencyNode parentNode = parents.next();
			if (this.ignoreDependenciesOfParentScopes.contains(parentNode.getDependency().getScope()))
				throw new NotInScopeException(parentNode.getArtifact(), artifact);
			
			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());
+26 −0
Original line number Diff line number Diff line
package com.inteligr8.alfresco.amp;

import org.eclipse.aether.artifact.Artifact;

public class NotInScopeException extends Exception {

	private static final long serialVersionUID = 8055701654626788700L;
	
	private Artifact notInScopeParentArtifact;
	private Artifact impactedChildArtifact;
	
	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;
	}

}