maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hbout...@apache.org
Subject svn commit: r1355837 - in /maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph: ./ filter/ internal/
Date Sat, 30 Jun 2012 23:37:47 GMT
Author: hboutemy
Date: Sat Jun 30 23:37:46 2012
New Revision: 1355837

URL: http://svn.apache.org/viewvc?rev=1355837&view=rev
Log:
copied ancestor filter

Added:
    maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/filter/AncestorOrSelfDependencyNodeFilter.java
  (with props)
Modified:
    maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/DependencyNode.java
    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/Maven2DependencyNode.java
    maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven3DependencyGraphBuilder.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/DependencyNode.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/DependencyNode.java?rev=1355837&r1=1355836&r2=1355837&view=diff
==============================================================================
--- maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/DependencyNode.java
(original)
+++ maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/DependencyNode.java
Sat Jun 30 23:37:46 2012
@@ -45,4 +45,11 @@ public interface DependencyNode
      * @since 1.1
      */
     public boolean accept( DependencyNodeVisitor visitor );
+
+    /**
+     * Gets the parent dependency node of this dependency node.
+     * 
+     * @return the parent dependency node
+     */
+    public DependencyNode getParent();
 }

Added: maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/filter/AncestorOrSelfDependencyNodeFilter.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/filter/AncestorOrSelfDependencyNodeFilter.java?rev=1355837&view=auto
==============================================================================
--- maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/filter/AncestorOrSelfDependencyNodeFilter.java
(added)
+++ maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/filter/AncestorOrSelfDependencyNodeFilter.java
Sat Jun 30 23:37:46 2012
@@ -0,0 +1,106 @@
+package org.apache.maven.shared.dependency.graph.filter;
+
+/*
+ * 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.
+ */
+
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.maven.shared.dependency.graph.DependencyNode;
+
+/**
+ * A dependency node filter than only accepts nodes that are ancestors of, or equal to, a
given list of nodes.
+ * 
+ * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
+ * @version $Id$
+ * @since 1.1
+ */
+public class AncestorOrSelfDependencyNodeFilter
+    implements DependencyNodeFilter
+{
+    // fields -----------------------------------------------------------------
+
+    /**
+     * The list of nodes that this filter accepts ancestors-or-self of.
+     */
+    private final List<DependencyNode> descendantNodes;
+
+    // constructors -----------------------------------------------------------
+
+    public AncestorOrSelfDependencyNodeFilter( DependencyNode descendantNode )
+    {
+        this( Collections.singletonList( descendantNode ) );
+    }
+
+    /**
+     * Creates a dependency node filter that only accepts nodes that are ancestors of, or
equal to, the specified list
+     * of nodes.
+     * 
+     * @param descendantNodes
+     *            the list of nodes to accept ancestors-or-self of
+     */
+    public AncestorOrSelfDependencyNodeFilter( List<DependencyNode> descendantNodes
)
+    {
+        this.descendantNodes = descendantNodes;
+    }
+
+    // DependencyNodeFilter methods -------------------------------------------
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean accept( DependencyNode node )
+    {
+        for ( DependencyNode descendantNode : descendantNodes )
+        {
+            if ( isAncestorOrSelf( node, descendantNode ) )
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    // private methods --------------------------------------------------------
+
+    /**
+     * Gets whether the first dependency node is an ancestor-or-self of the second.
+     * 
+     * @param ancestorNode
+     *            the ancestor-or-self dependency node
+     * @param descendantNode
+     *            the dependency node to test
+     * @return <code>true</code> if <code>ancestorNode</code> is
an ancestor, or equal to,
+     *         <code>descendantNode</code>
+     */
+    private boolean isAncestorOrSelf( DependencyNode ancestorNode, DependencyNode descendantNode
)
+    {
+        boolean ancestor = false;
+
+        while ( !ancestor && descendantNode != null )
+        {
+            ancestor = ancestorNode.equals( descendantNode );
+
+            descendantNode = descendantNode.getParent();
+        }
+
+        return ancestor;
+    }
+}

Propchange: maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/filter/AncestorOrSelfDependencyNodeFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/filter/AncestorOrSelfDependencyNodeFilter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/filter/AncestorOrSelfDependencyNodeFilter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=1355837&r1=1355836&r2=1355837&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
Sat Jun 30 23:37:46 2012
@@ -48,7 +48,7 @@ public class Maven2DependencyGraphBuilde
     {
         try
         {
-            return new Maven2DependencyNode( treeBuilder.buildDependencyTree( project ),
filter );
+            return new Maven2DependencyNode( null, treeBuilder.buildDependencyTree( project
), filter );
         }
         catch ( DependencyTreeBuilderException e )
         {

Modified: maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven2DependencyNode.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven2DependencyNode.java?rev=1355837&r1=1355836&r2=1355837&view=diff
==============================================================================
--- maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven2DependencyNode.java
(original)
+++ maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven2DependencyNode.java
Sat Jun 30 23:37:46 2012
@@ -41,8 +41,12 @@ public class Maven2DependencyNode
 
     private final List<DependencyNode> children;
 
-    public Maven2DependencyNode( org.apache.maven.shared.dependency.tree.DependencyNode node,
ArtifactFilter filter )
+    private final DependencyNode parent;
+
+    public Maven2DependencyNode( DependencyNode parent, org.apache.maven.shared.dependency.tree.DependencyNode
node,
+                                 ArtifactFilter filter )
     {
+        this.parent = parent;
         this.artifact = node.getArtifact();
 
         List<DependencyNode> nodes = new ArrayList<DependencyNode>( node.getChildren().size()
);
@@ -50,7 +54,7 @@ public class Maven2DependencyNode
         {
             if ( ( filter == null ) || filter.include( child.getArtifact() ) )
             {
-                nodes.add( new Maven2DependencyNode( child, filter ) );
+                nodes.add( new Maven2DependencyNode( this, child, filter ) );
             }
         }
 
@@ -67,4 +71,8 @@ public class Maven2DependencyNode
         return children;
     }
 
+    public DependencyNode getParent()
+    {
+        return parent;
+    }
 }

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=1355837&r1=1355836&r2=1355837&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
Sat Jun 30 23:37:46 2012
@@ -66,7 +66,7 @@ public class Maven3DependencyGraphBuilde
 
             DependencyResolutionResult result = resolver.resolve( request );
 
-            return new Maven3DependencyNode( factory, result.getDependencyGraph(), project.getArtifact(),
filter );
+            return new Maven3DependencyNode( null, factory, result.getDependencyGraph(),
project.getArtifact(), filter );
         }
         catch ( DependencyResolutionException e )
         {

Modified: maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven3DependencyNode.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven3DependencyNode.java?rev=1355837&r1=1355836&r2=1355837&view=diff
==============================================================================
--- maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven3DependencyNode.java
(original)
+++ maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven3DependencyNode.java
Sat Jun 30 23:37:46 2012
@@ -44,9 +44,14 @@ public class Maven3DependencyNode
 
     private final List<DependencyNode> children;
 
-    public Maven3DependencyNode( ArtifactFactory factory, org.sonatype.aether.graph.DependencyNode
node,
-                                 final Artifact artifact, ArtifactFilter filter )
+    private final DependencyNode parent;
+
+    public Maven3DependencyNode( DependencyNode parent, ArtifactFactory factory,
+                                 org.sonatype.aether.graph.DependencyNode node, final Artifact
artifact,
+                                 ArtifactFilter filter )
     {
+        this.parent = parent;
+
         if ( artifact != null )
         {
             this.artifact = artifact;
@@ -75,7 +80,7 @@ public class Maven3DependencyNode
         List<DependencyNode> nodes = new ArrayList<DependencyNode>( node.getChildren().size()
);
         for ( org.sonatype.aether.graph.DependencyNode child : node.getChildren() )
         {
-            DependencyNode tmpNode = new Maven3DependencyNode( factory, child, null, filter
);
+            DependencyNode tmpNode = new Maven3DependencyNode( this, factory, child, null,
filter );
 
             if ( tmpNode.getArtifact() != null )
             {
@@ -95,4 +100,8 @@ public class Maven3DependencyNode
         return children;
     }
 
+    public DependencyNode getParent()
+    {
+        return parent;
+    }
 }



Mime
View raw message