You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2007/01/30 05:02:19 UTC

svn commit: r501305 - in /maven/plugins/branches/maven-dependency-plugin-MDEP-50/src: main/java/org/apache/maven/plugin/dependency/ main/java/org/apache/maven/plugin/dependency/fromConfiguration/ test/java/org/apache/maven/plugin/dependency/fromConfigu...

Author: brianf
Date: Mon Jan 29 20:02:17 2007
New Revision: 501305

URL: http://svn.apache.org/viewvc?view=rev&rev=501305
Log:
mdep-50: fixed unit tests

Added:
    maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubArtifactCollector.java
Modified:
    maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java
    maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java
    maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java
    maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java
    maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/DependencyProjectStub.java

Modified: maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java?view=diff&rev=501305&r1=501304&r2=501305
==============================================================================
--- maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java (original)
+++ maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java Mon Jan 29 20:02:17 2007
@@ -351,4 +351,36 @@
     {
         this.archiverManager = archiverManager;
     }
+
+    /**
+     * @return Returns the artifactCollector.
+     */
+    public ArtifactCollector getArtifactCollector()
+    {
+        return this.artifactCollector;
+    }
+
+    /**
+     * @param theArtifactCollector The artifactCollector to set.
+     */
+    public void setArtifactCollector( ArtifactCollector theArtifactCollector )
+    {
+        this.artifactCollector = theArtifactCollector;
+    }
+
+    /**
+     * @return Returns the artifactMetadataSource.
+     */
+    public ArtifactMetadataSource getArtifactMetadataSource()
+    {
+        return this.artifactMetadataSource;
+    }
+
+    /**
+     * @param theArtifactMetadataSource The artifactMetadataSource to set.
+     */
+    public void setArtifactMetadataSource( ArtifactMetadataSource theArtifactMetadataSource )
+    {
+        this.artifactMetadataSource = theArtifactMetadataSource;
+    }
 }

Modified: maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java?view=diff&rev=501305&r1=501304&r2=501305
==============================================================================
--- maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java (original)
+++ maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java Mon Jan 29 20:02:17 2007
@@ -28,23 +28,17 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.TreeSet;
 
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
 import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
-import org.apache.maven.artifact.resolver.DebugResolutionListener;
 import org.apache.maven.artifact.resolver.ResolutionNode;
-import org.apache.maven.artifact.resolver.WarningResolutionListener;
-import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
-import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter;
 import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
 import org.apache.maven.artifact.versioning.VersionRange;
 import org.apache.maven.model.Dependency;
 import org.apache.maven.model.DependencyManagement;
-import org.apache.maven.model.Exclusion;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.dependency.AbstractDependencyMojo;
 import org.apache.maven.plugin.dependency.utils.DependencyUtil;
@@ -186,74 +180,7 @@
         return result;
     }
 
