You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2009/06/16 22:51:09 UTC

svn commit: r785389 - /maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java

Author: bentmann
Date: Tue Jun 16 20:51:09 2009
New Revision: 785389

URL: http://svn.apache.org/viewvc?rev=785389&view=rev
Log:
o Restored backward-compat regarding the lenient handling of the type of remote repositories provided to the project builder (this code is limited to the compat level so doesn't pollute clients of the new APIs)

Modified:
    maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java

Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java?rev=785389&r1=785388&r2=785389&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java (original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java Tue Jun 16 20:51:09 2009
@@ -16,11 +16,15 @@
  */
 
 import java.io.File;
+import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.InvalidRepositoryException;
 import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.model.Repository;
 import org.apache.maven.profiles.ProfileManager;
+import org.apache.maven.repository.RepositorySystem;
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.component.annotations.Requirement;
 
@@ -35,6 +39,9 @@
     @Requirement
     private ProjectBuilder projectBuilder;
 
+    @Requirement
+    private RepositorySystem repositorySystem;
+
     // ----------------------------------------------------------------------
     // MavenProjectBuilder Implementation
     // ----------------------------------------------------------------------
@@ -48,9 +55,54 @@
     public MavenProject buildFromRepository( Artifact artifact, ProjectBuilderConfiguration configuration )
         throws ProjectBuildingException
     {
+        normalizeToArtifactRepositories( configuration );
+
         return projectBuilder.build( artifact, configuration );
     }
 
+    private void normalizeToArtifactRepositories( ProjectBuilderConfiguration configuration )
+        throws ProjectBuildingException
+    {
+        /*
+         * This provides backward-compat with 2.x that allowed plugins like the maven-remote-resources-plugin:1.0 to
+         * populate the builder configuration with model repositories instead of artifact repositories.
+         */
+
+        List<?> repositories = configuration.getRemoteRepositories();
+
+        if ( repositories != null )
+        {
+            boolean normalized = false;
+
+            List<ArtifactRepository> repos = new ArrayList<ArtifactRepository>( repositories.size() );
+
+            for ( Object repository : repositories )
+            {
+                if ( repository instanceof Repository )
+                {
+                    try
+                    {
+                        repos.add( repositorySystem.buildArtifactRepository( (Repository) repository ) );
+                    }
+                    catch ( InvalidRepositoryException e )
+                    {
+                        throw new ProjectBuildingException( "", "Invalid remote repository " + repository, e );
+                    }
+                    normalized = true;
+                }
+                else
+                {
+                    repos.add( (ArtifactRepository) repository );
+                }
+            }
+
+            if ( normalized )
+            {
+                configuration.setRemoteRepositories( repos );
+            }
+        }
+    }
+
     // This is used by the SITE plugin.
     public MavenProject build( File project, ArtifactRepository localRepository, ProfileManager profileManager )
         throws ProjectBuildingException