maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rfscho...@apache.org
Subject svn commit: r1495697 - in /maven/enforcer/trunk/enforcer-rules/src: main/java/org/apache/maven/plugins/enforcer/ test/java/org/apache/maven/plugins/enforcer/
Date Sat, 22 Jun 2013 10:05:58 GMT
Author: rfscholte
Date: Sat Jun 22 10:05:58 2013
New Revision: 1495697

URL: http://svn.apache.org/r1495697
Log:
Always use DependencyGraphBuilder to get the dependencies
Default lookup fails with M2, so when component lookup fails, fall back to Maven2DependencyGraphBuilder

Modified:
    maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractBanDependencies.java
    maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestBannedDependencies.java
    maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestNoSnapshots.java
    maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireReleaseDeps.java

Modified: maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractBanDependencies.java
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractBanDependencies.java?rev=1495697&r1=1495696&r2=1495697&view=diff
==============================================================================
--- maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractBanDependencies.java
(original)
+++ maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractBanDependencies.java
Sat Jun 22 10:05:58 2013
@@ -19,17 +19,14 @@ package org.apache.maven.plugins.enforce
  * under the License.
  */
 
-import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Set;
 
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
 import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
 import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
 import org.apache.maven.plugin.logging.Log;
 import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.MavenProjectHelper;
 import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder;
 import org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException;
 import org.apache.maven.shared.dependency.graph.DependencyNode;
@@ -48,8 +45,8 @@ public abstract class AbstractBanDepende
 
     /** Specify if transitive dependencies should be searched (default) or only look at direct
dependencies. */
     private boolean searchTransitive = true;
-
-    private DependencyGraphBuilder graphBuilder;
+    
+    private transient DependencyGraphBuilder graphBuilder;
 
     /**
      * Execute the rule.
@@ -78,7 +75,15 @@ public abstract class AbstractBanDepende
         }
         catch ( ComponentLookupException e )
         {
-            throw new EnforcerRuleException( "Unable to lookup DependencyGraphBuilder: ",
e );
+            // real cause is probably that one of the Maven3 graph builder could not be initiated
and fails with a ClassNotFoundException
+            try
+            {
+                graphBuilder = (DependencyGraphBuilder) helper.getComponent( DependencyGraphBuilder.class.getName(),
"maven2" );
+            }
+            catch ( ComponentLookupException e1 )
+            {
+                throw new EnforcerRuleException( "Unable to lookup DependencyGraphBuilder:
", e );
+            }
         }
         
         // get the correct list of dependencies
@@ -113,44 +118,30 @@ public abstract class AbstractBanDepende
         return "Found Banned Dependency: " + artifact.getId() + "\n";
     }
 
-    @SuppressWarnings( "unchecked" )
     protected Set<Artifact> getDependenciesToCheck( MavenProject project )
     {
         Set<Artifact> dependencies = null;
-        if ( searchTransitive )
-        {
-            dependencies = project.getArtifacts();
-        }
-        else
-        {
-            dependencies = project.getDependencyArtifacts();
-        }
-        
-        // requiresDependencyCollection doesn't work for M2, this is the fallback
-        if( dependencies == null )
+        try
         {
-            try
+            DependencyNode node = graphBuilder.buildDependencyGraph( project, null );
+            if( searchTransitive )
             {
-                DependencyNode node = graphBuilder.buildDependencyGraph( project, null );
-                if( searchTransitive )
-                {
-                    dependencies  = getAllDescendants( node );
-                }
-                else if ( node.getChildren() != null )
-                {
-                    dependencies = new HashSet<Artifact>();
-                    for( DependencyNode depNode : node.getChildren() )
-                    {
-                        dependencies.add( depNode.getArtifact() );
-                    }
-                }
+                dependencies  = getAllDescendants( node );
             }
-            catch ( DependencyGraphBuilderException e )
+            else if ( node.getChildren() != null )
             {
-                // otherwise we need to change the signature of this protected method
-                throw new RuntimeException( e );
+                dependencies = new HashSet<Artifact>();
+                for( DependencyNode depNode : node.getChildren() )
+                {
+                    dependencies.add( depNode.getArtifact() );
+                }
             }
         }
+        catch ( DependencyGraphBuilderException e )
+        {
+            // otherwise we need to change the signature of this protected method
+            throw new RuntimeException( e );
+        }
         return dependencies;
     }
 
@@ -162,6 +153,7 @@ public abstract class AbstractBanDepende
             children = new HashSet<Artifact>();
             for( DependencyNode depNode : node.getChildren() )
             {
+                children.add( depNode.getArtifact() );
                 Set<Artifact> subNodes = getAllDescendants( depNode );
                 if( subNodes != null )
                 {

Modified: maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestBannedDependencies.java
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestBannedDependencies.java?rev=1495697&r1=1495696&r2=1495697&view=diff
==============================================================================
--- maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestBannedDependencies.java
(original)
+++ maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestBannedDependencies.java
Sat Jun 22 10:05:58 2013
@@ -22,12 +22,15 @@ package org.apache.maven.plugins.enforce
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Set;
 
 import junit.framework.TestCase;
 
+import org.apache.maven.artifact.Artifact;
 import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
 import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
 import org.apache.maven.plugin.testing.ArtifactStubFactory;
+import org.apache.maven.project.MavenProject;
 
 // TODO: Auto-generated Javadoc
 /**
@@ -52,7 +55,8 @@ public class TestBannedDependencies
         EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project );
         project.setArtifacts( factory.getMixedArtifacts() );
         project.setDependencyArtifacts( factory.getScopedArtifacts() );
-        BannedDependencies rule = new BannedDependencies();
+        
+        BannedDependencies rule = newBannedDependenciesRule();
 
         List<String> excludes = new ArrayList<String>();
         rule.setSearchTransitive( false );
@@ -143,7 +147,7 @@ public class TestBannedDependencies
         EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project );
         project.setArtifacts( factory.getMixedArtifacts() );
         project.setDependencyArtifacts( factory.getScopedArtifacts() );
-        BannedDependencies rule = new BannedDependencies();
+        BannedDependencies rule = newBannedDependenciesRule();
 
         List<String> excludes = new ArrayList<String>();
         List<String> includes = new ArrayList<String>();
@@ -170,6 +174,21 @@ public class TestBannedDependencies
         execute( rule, helper, true );
     }
 
+    private BannedDependencies newBannedDependenciesRule()
+    {
+        BannedDependencies rule = new BannedDependencies()
+        {
+            @Override
+            protected Set<Artifact> getDependenciesToCheck( MavenProject project )
+            {
+                // the integration with dependencyGraphTree is verified with the integration
tests
+                // for unit-testing 
+                return isSearchTransitive() ? project.getArtifacts() : project.getDependencyArtifacts();
+            }
+        };
+        return rule;
+    }
+
     /**
      * Simpler wrapper to execute and deal with the expected result.
      *

Modified: maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestNoSnapshots.java
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestNoSnapshots.java?rev=1495697&r1=1495696&r2=1495697&view=diff
==============================================================================
--- maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestNoSnapshots.java
(original)
+++ maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestNoSnapshots.java
Sat Jun 22 10:05:58 2013
@@ -20,12 +20,15 @@ package org.apache.maven.plugins.enforce
  */
 
 import java.io.IOException;
