Updated Branches:
  refs/heads/master 2fd4d482e -> 11f46bd4c

MNG-5503: Fix for the issue where Maven 3.1.0 fails to resolve artifacts 
produced by reactor build

The general strategy is to fall back to Aether artifact type and use its notion 
of identity as much as possible. I have
a simple IT taken from the sample project that I will also push.


Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/11f46bd4
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/11f46bd4
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/11f46bd4

Branch: refs/heads/master
Commit: 11f46bd4c4dfe51514e60fbb9f807bcbb07a14a9
Parents: 2fd4d48
Author: Jason van Zyl <ja...@tesla.io>
Authored: Tue Aug 20 05:54:28 2013 -0700
Committer: Jason van Zyl <ja...@tesla.io>
Committed: Tue Aug 20 05:54:28 2013 -0700

----------------------------------------------------------------------
 apache-maven/pom.xml                            |   2 +-
 .../java/org/apache/maven/ReactorReader.java    | 244 +++++++------------
 .../java/org/apache/maven/RepositoryUtils.java  |  10 +
 3 files changed, 94 insertions(+), 162 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/11f46bd4/apache-maven/pom.xml
----------------------------------------------------------------------
diff --git a/apache-maven/pom.xml b/apache-maven/pom.xml
index 4b8c579..c1aa9b6 100644
--- a/apache-maven/pom.xml
+++ b/apache-maven/pom.xml
@@ -96,7 +96,7 @@
         <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-remote-resources-plugin</artifactId>
-            <version>1.5-SNAPSHOT</version>
+            <version>1.5</version>
         </plugin>
         <plugin>
           <groupId>org.apache.rat</groupId>

http://git-wip-us.apache.org/repos/asf/maven/blob/11f46bd4/maven-core/src/main/java/org/apache/maven/ReactorReader.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/ReactorReader.java 
b/maven-core/src/main/java/org/apache/maven/ReactorReader.java
index 90d102f..9b19e27 100644
--- a/maven-core/src/main/java/org/apache/maven/ReactorReader.java
+++ b/maven-core/src/main/java/org/apache/maven/ReactorReader.java
@@ -19,12 +19,6 @@ package org.apache.maven;
  * under the License.
  */
 
-import org.apache.maven.artifact.ArtifactUtils;
-import org.apache.maven.project.MavenProject;
-import org.eclipse.aether.artifact.Artifact;
-import org.eclipse.aether.repository.WorkspaceReader;
-import org.eclipse.aether.repository.WorkspaceRepository;
-
 import java.io.File;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -35,6 +29,13 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.maven.artifact.ArtifactUtils;
+import org.apache.maven.project.MavenProject;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.repository.WorkspaceReader;
+import org.eclipse.aether.repository.WorkspaceRepository;
+import org.eclipse.aether.util.artifact.ArtifactIdUtils;
+
 /**
  * An implementation of a workspace reader that knows how to search the Maven 
reactor for artifacts.
  * 
@@ -43,8 +44,6 @@ import java.util.Map;
 class ReactorReader
     implements WorkspaceReader
 {
-    private static final Collection<String> JAR_LIKE_TYPES = Arrays.asList( 
"jar", "test-jar", "ejb-client" );
-
     private static final Collection<String> COMPILE_PHASE_TYPES = 
Arrays.asList( "jar", "ejb-client" );
 
     private Map<String, MavenProject> projectsByGAV;
@@ -52,7 +51,7 @@ class ReactorReader
     private Map<String, List<MavenProject>> projectsByGA;
 
     private WorkspaceRepository repository;
-    
+        
     public ReactorReader( Map<String, MavenProject> reactorProjects )
     {
         projectsByGAV = reactorProjects;
@@ -73,9 +72,64 @@ class ReactorReader
             projects.add( project );
         }
 
-        repository = new WorkspaceRepository( "reactor", new HashSet<String>( 
projectsByGAV.keySet() ) );
+        repository = new WorkspaceRepository( "reactor", new HashSet<String>( 
projectsByGAV.keySet() ) );        
+    }
+
+    //
+    // Public API
+    //
+    
+    public WorkspaceRepository getRepository()
+    {
+        return repository;
+    }
+    
+    public File findArtifact( Artifact artifact )
+    {
+        String projectKey = ArtifactUtils.key( artifact.getGroupId(), 
artifact.getArtifactId(), artifact.getVersion() );
+
+        MavenProject project = projectsByGAV.get( projectKey );
+
+        if ( project != null )
+        {
+            File file = find( project, artifact );
+            if ( file == null && project != project.getExecutionProject() )
+            {
+                file = find( project.getExecutionProject(), artifact );
+            }
+            return file;
+        }
+
+        return null;
     }
 
+    public List<String> findVersions( Artifact artifact )
+    {
+        String key = ArtifactUtils.versionlessKey( artifact.getGroupId(), 
artifact.getArtifactId() );
+
+        List<MavenProject> projects = projectsByGA.get( key );
+        if ( projects == null || projects.isEmpty() )
+        {
+            return Collections.emptyList();
+        }
+
+        List<String> versions = new ArrayList<String>();
+
+        for ( MavenProject project : projects )
+        {
+            if ( find( project, artifact ) != null )
+            {
+                versions.add( project.getVersion() );
+            }
+        }
+
+        return Collections.unmodifiableList( versions );
+    }    
+    
+    //
+    // Implementation
+    //
+    
     private File find( MavenProject project, Artifact artifact )
     {
         if ( "pom".equals( artifact.getExtension() ) )
@@ -83,7 +137,7 @@ class ReactorReader
             return project.getFile();
         }
 
-        org.apache.maven.artifact.Artifact projectArtifact = 
findMatchingArtifact( project, artifact );
+        Artifact projectArtifact = findMatchingArtifact( project, artifact );
 
         if ( hasArtifactFileFromPackagePhase( projectArtifact ) )
         {
@@ -116,7 +170,7 @@ class ReactorReader
         return null;
     }
 
-    private boolean hasArtifactFileFromPackagePhase( 
org.apache.maven.artifact.Artifact projectArtifact )
+    private boolean hasArtifactFileFromPackagePhase( Artifact projectArtifact )
     {
         return projectArtifact != null && projectArtifact.getFile() != null && 
projectArtifact.getFile().exists();
     }
@@ -136,122 +190,38 @@ class ReactorReader
      * 
      * Note that this 
      */
