You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jd...@apache.org on 2008/07/09 23:43:56 UTC

svn commit: r675351 - in /maven/artifact/trunk/src: main/java/org/apache/maven/artifact/metadata/ main/java/org/apache/maven/artifact/resolver/ test/java/org/apache/maven/artifact/deployer/ test/java/org/apache/maven/artifact/resolver/

Author: jdcasey
Date: Wed Jul  9 14:43:56 2008
New Revision: 675351

URL: http://svn.apache.org/viewvc?rev=675351&view=rev
Log:
[MNG-3380] Process relocations before attempting to resolve child nodes during artifact collection.

Modified:
    maven/artifact/trunk/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadataSource.java
    maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java
    maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java
    maven/artifact/trunk/src/test/java/org/apache/maven/artifact/deployer/SimpleArtifactMetadataSource.java
    maven/artifact/trunk/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java
    maven/artifact/trunk/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java

Modified: maven/artifact/trunk/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadataSource.java
URL: http://svn.apache.org/viewvc/maven/artifact/trunk/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadataSource.java?rev=675351&r1=675350&r2=675351&view=diff
==============================================================================
--- maven/artifact/trunk/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadataSource.java (original)
+++ maven/artifact/trunk/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadataSource.java Wed Jul  9 14:43:56 2008
@@ -42,6 +42,14 @@
         throws ArtifactMetadataRetrievalException;
 
     /**
+     * Resolve all relocations in the POM for this artifact, and return the new artifact coordinate.
+     */
+    Artifact retrieveRelocatedArtifact( Artifact artifact,
+                                        ArtifactRepository localRepository,
+                                        List<ArtifactRepository> remoteRepositories )
+        throws ArtifactMetadataRetrievalException;
+
+    /**
      * Get a list of available versions for an artifact in the remote repository
      *
      * @param artifact           artifact we are interested in. Only <code>groupid</code> and <code>artifactId</code>
@@ -61,7 +69,7 @@
     /**
      * Get a list of available versions for an artifact in the remote deployment repository. This ignores any update
      * policy checks and mirrors and always retrieves the latest information from the given repository.
-     * 
+     *
      * @param artifact artifact we are interested in. Only <code>groupid</code> and <code>artifactId</code> are
      *            needed, for instance the following code will work
      *            <code>artifactFactory.createProjectArtifact( "org.apache.maven", "maven", "" )</code>

Modified: maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java
URL: http://svn.apache.org/viewvc/maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java?rev=675351&r1=675350&r2=675351&view=diff
==============================================================================
--- maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java (original)
+++ maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java Wed Jul  9 14:43:56 2008
@@ -424,87 +424,100 @@
 
                         try
                         {
-                            Object childKey = child.getKey();
-                            if ( managedVersions.containsKey( childKey ) )
+                            Object childKey;
+                            do
                             {
-                                // If this child node is a managed dependency, ensure
-                                // we are using the dependency management version
-                                // of this child if applicable b/c we want to use the
-                                // managed version's POM, *not* any other version's POM.
-                                // We retrieve the POM below in the retrieval step.
-                                manageArtifact( child, managedVersions, listeners );
-
-                                // Also, we need to ensure that any exclusions it presents are
-                                // added to the artifact before we retrive the metadata
-                                // for the artifact; otherwise we may end up with unwanted
-                                // dependencies.
-                                Artifact ma = (Artifact) managedVersions.get( childKey );
-                                ArtifactFilter managedExclusionFilter = ma.getDependencyFilter();
-                                if ( null != managedExclusionFilter )
+                                childKey = child.getKey();
+
+                                if ( managedVersions.containsKey( childKey ) )
                                 {
-                                    if ( null != artifact.getDependencyFilter() )
-                                    {
-                                        AndArtifactFilter aaf = new AndArtifactFilter();
-                                        aaf.add( artifact.getDependencyFilter() );
-                                        aaf.add( managedExclusionFilter );
-                                        artifact.setDependencyFilter( aaf );
-                                    }
-                                    else
+                                    // If this child node is a managed dependency, ensure
+                                    // we are using the dependency management version
+                                    // of this child if applicable b/c we want to use the
+                                    // managed version's POM, *not* any other version's POM.
+                                    // We retrieve the POM below in the retrieval step.
+                                    manageArtifact( child, managedVersions, listeners );
+
+                                    // Also, we need to ensure that any exclusions it presents are
+                                    // added to the artifact before we retrive the metadata
+                                    // for the artifact; otherwise we may end up with unwanted
+                                    // dependencies.
+                                    Artifact ma = (Artifact) managedVersions.get( childKey );
+                                    ArtifactFilter managedExclusionFilter = ma.getDependencyFilter();
+                                    if ( null != managedExclusionFilter )
                                     {
-                                        artifact.setDependencyFilter( managedExclusionFilter );
+                                        if ( null != artifact.getDependencyFilter() )
+                                        {
+                                            AndArtifactFilter aaf = new AndArtifactFilter();
+                                            aaf.add( artifact.getDependencyFilter() );
+                                            aaf.add( managedExclusionFilter );
+                                            artifact.setDependencyFilter( aaf );
+                                        }
+                                        else
+                                        {
+                                            artifact.setDependencyFilter( managedExclusionFilter );
+                                        }
                                     }
                                 }
-                            }
 
-                            if ( artifact.getVersion() == null )
-                            {
-                                // set the recommended version
-                                // TODO: maybe its better to just pass the range through to retrieval and use a
-                                // transformation?
-                                ArtifactVersion version;
-                                if ( !artifact.isSelectedVersionKnown() )
+                                if ( artifact.getVersion() == null )
                                 {
-                                    List<ArtifactVersion> versions = artifact.getAvailableVersions();
-                                    if ( versions == null )
+                                    // set the recommended version
+                                    // TODO: maybe its better to just pass the range through to retrieval and use a
+                                    // transformation?
+                                    ArtifactVersion version;
+                                    if ( !artifact.isSelectedVersionKnown() )
                                     {
-                                        versions =
-                                            source.retrieveAvailableVersions( artifact, localRepository,
-                                                                              childRemoteRepositories );
-                                        artifact.setAvailableVersions( versions );
-                                    }
-
-                                    Collections.sort( versions );
+                                        List<ArtifactVersion> versions = artifact.getAvailableVersions();
+                                        if ( versions == null )
+                                        {
+                                            versions =
+                                                source.retrieveAvailableVersions( artifact, localRepository,
+                                                                                  childRemoteRepositories );
+                                            artifact.setAvailableVersions( versions );
+                                        }
 
-                                    VersionRange versionRange = artifact.getVersionRange();
+                                        Collections.sort( versions );
 
-                                    version = versionRange.matchVersion( versions );
+                                        VersionRange versionRange = artifact.getVersionRange();
 
-                                    if ( version == null )
-                                    {
-                                        // Getting the dependency trail so it can be logged in the exception
-                                        artifact.setDependencyTrail( node.getDependencyTrail() );
+                                        version = versionRange.matchVersion( versions );
 
-                                        if ( versions.isEmpty() )
+                                        if ( version == null )
                                         {
-                                            throw new OverConstrainedVersionException(
-                                                                                       "No versions are present in the repository for the artifact with a range "
-                                                                                           + versionRange, artifact,
-                                                                                           childRemoteRepositories );
-                                        }
+                                            // Getting the dependency trail so it can be logged in the exception
+                                            artifact.setDependencyTrail( node.getDependencyTrail() );
 
-                                        throw new OverConstrainedVersionException( "Couldn't find a version in "
-                                            + versions + " to match range " + versionRange, artifact,
-                                            childRemoteRepositories );
+                                            if ( versions.isEmpty() )
+                                            {
+                                                throw new OverConstrainedVersionException(
+                                                                                           "No versions are present in the repository for the artifact with a range "
+                                                                                               + versionRange, artifact,
+                                                                                               childRemoteRepositories );
+                                            }
+
+                                            throw new OverConstrainedVersionException( "Couldn't find a version in "
+                                                + versions + " to match range " + versionRange, artifact,
+                                                childRemoteRepositories );
+                                        }
                                     }
+                                    else
+                                    {
+                                        version = artifact.getSelectedVersion();
+                                    }
+
+                                    artifact.selectVersion( version.toString() );
+                                    fireEvent( ResolutionListener.SELECT_VERSION_FROM_RANGE, listeners, child );
                                 }
-                                else
+
+                                Artifact relocated = source.retrieveRelocatedArtifact( artifact, localRepository, childRemoteRepositories );
+                                if ( !artifact.equals( relocated ) )
                                 {
-                                    version = artifact.getSelectedVersion();
+                                    artifact = relocated;
+                                    child.setArtifact( artifact );
                                 }
-
-                                artifact.selectVersion( version.toString() );
-                                fireEvent( ResolutionListener.SELECT_VERSION_FROM_RANGE, listeners, child );
                             }
+                            while( !childKey.equals( child.getKey() ) );
 
                             artifact.setDependencyTrail( node.getDependencyTrail() );
 

Modified: maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java
URL: http://svn.apache.org/viewvc/maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java?rev=675351&r1=675350&r2=675351&view=diff
==============================================================================
--- maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java (original)
+++ maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java Wed Jul  9 14:43:56 2008
@@ -34,7 +34,7 @@
 
 public class ResolutionNode
 {
-    private final Artifact artifact;
+    private Artifact artifact;
 
     private List<ResolutionNode> children;
 
@@ -244,4 +244,9 @@
         return artifact.toString() + " (" + depth + "; " + ( active ? "enabled" : "disabled" ) + ")";
     }
 
+    public void setArtifact( Artifact artifact )
+    {
+        this.artifact = artifact;
+    }
+
 }

Modified: maven/artifact/trunk/src/test/java/org/apache/maven/artifact/deployer/SimpleArtifactMetadataSource.java
URL: http://svn.apache.org/viewvc/maven/artifact/trunk/src/test/java/org/apache/maven/artifact/deployer/SimpleArtifactMetadataSource.java?rev=675351&r1=675350&r2=675351&view=diff
==============================================================================
--- maven/artifact/trunk/src/test/java/org/apache/maven/artifact/deployer/SimpleArtifactMetadataSource.java (original)
+++ maven/artifact/trunk/src/test/java/org/apache/maven/artifact/deployer/SimpleArtifactMetadataSource.java Wed Jul  9 14:43:56 2008
@@ -24,8 +24,8 @@
 import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
 import org.apache.maven.artifact.metadata.ResolutionGroup;
 import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
 import org.apache.maven.artifact.versioning.ArtifactVersion;
+import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
 
 import java.util.Collections;
 import java.util.List;
@@ -55,4 +55,12 @@
     {
         return Collections.<ArtifactVersion>singletonList( new DefaultArtifactVersion( "10.1.3" ) );
     }
+
+    public Artifact retrieveRelocatedArtifact( Artifact artifact,
+                                               ArtifactRepository localRepository,
+                                               List<ArtifactRepository> remoteRepositories )
+        throws ArtifactMetadataRetrievalException
+    {
+        return artifact;
+    }
 }

Modified: maven/artifact/trunk/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java
URL: http://svn.apache.org/viewvc/maven/artifact/trunk/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java?rev=675351&r1=675350&r2=675351&view=diff
==============================================================================
--- maven/artifact/trunk/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java (original)
+++ maven/artifact/trunk/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java Wed Jul  9 14:43:56 2008
@@ -146,6 +146,14 @@
             {
                 throw new UnsupportedOperationException( "Cannot get available versions in this test case" );
             }
+
+            public Artifact retrieveRelocatedArtifact( Artifact artifact,
+                                                       ArtifactRepository localRepository,
+                                                       List<ArtifactRepository> remoteRepositories )
+                throws ArtifactMetadataRetrievalException
+            {
+                return artifact;
+            }
         };
 
         ArtifactResolutionResult result =
@@ -213,6 +221,14 @@
             {
                 throw new UnsupportedOperationException( "Cannot get available versions in this test case" );
             }
+
+            public Artifact retrieveRelocatedArtifact( Artifact artifact,
+                                                       ArtifactRepository localRepository,
+                                                       List<ArtifactRepository> remoteRepositories )
+                throws ArtifactMetadataRetrievalException
+            {
+                return artifact;
+            }
         };
 
         ArtifactResolutionResult result =
@@ -295,6 +311,14 @@
             {
                 throw new UnsupportedOperationException( "Cannot get available versions in this test case" );
             }
+
+            public Artifact retrieveRelocatedArtifact( Artifact artifact,
+                                                       ArtifactRepository localRepository,
+                                                       List<ArtifactRepository> remoteRepositories )
+                throws ArtifactMetadataRetrievalException
+            {
+                return artifact;
+            }
         };
 
         ArtifactResolutionResult result = null;

Modified: maven/artifact/trunk/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java
URL: http://svn.apache.org/viewvc/maven/artifact/trunk/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java?rev=675351&r1=675350&r2=675351&view=diff
==============================================================================
--- maven/artifact/trunk/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java (original)
+++ maven/artifact/trunk/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java Wed Jul  9 14:43:56 2008
@@ -19,17 +19,6 @@
  * under the License.
  */
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-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.metadata.ArtifactMetadataRetrievalException;
@@ -46,9 +35,20 @@
 import org.apache.maven.artifact.versioning.VersionRange;
 import org.codehaus.plexus.PlexusTestCase;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 /**
  * Test the default artifact collector.
- * 
+ *
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
  * @version $Id$
  */
