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:44:10 UTC

svn commit: r675352 - in /maven/components/trunk/maven-project/src: main/java/org/apache/maven/project/artifact/MavenMetadataSource.java test/java/org/apache/maven/project/TestArtifactResolver.java

Author: jdcasey
Date: Wed Jul  9 14:44:10 2008
New Revision: 675352

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

Modified:
    maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
    maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/TestArtifactResolver.java

Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java?rev=675352&r1=675351&r2=675352&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java Wed Jul  9 14:44:10 2008
@@ -89,16 +89,59 @@
     private boolean strictlyEnforceThePresenceOfAValidMavenPOM = false;
 
     /**
-     * Retrieve the metadata for the project from the repository.
-     * Uses the ProjectBuilder, to enable post-processing and inheritance calculation before retrieving the
-     * associated artifacts.
+     * Resolve all relocations in the POM for this artifact, and return the new artifact coordinate.
      */
-    public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
+    public Artifact retrieveRelocatedArtifact( Artifact artifact,
+                                               ArtifactRepository localRepository,
+                                               List<ArtifactRepository> remoteRepositories )
+        throws ArtifactMetadataRetrievalException
+    {
+        if ( artifact instanceof ActiveProjectArtifact )
+        {
+            return artifact;
+        }
+
+        ProjectRelocation res = retrieveRelocatedProject( artifact, localRepository, remoteRepositories );
+        MavenProject project = res.project;
+
+        if ( project == null || getRelocationKey( artifact ).equals( getRelocationKey( project.getArtifact() ) ) )
+        {
+            return artifact;
+        }
+
+        Artifact result = null;
+        if ( artifact.getClassifier() != null )
+        {
+            result = artifactFactory.createArtifactWithClassifier( project.getGroupId(), project.getArtifactId(), project.getVersion(), artifact.getType(), artifact.getClassifier() );
+        }
+        else
+        {
+            result = artifactFactory.createArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(), artifact.getScope(), artifact.getType() );
+        }
+
+        result.setScope( artifact.getScope() );
+        result.setArtifactHandler( artifact.getArtifactHandler() );
+        result.setDependencyFilter( artifact.getDependencyFilter() );
+        result.setDependencyTrail( artifact.getDependencyTrail() );
+        result.setOptional( artifact.isOptional() );
+        result.setRelease( artifact.isRelease() );
+
+        return result;
+    }
+
+    private String getRelocationKey( Artifact artifact )
+    {
+        return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion();
+    }
+
+    private ProjectRelocation retrieveRelocatedProject( Artifact artifact,
+                                                   ArtifactRepository localRepository,
+                                                   List<ArtifactRepository> remoteRepositories )
         throws ArtifactMetadataRetrievalException
     {
         if ( remoteRepositories == null )
         {
-            remoteRepositories = Collections.EMPTY_LIST;
+            remoteRepositories = Collections.emptyList();
         }
 
         try
@@ -111,7 +154,6 @@
         }
 
         MavenProject project = null;
-
         Artifact pomArtifact;
 
         boolean done = false;
@@ -181,14 +223,17 @@
                         if ( relocation.getGroupId() != null )
                         {
                             artifact.setGroupId( relocation.getGroupId() );
+                            project.setGroupId( relocation.getGroupId() );
                         }
                         if ( relocation.getArtifactId() != null )
                         {
                             artifact.setArtifactId( relocation.getArtifactId() );
+                            project.setArtifactId( relocation.getArtifactId() );
                         }
                         if ( relocation.getVersion() != null )
                         {
                             artifact.setVersionRange( VersionRange.createFromVersion( relocation.getVersion() ) );
+                            project.setVersion( relocation.getVersion() );
                         }
 
                         if ( ( artifact.getDependencyFilter() != null ) &&
@@ -239,6 +284,25 @@
         }
         while ( !done );
 
+        ProjectRelocation res = new ProjectRelocation();
+        res.project = project;
+        res.pomArtifact = pomArtifact;
+
+        return res;
+    }
+
+    /**
+     * Retrieve the metadata for the project from the repository.
+     * Uses the ProjectBuilder, to enable post-processing and inheritance calculation before retrieving the
+     * associated artifacts.
+     */
+    public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
+        throws ArtifactMetadataRetrievalException
+    {
+        ProjectRelocation res = retrieveRelocatedProject( artifact, localRepository, remoteRepositories );
+        MavenProject project = res.project;
+        Artifact pomArtifact = res.pomArtifact;
+
         // last ditch effort to try to get this set...
         if ( artifact.getDownloadUrl() == null )
         {
@@ -511,4 +575,11 @@
     {
         container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
     }
+
+    private static final class ProjectRelocation
+    {
+        private MavenProject project;
+        private Artifact pomArtifact;
+    }
+
 }

Modified: maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/TestArtifactResolver.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/TestArtifactResolver.java?rev=675352&r1=675351&r2=675352&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/TestArtifactResolver.java (original)
+++ maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/TestArtifactResolver.java Wed Jul  9 14:44:10 2008
@@ -189,6 +189,14 @@
 
             return projectArtifacts;
         }
+
+        public Artifact retrieveRelocatedArtifact( Artifact artifact,
+                                                   ArtifactRepository localRepository,
+                                                   List<ArtifactRepository> remoteRepositories )
+            throws ArtifactMetadataRetrievalException
+        {
+            return artifact;
+        }
     }
 
     public Source source()
@@ -199,12 +207,14 @@
     /**
      * @noinspection RefusedBequest
      */
+    @Override
     public void resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
         throws ArtifactResolutionException
     {
         artifact.setFile( new File( "dummy" ) );
     }
 
+    @Override
     public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
                                                          ArtifactRepository localRepository, List remoteRepositories,
                                                          ArtifactMetadataSource source, ArtifactFilter filter )
@@ -214,6 +224,7 @@
                                           new Source( artifactFactory, repositoryFactory, container ), filter );
     }
 
+    @Override
     public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
                                                          List remoteRepositories, ArtifactRepository localRepository,
                                                          ArtifactMetadataSource source )
@@ -226,7 +237,7 @@
     public void contextualize( Context context )
         throws ContextException
     {
-        this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
+        container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
     }
 
 }
\ No newline at end of file