removed code duplication: maven-core can use base MavenRepositorySystemSession provided by maven-aether-provider as a basis before adding environment configuration

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1407851 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Herve Boutemy 2012-11-10 17:14:21 +00:00
parent 13bb4ba1be
commit 994a27d004
8 changed files with 42 additions and 52 deletions

View File

@ -42,14 +42,15 @@ import org.sonatype.aether.util.repository.DefaultMirrorSelector;
import org.sonatype.aether.util.repository.DefaultProxySelector;
/**
* A simplistic repository system session that mimics Maven's behavior to help third-party developers that want to embed
* Maven's dependency resolution into their own applications.
* The base Maven repository system session, without environment configuration (authentication, mirror,
* proxy, ...).
*
* <p><strong>Warning:</strong> This class is not intended for
* usage by Maven plugins, those should always acquire the current repository system session via
* <a href="/ref/current/maven-core/apidocs/org/apache/maven/plugin/PluginParameterExpressionEvaluator.html">plugin
* parameter injection</a>, since the current repository system session is created by Maven in
* <code><a href="/ref/current/maven-core/apidocs/org/apache/maven/DefaultMaven.html">DefaultMaven.newRepositorySession(MavenExecutionRequest request)</a></code>.</p>
* <a href="/ref/current/maven-core/apidocs/org/apache/maven/DefaultMaven.html">
* <code>DefaultMaven.newRepositorySession(MavenExecutionRequest request)</code></a>.</p>
*
* @author Benjamin Bentmann
*/
@ -58,17 +59,17 @@ public class MavenRepositorySystemSession
{
/**
* Creates a new Maven-like repository system session by initializing the session with values typical for
* Creates a new Maven repository system session by initializing the session with values typical for
* Maven-based resolution. In more detail, this constructor configures settings relevant for the processing of
* dependency graphs, most other settings remain at their generic default value. Use the various setters to further
* configure the session with authentication, mirror, proxy and other information required for your environment.
*
* @param standalone is this instance expected to be used inside Maven, with Plexus and Maven core components, or
* standalone? If standalone, System properties are used and classical Maven artifact handlers are pre-configured
* to mimic complete Maven repository system session.
*/
public MavenRepositorySystemSession()
public MavenRepositorySystemSession( boolean standalone )
{
setMirrorSelector( new DefaultMirrorSelector() );
setAuthenticationSelector( new DefaultAuthenticationSelector() );
setProxySelector( new DefaultProxySelector() );
DependencyTraverser depTraverser = new FatArtifactTraverser();
setDependencyTraverser( depTraverser );
@ -86,26 +87,33 @@ public class MavenRepositorySystemSession
new JavaDependencyContextRefiner() );
setDependencyGraphTransformer( transformer );
DefaultArtifactTypeRegistry stereotypes = new DefaultArtifactTypeRegistry();
stereotypes.add( new DefaultArtifactType( "pom" ) );
stereotypes.add( new DefaultArtifactType( "maven-plugin", "jar", "", "java" ) );
stereotypes.add( new DefaultArtifactType( "jar", "jar", "", "java" ) );
stereotypes.add( new DefaultArtifactType( "ejb", "jar", "", "java" ) );
stereotypes.add( new DefaultArtifactType( "ejb-client", "jar", "client", "java" ) );
stereotypes.add( new DefaultArtifactType( "test-jar", "jar", "tests", "java" ) );
stereotypes.add( new DefaultArtifactType( "javadoc", "jar", "javadoc", "java" ) );
stereotypes.add( new DefaultArtifactType( "java-source", "jar", "sources", "java", false, false ) );
stereotypes.add( new DefaultArtifactType( "war", "war", "", "java", false, true ) );
stereotypes.add( new DefaultArtifactType( "ear", "ear", "", "java", false, true ) );
stereotypes.add( new DefaultArtifactType( "rar", "rar", "", "java", false, true ) );
stereotypes.add( new DefaultArtifactType( "par", "par", "", "java", false, true ) );
setArtifactTypeRegistry( stereotypes );
setIgnoreInvalidArtifactDescriptor( true );
setIgnoreMissingArtifactDescriptor( true );
setSystemProps( System.getProperties() );
setConfigProps( System.getProperties() );
if ( standalone )
{
setMirrorSelector( new DefaultMirrorSelector() );
setAuthenticationSelector( new DefaultAuthenticationSelector() );
setProxySelector( new DefaultProxySelector() );
DefaultArtifactTypeRegistry stereotypes = new DefaultArtifactTypeRegistry();
stereotypes.add( new DefaultArtifactType( "pom" ) );
stereotypes.add( new DefaultArtifactType( "maven-plugin", "jar", "", "java" ) );
stereotypes.add( new DefaultArtifactType( "jar", "jar", "", "java" ) );
stereotypes.add( new DefaultArtifactType( "ejb", "jar", "", "java" ) );
stereotypes.add( new DefaultArtifactType( "ejb-client", "jar", "client", "java" ) );
stereotypes.add( new DefaultArtifactType( "test-jar", "jar", "tests", "java" ) );
stereotypes.add( new DefaultArtifactType( "javadoc", "jar", "javadoc", "java" ) );
stereotypes.add( new DefaultArtifactType( "java-source", "jar", "sources", "java", false, false ) );
stereotypes.add( new DefaultArtifactType( "war", "war", "", "java", false, true ) );
stereotypes.add( new DefaultArtifactType( "ear", "ear", "", "java", false, true ) );
stereotypes.add( new DefaultArtifactType( "rar", "rar", "", "java", false, true ) );
stereotypes.add( new DefaultArtifactType( "par", "par", "", "java", false, true ) );
setArtifactTypeRegistry( stereotypes );
setSystemProps( System.getProperties() );
setConfigProps( System.getProperties() );
}
}
}

