You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by jd...@apache.org on 2005/08/22 22:31:26 UTC

svn commit: r239243 - /maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java

Author: jdcasey
Date: Mon Aug 22 13:31:24 2005
New Revision: 239243

URL: http://svn.apache.org/viewcvs?rev=239243&view=rev
Log:
Resolving: MNG-757 according to the comments in the issue.

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

Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java?rev=239243&r1=239242&r2=239243&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 Mon Aug 22 13:31:24 2005
@@ -58,6 +58,9 @@
 
     private ArtifactFactory artifactFactory;
 
+    // lazily instantiated and cached.
+    private MavenProject superProject;
+
     /**
      * Retrieve the metadata for the project from the repository.
      * Uses the ProjectBuilder, to enable post-processing and inheritance calculation before retrieving the
@@ -134,12 +137,65 @@
             Set artifacts = project.createArtifacts( artifactFactory, artifact.getScope(),
                                                      artifact.getDependencyFilter() );
 
-            return new ResolutionGroup( pomArtifact, artifacts, project.getRemoteArtifactRepositories() );
+            
+            List repositories = aggregateRepositoryLists( remoteRepositories, project.getRemoteArtifactRepositories() );
+            
+            return new ResolutionGroup( pomArtifact, artifacts, repositories );
         }
         catch ( InvalidVersionSpecificationException e )
         {
             throw new ArtifactMetadataRetrievalException( "Unable to read the metadata file", e );
         }
+        catch ( ProjectBuildingException e )
+        {
+            throw new ArtifactMetadataRetrievalException( "Unable to read the metadata file", e );
+        }
+    }
+
+    private List aggregateRepositoryLists( List remoteRepositories, List remoteArtifactRepositories )
+        throws ProjectBuildingException
+    {
+        if ( superProject == null )
+        {
+            superProject = mavenProjectBuilder.buildStandaloneSuperProject( null );
+        }
+
+        List repositories = new ArrayList();
+
+        repositories.addAll( remoteRepositories );
+
+        // ensure that these are defined
+        for ( Iterator it = superProject.getRemoteArtifactRepositories().iterator(); it.hasNext(); )
+        {
+            ArtifactRepository superRepo = (ArtifactRepository) it.next();
+
+            for ( Iterator aggregatedIterator = repositories.iterator(); aggregatedIterator.hasNext(); )
+            {
+                ArtifactRepository repo = (ArtifactRepository) aggregatedIterator.next();
+
+                // if the repository exists in the list and was introduced by another POM's super-pom, 
+                // remove it...the repository definitions from the super-POM should only be at the end of
+                // the list.
+                // if the repository has been redefined, leave it.
+                if ( repo.getId().equals( superRepo.getId() ) && repo.getUrl().equals( superRepo.getUrl() ) )
+                {
+                    aggregatedIterator.remove();
+                }
+            }
+        }
+
+        // this list should contain the super-POM repositories, so we don't have to explicitly add them back.
+        for ( Iterator it = remoteArtifactRepositories.iterator(); it.hasNext(); )
+        {
+            ArtifactRepository repository = (ArtifactRepository) it.next();
+
+            if ( !repositories.contains( repository ) )
+            {
+                repositories.add( repository );
+            }
+        }
+
+        return repositories;
     }
 
     public static Set createArtifacts( ArtifactFactory artifactFactory, List dependencies, String inheritedScope,



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org