Search in sources :

Example 1 with DependencyNodeFilter

use of org.apache.maven.shared.dependency.graph.filter.DependencyNodeFilter in project maven-plugins by apache.

the class TreeMojo 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 String serializeDependencyTree(DependencyNode rootNode) {
    StringWriter writer = new StringWriter();
    DependencyNodeVisitor visitor = getSerializingDependencyNodeVisitor(writer);
    // TODO: remove the need for this when the serializer can calculate last nodes from visitor calls only
    visitor = new BuildingDependencyNodeVisitor(visitor);
    DependencyNodeFilter filter = createDependencyNodeFilter();
    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);
    return writer.toString();
}
Also used : FilteringDependencyNodeVisitor(org.apache.maven.shared.dependency.graph.traversal.FilteringDependencyNodeVisitor) CollectingDependencyNodeVisitor(org.apache.maven.shared.dependency.graph.traversal.CollectingDependencyNodeVisitor) BuildingDependencyNodeVisitor(org.apache.maven.shared.dependency.graph.traversal.BuildingDependencyNodeVisitor) StringWriter(java.io.StringWriter) AncestorOrSelfDependencyNodeFilter(org.apache.maven.shared.dependency.graph.filter.AncestorOrSelfDependencyNodeFilter) ArtifactDependencyNodeFilter(org.apache.maven.shared.dependency.graph.filter.ArtifactDependencyNodeFilter) DependencyNodeFilter(org.apache.maven.shared.dependency.graph.filter.DependencyNodeFilter) AndDependencyNodeFilter(org.apache.maven.shared.dependency.graph.filter.AndDependencyNodeFilter) AncestorOrSelfDependencyNodeFilter(org.apache.maven.shared.dependency.graph.filter.AncestorOrSelfDependencyNodeFilter) FilteringDependencyNodeVisitor(org.apache.maven.shared.dependency.graph.traversal.FilteringDependencyNodeVisitor) DependencyNodeVisitor(org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor) BuildingDependencyNodeVisitor(org.apache.maven.shared.dependency.graph.traversal.BuildingDependencyNodeVisitor) CollectingDependencyNodeVisitor(org.apache.maven.shared.dependency.graph.traversal.CollectingDependencyNodeVisitor) SerializingDependencyNodeVisitor(org.apache.maven.shared.dependency.graph.traversal.SerializingDependencyNodeVisitor)

Example 2 with DependencyNodeFilter

use of org.apache.maven.shared.dependency.graph.filter.DependencyNodeFilter in project maven-plugins by apache.

the class TreeMojo method createDependencyNodeFilter.

/**
     * Gets the dependency node filter to use when serializing the dependency graph.
     *
     * @return the dependency node filter, or <code>null</code> if none required
     */
private DependencyNodeFilter createDependencyNodeFilter() {
    List<DependencyNodeFilter> filters = new ArrayList<DependencyNodeFilter>();
    // filter includes
    if (includes != null) {
        List<String> patterns = Arrays.asList(includes.split(","));
        getLog().debug("+ Filtering dependency tree by artifact include patterns: " + patterns);
        ArtifactFilter artifactFilter = new StrictPatternIncludesArtifactFilter(patterns);
        filters.add(new ArtifactDependencyNodeFilter(artifactFilter));
    }
    // filter excludes
    if (excludes != null) {
        List<String> patterns = Arrays.asList(excludes.split(","));
        getLog().debug("+ Filtering dependency tree by artifact exclude patterns: " + patterns);
        ArtifactFilter artifactFilter = new StrictPatternExcludesArtifactFilter(patterns);
        filters.add(new ArtifactDependencyNodeFilter(artifactFilter));
    }
    return filters.isEmpty() ? null : new AndDependencyNodeFilter(filters);
}
Also used : StrictPatternExcludesArtifactFilter(org.apache.maven.shared.artifact.filter.StrictPatternExcludesArtifactFilter) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) StrictPatternIncludesArtifactFilter(org.apache.maven.shared.artifact.filter.StrictPatternIncludesArtifactFilter) ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) StrictPatternIncludesArtifactFilter(org.apache.maven.shared.artifact.filter.StrictPatternIncludesArtifactFilter) ArtifactDependencyNodeFilter(org.apache.maven.shared.dependency.graph.filter.ArtifactDependencyNodeFilter) StrictPatternExcludesArtifactFilter(org.apache.maven.shared.artifact.filter.StrictPatternExcludesArtifactFilter) AndDependencyNodeFilter(org.apache.maven.shared.dependency.graph.filter.AndDependencyNodeFilter) ArrayList(java.util.ArrayList) ArtifactDependencyNodeFilter(org.apache.maven.shared.dependency.graph.filter.ArtifactDependencyNodeFilter) DependencyNodeFilter(org.apache.maven.shared.dependency.graph.filter.DependencyNodeFilter) AndDependencyNodeFilter(org.apache.maven.shared.dependency.graph.filter.AndDependencyNodeFilter) AncestorOrSelfDependencyNodeFilter(org.apache.maven.shared.dependency.graph.filter.AncestorOrSelfDependencyNodeFilter)

Aggregations

AncestorOrSelfDependencyNodeFilter (org.apache.maven.shared.dependency.graph.filter.AncestorOrSelfDependencyNodeFilter)2 AndDependencyNodeFilter (org.apache.maven.shared.dependency.graph.filter.AndDependencyNodeFilter)2 ArtifactDependencyNodeFilter (org.apache.maven.shared.dependency.graph.filter.ArtifactDependencyNodeFilter)2 DependencyNodeFilter (org.apache.maven.shared.dependency.graph.filter.DependencyNodeFilter)2 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)1 ScopeArtifactFilter (org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter)1 StrictPatternExcludesArtifactFilter (org.apache.maven.shared.artifact.filter.StrictPatternExcludesArtifactFilter)1 StrictPatternIncludesArtifactFilter (org.apache.maven.shared.artifact.filter.StrictPatternIncludesArtifactFilter)1 BuildingDependencyNodeVisitor (org.apache.maven.shared.dependency.graph.traversal.BuildingDependencyNodeVisitor)1 CollectingDependencyNodeVisitor (org.apache.maven.shared.dependency.graph.traversal.CollectingDependencyNodeVisitor)1 DependencyNodeVisitor (org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor)1 FilteringDependencyNodeVisitor (org.apache.maven.shared.dependency.graph.traversal.FilteringDependencyNodeVisitor)1 SerializingDependencyNodeVisitor (org.apache.maven.shared.dependency.graph.traversal.SerializingDependencyNodeVisitor)1