diff --git a/src/main/java/com/inteligr8/wildfly/maven/IndexingDependencyGraphTransformer.java b/src/main/java/com/inteligr8/wildfly/maven/IndexingDependencyGraphTransformer.java index c82e763..4c1d320 100644 --- a/src/main/java/com/inteligr8/wildfly/maven/IndexingDependencyGraphTransformer.java +++ b/src/main/java/com/inteligr8/wildfly/maven/IndexingDependencyGraphTransformer.java @@ -16,21 +16,21 @@ package com.inteligr8.wildfly.maven; import java.util.Collections; import java.util.List; -import java.util.Set; import java.util.Stack; import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.DefaultArtifact; +import org.apache.maven.artifact.handler.DefaultArtifactHandler; +import org.apache.maven.artifact.resolver.filter.ExclusionArtifactFilter; +import org.apache.maven.model.Exclusion; import org.apache.maven.model.building.ModelBuildingException; import org.apache.maven.model.resolution.UnresolvableModelException; import org.eclipse.aether.RepositoryException; -import org.eclipse.aether.artifact.DefaultArtifact; import org.eclipse.aether.collection.DependencyGraphTransformationContext; import org.eclipse.aether.collection.DependencyGraphTransformer; import org.eclipse.aether.graph.DependencyFilter; import org.eclipse.aether.graph.DependencyNode; -import org.eclipse.aether.resolution.ArtifactRequest; import org.eclipse.aether.resolution.ArtifactResolutionException; -import org.eclipse.aether.resolution.ArtifactResult; import org.eclipse.aether.util.artifact.JavaScopes; import org.eclipse.aether.util.filter.DependencyFilterUtils; import org.eclipse.aether.util.filter.ScopeDependencyFilter; @@ -67,7 +67,7 @@ public class IndexingDependencyGraphTransformer implements DependencyGraphTransf */ @Override public DependencyNode transformGraph(DependencyNode node, DependencyGraphTransformationContext context) throws RepositoryException { - this.crawl(node, new Stack()); + this.crawl(node, new Stack(), new Stack()); return this.transfomer.transformGraph(node, context); } @@ -78,16 +78,42 @@ public class IndexingDependencyGraphTransformer implements DependencyGraphTransf * @param node A dependency. * @param ancestors A stack of ancestral artifacts; parent on top; root on bottom; empty if root. */ - private void crawl(DependencyNode node, Stack ancestors) { + private void crawl(DependencyNode node, Stack ancestors, Stack exclusions) { + if (this.dac.getLog().isDebugEnabled()) + this.dac.getLog().debug("Crawling: " + ancestors + ": " + node); + if (!new ExclusionArtifactFilter(exclusions).include(this.toMavenArtifact(node.getArtifact()))) { + if (this.dac.getLog().isDebugEnabled()) + this.dac.getLog().debug("Excluding: " + node); + return; + } + if (!this.filter.accept(node, ancestors)) return; + boolean doExclude = node.getDependency() != null && node.getDependency().getExclusions() != null && !node.getDependency().getExclusions().isEmpty(); + int pushedExclusions = 0; + if (doExclude) { + if (this.dac.getLog().isDebugEnabled()) + this.dac.getLog().debug("Will start excluding: " + node.getDependency().getExclusions()); + for (org.eclipse.aether.graph.Exclusion exclusion : node.getDependency().getExclusions()) { + exclusions.push(this.toMavenExclusion(exclusion)); + pushedExclusions++; + } + } + this.index(node, Collections.unmodifiableList(ancestors)); ancestors.push(node); for (DependencyNode child : node.getChildren()) - this.crawl(child, ancestors); + this.crawl(child, ancestors, exclusions); ancestors.pop(); + + if (doExclude) { + if (this.dac.getLog().isDebugEnabled()) + this.dac.getLog().debug("Will stop excluding: " + node.getDependency().getExclusions()); + for (int e = 0; e < pushedExclusions; e++) + exclusions.pop(); + } } /** @@ -121,17 +147,22 @@ public class IndexingDependencyGraphTransformer implements DependencyGraphTransf switch (type) { case SystemModule: - case InSystemModule: if (this.dac.getLog().isDebugEnabled()) this.dac.getLog().debug(nodeId + ": is in a module"); this.dindex.indexType(nodeId, DependencyType.InSystemModule); return; + case InSystemModule: + this.dac.getLog().debug(nodeId + ": is a dependency of something in a module, but not yet indexed (was excluded?)"); + //this.dindex.indexType(nodeId, DependencyType.InSystemModule); + return; case Module: - case InModule: if (this.dac.getLog().isDebugEnabled()) this.dac.getLog().debug(nodeId + ": is in a module"); this.dindex.indexType(nodeId, DependencyType.InModule); return; + case InModule: + this.dac.getLog().debug(nodeId + ": is a dependency of something in a module, but not yet indexed (was excluded?)"); + return; default: // continue } @@ -165,5 +196,19 @@ public class IndexingDependencyGraphTransformer implements DependencyGraphTransf this.dac.getLog().warn("Filtering out dependency '" + node.getDependency() + "' due to exception", e); } } + + private Artifact toMavenArtifact(org.eclipse.aether.artifact.Artifact aetherArtifact) { + Artifact artifact = new DefaultArtifact(aetherArtifact.getGroupId(), aetherArtifact.getArtifactId(), aetherArtifact.getVersion(), DefaultArtifact.SCOPE_COMPILE, aetherArtifact.getExtension(), aetherArtifact.getClassifier(), new DefaultArtifactHandler()); + artifact.setGroupId(aetherArtifact.getGroupId()); + artifact.setArtifactId(aetherArtifact.getArtifactId()); + return artifact; + } + + private Exclusion toMavenExclusion(org.eclipse.aether.graph.Exclusion aetherExclusion) { + Exclusion exclusion = new Exclusion(); + exclusion.setGroupId(aetherExclusion.getGroupId()); + exclusion.setArtifactId(aetherExclusion.getArtifactId()); + return exclusion; + } } diff --git a/src/main/java/com/inteligr8/wildfly/maven/ValidationDependencyFilter.java b/src/main/java/com/inteligr8/wildfly/maven/ValidationDependencyFilter.java index cb196ed..f9f1eb2 100644 --- a/src/main/java/com/inteligr8/wildfly/maven/ValidationDependencyFilter.java +++ b/src/main/java/com/inteligr8/wildfly/maven/ValidationDependencyFilter.java @@ -43,10 +43,14 @@ public class ValidationDependencyFilter implements DependencyFilter { DependencyType type = this.dindex.getType(parentId); if (type == null) { - switch (parent.getDependency().getScope()) { - case "test": - this.dac.getLog().debug("The dependency parent was excluded as a test artifact: " + parent); - default: + if (parent.getDependency() == null) { + this.dac.getLog().warn("Has no dependency information: " + parent.getArtifact() + " => " + node.getArtifact()); + } else { + switch (parent.getDependency().getScope()) { + case "test": + this.dac.getLog().debug("The dependency parent was excluded as a test artifact: " + parent); + default: + } } continue;