From b69b4ab4f9628c578820a63ad2a8216dc033d4df Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Wed, 22 Jul 2009 17:56:18 +0000 Subject: [PATCH] o add default plugin artifact repositories in the populator git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@796817 13f79535-47bb-0310-9956-ffa450edef68 --- .../DefaultMavenExecutionRequest.java | 15 ++++++ .../execution/MavenExecutionRequest.java | 2 + ...DefaultMavenExecutionRequestPopulator.java | 51 ++++++++++++++----- 3 files changed, 56 insertions(+), 12 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java index a84ed2ba19..5a31fec96a 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java @@ -837,6 +837,21 @@ public class DefaultMavenExecutionRequest return remoteRepositories; } + public MavenExecutionRequest addPluginArtifactRepository( ArtifactRepository repository ) + { + for ( ArtifactRepository repo : getPluginArtifactRepositories() ) + { + if ( repo.getId() != null && repo.getId().equals( repository.getId() ) ) + { + return this; + } + } + + getPluginArtifactRepositories().add( repository ); + + return this; + } + public List getPluginArtifactRepositories() { if ( pluginArtifactRepositories == null ) diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java index 1478b95a62..c111cb470a 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java @@ -207,6 +207,8 @@ public interface MavenExecutionRequest MavenExecutionRequest setGlobalSettingsFile( File globalSettingsFile ); MavenExecutionRequest addRemoteRepository( ArtifactRepository repository ); + MavenExecutionRequest addPluginArtifactRepository( ArtifactRepository repository ); + /** * Set a new list of remote repositories to use the execution request. This is necessary if you perform * transformations on the remote repositories being used. For example if you replace existing repositories with diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java b/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java index faf68086ae..b43db2f481 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java +++ b/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java @@ -75,13 +75,13 @@ public class DefaultMavenExecutionRequestPopulator request.setBaseDirectory( new File( System.getProperty( "user.dir" ) ) ); } } - + private void populateDefaultPluginGroups( MavenExecutionRequest request ) { request.addPluginGroup( "org.apache.maven.plugins" ); request.addPluginGroup( "org.codehaus.mojo" ); } - + // Process plugin groups // Get profile models // Get active profiles @@ -89,18 +89,18 @@ public class DefaultMavenExecutionRequestPopulator throws MavenEmbedderException { Settings settings = request.getSettings(); - + request.addPluginGroups( settings.getPluginGroups() ); populateDefaultPluginGroups( request ); - + List settingsProfiles = settings.getProfiles(); // We just need to keep track of what profiles are being activated by the settings. We don't need to process // them here. This should be taken care of by the project builder. // - request.addActiveProfiles( settings.getActiveProfiles() ); - + request.addActiveProfiles( settings.getActiveProfiles() ); + // We only need to take the profiles and make sure they are available when the calculation of the active profiles // is determined. // @@ -108,11 +108,13 @@ public class DefaultMavenExecutionRequestPopulator { for ( org.apache.maven.settings.Profile rawProfile : settings.getProfiles() ) { - request.addProfile( SettingsUtils.convertFromSettingsProfile( rawProfile ) ); + request.addProfile( SettingsUtils.convertFromSettingsProfile( rawProfile ) ); } } - + injectDefaultRepositories( request ); + + injectDefaultPluginRepositories( request ); processRepositoriesInSettings( request ); } @@ -130,7 +132,7 @@ public class DefaultMavenExecutionRequestPopulator } if ( !definedRepositories.contains( RepositorySystem.DEFAULT_REMOTE_REPO_ID ) ) - { + { try { request.addRemoteRepository( repositorySystem.createDefaultRemoteRepository() ); @@ -142,6 +144,31 @@ public class DefaultMavenExecutionRequestPopulator } } + private void injectDefaultPluginRepositories( MavenExecutionRequest request ) + throws MavenEmbedderException + { + Set definedRepositories = new HashSet(); + if ( request.getPluginArtifactRepositories() != null ) + { + for ( ArtifactRepository repository : request.getPluginArtifactRepositories() ) + { + definedRepositories.add( repository.getId() ); + } + } + + if ( !definedRepositories.contains( RepositorySystem.DEFAULT_REMOTE_REPO_ID ) ) + { + try + { + request.addPluginArtifactRepository( repositorySystem.createDefaultRemoteRepository() ); + } + catch ( InvalidRepositoryException e ) + { + throw new MavenEmbedderException( "Cannot create default remote repository.", e ); + } + } + } + private void processRepositoriesInSettings( MavenExecutionRequest request ) throws MavenEmbedderException { @@ -158,7 +185,7 @@ public class DefaultMavenExecutionRequestPopulator // www.google.com|*.somewhere.com // // - + /* Proxy proxy = settings.getActiveProxy(); @@ -302,7 +329,7 @@ public class DefaultMavenExecutionRequestPopulator throws MavenEmbedderException { pom( request ); - + settings( request ); localRepository( request ); @@ -310,7 +337,7 @@ public class DefaultMavenExecutionRequestPopulator toolchains( request ); processSettings( request ); - + return request; } }