maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hbout...@apache.org
Subject svn commit: r1478593 - in /maven/plugins/trunk/maven-dependency-plugin: ./ src/it/tree-verbose/ src/main/java/org/apache/maven/plugin/dependency/
Date Thu, 02 May 2013 22:43:07 GMT
Author: hboutemy
Date: Thu May  2 22:43:06 2013
New Revision: 1478593

URL: http://svn.apache.org/r1478593
Log:
[MDEP-374] restore dependency:tree verbose mode

Added:
    maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/
    maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/expected.txt   (with props)
    maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/invoker.properties   (with
props)
    maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/pom.xml   (with props)
    maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/verify.bsh   (with props)
Modified:
    maven/plugins/trunk/maven-dependency-plugin/pom.xml
    maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/TreeMojo.java

Modified: maven/plugins/trunk/maven-dependency-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/pom.xml?rev=1478593&r1=1478592&r2=1478593&view=diff
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-dependency-plugin/pom.xml Thu May  2 22:43:06 2013
@@ -176,7 +176,7 @@ under the License.
     <dependency>
       <groupId>org.apache.maven.shared</groupId>
       <artifactId>maven-dependency-tree</artifactId>
-      <version>2.0</version>
+      <version>2.1-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.apache.maven.shared</groupId>