-    /**
-     * Returns the list of project artifacts. Also artifacts generated from
-     * referenced projects will be added, but with the <code>resolved</code>
-     * property set to true.
-     * 
-     * @return list of projects artifacts
-     * @throws MojoExecutionException
-     *             if unable to parse dependency versions
-     */
-    private Set getProjectArtifacts()
-        throws MojoExecutionException
-    {
-        // keep it sorted, this should avoid random classpath order in tests
-        Set artifacts = new TreeSet();
-
-        for ( Iterator dependencies = getProject().getDependencies().iterator(); dependencies.hasNext(); )
-        {
-            Dependency dependency = (Dependency) dependencies.next();
-
-            String groupId = dependency.getGroupId();
-            String artifactId = dependency.getArtifactId();
-            VersionRange versionRange;
-            try
-            {
-                versionRange = VersionRange.createFromVersionSpec( dependency.getVersion() );
-            }
-            catch ( InvalidVersionSpecificationException e )
-            {
-                throw new MojoExecutionException( "unable to parse version", e );
-            }
-
-            String type = dependency.getType();
-            if ( type == null )
-            {
-                type = "jar"; //$NON-NLS-1$
-            }
-            String classifier = dependency.getClassifier();
-            boolean optional = dependency.isOptional();
-            String scope = dependency.getScope();
-            if ( scope == null )
-            {
-                scope = Artifact.SCOPE_COMPILE;
-            }
-
-            Artifact art = factory.createDependencyArtifact( groupId, artifactId, versionRange, type, classifier,
-                                                             scope, optional );
-
-            if ( scope.equalsIgnoreCase( Artifact.SCOPE_SYSTEM ) )
-            {
-                art.setFile( new File( dependency.getSystemPath() ) );
-            }
-
-            List exclusions = new ArrayList();
-            for ( Iterator j = dependency.getExclusions().iterator(); j.hasNext(); )
-            {
-                Exclusion e = (Exclusion) j.next();
-                exclusions.add( e.getGroupId() + ":" + e.getArtifactId() ); //$NON-NLS-1$
-            }
-
-            ArtifactFilter newFilter = new ExcludesArtifactFilter( exclusions );
-
-            art.setDependencyFilter( newFilter );
-
-            artifacts.add( art );
-        }
-
-        return artifacts;
-    }
+  
 
     /**
      * Resolves the Artifact from the remote repository if nessessary. If no

Modified: maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java?view=diff&rev=501305&r1=501304&r2=501305
==============================================================================
--- maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java (original)
+++ maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java Mon Jan 29 20:02:17 2007
@@ -31,6 +31,7 @@
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.dependency.AbstractDependencyMojoTestCase;
 import org.apache.maven.plugin.dependency.testUtils.DependencyTestUtils;
+import org.apache.maven.plugin.dependency.testUtils.stubs.StubArtifactCollector;
 import org.apache.maven.plugin.dependency.testUtils.stubs.StubArtifactRepository;
 import org.apache.maven.plugin.dependency.testUtils.stubs.StubArtifactResolver;
 import org.apache.maven.plugin.dependency.utils.DependencyUtil;
@@ -64,6 +65,8 @@
         mojo.setFactory( DependencyTestUtils.getArtifactFactory() );
         mojo.setResolver( new StubArtifactResolver( stubFactory, false, false ) );
         mojo.setLocal( new StubArtifactRepository( this.testDir.getAbsolutePath() ) );
+        mojo.setArtifactCollector( new StubArtifactCollector());
+    
     }
 
     public ArtifactItem getSingleArtifactItem( boolean removeVersion )

Modified: maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java?view=diff&rev=501305&r1=501304&r2=501305
==============================================================================
--- maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java (original)
+++ maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java Mon Jan 29 20:02:17 2007
@@ -32,6 +32,7 @@
 import org.apache.maven.plugin.dependency.AbstractDependencyMojoTestCase;
 import org.apache.maven.plugin.dependency.testUtils.ArtifactStubFactory;
 import org.apache.maven.plugin.dependency.testUtils.DependencyTestUtils;
+import org.apache.maven.plugin.dependency.testUtils.stubs.StubArtifactCollector;
 import org.apache.maven.plugin.dependency.testUtils.stubs.StubArtifactRepository;
 import org.apache.maven.plugin.dependency.testUtils.stubs.StubArtifactResolver;
 import org.apache.maven.plugin.dependency.utils.markers.DefaultFileMarkerHandler;
@@ -73,6 +74,7 @@
         mojo.setFactory( DependencyTestUtils.getArtifactFactory() );
         mojo.setResolver( new StubArtifactResolver( stubFactory, false, false ) );
         mojo.setLocal( new StubArtifactRepository( this.testDir.getAbsolutePath() ) );
+        mojo.setArtifactCollector( new StubArtifactCollector());
     }
 
     public ArtifactItem getSingleArtifactItem( boolean removeVersion )

Modified: maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/DependencyProjectStub.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/DependencyProjectStub.java?view=diff&rev=501305&r1=501304&r2=501305
==============================================================================
--- maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/DependencyProjectStub.java (original)
+++ maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/DependencyProjectStub.java Mon Jan 29 20:02:17 2007
@@ -28,10 +28,13 @@
 import java.util.Set;
 
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
 import org.apache.maven.artifact.DependencyResolutionRequiredException;
 import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.handler.ArtifactHandler;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+import org.apache.maven.artifact.versioning.VersionRange;
 import org.apache.maven.model.Build;
 import org.apache.maven.model.CiManagement;
 import org.apache.maven.model.Contributor;
@@ -180,6 +183,15 @@
 
     public Artifact getArtifact()
     {
+        if (artifact == null)
+        {
+            ArtifactHandler ah = new DefaultArtifactHandlerStub("jar",null);
+            
+            VersionRange vr = VersionRange.createFromVersion( "1.0" );
+            Artifact art = new DefaultArtifact( "group", "artifact", vr, Artifact.SCOPE_COMPILE, "jar", null, ah,
+                                                     false );
+            setArtifact(art);
+        }
         return artifact;
     }
 

Added: maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubArtifactCollector.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubArtifactCollector.java?view=auto&rev=501305
==============================================================================
--- maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubArtifactCollector.java (added)
+++ maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubArtifactCollector.java Mon Jan 29 20:02:17 2007
@@ -0,0 +1,96 @@
+package org.apache.maven.plugin.dependency.testUtils.stubs;
+
+/* 
+ * 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.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactCollector;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
+import org.apache.maven.artifact.resolver.ResolutionNode;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+
+/**
+ * @author brianf
+ *
+ */
+public class StubArtifactCollector
+    implements ArtifactCollector
+{
+
+    /**
+     * 
+     */
+    public StubArtifactCollector()
+    {
+        super();
+        // TODO Auto-generated constructor stub
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.maven.artifact.resolver.ArtifactCollector#collect(java.util.Set, org.apache.maven.artifact.Artifact, org.apache.maven.artifact.repository.ArtifactRepository, java.util.List, org.apache.maven.artifact.metadata.ArtifactMetadataSource, org.apache.maven.artifact.resolver.filter.ArtifactFilter, java.util.List)
+     */
+    public ArtifactResolutionResult collect( Set theArtifacts, Artifact theOriginatingArtifact,
+                                            ArtifactRepository theLocalRepository, List theRemoteRepositories,
+                                            ArtifactMetadataSource theSource, ArtifactFilter theFilter,
+                                            List theListeners )
+        throws ArtifactResolutionException
+    {
+        Set nodes = new HashSet();
+        ArtifactResolutionResult arr = new ArtifactResolutionResult();
+
+        Iterator iter = theArtifacts.iterator();
+        while (iter.hasNext())
+        {  
+            nodes.add(new ResolutionNode((Artifact) iter.next(),theRemoteRepositories));
+        }
+        arr.setArtifactResolutionNodes(nodes);
+        return arr;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.maven.artifact.resolver.ArtifactCollector#collect(java.util.Set, org.apache.maven.artifact.Artifact, java.util.Map, org.apache.maven.artifact.repository.ArtifactRepository, java.util.List, org.apache.maven.artifact.metadata.ArtifactMetadataSource, org.apache.maven.artifact.resolver.filter.ArtifactFilter, java.util.List)
+     */
+    public ArtifactResolutionResult collect( Set theArtifacts, Artifact theOriginatingArtifact, Map theManagedVersions,
+                                            ArtifactRepository theLocalRepository, List theRemoteRepositories,
+                                            ArtifactMetadataSource theSource, ArtifactFilter theFilter,
+                                            List theListeners )
+        throws ArtifactResolutionException
+    {
+        Set nodes = new HashSet();
+        ArtifactResolutionResult arr = new ArtifactResolutionResult();
+
+        Iterator iter = theArtifacts.iterator();
+        while (iter.hasNext())
+        {  
+            nodes.add(new ResolutionNode((Artifact) iter.next(),theRemoteRepositories));
+        }
+        arr.setArtifactResolutionNodes(nodes);
+        return arr;
+    }
+
+}