Search in sources :

Example 1 with CollectingDependencyNodeVisitor

use of org.apache.maven.shared.dependency.tree.traversal.CollectingDependencyNodeVisitor in project camel by apache.

the class SpringBootStarterMojo method filterIncludedArtifacts.

private Set<String> filterIncludedArtifacts(Set<String> artifacts) throws DependencyTreeBuilderException {
    Set<String> included = new TreeSet<>();
    ArtifactFilter artifactFilter = new ScopeArtifactFilter(null);
    DependencyNode node = treeBuilder.buildDependencyTree(project, localRepository, artifactFactory, artifactMetadataSource, artifactFilter, artifactCollector);
    CollectingDependencyNodeVisitor visitor = new CollectingDependencyNodeVisitor();
    node.accept(visitor);
    List<DependencyNode> nodes = visitor.getNodes();
    for (DependencyNode dependencyNode : nodes) {
        Artifact artifact = dependencyNode.getArtifact();
        getLog().debug("Found dependency node: " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() + " - scope=" + artifact.getScope());
        if (!Artifact.SCOPE_TEST.equals(artifact.getScope()) && !Artifact.SCOPE_PROVIDED.equals(artifact.getScope())) {
            String canonicalName = artifact.getGroupId() + ":" + artifact.getArtifactId();
            if (artifacts.contains(canonicalName)) {
                getLog().debug(canonicalName + " marked for exclusion");
                included.add(canonicalName);
            }
        }
    }
    return included;
}
Also used : ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) CollectingDependencyNodeVisitor(org.apache.maven.shared.dependency.tree.traversal.CollectingDependencyNodeVisitor) ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) TreeSet(java.util.TreeSet) DependencyNode(org.apache.maven.shared.dependency.tree.DependencyNode) Artifact(org.apache.maven.artifact.Artifact)

Example 2 with CollectingDependencyNodeVisitor

use of org.apache.maven.shared.dependency.tree.traversal.CollectingDependencyNodeVisitor in project scala-maven-plugin by davidB.

the class ScalaMojoSupport method checkArtifactForScalaVersion.

/**
 * Visits a node (and all dependencies) to see if it contains duplicate scala versions
 */
private void checkArtifactForScalaVersion(VersionNumber requiredScalaVersion, DependencyNode rootNode) throws Exception {
    final CheckScalaVersionVisitor visitor = new CheckScalaVersionVisitor(requiredScalaVersion, getLog(), getScalaOrganization());
    CollectingDependencyNodeVisitor collectingVisitor = new CollectingDependencyNodeVisitor();
    DependencyNodeVisitor firstPassVisitor = new FilteringDependencyNodeVisitor(collectingVisitor, createScalaDistroDependencyFilter());
    rootNode.accept(firstPassVisitor);
    DependencyNodeFilter secondPassFilter = new AncestorOrSelfDependencyNodeFilter(collectingVisitor.getNodes());
    DependencyNodeVisitor filteredVisitor = new FilteringDependencyNodeVisitor(visitor, secondPassFilter);
    rootNode.accept(filteredVisitor);
    if (visitor.isFailed()) {
        visitor.logScalaDependents();
        if (failOnMultipleScalaVersions) {
            getLog().error("Multiple versions of scala libraries detected!");
            throw new MojoFailureException("Multiple versions of scala libraries detected!");
        }
        getLog().warn("Multiple versions of scala libraries detected!");
    }
}
Also used : FilteringDependencyNodeVisitor(org.apache.maven.shared.dependency.tree.traversal.FilteringDependencyNodeVisitor) CollectingDependencyNodeVisitor(org.apache.maven.shared.dependency.tree.traversal.CollectingDependencyNodeVisitor) AncestorOrSelfDependencyNodeFilter(org.apache.maven.shared.dependency.tree.filter.AncestorOrSelfDependencyNodeFilter) CheckScalaVersionVisitor(scala_maven_dependency.CheckScalaVersionVisitor) AncestorOrSelfDependencyNodeFilter(org.apache.maven.shared.dependency.tree.filter.AncestorOrSelfDependencyNodeFilter) AndDependencyNodeFilter(org.apache.maven.shared.dependency.tree.filter.AndDependencyNodeFilter) DependencyNodeFilter(org.apache.maven.shared.dependency.tree.filter.DependencyNodeFilter) MojoFailureException(org.apache.maven.plugin.MojoFailureException) DependencyNodeVisitor(org.apache.maven.shared.dependency.tree.traversal.DependencyNodeVisitor) FilteringDependencyNodeVisitor(org.apache.maven.shared.dependency.tree.traversal.FilteringDependencyNodeVisitor) CollectingDependencyNodeVisitor(org.apache.maven.shared.dependency.tree.traversal.CollectingDependencyNodeVisitor)