Added: maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/expected.txt
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/expected.txt?rev=1478593&view=auto
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/expected.txt (added)
+++ maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/expected.txt Thu May 
2 22:43:06 2013
@@ -0,0 +1,84 @@
+org.apache.maven.its.dependency:tree-verbose:jar:1.0-SNAPSHOT
++- org.apache.maven:maven-project:jar:2.0.6:compile
+|  +- org.apache.maven:maven-settings:jar:2.0.6:compile
+|  |  +- (org.apache.maven:maven-model:jar:2.0.5:test - version managed from 2.0.6; scope
managed from compile; omitted for duplicate)
+|  |  +- (org.codehaus.plexus:plexus-utils:jar:1.4.1:compile - omitted for duplicate)
+|  |  \- (org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9-stable-1:compile -
omitted for duplicate)
+|  +- (org.apache.maven:maven-profile:jar:2.0.6:compile - omitted for conflict with 2.0.4)
+|  +- (org.apache.maven:maven-model:jar:2.0.5:test - version managed from 2.0.4; scope managed
from compile; omitted for conflict with 2.0.7)
+|  +- org.apache.maven:maven-artifact-manager:jar:2.0.6:compile
+|  |  +- org.apache.maven:maven-repository-metadata:jar:2.0.6:compile
+|  |  |  \- (org.codehaus.plexus:plexus-utils:jar:1.4.1:compile - omitted for duplicate)
+|  |  +- (org.codehaus.plexus:plexus-utils:jar:1.4.1:compile - omitted for duplicate)
+|  |  +- (org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9-stable-1:compile -
omitted for duplicate)
+|  |  \- org.apache.maven.wagon:wagon-provider-api:jar:1.0-beta-2:compile
+|  |     \- (org.codehaus.plexus:plexus-utils:jar:1.0.4:compile - omitted for conflict with
1.4.1)
+|  +- org.apache.maven:maven-plugin-registry:jar:2.0.6:compile
+|  |  +- (org.codehaus.plexus:plexus-utils:jar:1.4.1:compile - omitted for duplicate)
+|  |  \- (org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9-stable-1:compile -
omitted for duplicate)
+|  +- org.codehaus.plexus:plexus-utils:jar:1.4.1:compile
+|  \- org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9-stable-1:compile
+|     +- junit:junit:jar:3.8.1:compile
+|     +- (org.codehaus.plexus:plexus-utils:jar:1.0.4:compile - omitted for conflict with
1.4.1)
+|     \- classworlds:classworlds:jar:1.1-alpha-2:compile
++- org.apache.maven:maven-profile:jar:2.0.4:test (scope not updated to compile)
+|  +- (org.apache.maven:maven-model:jar:2.0.5:test - version managed from 2.0.4; scope managed
from compile; omitted for duplicate)
+|  +- (org.codehaus.plexus:plexus-utils:jar:1.1:test - omitted for conflict with 1.4.1)
+|  \- (org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9:test - omitted for conflict
with 1.0-alpha-9-stable-1)
++- org.apache.maven:maven-model:jar:2.0.7:runtime
+|  \- (org.codehaus.plexus:plexus-utils:jar:1.4.1:runtime - omitted for duplicate)
+\- org.apache.xmlgraphics:batik-bridge:jar:1.7:compile
+   +- org.apache.xmlgraphics:batik-anim:jar:1.7:compile
+   |  +- (org.apache.xmlgraphics:batik-awt-util:jar:1.7:compile - omitted for duplicate)
+   |  +- (org.apache.xmlgraphics:batik-dom:jar:1.7:compile - omitted for duplicate)
+   |  +- (org.apache.xmlgraphics:batik-ext:jar:1.7:compile - omitted for duplicate)
+   |  +- (org.apache.xmlgraphics:batik-parser:jar:1.7:compile - omitted for duplicate)
+   |  +- (org.apache.xmlgraphics:batik-anim:jar:1.7:compile - omitted for cycle)
+   |  +- (org.apache.xmlgraphics:batik-svg-dom:jar:1.7:compile - omitted for duplicate)
+   |  +- (org.apache.xmlgraphics:batik-util:jar:1.7:compile - omitted for duplicate)
+   |  +- (xml-apis:xml-apis:jar:1.3.04:compile - omitted for duplicate)
+   |  \- (xml-apis:xml-apis-ext:jar:1.3.04:compile - omitted for duplicate)
+   +- org.apache.xmlgraphics:batik-awt-util:jar:1.7:compile
+   |  \- (org.apache.xmlgraphics:batik-util:jar:1.7:compile - omitted for duplicate)
+   +- org.apache.xmlgraphics:batik-css:jar:1.7:compile
+   |  +- (org.apache.xmlgraphics:batik-ext:jar:1.7:compile - omitted for duplicate)
+   |  +- (org.apache.xmlgraphics:batik-util:jar:1.7:compile - omitted for duplicate)
+   |  +- (xml-apis:xml-apis:jar:1.3.04:compile - omitted for duplicate)
+   |  \- (xml-apis:xml-apis-ext:jar:1.3.04:compile - omitted for duplicate)
+   +- org.apache.xmlgraphics:batik-dom:jar:1.7:compile
+   |  +- (org.apache.xmlgraphics:batik-css:jar:1.7:compile - omitted for duplicate)
+   |  +- (org.apache.xmlgraphics:batik-ext:jar:1.7:compile - omitted for duplicate)
+   |  +- (org.apache.xmlgraphics:batik-util:jar:1.7:compile - omitted for duplicate)
+   |  +- (org.apache.xmlgraphics:batik-xml:jar:1.7:compile - omitted for duplicate)
+   |  +- (xalan:xalan:jar:2.6.0:compile - omitted for duplicate)
+   |  +- (xml-apis:xml-apis:jar:1.3.04:compile - omitted for duplicate)
+   |  \- (xml-apis:xml-apis-ext:jar:1.3.04:compile - omitted for duplicate)
+   +- org.apache.xmlgraphics:batik-ext:jar:1.7:compile
+   |  \- (xml-apis:xml-apis:jar:1.3.04:compile - omitted for duplicate)
+   +- (org.apache.xmlgraphics:batik-bridge:jar:1.7:compile - omitted for cycle)
+   +- org.apache.xmlgraphics:batik-gvt:jar:1.7:compile
+   |  \- (org.apache.xmlgraphics:batik-awt-util:jar:1.7:compile - omitted for duplicate)
+   +- org.apache.xmlgraphics:batik-parser:jar:1.7:compile
+   |  +- (org.apache.xmlgraphics:batik-awt-util:jar:1.7:compile - omitted for duplicate)
+   |  +- (org.apache.xmlgraphics:batik-util:jar:1.7:compile - omitted for duplicate)
+   |  \- (org.apache.xmlgraphics:batik-xml:jar:1.7:compile - omitted for duplicate)
+   +- (org.apache.xmlgraphics:batik-bridge:jar:1.7:compile - omitted for cycle)
+   +- org.apache.xmlgraphics:batik-script:jar:1.7:compile
+   +- org.apache.xmlgraphics:batik-svg-dom:jar:1.7:compile
+   |  +- (org.apache.xmlgraphics:batik-svg-dom:jar:1.7:compile - omitted for cycle)
+   |  +- (org.apache.xmlgraphics:batik-anim:jar:1.7:compile - omitted for duplicate)
+   |  +- (org.apache.xmlgraphics:batik-awt-util:jar:1.7:compile - omitted for duplicate)
+   |  +- (org.apache.xmlgraphics:batik-css:jar:1.7:compile - omitted for duplicate)
+   |  +- (org.apache.xmlgraphics:batik-dom:jar:1.7:compile - omitted for duplicate)
+   |  +- (org.apache.xmlgraphics:batik-ext:jar:1.7:compile - omitted for duplicate)
+   |  +- (org.apache.xmlgraphics:batik-parser:jar:1.7:compile - omitted for duplicate)
+   |  +- (org.apache.xmlgraphics:batik-util:jar:1.7:compile - omitted for duplicate)
+   |  +- (xml-apis:xml-apis:jar:1.3.04:compile - omitted for duplicate)
+   |  \- (xml-apis:xml-apis-ext:jar:1.3.04:compile - omitted for duplicate)
+   +- org.apache.xmlgraphics:batik-util:jar:1.7:compile
+   +- org.apache.xmlgraphics:batik-xml:jar:1.7:compile
+   |  \- (org.apache.xmlgraphics:batik-util:jar:1.7:compile - omitted for duplicate)
+   +- xalan:xalan:jar:2.6.0:compile
+   |  \- (xml-apis:xml-apis:jar:1.0.b2:compile - omitted for conflict with 1.3.04)
+   +- xml-apis:xml-apis:jar:1.3.04:compile
+   \- xml-apis:xml-apis-ext:jar:1.3.04:compile

