mirror of https://github.com/apache/maven.git
o the request populator is now responsible for initializing everything, anything you want to know about how the front-end is configuration, or initialized can be found in this class. i think i have almost everything out of the Maven component and in the Embedder. this is the one place to look now and I know feel comfortable about documenting it
o the profiles additions from settings are now process in the request populator and taken out of the default profile manager itself which has resulted in decoupling the Settings from the profile manager. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@573435 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f785811d57
commit
a698b7ef49
|
@ -33,7 +33,6 @@ import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
|||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
import org.apache.maven.context.BuildContextManager;
|
||||
import org.apache.maven.embedder.execution.MavenExecutionRequestPopulator;
|
||||
import org.apache.maven.embedder.writer.WriterUtils;
|
||||
import org.apache.maven.execution.DefaultMavenExecutionRequest;
|
||||
|
@ -54,13 +53,10 @@ import org.apache.maven.plugin.PluginNotFoundException;
|
|||
import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
|
||||
import org.apache.maven.plugin.version.PluginVersionNotFoundException;
|
||||
import org.apache.maven.plugin.version.PluginVersionResolutionException;
|
||||
import org.apache.maven.profiles.manager.DefaultProfileManager;
|
||||
import org.apache.maven.profiles.manager.ProfileManager;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
import org.apache.maven.project.MavenProjectBuildingResult;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
import org.apache.maven.settings.MavenSettingsBuilder;
|
||||
import org.apache.maven.settings.Settings;
|
||||
import org.apache.maven.settings.io.jdom.SettingsJDOMWriter;
|
||||
import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader;
|
||||
|
@ -77,7 +73,6 @@ import org.codehaus.plexus.classworlds.ClassWorld;
|
|||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||
import org.codehaus.plexus.classworlds.realm.DuplicateRealmException;
|
||||
import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentRepositoryException;
|
||||
import org.codehaus.plexus.configuration.PlexusConfigurationException;
|
||||
|
@ -142,8 +137,6 @@ public class MavenEmbedder
|
|||
|
||||
private MavenJDOMWriter modelWriter;
|
||||
|
||||
private ProfileManager profileManager;
|
||||
|
||||
private PluginDescriptorBuilder pluginDescriptorBuilder;
|
||||
|
||||
private ArtifactRepositoryFactory artifactRepositoryFactory;
|
||||
|
@ -158,18 +151,12 @@ public class MavenEmbedder
|
|||
|
||||
private Maven maven;
|
||||
|
||||
private MavenSettingsBuilder settingsBuilder;
|
||||
|
||||
private MavenExecutionRequestPopulator populator;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Configuration
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private Settings settings;
|
||||
|
||||
private ArtifactRepository localRepository;
|
||||
|
||||
private ClassWorld classWorld;
|
||||
|
||||
private ClassRealm realm;
|
||||
|
@ -184,8 +171,6 @@ public class MavenEmbedder
|
|||
|
||||
private Configuration configuration;
|
||||
|
||||
private BuildContextManager buildContextManager;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Constructors
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -207,12 +192,12 @@ public class MavenEmbedder
|
|||
|
||||
public ArtifactRepository getLocalRepository()
|
||||
{
|
||||
return localRepository;
|
||||
return request.getLocalRepository();
|
||||
}
|
||||
|
||||
public Settings getSettings()
|
||||
{
|
||||
return settings;
|
||||
return request.getSettings();
|
||||
}
|
||||
|
||||
public MavenEmbedderLogger getLogger()
|
||||
|
@ -342,10 +327,6 @@ public class MavenEmbedder
|
|||
{
|
||||
PluginManager pluginManager = (PluginManager) container.lookup( PluginManager.ROLE );
|
||||
|
||||
MavenExecutionRequest request = new DefaultMavenExecutionRequest()
|
||||
.setSettings( settings )
|
||||
.setLocalRepository( localRepository );
|
||||
|
||||
MavenSession session = new MavenSession( container, request, null, null );
|
||||
|
||||
pluginManager.verifyPlugin( plugin, project, session );
|
||||
|
@ -411,7 +392,7 @@ public class MavenEmbedder
|
|||
public MavenProject readProject( File mavenProject )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
return mavenProjectBuilder.build( mavenProject, localRepository, profileManager, false );
|
||||
return mavenProjectBuilder.build( mavenProject, request.getLocalRepository(), request.getProfileManager(), false );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -466,7 +447,7 @@ public class MavenEmbedder
|
|||
projectBuildingResult = mavenProjectBuilder.buildWithDependencies(
|
||||
new File( request.getPomFile() ),
|
||||
request.getLocalRepository(),
|
||||
profileManager,
|
||||
request.getProfileManager(),
|
||||
request.getTransferListener() );
|
||||
}
|
||||
catch ( ProjectBuildingException e )
|
||||
|
@ -575,13 +556,11 @@ public class MavenEmbedder
|
|||
return LifecycleUtils.getValidSitePhaseNames();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Remote Repository
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// LegacyLifecycle
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private MavenExecutionRequest request;
|
||||
|
||||
private void start( Configuration configuration )
|
||||
throws MavenEmbedderException
|
||||
|
@ -649,20 +628,10 @@ public class MavenEmbedder
|
|||
|
||||
maven = (Maven) container.lookup( Maven.ROLE );
|
||||
|
||||
settingsBuilder = (MavenSettingsBuilder) container.lookup( MavenSettingsBuilder.ROLE );
|
||||
|
||||
pluginDescriptorBuilder = new PluginDescriptorBuilder();
|
||||
|
||||
profileManager = new DefaultProfileManager( container, configuration.getSystemProperties() );
|
||||
|
||||
profileManager.explicitlyActivate( configuration.getActiveProfiles() );
|
||||
|
||||
profileManager.explicitlyDeactivate( configuration.getInactiveProfiles() );
|
||||
|
||||
mavenProjectBuilder = (MavenProjectBuilder) container.lookup( MavenProjectBuilder.ROLE );
|
||||
|
||||
buildContextManager = (BuildContextManager) container.lookup( BuildContextManager.ROLE, "default" );
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Artifact related components
|
||||
// ----------------------------------------------------------------------
|
||||
|
@ -681,21 +650,11 @@ public class MavenEmbedder
|
|||
|
||||
artifactHandlerManager = (ArtifactHandlerManager) container.lookup( ArtifactHandlerManager.ROLE );
|
||||
|
||||
try
|
||||
{
|
||||
settings = settingsBuilder.buildSettings( configuration.getUserSettingsFile(),
|
||||
configuration.getGlobalSettingsFile() );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
// If something goes wrong with parsing the settings
|
||||
settings = new Settings();
|
||||
}
|
||||
|
||||
localRepository = createLocalRepository( settings );
|
||||
|
||||
profileManager.loadSettingsProfiles( settings );
|
||||
// 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.
|
||||
request = new DefaultMavenExecutionRequest();
|
||||
|
||||
populator.populateDefaults( request, this );
|
||||
}
|
||||
catch ( ComponentLookupException e )
|
||||
{
|
||||
|
@ -749,20 +708,7 @@ public class MavenEmbedder
|
|||
public void stop()
|
||||
throws MavenEmbedderException
|
||||
{
|
||||
try
|
||||
{
|
||||
buildContextManager.clearBuildContext();
|
||||
|
||||
container.release( buildContextManager );
|
||||
|
||||
container.release( mavenProjectBuilder );
|
||||
|
||||
container.release( artifactRepositoryFactory );
|
||||
}
|
||||
catch ( ComponentLifecycleException e )
|
||||
{
|
||||
throw new MavenEmbedderException( "Cannot stop the embedder.", e );
|
||||
}
|
||||
container.dispose();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
|
|
@ -28,14 +28,17 @@ import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
|||
import org.apache.maven.embedder.MavenEmbedder;
|
||||
import org.apache.maven.embedder.MavenEmbedderException;
|
||||
import org.apache.maven.execution.MavenExecutionRequest;
|
||||
import org.apache.maven.model.Profile;
|
||||
import org.apache.maven.monitor.event.DefaultEventMonitor;
|
||||
import org.apache.maven.plugin.Mojo;
|
||||
import org.apache.maven.profiles.manager.DefaultProfileManager;
|
||||
import org.apache.maven.profiles.manager.ProfileManager;
|
||||
import org.apache.maven.settings.MavenSettingsBuilder;
|
||||
import org.apache.maven.settings.Mirror;
|
||||
import org.apache.maven.settings.Proxy;
|
||||
import org.apache.maven.settings.Server;
|
||||
import org.apache.maven.settings.Settings;
|
||||
import org.apache.maven.settings.SettingsUtils;
|
||||
import org.apache.maven.wagon.repository.RepositoryPermissions;
|
||||
import org.codehaus.plexus.PlexusConstants;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
|
@ -50,6 +53,7 @@ import org.codehaus.plexus.util.xml.Xpp3Dom;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* DefaultMavenExecutionRequestPopulator
|
||||
|
@ -68,6 +72,8 @@ public class DefaultMavenExecutionRequestPopulator
|
|||
|
||||
private WagonManager wagonManager;
|
||||
|
||||
private MavenSettingsBuilder settingsBuilder;
|
||||
|
||||
public MavenExecutionRequest populateDefaults( MavenExecutionRequest request,
|
||||
MavenEmbedder embedder )
|
||||
throws MavenEmbedderException
|
||||
|
@ -88,12 +94,22 @@ public class DefaultMavenExecutionRequestPopulator
|
|||
|
||||
if ( request.getSettings() == null )
|
||||
{
|
||||
request.setSettings( embedder.getSettings() );
|
||||
try
|
||||
{
|
||||
request.setSettings(
|
||||
settingsBuilder.buildSettings(
|
||||
embedder.getConfiguration().getUserSettingsFile(),
|
||||
embedder.getConfiguration().getGlobalSettingsFile() ) );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
request.setSettings( new Settings() );
|
||||
}
|
||||
}
|
||||
|
||||
if ( request.getLocalRepository() == null )
|
||||
{
|
||||
request.setLocalRepository( embedder.getLocalRepository() );
|
||||
request.setLocalRepository( embedder.createLocalRepository( request.getSettings() ) );
|
||||
}
|
||||
|
||||
// Repository update policies
|
||||
|
@ -168,7 +184,15 @@ public class DefaultMavenExecutionRequestPopulator
|
|||
|
||||
// Create the standard profile manager
|
||||
|
||||
request.setProfileManager( createProfileManager( request ) );
|
||||
ProfileManager globalProfileManager = new DefaultProfileManager( container );
|
||||
|
||||
loadSettingsProfiles( globalProfileManager, request.getSettings() );
|
||||
|
||||
globalProfileManager.explicitlyActivate( request.getActiveProfiles() );
|
||||
|
||||
globalProfileManager.explicitlyDeactivate( request.getInactiveProfiles() );
|
||||
|
||||
request.setProfileManager( globalProfileManager );
|
||||
|
||||
return request;
|
||||
}
|
||||
|
@ -229,23 +253,6 @@ public class DefaultMavenExecutionRequestPopulator
|
|||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Profile Manager
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public ProfileManager createProfileManager( MavenExecutionRequest request )
|
||||
{
|
||||
ProfileManager globalProfileManager = new DefaultProfileManager( container, request.getProperties() );
|
||||
|
||||
globalProfileManager.loadSettingsProfiles( request.getSettings() );
|
||||
|
||||
globalProfileManager.explicitlyActivate( request.getActiveProfiles() );
|
||||
|
||||
globalProfileManager.explicitlyDeactivate( request.getInactiveProfiles() );
|
||||
|
||||
return globalProfileManager;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// LegacyLifecycle
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -255,4 +262,26 @@ public class DefaultMavenExecutionRequestPopulator
|
|||
{
|
||||
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
|
||||
}
|
||||
|
||||
public void loadSettingsProfiles( ProfileManager profileManager, Settings settings )
|
||||
{
|
||||
List settingsProfiles = settings.getProfiles();
|
||||
|
||||
if ( settingsProfiles != null && !settingsProfiles.isEmpty() )
|
||||
{
|
||||
List settingsActiveProfileIds = settings.getActiveProfiles();
|
||||
|
||||
profileManager.explicitlyActivate( settingsActiveProfileIds );
|
||||
|
||||
for ( Iterator it = settings.getProfiles().iterator(); it.hasNext(); )
|
||||
{
|
||||
org.apache.maven.settings.Profile rawProfile = (org.apache.maven.settings.Profile) it.next();
|
||||
|
||||
Profile profile = SettingsUtils.convertFromSettingsProfile( rawProfile );
|
||||
|
||||
profileManager.addProfile( profile );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue