maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hbout...@apache.org
Subject svn commit: r1356361 - /maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/
Date Mon, 02 Jul 2012 17:14:17 GMT
Author: hboutemy
Date: Mon Jul  2 17:14:16 2012
New Revision: 1356361

URL: http://svn.apache.org/viewvc?rev=1356361&view=rev
Log:
replaced DependencyNode implementations with DefaultDependencyNode

Added:
    maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/DefaultDependencyNode.java
      - copied, changed from r1353122, maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/AbstractDependencyNode.java
Removed:
    maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/AbstractDependencyNode.java
    maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven2DependencyNode.java
    maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven3DependencyNode.java
Modified:
    maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven2DependencyGraphBuilder.java
    maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven3DependencyGraphBuilder.java

Copied: maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/DefaultDependencyNode.java
(from r1353122, maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/AbstractDependencyNode.java)
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/DefaultDependencyNode.java?p2=maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/DefaultDependencyNode.java&p1=maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/AbstractDependencyNode.java&r1=1353122&r2=1356361&rev=1356361&view=diff
==============================================================================
--- maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/AbstractDependencyNode.java
(original)
+++ maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/DefaultDependencyNode.java
Mon Jul  2 17:14:16 2012
@@ -1,11 +1,26 @@
 package org.apache.maven.shared.dependency.graph.internal;
 
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
 import org.apache.maven.shared.dependency.graph.DependencyNode;
 import org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor;
 
-public abstract class AbstractDependencyNode
+public class DefaultDependencyNode
     implements DependencyNode
 {
+    private final Artifact artifact;
+
+    private final DependencyNode parent;
+
+    private List<DependencyNode> children;
+
+    public DefaultDependencyNode( DependencyNode parent, Artifact artifact )
+    {
+        this.parent = parent;
+        this.artifact = artifact;
+    }
+
     /**
      * Applies the specified dependency node visitor to this dependency node and its children.
      * 
@@ -29,4 +44,24 @@ public abstract class AbstractDependency
 
         return visitor.endVisit( this );
     }
+
+    public Artifact getArtifact()
+    {
+        return artifact;
+    }
+
+    public void setChildren( List<DependencyNode> children )
+    {
+        this.children = children;
+    }
+
+    public List<DependencyNode> getChildren()
+    {
+        return children;
+    }
+
+    public DependencyNode getParent()
+    {
+        return parent;
+    }
 }

Modified: maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven2DependencyGraphBuilder.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven2DependencyGraphBuilder.java?rev=1356361&r1=1356360&r2=1356361&view=diff
==============================================================================
--- maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven2DependencyGraphBuilder.java
(original)
+++ maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven2DependencyGraphBuilder.java
Mon Jul  2 17:14:16 2012
@@ -19,6 +19,10 @@ package org.apache.maven.shared.dependen
  * under the License.
  */
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
 import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder;
@@ -48,11 +52,37 @@ public class Maven2DependencyGraphBuilde
     {
         try
         {
-            return new Maven2DependencyNode( null, treeBuilder.buildDependencyTree( project
), filter );
+            return buildDependencyNode( null, treeBuilder.buildDependencyTree( project ),
filter );
         }
         catch ( DependencyTreeBuilderException e )
         {
             throw new DependencyGraphBuilderException( e.getMessage(), e );
         }
     }
+
+    private DependencyNode buildDependencyNode( DependencyNode parent,
+                                                org.apache.maven.shared.dependency.tree.DependencyNode
node,
+                                                ArtifactFilter filter )
+    {
+        DefaultDependencyNode current = new DefaultDependencyNode( parent, node.getArtifact()
);
+
+        List<DependencyNode> nodes = new ArrayList<DependencyNode>( node.getChildren().size()
);
+        for ( org.apache.maven.shared.dependency.tree.DependencyNode child : node.getChildren()
)
+        {
+            if ( child.getState() != org.apache.maven.shared.dependency.tree.DependencyNode.INCLUDED
)
+            {
+                // only included nodes are supported in the graph API
+                continue;
+            }
+
+            if ( ( filter == null ) || filter.include( child.getArtifact() ) )
+            {
+                nodes.add( buildDependencyNode( current, child, filter ) );
+            }
+        }
+
+        current.setChildren( Collections.unmodifiableList( nodes ) );
+
+        return current;
+    }
 }

Modified: maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven3DependencyGraphBuilder.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven3DependencyGraphBuilder.java?rev=1356361&r1=1356360&r2=1356361&view=diff
==============================================================================
--- maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven3DependencyGraphBuilder.java
(original)
+++ maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven3DependencyGraphBuilder.java
Mon Jul  2 17:14:16 2012
@@ -20,9 +20,14 @@ package org.apache.maven.shared.dependen
  */
 
 import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 
+import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+import org.apache.maven.artifact.versioning.VersionRange;
 import org.apache.maven.project.DefaultDependencyResolutionRequest;
 import org.apache.maven.project.DependencyResolutionException;
 import org.apache.maven.project.DependencyResolutionRequest;
@@ -35,6 +40,7 @@ import org.apache.maven.shared.dependenc
 import org.apache.maven.shared.dependency.graph.DependencyNode;
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.component.annotations.Requirement;
+import org.sonatype.aether.graph.Dependency;
 
 /**
  * Wrapper around Maven 3 dependency resolver.
@@ -66,7 +72,7 @@ public class Maven3DependencyGraphBuilde
 
             DependencyResolutionResult result = resolver.resolve( request );
 
-            return new Maven3DependencyNode( null, factory, result.getDependencyGraph(),
project.getArtifact(), filter );
+            return buildDependencyNode( null, result.getDependencyGraph(), project.getArtifact(),
filter );
         }
         catch ( DependencyResolutionException e )
         {
@@ -91,4 +97,35 @@ public class Maven3DependencyGraphBuilde
     {
         return object.getClass().getMethod( method ).invoke( object );
     }
+
+    private Artifact getDependencyArtifact( Dependency dep )
+    {
+        org.sonatype.aether.artifact.Artifact artifact = dep.getArtifact();
+
+        return factory.createDependencyArtifact( artifact.getGroupId(), artifact.getArtifactId(),
+                                                 VersionRange.createFromVersion( artifact.getVersion()
),
+                                                 artifact.getExtension(), artifact.getClassifier(),
dep.getScope(),
+                                                 dep.isOptional() );
+    }
+
+    private DependencyNode buildDependencyNode( DependencyNode parent, org.sonatype.aether.graph.DependencyNode
node,
+                                                Artifact artifact, ArtifactFilter filter
)
+    {
+        DefaultDependencyNode current = new DefaultDependencyNode( parent, artifact );
+
+        List<DependencyNode> nodes = new ArrayList<DependencyNode>( node.getChildren().size()
);
+        for ( org.sonatype.aether.graph.DependencyNode child : node.getChildren() )
+        {
+            Artifact childArtifact = getDependencyArtifact( child.getDependency() );
+
+            if ( ( filter == null ) || filter.include( childArtifact ) )
+            {
+                nodes.add( buildDependencyNode( current, child, childArtifact, filter ) );
+            }
+        }
+
+        current.setChildren( Collections.unmodifiableList( nodes ) );
+
+        return current;
+    }
 }



Mime
View raw message