diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java index 7bfbdbee50..cc2877f214 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java @@ -166,26 +166,23 @@ public class LifecycleExecutorTest throws Exception { ArtifactRepository localRepository = repositorySystem.createDefaultLocalRepository(); - - Repository repository = new Repository(); - repository.setUrl( "http://repo1.maven.org/maven2" ); - repository.setId( "central" ); - - ProjectBuilderConfiguration configuration = new DefaultProjectBuilderConfiguration() - .setLocalRepository( localRepository ) - .setRemoteRepositories( Arrays.asList( repositorySystem.buildArtifactRepository( repository ) ) ); - - MavenProject project = projectBuilder.build( pom, configuration ); - + ArtifactRepository remoteRepository = repositorySystem.createDefaultRemoteRepository(); + MavenExecutionRequest request = new DefaultMavenExecutionRequest() .setProjectPresent( true ) .setPluginGroups( Arrays.asList( new String[] { "org.apache.maven.plugins" } ) ) .setLocalRepository( localRepository ) - .setRemoteRepositories( Arrays.asList( repositorySystem.buildArtifactRepository( repository ) ) ) + .setRemoteRepositories( Arrays.asList( remoteRepository ) ) .setGoals( Arrays.asList( new String[] { "package" } ) ) .addEventMonitor( new DefaultEventMonitor( new ConsoleLogger( 0, "" ) ) ) .setProperties( new Properties() ); + ProjectBuilderConfiguration configuration = new DefaultProjectBuilderConfiguration() + .setLocalRepository( localRepository ) + .setRemoteRepositories( Arrays.asList( remoteRepository ) ); + + MavenProject project = projectBuilder.build( pom, configuration ); + List projects = new ArrayList(); projects.add( project ); 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 7dfc4c607b..c77740da13 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 @@ -192,22 +192,14 @@ public class DefaultMavenExecutionRequestPopulator } if ( !definedRepositories.contains( "central" ) ) - { - Repository repo = new Repository(); - repo.setId( "central" ); - repo.setUrl( "http://repo1.maven.org/maven2" ); - repo.setName( "Maven Repository Switchboard" ); - RepositoryPolicy snapshotPolicy = new RepositoryPolicy(); - snapshotPolicy.setEnabled( false ); - repo.setSnapshots( snapshotPolicy ); + { try { - ArtifactRepository ar = repositorySystem.buildArtifactRepository( repo ); - request.addRemoteRepository( ar ); + request.addRemoteRepository( repositorySystem.createDefaultRemoteRepository() ); } catch ( InvalidRepositoryException e ) { - throw new MavenEmbedderException( "Cannot create remote repository " + repo.getId(), e ); + throw new MavenEmbedderException( "Cannot create default remote repository.", e ); } } } diff --git a/maven-repository/src/main/java/org/apache/maven/repository/LegacyRepositorySystem.java b/maven-repository/src/main/java/org/apache/maven/repository/LegacyRepositorySystem.java index 51f373c1aa..3a76f102e5 100644 --- a/maven-repository/src/main/java/org/apache/maven/repository/LegacyRepositorySystem.java +++ b/maven-repository/src/main/java/org/apache/maven/repository/LegacyRepositorySystem.java @@ -314,9 +314,7 @@ public class LegacyRepositorySystem return new ArtifactRepositoryPolicy( enabled, updatePolicy, checksumPolicy ); } - - // From MavenExecutionRequestPopulator - + public ArtifactRepository createDefaultLocalRepository() throws InvalidRepositoryException { @@ -328,14 +326,20 @@ public class LegacyRepositorySystem { try { - return createRepository( localRepository.toURI().toURL().toString(), "maven.repo.local" ); + return createRepository( localRepository.toURI().toURL().toString(), RepositorySystem.DEFAULT_LOCAL_REPO_ID ); } catch ( MalformedURLException e ) { - throw new InvalidRepositoryException( "Error creating local repository.", "maven.repo.local", e ); + throw new InvalidRepositoryException( "Error creating local repository.", RepositorySystem.DEFAULT_LOCAL_REPO_ID, e ); } } + public ArtifactRepository createDefaultRemoteRepository() + throws InvalidRepositoryException + { + return createRepository( RepositorySystem.DEFAULT_REMOTE_REPO_URL, RepositorySystem.DEFAULT_REMOTE_REPO_ID ); + } + public ArtifactRepository createLocalRepository( String url, String repositoryId ) throws IOException { diff --git a/maven-repository/src/main/java/org/apache/maven/repository/RepositorySystem.java b/maven-repository/src/main/java/org/apache/maven/repository/RepositorySystem.java index f13c232935..c2701ca0d1 100644 --- a/maven-repository/src/main/java/org/apache/maven/repository/RepositorySystem.java +++ b/maven-repository/src/main/java/org/apache/maven/repository/RepositorySystem.java @@ -42,6 +42,7 @@ import org.apache.maven.wagon.events.TransferListener; */ public interface RepositorySystem { + // Default local repository static final String DEFAULT_LOCAL_REPO_ID = "local"; static final String userHome = System.getProperty( "user.home" ); @@ -50,6 +51,11 @@ public interface RepositorySystem static final File defaultUserLocalRepository = new File( userMavenConfigurationHome, "repository" ); + // Default remote repository + static final String DEFAULT_REMOTE_REPO_ID = "central"; + + static final String DEFAULT_REMOTE_REPO_URL = "http://repo1.maven.org/maven2"; + Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type ); Artifact createProjectArtifact( String groupId, String artifactId, String metaVersionId ); @@ -74,6 +80,9 @@ public interface RepositorySystem ArtifactRepository createLocalRepository( String url, String repositoryId ) throws IOException; + ArtifactRepository createDefaultRemoteRepository() + throws InvalidRepositoryException; + ArtifactRepository createDefaultLocalRepository() throws InvalidRepositoryException;