From ecf09e66f5745030a12846e44a89942f6bd1bf08 Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Mon, 23 Mar 2009 17:38:44 +0000 Subject: [PATCH] o locate all repository related constants into the RepositorySystem o add a method to the RepositorySystem for creating the default local repository o make the test utils for the lifecycle executor use the createDefaultLocalRepository method to decouple from my home directory git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@757464 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/maven/lifecycle/LifecycleExecutorTest.java | 9 +-------- .../java/org/apache/maven/embedder/MavenEmbedder.java | 8 +------- .../DefaultMavenExecutionRequestPopulator.java | 5 ++--- .../maven/repository/LegacyRepositorySystem.java | 7 ++++++- .../org/apache/maven/repository/RepositorySystem.java | 11 +++++++++++ 5 files changed, 21 insertions(+), 19 deletions(-) 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 636b6a80a4..6698e912ba 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 @@ -163,17 +163,10 @@ public class LifecycleExecutorTest containerConfiguration.addComponentDiscoveryListener( new MavenPluginCollector() ); } - //!!jvz The repository system needs to know about the defaults for Maven, it's tied up in the embedder right now. - protected ArtifactRepository getLocalRepository() - throws InvalidRepositoryException - { - return repositorySystem.createLocalRepository( new File( "/Users/jvanzyl/.m2/repository" ) ); - } - protected MavenSession createMavenSession( File pom ) throws Exception { - ArtifactRepository localRepository = getLocalRepository(); + ArtifactRepository localRepository = repositorySystem.createDefaultLocalRepository(); Repository repository = new Repository(); repository.setUrl( "http://repo1.maven.org/maven2" ); diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java index 3bec1784e1..6f664b414c 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java +++ b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java @@ -81,14 +81,10 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParserException; */ public class MavenEmbedder { - public static final String DEFAULT_LOCAL_REPO_ID = "local"; - public static final String userHome = System.getProperty( "user.home" ); public static final File userMavenConfigurationHome = new File( userHome, ".m2" ); - public static final File defaultUserLocalRepository = new File( userMavenConfigurationHome, "repository" ); - public static final File DEFAULT_USER_SETTINGS_FILE = new File( userMavenConfigurationHome, "settings.xml" ); public static final File DEFAULT_GLOBAL_SETTINGS_FILE = @@ -110,8 +106,6 @@ public class MavenEmbedder private MavenProjectBuilder mavenProjectBuilder; - private RepositorySystem repositorySystem; - private MavenXpp3Reader modelReader; private MavenXpp3Writer modelWriter; @@ -458,7 +452,7 @@ public class MavenEmbedder populator = container.lookup( MavenExecutionRequestPopulator.class ); - repositorySystem = container.lookup( RepositorySystem.class ); + container.lookup( RepositorySystem.class ); // This is temporary as we can probably cache a single request and use it for default values and // simply cascade values in from requests used for individual executions. 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 38a9abef73..7dfc4c607b 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 @@ -27,7 +27,6 @@ import org.apache.maven.Maven; import org.apache.maven.artifact.InvalidRepositoryException; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.embedder.Configuration; -import org.apache.maven.embedder.MavenEmbedder; import org.apache.maven.embedder.MavenEmbedderException; import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.model.Profile; @@ -412,12 +411,12 @@ public class DefaultMavenExecutionRequestPopulator if ( StringUtils.isEmpty( localRepositoryPath ) ) { - localRepositoryPath = MavenEmbedder.defaultUserLocalRepository.getAbsolutePath(); + localRepositoryPath = RepositorySystem.defaultUserLocalRepository.getAbsolutePath(); } try { - return repositorySystem.createLocalRepository( localRepositoryPath, MavenEmbedder.DEFAULT_LOCAL_REPO_ID ); + return repositorySystem.createLocalRepository( localRepositoryPath, RepositorySystem.DEFAULT_LOCAL_REPO_ID ); } catch ( IOException 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 bb029a3bbf..51f373c1aa 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 @@ -64,7 +64,6 @@ import org.codehaus.plexus.util.StringUtils; public class LegacyRepositorySystem implements RepositorySystem { - @Requirement private WagonManager wagonManager; @@ -318,6 +317,12 @@ public class LegacyRepositorySystem // From MavenExecutionRequestPopulator + public ArtifactRepository createDefaultLocalRepository() + throws InvalidRepositoryException + { + return createLocalRepository( RepositorySystem.defaultUserLocalRepository ); + } + public ArtifactRepository createLocalRepository( File localRepository ) throws InvalidRepositoryException { 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 f47d07ec27..f13c232935 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,14 @@ import org.apache.maven.wagon.events.TransferListener; */ public interface RepositorySystem { + static final String DEFAULT_LOCAL_REPO_ID = "local"; + + static final String userHome = System.getProperty( "user.home" ); + + static final File userMavenConfigurationHome = new File( userHome, ".m2" ); + + static final File defaultUserLocalRepository = new File( userMavenConfigurationHome, "repository" ); + Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type ); Artifact createProjectArtifact( String groupId, String artifactId, String metaVersionId ); @@ -66,6 +74,9 @@ public interface RepositorySystem ArtifactRepository createLocalRepository( String url, String repositoryId ) throws IOException; + ArtifactRepository createDefaultLocalRepository() + throws InvalidRepositoryException; + ArtifactRepository createLocalRepository( File localRepository ) throws InvalidRepositoryException;