-    private org.apache.maven.artifact.Artifact findMatchingArtifact( 
MavenProject project, Artifact requestedArtifact )
+    private Artifact findMatchingArtifact( MavenProject project, Artifact 
requestedArtifact )
     {
-        String requestedRepositoryConflictId = getConflictId( 
requestedArtifact );
+        String requestedRepositoryConflictId = 
ArtifactIdUtils.toVersionlessId( requestedArtifact );
 
-        org.apache.maven.artifact.Artifact mainArtifact = 
project.getArtifact();
-        if ( requestedRepositoryConflictId.equals( getConflictId( mainArtifact 
) ) )
+        Artifact mainArtifact = RepositoryUtils.toArtifact( 
project.getArtifact() );
+        if ( requestedRepositoryConflictId.equals( 
ArtifactIdUtils.toVersionlessId( mainArtifact ) ) )
         {
             return mainArtifact;
         }
 
-        Collection<org.apache.maven.artifact.Artifact> attachedArtifacts = 
project.getAttachedArtifacts();
-        if ( attachedArtifacts != null && !attachedArtifacts.isEmpty() )
+        for ( Artifact attachedArtifact : RepositoryUtils.toArtifacts( 
project.getAttachedArtifacts() ) )
         {
-            for ( org.apache.maven.artifact.Artifact attachedArtifact : 
attachedArtifacts )
+            if ( attachedArtifactComparison ( requestedArtifact, 
attachedArtifact ) )
             {
-                /*
-                 * Don't use the conflict ids, use a customized comparison 
that takes various ideas into account.
-                 */
-                if ( attachedArtifactComparison ( requestedArtifact, 
attachedArtifact ) )
-                {
-                    return attachedArtifact;
-                }
+                return attachedArtifact;
             }
         }
 
         return null;
     }