@@ -65,16 +65,17 @@
 
     private static final String GROUP_ID = "test";
 
+    @Override
     protected void setUp()
         throws Exception
     {
         super.setUp();
 
-        this.source = new Source();
-        this.artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
-        this.artifactCollector = (ArtifactCollector) lookup( ArtifactCollector.ROLE );
+        source = new Source();
+        artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
+        artifactCollector = (ArtifactCollector) lookup( ArtifactCollector.ROLE );
 
-        this.projectArtifact = createArtifactSpec( "project", "1.0", null );
+        projectArtifact = createArtifactSpec( "project", "1.0", null );
     }
 
     // works, but we don't fail on cycles presently
@@ -824,7 +825,7 @@
         private ArtifactSpec addDependency( String id, String version, String scope, boolean optional )
             throws InvalidVersionSpecificationException
         {
-            ArtifactSpec dep = createArtifactSpec( id, version, scope, this.artifact.getScope(), optional );
+            ArtifactSpec dep = createArtifactSpec( id, version, scope, artifact.getScope(), optional );
             return addDependency( dep );
         }
 
@@ -955,5 +956,13 @@
             }
             return artifactVersions;
         }
+
+        public Artifact retrieveRelocatedArtifact( Artifact artifact,
+                                                   ArtifactRepository localRepository,
+                                                   List<ArtifactRepository> remoteRepositories )
+            throws ArtifactMetadataRetrievalException
+        {
+            return artifact;
+        }
     }
 }