mdep-50: fixed unit tests

git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/branches/maven-dependency-plugin-MDEP-50@501305 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java b/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java
index a20ee5d..38e5f38 100644
--- a/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java
+++ b/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java
@@ -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;
+    }
 }
diff --git a/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java b/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java
index ed23cf9..35f84e7 100644
--- a/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java
+++ b/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java
@@ -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
diff --git a/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java b/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java
index cca4891..ec2ab5b 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java
@@ -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 )

diff --git a/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java b/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java
index 140f66d..3fe3a5a 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java
@@ -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 )

diff --git a/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/DependencyProjectStub.java b/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/DependencyProjectStub.java
index 7cb0b6f..f044bd9 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/DependencyProjectStub.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/DependencyProjectStub.java
@@ -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;

     }

 

diff --git a/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubArtifactCollector.java b/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubArtifactCollector.java
new file mode 100644
index 0000000..dcee7e9
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubArtifactCollector.java
@@ -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;

+    }

+

+}