Example 3 with CollectingDependencyNodeVisitor

use of org.apache.maven.shared.dependency.tree.traversal.CollectingDependencyNodeVisitor in project maven-plugins by apache.

the class DependencyConvergenceReport method serializeDependencyTree.

/**
 * Serializes the specified dependency tree to a string.
 *
 * @param rootNode the dependency tree root node to serialize
 * @return the serialized dependency tree
 */
private void serializeDependencyTree(DependencyNode rootNode, String key, Sink sink) {
    DependencyNodeVisitor visitor = getSerializingDependencyNodeVisitor(sink);
    visitor = new BuildingDependencyNodeVisitor(visitor);
    DependencyNodeFilter filter = createDependencyNodeFilter(key);
    if (filter != null) {
        CollectingDependencyNodeVisitor collectingVisitor = new CollectingDependencyNodeVisitor();
        DependencyNodeVisitor firstPassVisitor = new FilteringDependencyNodeVisitor(collectingVisitor, filter);
        rootNode.accept(firstPassVisitor);
        DependencyNodeFilter secondPassFilter = new AncestorOrSelfDependencyNodeFilter(collectingVisitor.getNodes());
        visitor = new FilteringDependencyNodeVisitor(visitor, secondPassFilter);
    }
    rootNode.accept(visitor);
}
Also used : FilteringDependencyNodeVisitor(org.apache.maven.shared.dependency.tree.traversal.FilteringDependencyNodeVisitor) CollectingDependencyNodeVisitor(org.apache.maven.shared.dependency.tree.traversal.CollectingDependencyNodeVisitor) BuildingDependencyNodeVisitor(org.apache.maven.shared.dependency.tree.traversal.BuildingDependencyNodeVisitor) AncestorOrSelfDependencyNodeFilter(org.apache.maven.shared.dependency.tree.filter.AncestorOrSelfDependencyNodeFilter) ArtifactDependencyNodeFilter(org.apache.maven.shared.dependency.tree.filter.ArtifactDependencyNodeFilter) AncestorOrSelfDependencyNodeFilter(org.apache.maven.shared.dependency.tree.filter.AncestorOrSelfDependencyNodeFilter) AndDependencyNodeFilter(org.apache.maven.shared.dependency.tree.filter.AndDependencyNodeFilter) DependencyNodeFilter(org.apache.maven.shared.dependency.tree.filter.DependencyNodeFilter) SinkSerializingDependencyNodeVisitor(org.apache.maven.report.projectinfo.dependencies.SinkSerializingDependencyNodeVisitor) DependencyNodeVisitor(org.apache.maven.shared.dependency.tree.traversal.DependencyNodeVisitor) FilteringDependencyNodeVisitor(org.apache.maven.shared.dependency.tree.traversal.FilteringDependencyNodeVisitor) CollectingDependencyNodeVisitor(org.apache.maven.shared.dependency.tree.traversal.CollectingDependencyNodeVisitor) BuildingDependencyNodeVisitor(org.apache.maven.shared.dependency.tree.traversal.BuildingDependencyNodeVisitor)

Aggregations

CollectingDependencyNodeVisitor (org.apache.maven.shared.dependency.tree.traversal.CollectingDependencyNodeVisitor)3 AncestorOrSelfDependencyNodeFilter (org.apache.maven.shared.dependency.tree.filter.AncestorOrSelfDependencyNodeFilter)2 AndDependencyNodeFilter (org.apache.maven.shared.dependency.tree.filter.AndDependencyNodeFilter)2 DependencyNodeFilter (org.apache.maven.shared.dependency.tree.filter.DependencyNodeFilter)2 DependencyNodeVisitor (org.apache.maven.shared.dependency.tree.traversal.DependencyNodeVisitor)2 FilteringDependencyNodeVisitor (org.apache.maven.shared.dependency.tree.traversal.FilteringDependencyNodeVisitor)2 TreeSet (java.util.TreeSet)1 Artifact (org.apache.maven.artifact.Artifact)1 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)1 ScopeArtifactFilter (org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 SinkSerializingDependencyNodeVisitor (org.apache.maven.report.projectinfo.dependencies.SinkSerializingDependencyNodeVisitor)1 DependencyNode (org.apache.maven.shared.dependency.tree.DependencyNode)1 ArtifactDependencyNodeFilter (org.apache.maven.shared.dependency.tree.filter.ArtifactDependencyNodeFilter)1 BuildingDependencyNodeVisitor (org.apache.maven.shared.dependency.tree.traversal.BuildingDependencyNodeVisitor)1 CheckScalaVersionVisitor (scala_maven_dependency.CheckScalaVersionVisitor)1