-    
-    /**
-     * Try to satisfy both MNG-4065 and MNG-5214. Consider jar and test-jar 
equivalent.
-     * @param requestedType
-     * @param artifactType
-     * @return
-     */
-    private boolean attachedArtifactComparison ( Artifact requestedArtifact, 
org.apache.maven.artifact.Artifact attachedArtifact )
-    {
-        if ( ! requestedArtifact.getGroupId().equals ( 
attachedArtifact.getGroupId() ) ) 
-        { 
-            return false;
-        }
-        if ( ! requestedArtifact.getArtifactId().equals ( 
attachedArtifact.getArtifactId() ) ) 
-        { 
-            return false;
-        }
-        String requestedExtension = requestedArtifact.getExtension();
-        String attachedExtension = null;
-        if ( attachedArtifact.getArtifactHandler() != null ) 
-            {
-                attachedExtension = 
attachedArtifact.getArtifactHandler().getExtension();
-            }
-        String requestedType = requestedArtifact.getProperty ( "type", "" );
-        String attachedType = attachedArtifact.getType();
-        boolean typeOk = false;
-        
-        if ( requestedExtension.equals ( attachedExtension ) )
-        {
-            // the ideal case.
-            typeOk = true;
-        }
-        else if ( requestedType.equals( attachedType ) )
-        {
-            typeOk = true;
-        }
-        else if ( JAR_LIKE_TYPES.contains( requestedType ) && 
JAR_LIKE_TYPES.contains( attachedType ) )
-        {
-            typeOk = true;
-        }
         
-        if ( !typeOk )
-        {
-            return false;
-        }
-        return requestedArtifact.getClassifier().equals ( 
attachedArtifact.getClassifier() );
-    }
-    
-    /**
-     * Gets the repository conflict id of the specified artifact. Unlike the 
dependency conflict id, the repository
-     * conflict id uses the artifact file extension instead of the artifact 
type. Hence, the repository conflict id more
-     * closely reflects the identity of artifacts as perceived by a repository.
-     * 
-     * @param artifact The artifact, must not be <code>null</code>.
-     * @return The repository conflict id, never <code>null</code>.
-     */
-    private String getConflictId( org.apache.maven.artifact.Artifact artifact )
+    private boolean attachedArtifactComparison( Artifact requested, Artifact 
attached )
     {
-        StringBuilder buffer = new StringBuilder( 128 );
-        buffer.append( artifact.getGroupId() );
-        buffer.append( ':' ).append( artifact.getArtifactId() );
-        if ( artifact.getArtifactHandler() != null )
-        {
-            buffer.append( ':' ).append( 
artifact.getArtifactHandler().getExtension() );
-        }
-        else
-        {
-            buffer.append( ':' ).append( artifact.getType() );
-        }
-        if ( artifact.hasClassifier() )
-        {
-            buffer.append( ':' ).append( artifact.getClassifier() );
-        }
-        return buffer.toString();
-    }
-
-    private String getConflictId( Artifact artifact )
-    {
-        StringBuilder buffer = new StringBuilder( 128 );
-        buffer.append( artifact.getGroupId() );
-        buffer.append( ':' ).append( artifact.getArtifactId() );
-        buffer.append( ':' ).append( artifact.getExtension() );
-        if ( artifact.getClassifier().length() > 0 )
-        {
-            buffer.append( ':' ).append( artifact.getClassifier() );
-        }
-        return buffer.toString();
-    }
-
+          //
+          // We are taking as much as we can from the 
DefaultArtifact.equals(). The requested artifact has no file so
+          // we want to remove that from the comparision.          
+          //
+          return requested.getArtifactId().equals( attached.getArtifactId() ) 
&& requested.getGroupId().equals( attached.getGroupId() )
+            && requested.getVersion().equals( attached.getVersion() ) && 
requested.getExtension().equals( attached.getExtension() )
+            && requested.getClassifier().equals( attached.getClassifier() );
+    }    
+       
     /**
      * Determines whether the specified artifact refers to test classes.
      * 
@@ -263,52 +233,4 @@ class ReactorReader
         return ( "test-jar".equals( artifact.getProperty( "type", "" ) ) )
             || ( "jar".equals( artifact.getExtension() ) && "tests".equals( 
artifact.getClassifier() ) );
     }
-
-    public File findArtifact( Artifact artifact )
-    {
-        String projectKey = ArtifactUtils.key( artifact.getGroupId(), 
artifact.getArtifactId(), artifact.getVersion() );
-
-        MavenProject project = projectsByGAV.get( projectKey );
-
-        if ( project != null )
-        {
-            File file = find( project, artifact );
-            if ( file == null && project != project.getExecutionProject() )
-            {
-                file = find( project.getExecutionProject(), artifact );
-            }
-            return file;
-        }
-
-        return null;
-    }
-
-    public List<String> findVersions( Artifact artifact )
-    {
-        String key = ArtifactUtils.versionlessKey( artifact.getGroupId(), 
artifact.getArtifactId() );
-
-        List<MavenProject> projects = projectsByGA.get( key );
-        if ( projects == null || projects.isEmpty() )
-        {
-            return Collections.emptyList();
-        }
-
-        List<String> versions = new ArrayList<String>();
-
-        for ( MavenProject project : projects )
-        {
-            if ( find( project, artifact ) != null )
-            {
-                versions.add( project.getVersion() );
-            }
-        }
-
-        return Collections.unmodifiableList( versions );
-    }
-
-    public WorkspaceRepository getRepository()
-    {
-        return repository;
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/maven/blob/11f46bd4/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java 
b/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java
index 9b68a2e..c966e9a 100644
--- a/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java
+++ b/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java
@@ -350,4 +350,14 @@ public class RepositoryUtils
 
     }
 
+    public static Collection<Artifact> 
toArtifacts(Collection<org.apache.maven.artifact.Artifact> artifactsToConvert ) 
+    {
+        List<Artifact> artifacts = new ArrayList<Artifact>();
+        for( org.apache.maven.artifact.Artifact a : artifactsToConvert )
+        {
+            artifacts.add(toArtifact(a));
+        }
+        return artifacts;
+    }
+
 }

Reply via email to