Propchange: maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/expected.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/expected.txt
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/expected.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/invoker.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/invoker.properties?rev=1478593&view=auto
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/invoker.properties (added)
+++ maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/invoker.properties Thu
May  2 22:43:06 2013
@@ -0,0 +1 @@
+invoker.goals = clean dependency:tree

Propchange: maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/invoker.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/invoker.properties
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/invoker.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/pom.xml?rev=1478593&view=auto
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/pom.xml (added)
+++ maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/pom.xml Thu May  2 22:43:06
2013
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~   http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.dependency</groupId>
+  <artifactId>tree-verbose</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <name>VerboseTest</name>
+  <description>
+    Test verbose dependency:tree with actual Maven version.
+  </description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <dependencyManagement>
+    <dependencies>
+      <dependency>
+        <groupId>org.apache.maven</groupId>
+        <artifactId>maven-model</artifactId>
+        <version>2.0.5</version>
+        <scope>test</scope>
+      </dependency>
+    </dependencies>
+  </dependencyManagement>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-project</artifactId>
+      <version>2.0.6</version>
+      <exclusions>
+        <exclusion>
+          <groupId>org.apache.maven</groupId>
+          <artifactId>maven-artifact</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-profile</artifactId>
+      <version>2.0.4</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-model</artifactId>
+      <version>2.0.7</version>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.xmlgraphics</groupId>
+      <artifactId>batik-bridge</artifactId>
+      <version>1.7</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>@project.groupId@</groupId>
+          <artifactId>@project.artifactId@</artifactId>
+          <version>@project.version@</version>
+          <configuration>
+            <outputFile>target/tree.txt</outputFile>
+            <verbose>true</verbose>
+          </configuration>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+</project>