+import java.util.Set;
 
 import junit.framework.TestCase;
 
+import org.apache.maven.artifact.Artifact;
 import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
 import org.apache.maven.plugin.testing.ArtifactStubFactory;
 import org.apache.maven.plugins.enforcer.utils.TestEnforcerRuleUtils;
+import org.apache.maven.project.MavenProject;
 
 /**
  * The Class TestNoSnapshots.
@@ -50,7 +53,7 @@ public class TestNoSnapshots
         EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project );
         project.setArtifacts( factory.getMixedArtifacts() );
         project.setDependencyArtifacts( factory.getScopedArtifacts() );
-        NoSnapshots rule = new NoSnapshots();
+        NoSnapshots rule = newNoSnapshots();
         rule.setSearchTransitive( false );
 
         TestEnforcerRuleUtils.execute( rule, helper, false );
@@ -64,12 +67,26 @@ public class TestNoSnapshots
         TestEnforcerRuleUtils.execute( rule, helper, true );
     }
 
+    private NoSnapshots newNoSnapshots()
+    {
+        NoSnapshots rule = new NoSnapshots()
+        {
+            protected Set<Artifact> getDependenciesToCheck( MavenProject project )
+            {
+                // the integration with dependencyGraphTree is verified with the integration
tests
+                // for unit-testing 
+                return isSearchTransitive() ? project.getArtifacts() : project.getDependencyArtifacts();
+            }
+        };
+        return rule;
+    }
+
     /**
      * Test id.
      */
     public void testId()
     {
-        NoSnapshots rule = new NoSnapshots();
+        NoSnapshots rule = newNoSnapshots();
         rule.getCacheId();
     }
 }

Modified: maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireReleaseDeps.java
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireReleaseDeps.java?rev=1495697&r1=1495696&r2=1495697&view=diff
==============================================================================
--- maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireReleaseDeps.java
(original)
+++ maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireReleaseDeps.java
Sat Jun 22 10:05:58 2013
@@ -20,12 +20,15 @@ package org.apache.maven.plugins.enforce
  */
 
 import java.io.IOException;
+import java.util.Set;
 
 import junit.framework.TestCase;
 
+import org.apache.maven.artifact.Artifact;
 import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
 import org.apache.maven.plugin.testing.ArtifactStubFactory;
 import org.apache.maven.plugins.enforcer.utils.TestEnforcerRuleUtils;
+import org.apache.maven.project.MavenProject;
 
 // TODO: Auto-generated Javadoc
 /**
@@ -51,7 +54,7 @@ public class TestRequireReleaseDeps
         EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project );
         project.setArtifacts( factory.getMixedArtifacts() );
         project.setDependencyArtifacts( factory.getScopedArtifacts() );
-        RequireReleaseDeps rule = new RequireReleaseDeps();
+        RequireReleaseDeps rule = newRequireReleaseDeps();
         rule.setSearchTransitive( false );
 
         TestEnforcerRuleUtils.execute( rule, helper, false );
@@ -90,12 +93,26 @@ public class TestRequireReleaseDeps
 
     }
 
+    private RequireReleaseDeps newRequireReleaseDeps()
+    {
+        RequireReleaseDeps rule = new RequireReleaseDeps()
+        {
+            protected Set<Artifact> getDependenciesToCheck( MavenProject project )
+            {
+                // the integration with dependencyGraphTree is verified with the integration
tests
+                // for unit-testing 
+                return isSearchTransitive() ? project.getArtifacts() : project.getDependencyArtifacts();
+            }
+        };        
+        return rule;
+    }
+
     /**
      * Test id.
      */
     public void testId()
     {
-        RequireReleaseDeps rule = new RequireReleaseDeps();
+        RequireReleaseDeps rule = newRequireReleaseDeps();
         rule.getCacheId();
     }
 }



Mime
View raw message