mirror of https://github.com/apache/maven.git
o add standard method for creating central in the repository system
git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@757602 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ef8a681a17
commit
43e21dd1a5
|
@ -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 );
|
||||
|
||||
|
|
|
@ -193,21 +193,13 @@ 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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -315,8 +315,6 @@ 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
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue