Author: brianf
Date: Mon Jan 29 20:10:28 2007
New Revision: 501306

URL: http://svn.apache.org/viewvc?view=rev&rev=501306
Log:
merged in mdep-50 branch

Added:
    
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubArtifactCollector.java
      - copied unchanged from r501305, 
maven/plugins/branches/maven-dependency-plugin-MDEP-50/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubArtifactCollector.java
Modified:
    maven/plugins/trunk/maven-dependency-plugin/src/it/mdep-50/pom.xml
    
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java
    
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java
    
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java
    
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java
    
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/DependencyProjectStub.java

Modified: maven/plugins/trunk/maven-dependency-plugin/src/it/mdep-50/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/it/mdep-50/pom.xml?view=diff&rev=501306&r1=501305&r2=501306
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/it/mdep-50/pom.xml 
(original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/it/mdep-50/pom.xml Mon Jan 
29 20:10:28 2007
@@ -5,18 +5,6 @@
        <artifactId>mdep-50-it</artifactId>
        <version>1</version>
        <packaging>jar</packaging>
-       <dependencies>
-               <dependency>
-                       <groupId>junit</groupId>
-                       <artifactId>junit</artifactId>
-                       <version>[3.7,4.0)</version>
-               </dependency>
-               <dependency>
-                       <groupId>ant</groupId>
-                       <artifactId>ant</artifactId>
-                       <version>1.6</version>
-               </dependency>
-       </dependencies>
        <build>
                <defaultGoal>generate-sources</defaultGoal>
                <plugins>
@@ -37,6 +25,11 @@
                                                                        
<groupId>junit</groupId>
                                                                        
<artifactId>junit</artifactId>
                                                                        
<version>[3.7,4.0)</version>
+                                                               </artifactItem>
+                                                               <artifactItem>
+                                                                       
<groupId>ant</groupId>
+                                                                       
<artifactId>ant</artifactId>
+                                                                       
<version>[1.1,1.5)</version>
                                                                </artifactItem>
                                                        </artifactItems>
                                                </configuration>

Modified: 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java?view=diff&rev=501306&r1=501305&r2=501306
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java
 Mon Jan 29 20:10:28 2007
@@ -24,6 +24,8 @@
 import java.lang.reflect.Field;
 import java.util.List;
 
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.resolver.ArtifactCollector;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.dependency.utils.SilentLog;
@@ -62,6 +64,22 @@
     protected org.apache.maven.artifact.resolver.ArtifactResolver resolver;
 
     /**
+     * Artifact collector, needed to resolve dependencies.
+     * 
+     * @component role="org.apache.maven.artifact.resolver.ArtifactCollector"
+     * @required
+     * @readonly
+     */
+    protected ArtifactCollector artifactCollector;
+
+    /**
+     * @component 
role="org.apache.maven.artifact.metadata.ArtifactMetadataSource" hint="maven"
+     * @required
+     * @readonly
+     */
+    protected ArtifactMetadataSource artifactMetadataSource;
+    
+    /**
      * Location of the local repository.
      * 
      * @parameter expression="${localRepository}"
@@ -332,5 +350,37 @@
     public void setArchiverManager( ArchiverManager archiverManager )
     {
         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/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java?view=diff&rev=501306&r1=501305&r2=501306
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java
 Mon Jan 29 20:10:28 2007
@@ -21,13 +21,24 @@
 
 import java.io.File;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+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.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.ResolutionNode;
+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.plugin.MojoExecutionException;
 import org.apache.maven.plugin.dependency.AbstractDependencyMojo;
 import org.apache.maven.plugin.dependency.utils.DependencyUtil;
@@ -169,6 +180,8 @@
         return result;
     }
 
+  
+
     /**
      * Resolves the Artifact from the remote repository if nessessary. If no
      * version is specified, it will be retrieved from the dependency list or
@@ -188,21 +201,48 @@
     {
         Artifact artifact;
 
+        Map managedVersions = createManagedVersionMap( factory, 
project.getId(), project.getDependencyManagement() );
+        VersionRange vr;
+        try
+        {
+            vr = VersionRange.createFromVersionSpec( artifactItem.getVersion() 
);
+        }
+        catch ( InvalidVersionSpecificationException e1 )
+        {
+            // TODO Auto-generated catch block
+            e1.printStackTrace();
+            vr = VersionRange.createFromVersion( artifactItem.getVersion() );
+        }
+
         if ( StringUtils.isEmpty( artifactItem.getClassifier() ) )
         {
-            artifact = factory.createArtifact( artifactItem.getGroupId(), 
artifactItem.getArtifactId(), artifactItem
-                .getVersion(), Artifact.SCOPE_PROVIDED, artifactItem.getType() 
);
+            artifact = factory.createDependencyArtifact( 
artifactItem.getGroupId(), artifactItem.getArtifactId(), vr,
+                                                         
artifactItem.getType(), null, Artifact.SCOPE_COMPILE );
         }
         else
         {
-            artifact = factory.createArtifactWithClassifier( 
artifactItem.getGroupId(), artifactItem.getArtifactId(),
-                                                             
artifactItem.getVersion(), artifactItem.getType(),
-                                                             
artifactItem.getClassifier() );
+            artifact = factory.createDependencyArtifact( 
artifactItem.getGroupId(), artifactItem.getArtifactId(), vr,
+                                                         
artifactItem.getType(), artifactItem.getClassifier(), Artifact.SCOPE_COMPILE );
         }
 
         try
         {
-            resolver.resolve( artifact, remoteRepos, local );
+            List listeners = new ArrayList();
+
+            Set theSet = new HashSet();
+            theSet.add( artifact );
+            ArtifactResolutionResult artifactResolutionResult = 
artifactCollector.collect( theSet, project
+                .getArtifact(), managedVersions, this.local, 
project.getRemoteArtifactRepositories(),
+                                                                               
            artifactMetadataSource,
+                                                                               
            null, listeners );
+            Iterator iter = 
artifactResolutionResult.getArtifactResolutionNodes().iterator();
+            while ( iter.hasNext() )
+            {
+                ResolutionNode node = (ResolutionNode) iter.next();
+                artifact = node.getArtifact();
+            }
+
+             resolver.resolve( artifact, remoteRepos, local );
         }
         catch ( ArtifactResolutionException e )
         {
@@ -266,6 +306,40 @@
         return result;
     }
 
+    private Map createManagedVersionMap( ArtifactFactory artifactFactory, 
String projectId,
+                                        DependencyManagement 
dependencyManagement )
+        throws MojoExecutionException
+    {
+        Map map;
+        if ( dependencyManagement != null && 
dependencyManagement.getDependencies() != null )
+        {
+            map = new HashMap();
+            for ( Iterator i = 
dependencyManagement.getDependencies().iterator(); i.hasNext(); )
+            {
+                Dependency d = (Dependency) i.next();
+
+                try
+                {
+                    VersionRange versionRange = 
VersionRange.createFromVersionSpec( d.getVersion() );
+                    Artifact artifact = 
artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(),
+                                                                               
   versionRange, d.getType(), d
+                                                                               
       .getClassifier(), d.getScope(), d
+                                                                               
       .isOptional() );
+                    map.put( d.getManagementKey(), artifact );
+                }
+                catch ( InvalidVersionSpecificationException e )
+                {
+                    throw new MojoExecutionException( "Unable to parse 
version", e );
+                }
+            }
+        }
+        else
+        {
+            map = Collections.EMPTY_MAP;
+        }
+        return map;
+    }
+
     /**
      * @return Returns the artifactItems.
      */
@@ -275,7 +349,8 @@
     }
 
     /**
-     * @param theArtifactItems The artifactItems to set.
+     * @param theArtifactItems
+     *            The artifactItems to set.
      */
     public void setArtifactItems( ArrayList theArtifactItems )
     {
@@ -291,7 +366,8 @@
     }
 
     /**
-     * @param theOutputDirectory The outputDirectory to set.
+     * @param theOutputDirectory
+     *            The outputDirectory to set.
      */
     public void setOutputDirectory( File theOutputDirectory )
     {
@@ -307,7 +383,8 @@
     }
 
     /**
-     * @param theOverWriteIfNewer The overWriteIfNewer to set.
+     * @param theOverWriteIfNewer
+     *            The overWriteIfNewer to set.
      */
     public void setOverWriteIfNewer( boolean theOverWriteIfNewer )
     {
@@ -323,7 +400,8 @@
     }
 
     /**
-     * @param theOverWriteReleases The overWriteReleases to set.
+     * @param theOverWriteReleases
+     *            The overWriteReleases to set.
      */
     public void setOverWriteReleases( boolean theOverWriteReleases )
     {
@@ -339,7 +417,8 @@
     }
 
     /**
-     * @param theOverWriteSnapshots The overWriteSnapshots to set.
+     * @param theOverWriteSnapshots
+     *            The overWriteSnapshots to set.
      */
     public void setOverWriteSnapshots( boolean theOverWriteSnapshots )
     {

Modified: 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java?view=diff&rev=501306&r1=501305&r2=501306
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java
 Mon Jan 29 20:10:28 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/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java?view=diff&rev=501306&r1=501305&r2=501306
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java
 Mon Jan 29 20:10:28 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/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/DependencyProjectStub.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/DependencyProjectStub.java?view=diff&rev=501306&r1=501305&r2=501306
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/DependencyProjectStub.java
 (original)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/DependencyProjectStub.java
 Mon Jan 29 20:10:28 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;
     }
 


Reply via email to