Propchange: maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/verify.bsh
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/verify.bsh?rev=1478593&view=auto
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/verify.bsh (added)
+++ maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/verify.bsh Thu May  2
22:43:06 2013
@@ -0,0 +1,18 @@
+import java.io.*;
+
+import org.codehaus.plexus.util.*;
+
+String actual = FileUtils.fileRead( new File( basedir, "target/tree.txt" ) );
+String expected = FileUtils.fileRead( new File( basedir, "expected.txt" ) );
+
+actual = actual.replaceAll( "[\n\r]+", "\n" );
+expected = expected.replaceAll( "[\n\r]+", "\n" );
+
+System.out.println( "Checking dependency tree..." );
+
+if ( !actual.equals( expected ) )
+{
+    throw new Exception( "Unexpected dependency tree" );
+}
+
+return true;

Propchange: maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/verify.bsh
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-dependency-plugin/src/it/tree-verbose/verify.bsh
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/TreeMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/TreeMojo.java?rev=1478593&r1=1478592&r2=1478593&view=diff
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/TreeMojo.java
(original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/TreeMojo.java
Thu May  2 22:43:06 2013
@@ -19,6 +19,7 @@ package org.apache.maven.plugin.dependen
  * under the License.
  */
 
+import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
 import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
 import org.apache.maven.artifact.versioning.ArtifactVersion;
@@ -50,7 +51,10 @@ import org.apache.maven.shared.dependenc
 import org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor;
 import org.apache.maven.shared.dependency.graph.traversal.FilteringDependencyNodeVisitor;
 import org.apache.maven.shared.dependency.graph.traversal.SerializingDependencyNodeVisitor;
-import org.apache.maven.shared.dependency.graph.traversal.SerializingDependencyNodeVisitor.TreeTokens;
+import org.apache.maven.shared.dependency.graph.traversal.SerializingDependencyNodeVisitor.GraphTokens;
+import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder;
+import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException;
+import org.apache.maven.shared.dependency.tree.traversal.SerializingDependencyNodeVisitor.TreeTokens;
 
 import java.io.File;
 import java.io.IOException;
@@ -86,6 +90,12 @@ public class TreeMojo
     private DependencyGraphBuilder dependencyGraphBuilder;
 
     /**
+     * The dependency tree builder to use for verbose output.
+     */
+    @Component
+    private DependencyTreeBuilder dependencyTreeBuilder;
+
+    /**
      * If specified, this parameter will cause the dependency tree to be written to the path
specified, instead of
      * writing to the console.
      *
@@ -129,7 +139,6 @@ public class TreeMojo
      * Whether to include omitted nodes in the serialized dependency tree.
      *
      * @since 2.0-alpha-6
-     * @deprecated in 2.5
      */
     @Parameter( property = "verbose", defaultValue = "false" )
     private boolean verbose;
@@ -186,6 +195,8 @@ public class TreeMojo
     @Parameter( property = "skip", defaultValue = "false" )
     private boolean skip;
 
+    @Parameter( defaultValue = "${localRepository}", readonly = true )
+    private ArtifactRepository localRepository;
 
     // Mojo methods -----------------------------------------------------------
 
@@ -207,15 +218,30 @@ public class TreeMojo
             this.outputFile = output;
         }
 
