maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bentm...@apache.org
Subject svn commit: r1002852 - in /maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project: ./ artifact/
Date Wed, 29 Sep 2010 21:31:35 GMT
Author: bentmann
Date: Wed Sep 29 21:31:34 2010
New Revision: 1002852

URL: http://svn.apache.org/viewvc?rev=1002852&view=rev
Log:
[MNG-4842] [regression] Repositories discovered in dependency POMs override repositories configured
for original resolution request of POM

Added:
    maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/ProjectModelResolver.java
      - copied, changed from r1002506, maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/ReactorModelResolver.java
Removed:
    maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/ReactorModelResolver.java
Modified:
    maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
    maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java
    maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java
    maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java
    maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java

Modified: maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java?rev=1002852&r1=1002851&r2=1002852&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
(original)
+++ maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
Wed Sep 29 21:31:34 2010
@@ -208,9 +208,9 @@ public class DefaultProjectBuilder
                                                           ReactorModelPool modelPool )
     {
         ModelResolver resolver =
-            new ReactorModelResolver( configuration.getRepositorySession(), artifactResolver,
-                                      repositoryManager,
-                                      RepositoryUtils.toRepos( configuration.getRemoteRepositories()
), modelPool );
+            new ProjectModelResolver( configuration.getRepositorySession(), artifactResolver,
repositoryManager,
+                                      RepositoryUtils.toRepos( configuration.getRemoteRepositories()
),
+                                      configuration.getRepositoryMerging(), modelPool );
 
         ModelBuildingRequest request = new DefaultModelBuildingRequest();
 

Modified: maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java?rev=1002852&r1=1002851&r2=1002852&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java
(original)
+++ maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java
Wed Sep 29 21:31:34 2010
@@ -105,24 +105,48 @@ public class DefaultProjectBuildingHelpe
                                                                 ProjectBuildingRequest request
)
         throws InvalidRepositoryException
     {
-        List<ArtifactRepository> artifactRepositories = new ArrayList<ArtifactRepository>();
-        Collection<String> repoIds = new HashSet<String>();
+        List<ArtifactRepository> internalRepositories = new ArrayList<ArtifactRepository>();
 
         for ( Repository repository : pomRepositories )
         {
-            artifactRepositories.add( repositorySystem.buildArtifactRepository( repository
) );
-            repoIds.add( repository.getId() );
+            internalRepositories.add( repositorySystem.buildArtifactRepository( repository
) );
         }
 
-        repositorySystem.injectMirror( request.getRepositorySession(), artifactRepositories
);
+        repositorySystem.injectMirror( request.getRepositorySession(), internalRepositories
);
+
+        repositorySystem.injectProxy( request.getRepositorySession(), internalRepositories
);
+
+        repositorySystem.injectAuthentication( request.getRepositorySession(), internalRepositories
);
+
+        List<ArtifactRepository> dominantRepositories;
+        List<ArtifactRepository> recessiveRepositories;
+
+        if ( ProjectBuildingRequest.RepositoryMerging.REQUEST_DOMINANT.equals( request.getRepositoryMerging()
) )
+        {
+            dominantRepositories = externalRepositories;
+            recessiveRepositories = internalRepositories;
+        }
+        else
+        {
+            dominantRepositories = internalRepositories;
+            recessiveRepositories = externalRepositories;
+        }
 
-        repositorySystem.injectProxy( request.getRepositorySession(), artifactRepositories
);
+        List<ArtifactRepository> artifactRepositories = new ArrayList<ArtifactRepository>();
+        Collection<String> repoIds = new HashSet<String>();
 
-        repositorySystem.injectAuthentication( request.getRepositorySession(), artifactRepositories
);
+        if ( dominantRepositories != null )
+        {
+            for ( ArtifactRepository repository : dominantRepositories )
+            {
+                repoIds.add( repository.getId() );
+                artifactRepositories.add( repository );
+            }
+        }
 
-        if ( externalRepositories != null )
+        if ( recessiveRepositories != null )
         {
-            for ( ArtifactRepository repository : externalRepositories )
+            for ( ArtifactRepository repository : recessiveRepositories )
             {
                 if ( repoIds.add( repository.getId() ) )
                 {

Modified: maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java?rev=1002852&r1=1002851&r2=1002852&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java
(original)
+++ maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java
Wed Sep 29 21:31:34 2010
@@ -61,6 +61,8 @@ public class DefaultProjectBuildingReque
 
     private boolean resolveDependencies;
 
+    private RepositoryMerging repositoryMerging = RepositoryMerging.POM_DOMINANT;
+
     public DefaultProjectBuildingRequest()
     {
         processPlugins = true;
@@ -301,4 +303,19 @@ public class DefaultProjectBuildingReque
         return this;
     }
 
+    public DefaultProjectBuildingRequest setRepositoryMerging( RepositoryMerging repositoryMerging
)
+    {
+        if ( repositoryMerging == null )
+        {
+            throw new IllegalArgumentException( "repository merge mode not specified" );
+        }
+        this.repositoryMerging = repositoryMerging;
+        return this;
+    }
+
+    public RepositoryMerging getRepositoryMerging()
+    {
+        return repositoryMerging;
+    }
+
 }

Modified: maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java?rev=1002852&r1=1002851&r2=1002852&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java
(original)
+++ maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java
Wed Sep 29 21:31:34 2010
@@ -151,4 +151,39 @@ public interface ProjectBuildingRequest
 
     ProjectBuildingRequest setRepositorySession( RepositorySystemSession repositorySession
);
 
+    /**
+     * Sets the merge mode used to combine repositories declared in the POM with the repositories
specified in this
+     * request.
+     * 
+     * @param mode The repository merge mode, must not be {@code null}.
+     * @return This request for chaining, never {@code null}.
+     * @see #setRemoteRepositories(List)
+     */
+    ProjectBuildingRequest setRepositoryMerging( RepositoryMerging mode );
+
+    /**
+     * Gets the merge mode used to combine repositories declared in the POM with the repositories
specified in this
+     * request
+     * 
+     * @return The merge mode, never {@code null}.
+     */
+    RepositoryMerging getRepositoryMerging();
+
+    /**
+     * The possible merge modes for combining remote repositories.
+     */
+    enum RepositoryMerging
+    {
+
+        /**
+         * The repositories declared in the POM have precedence over the repositories specified
in the request.
+         */
+        POM_DOMINANT,
+
+        /**
+         * The repositories specified in the request have precedence over the repositories
declared in the POM.
+         */
+        REQUEST_DOMINANT,
+    }
+
 }

Copied: maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/ProjectModelResolver.java
(from r1002506, maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/ReactorModelResolver.java)
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/ProjectModelResolver.java?p2=maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/ProjectModelResolver.java&p1=maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/ReactorModelResolver.java&r1=1002506&r2=1002852&rev=1002852&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/ReactorModelResolver.java
(original)
+++ maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/ProjectModelResolver.java
Wed Sep 29 21:31:34 2010
@@ -48,7 +48,7 @@ import org.sonatype.aether.util.artifact
  * 
  * @author Benjamin Bentmann
  */
-class ReactorModelResolver
+class ProjectModelResolver
     implements ModelResolver
 {
 
@@ -60,7 +60,7 @@ class ReactorModelResolver
 
     private List<RemoteRepository> pomRepositories;
 
-    private final List<RemoteRepository> defaultRepositories;
+    private final List<RemoteRepository> externalRepositories;
 
     private final ArtifactResolver resolver;
 
@@ -70,28 +70,32 @@ class ReactorModelResolver
 
     private final ReactorModelPool modelPool;
 
-    public ReactorModelResolver( RepositorySystemSession session, ArtifactResolver resolver,
+    private final ProjectBuildingRequest.RepositoryMerging repositoryMerging;
+
+    public ProjectModelResolver( RepositorySystemSession session, ArtifactResolver resolver,
                                  RemoteRepositoryManager remoteRepositoryManager, List<RemoteRepository>
repositories,
-                                 ReactorModelPool modelPool )
+                                 ProjectBuildingRequest.RepositoryMerging repositoryMerging,
ReactorModelPool modelPool )
     {
         this.session = session;
         this.resolver = resolver;
         this.remoteRepositoryManager = remoteRepositoryManager;
         this.pomRepositories = new ArrayList<RemoteRepository>();
-        this.defaultRepositories = repositories;
+        this.externalRepositories = repositories;
         this.repositories = repositories;
+        this.repositoryMerging = repositoryMerging;
         this.repositoryIds = new HashSet<String>();
         this.modelPool = modelPool;
     }
 
-    private ReactorModelResolver( ReactorModelResolver original )
+    private ProjectModelResolver( ProjectModelResolver original )
     {
         this.session = original.session;
         this.resolver = original.resolver;
         this.remoteRepositoryManager = original.remoteRepositoryManager;
         this.pomRepositories = original.pomRepositories;
-        this.defaultRepositories = original.defaultRepositories;
+        this.externalRepositories = original.externalRepositories;
         this.repositories = original.repositories;
+        this.repositoryMerging = original.repositoryMerging;
         this.repositoryIds = new HashSet<String>( original.repositoryIds );
         this.modelPool = original.modelPool;
     }
@@ -106,10 +110,17 @@ class ReactorModelResolver
 
         List<RemoteRepository> newRepositories = Collections.singletonList( convert(
repository ) );
 
-        pomRepositories =
-            remoteRepositoryManager.aggregateRepositories( session, pomRepositories, newRepositories,
true );
-        repositories =
-            remoteRepositoryManager.aggregateRepositories( session, pomRepositories, defaultRepositories,
false );
+        if ( ProjectBuildingRequest.RepositoryMerging.REQUEST_DOMINANT.equals( repositoryMerging
) )
+        {
+            repositories = remoteRepositoryManager.aggregateRepositories( session, repositories,
newRepositories, true );
+        }
+        else
+        {
+            pomRepositories =
+                remoteRepositoryManager.aggregateRepositories( session, pomRepositories,
newRepositories, true );
+            repositories =
+                remoteRepositoryManager.aggregateRepositories( session, pomRepositories,
externalRepositories, false );
+        }
     }
 
     private static RemoteRepository convert( Repository repository )
@@ -145,7 +156,7 @@ class ReactorModelResolver
 
     public ModelResolver newCopy()
     {
-        return new ReactorModelResolver( this );
+        return new ProjectModelResolver( this );
     }
 
     public ModelSource resolveModel( String groupId, String artifactId, String version )

Modified: maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java?rev=1002852&r1=1002851&r2=1002852&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
(original)
+++ maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
Wed Sep 29 21:31:34 2010
@@ -573,6 +573,7 @@ public class MavenMetadataSource
                     configuration.setRemoteRepositories( repositoryRequest.getRemoteRepositories()
);
                     configuration.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL
);
                     configuration.setProcessPlugins( false );
+                    configuration.setRepositoryMerging( ProjectBuildingRequest.RepositoryMerging.REQUEST_DOMINANT
);
                     configuration.setSystemProperties( getSystemProperties() );
                     configuration.setRepositorySession( legacySupport.getRepositorySession()
);
 



Mime
View raw message