View File

@ -56,7 +56,7 @@ public abstract class AbstractRepositoryTestCase
public static RepositorySystemSession newMavenRepositorySystemSession( RepositorySystem system )
{
MavenRepositorySystemSession session = new MavenRepositorySystemSession();
MavenRepositorySystemSession session = new MavenRepositorySystemSession( true );
LocalRepository localRepo = new LocalRepository( "target/local-repo" );
session.setLocalRepositoryManager( system.newLocalRepositoryManager( localRepo ) );

View File

@ -166,7 +166,7 @@ public abstract class AbstractMavenProjectTestCase
protected void initRepoSession( ProjectBuildingRequest request )
{
File localRepo = new File( request.getLocalRepository().getBasedir() );
MavenRepositorySystemSession session = new MavenRepositorySystemSession();
MavenRepositorySystemSession session = new MavenRepositorySystemSession( true );
session.setLocalRepositoryManager( new LegacyLocalRepositoryManager( localRepo ) );
request.setRepositorySession( session );
}

View File

@ -58,6 +58,7 @@ import org.apache.maven.project.ProjectBuildingResult;
import org.apache.maven.project.ProjectSorter;
import org.apache.maven.repository.DelegatingLocalArtifactRepository;
import org.apache.maven.repository.LocalRepositoryNotAccessibleException;
import org.apache.maven.repository.internal.MavenRepositorySystemSession;
import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Server;
@ -331,12 +332,10 @@ public class DefaultMaven
public RepositorySystemSession newRepositorySession( MavenExecutionRequest request )
{
DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
MavenRepositorySystemSession session = new MavenRepositorySystemSession( false );
session.setCache( request.getRepositoryCache() );
session.setIgnoreInvalidArtifactDescriptor( true ).setIgnoreMissingArtifactDescriptor( true );
Map<Object, Object> configProps = new LinkedHashMap<Object, Object>();
configProps.put( ConfigurationProperties.USER_AGENT, getUserAgent() );
configProps.put( ConfigurationProperties.INTERACTIVE, Boolean.valueOf( request.isInteractiveMode() ) );
@ -434,23 +433,6 @@ public class DefaultMaven
}
session.setAuthenticationSelector( authSelector );
DependencyTraverser depTraverser = new FatArtifactTraverser();
session.setDependencyTraverser( depTraverser );
DependencyManager depManager = new ClassicDependencyManager();
session.setDependencyManager( depManager );
DependencySelector depFilter =
new AndDependencySelector( new ScopeDependencySelector( "test", "provided" ), new OptionalDependencySelector(),
new ExclusionDependencySelector() );
session.setDependencySelector( depFilter );
DependencyGraphTransformer transformer =
new ChainedDependencyGraphTransformer( new ConflictMarker(), new JavaEffectiveScopeCalculator(),
new NearestVersionConflictResolver(),
new JavaDependencyContextRefiner() );
session.setDependencyGraphTransformer( transformer );
session.setTransferListener( request.getTransferListener() );
session.setRepositoryListener( eventSpyDispatcher.chainListener( new LoggingRepositoryListener( logger ) ) );

View File

@ -162,7 +162,7 @@ public abstract class AbstractCoreMavenComponentTestCase
protected void initRepoSession( ProjectBuildingRequest request )
{
File localRepo = new File( request.getLocalRepository().getBasedir() );
MavenRepositorySystemSession session = new MavenRepositorySystemSession();
MavenRepositorySystemSession session = new MavenRepositorySystemSession( true );
session.setLocalRepositoryManager( new SimpleLocalRepositoryManager( localRepo ) );
request.setRepositorySession( session );
}

View File

@ -170,7 +170,7 @@ public abstract class AbstractMavenProjectTestCase
protected void initRepoSession( ProjectBuildingRequest request )
{
File localRepo = new File( request.getLocalRepository().getBasedir() );
MavenRepositorySystemSession repoSession = new MavenRepositorySystemSession();
MavenRepositorySystemSession repoSession = new MavenRepositorySystemSession( true );
repoSession.setLocalRepositoryManager( new LegacyLocalRepositoryManager( localRepo ) );
request.setRepositorySession( repoSession );
}

View File

@ -1839,7 +1839,7 @@ public class PomConstructionTest
config.setUserProperties( executionProperties );
config.setValidationLevel( lenientValidation ? ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0
: ModelBuildingRequest.VALIDATION_LEVEL_STRICT );
MavenRepositorySystemSession repoSession = new MavenRepositorySystemSession();
MavenRepositorySystemSession repoSession = new MavenRepositorySystemSession( true );
repoSession.setLocalRepositoryManager( new SimpleLocalRepositoryManager(
new File(
config.getLocalRepository().getBasedir() ) ) );

View File

@ -113,7 +113,7 @@ public class PomConstructionWithSettingsTest
config.setLocalRepository( repositorySystem.createArtifactRepository( "local", localRepoUrl,
new DefaultRepositoryLayout(), null, null ) );
config.setActiveProfileIds( settings.getActiveProfiles() );
MavenRepositorySystemSession repoSession = new MavenRepositorySystemSession();
MavenRepositorySystemSession repoSession = new MavenRepositorySystemSession( true );
repoSession.setLocalRepositoryManager( new SimpleLocalRepositoryManager(
new File(
config.getLocalRepository().getBasedir() ) ) );