-        ArtifactFilter artifactFilter = createResolvingArtifactFilter();
-
         try
         {
+            String dependencyTreeString = null;
+
             // TODO: note that filter does not get applied due to MNG-3236
 
-            rootNode = dependencyGraphBuilder.buildDependencyGraph( project, artifactFilter
);
+            ArtifactFilter artifactFilter = createResolvingArtifactFilter();
 
-            String dependencyTreeString = serializeDependencyTree( rootNode );
+            if ( verbose )
+            {
+                // verbose mode force Maven 2 dependency tree component use
+                dependencyTreeString =
+                    serializeVerboseDependencyTree( dependencyTreeBuilder.buildDependencyTree(
project,
+                                                                                        
      localRepository,
+                                                                                        
      artifactFilter ) );
+            }
+            else
+            {
+                // non-verbose mode use dependency graph component, which gives consistent
results with Maven version
+                // running
+                rootNode = dependencyGraphBuilder.buildDependencyGraph( project, artifactFilter
);
+
+                dependencyTreeString = serializeDependencyTree( rootNode );
+            }
 
             if ( outputFile != null )
             {
@@ -232,6 +258,10 @@ public class TreeMojo
         {
             throw new MojoExecutionException( "Cannot build project dependency graph", exception
);
         }
+        catch ( DependencyTreeBuilderException exception )
+        {
+            throw new MojoExecutionException( "Cannot build project dependency tree", exception
);
+        }
         catch ( IOException exception )
         {
             throw new MojoExecutionException( "Cannot serialise project dependency graph",
exception );
@@ -329,6 +359,46 @@ public class TreeMojo
         return writer.toString();
     }
 
+    /**
+     * Serializes the specified dependency tree to a string.
+     *
+     * @param rootNode the dependency tree root node to serialize
+     * @return the serialized dependency tree
+     */
+    private String serializeVerboseDependencyTree( org.apache.maven.shared.dependency.tree.DependencyNode
rootNode )
+    {
+        StringWriter writer = new StringWriter();
+
+        org.apache.maven.shared.dependency.tree.traversal.DependencyNodeVisitor visitor =
+            new org.apache.maven.shared.dependency.tree.traversal.SerializingDependencyNodeVisitor(
writer,
+                                                                                        
           toTreeTokens( tokens ) );
+
+        // TODO: remove the need for this when the serializer can calculate last nodes from
visitor calls only
+        visitor = new org.apache.maven.shared.dependency.tree.traversal.BuildingDependencyNodeVisitor(
visitor );
+
+        org.apache.maven.shared.dependency.tree.filter.DependencyNodeFilter filter = createVerboseDependencyNodeFilter();
+
+        if ( filter != null )
+        {
+            org.apache.maven.shared.dependency.tree.traversal.CollectingDependencyNodeVisitor
collectingVisitor =
+                new org.apache.maven.shared.dependency.tree.traversal.CollectingDependencyNodeVisitor();
+            org.apache.maven.shared.dependency.tree.traversal.DependencyNodeVisitor firstPassVisitor
=
+                new org.apache.maven.shared.dependency.tree.traversal.FilteringDependencyNodeVisitor(
collectingVisitor,
+                                                                                        
             filter );
+            rootNode.accept( firstPassVisitor );
+
+            org.apache.maven.shared.dependency.tree.filter.DependencyNodeFilter secondPassFilter
=
+                new org.apache.maven.shared.dependency.tree.filter.AncestorOrSelfDependencyNodeFilter(
collectingVisitor.getNodes() );
+            visitor =
+                new org.apache.maven.shared.dependency.tree.traversal.FilteringDependencyNodeVisitor(
visitor,
+                                                                                        
             secondPassFilter );
+        }
+
+        rootNode.accept( visitor );
+
+        return writer.toString();
+    }
+
     public DependencyNodeVisitor getSerializingDependencyNodeVisitor( Writer writer )
     {
         if ( "graphml".equals( outputType ) )
@@ -345,8 +415,38 @@ public class TreeMojo
         }
         else
         {
-            return new SerializingDependencyNodeVisitor( writer, toTreeTokens( tokens ) );
+            return new SerializingDependencyNodeVisitor( writer, toGraphTokens( tokens )
);
+        }
+    }
+
+    /**
+     * Gets the graph tokens instance for the specified name.
+     *
+     * @param tokens the graph tokens name
+     * @return the <code>GraphTokens</code> instance
+     */
+    private GraphTokens toGraphTokens( String tokens )
+    {
+        GraphTokens graphTokens;
+
+        if ( "whitespace".equals( tokens ) )
+        {
+            getLog().debug( "+ Using whitespace tree tokens" );
+
+            graphTokens = SerializingDependencyNodeVisitor.WHITESPACE_TOKENS;
+        }
+        else if ( "extended".equals( tokens ) )
+        {
+            getLog().debug( "+ Using extended tree tokens" );
+
+            graphTokens = SerializingDependencyNodeVisitor.EXTENDED_TOKENS;
+        }
+        else
+        {
+            graphTokens = SerializingDependencyNodeVisitor.STANDARD_TOKENS;
         }
+
+        return graphTokens;
     }
 
     /**
@@ -363,24 +463,27 @@ public class TreeMojo
         {
             getLog().debug( "+ Using whitespace tree tokens" );
 
-            treeTokens = SerializingDependencyNodeVisitor.WHITESPACE_TOKENS;
+            treeTokens =
+                org.apache.maven.shared.dependency.tree.traversal.SerializingDependencyNodeVisitor.WHITESPACE_TOKENS;
         }
         else if ( "extended".equals( tokens ) )
         {
             getLog().debug( "+ Using extended tree tokens" );
 
-            treeTokens = SerializingDependencyNodeVisitor.EXTENDED_TOKENS;
+            treeTokens =
+                org.apache.maven.shared.dependency.tree.traversal.SerializingDependencyNodeVisitor.EXTENDED_TOKENS;
         }
         else
         {
-            treeTokens = SerializingDependencyNodeVisitor.STANDARD_TOKENS;
+            treeTokens =
+                org.apache.maven.shared.dependency.tree.traversal.SerializingDependencyNodeVisitor.STANDARD_TOKENS;
         }
 
         return treeTokens;
     }
 
     /**
-     * Gets the dependency node filter to use when serializing the dependency tree.
+     * Gets the dependency node filter to use when serializing the dependency graph.
      *
      * @return the dependency node filter, or <code>null</code> if none required
      */
@@ -388,14 +491,6 @@ public class TreeMojo
     {
         List<DependencyNodeFilter> filters = new ArrayList<DependencyNodeFilter>();
 
-        // filter node states
-        /*if ( !verbose )
-        {
-            getLog().debug( "+ Filtering omitted nodes from dependency tree" );
-
-            filters.add( StateDependencyNodeFilter.INCLUDED );
-        }*/
-
         // filter includes
         if ( includes != null )
         {
@@ -421,6 +516,44 @@ public class TreeMojo
         return filters.isEmpty() ? null : new AndDependencyNodeFilter( filters );
     }
 
+    /**
+     * Gets the dependency node filter to use when serializing the dependency tree.
+     *
+     * @return the dependency node filter, or <code>null</code> if none required
+     */
+    private org.apache.maven.shared.dependency.tree.filter.DependencyNodeFilter createVerboseDependencyNodeFilter()
+    {
+        List<org.apache.maven.shared.dependency.tree.filter.DependencyNodeFilter> filters
=
+            new ArrayList<org.apache.maven.shared.dependency.tree.filter.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 org.apache.maven.shared.dependency.tree.filter.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 org.apache.maven.shared.dependency.tree.filter.ArtifactDependencyNodeFilter(
+                                                                                        
                 artifactFilter ) );
+        }
+
+        return filters.isEmpty() ? null
+                        : new org.apache.maven.shared.dependency.tree.filter.AndDependencyNodeFilter(
filters );
+    }
+
     //following is required because the version handling in maven code
     //doesn't work properly. I ripped it out of the enforcer rules.
 



Mime
View raw message