Improving the use of project sessions in the embedder, and exporting control over the project session map to the embedder instead of Maven.execute().

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@588144 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2007-10-25 05:13:22 +00:00
parent b11111f75a
commit b0cc7be1ac
5 changed files with 78 additions and 83 deletions

View File

@ -63,7 +63,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -160,14 +159,12 @@ public class DefaultMaven
return reactorManager;
}
public MavenExecutionResult execute( MavenExecutionRequest request )
public MavenExecutionResult execute( MavenExecutionRequest request, Map projectSessions )
{
request.setStartTime( new Date() );
MavenExecutionResult result = new DefaultMavenExecutionResult();
Map projectSessions = new HashMap();
ReactorManager reactorManager = createReactorManager(
request,
result,
@ -192,66 +189,59 @@ public class DefaultMaven
dispatcher,
projectSessions );
for ( Iterator i = request.getGoals().iterator(); i.hasNext(); )
{
String goal = (String) i.next();
TaskValidationResult tvr = lifecycleExecutor.isTaskValid( goal, session, reactorManager.getTopLevelProject() );
if ( !tvr.isTaskValid() )
{
result.addBuildFailureException( new InvalidTaskException( tvr ) );
return result;
}
}
getLogger().info( "Scanning for projects..." );
if ( reactorManager.hasMultipleProjects() )
{
getLogger().info( "Reactor build order: " );
for ( Iterator i = reactorManager.getSortedProjects().iterator(); i.hasNext(); )
{
MavenProject project = (MavenProject) i.next();
getLogger().info( " " + project.getName() );
}
}
initializeBuildContext( request );
try
{
for ( Iterator i = request.getGoals().iterator(); i.hasNext(); )
{
String goal = (String) i.next();
TaskValidationResult tvr = lifecycleExecutor.isTaskValid( goal, session, reactorManager.getTopLevelProject() );
if ( !tvr.isTaskValid() )
{
result.addBuildFailureException( new InvalidTaskException( tvr ) );
return result;
}
}
getLogger().info( "Scanning for projects..." );
if ( reactorManager.hasMultipleProjects() )
{
getLogger().info( "Reactor build order: " );
for ( Iterator i = reactorManager.getSortedProjects().iterator(); i.hasNext(); )
{
MavenProject project = (MavenProject) i.next();
getLogger().info( " " + project.getName() );
}
}
initializeBuildContext( request );
try
{
lifecycleExecutor.execute(
session,
reactorManager,
dispatcher );
}
catch ( LifecycleExecutionException e )
{
result.addLifecycleExecutionException( e );
return result;
}
catch ( BuildFailureException e )
{
result.addBuildFailureException( e );
return result;
}
result.setTopologicallySortedProjects( reactorManager.getSortedProjects() );
result.setProject( reactorManager.getTopLevelProject() );
lifecycleExecutor.execute(
session,
reactorManager,
dispatcher );
}
catch ( LifecycleExecutionException e )
{
result.addLifecycleExecutionException( e );
return result;
}
finally
catch ( BuildFailureException e )
{
session.dispose();
result.addBuildFailureException( e );
return result;
}
result.setTopologicallySortedProjects( reactorManager.getSortedProjects() );
result.setProject( reactorManager.getTopLevelProject() );
return result;
}
/**

View File

@ -53,7 +53,7 @@ public interface Maven
static final int LOGGING_LEVEL_DISABLE = 5;
MavenExecutionResult execute( MavenExecutionRequest request );
MavenExecutionResult execute( MavenExecutionRequest request, Map projectSessions );
ReactorManager createReactorManager( MavenExecutionRequest request, MavenExecutionResult result, Map projectSessions );
}

View File

@ -30,7 +30,6 @@ import org.codehaus.plexus.component.repository.exception.ComponentLookupExcepti
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -73,15 +72,6 @@ public class MavenSession
this.projectSessions = projectSessions == null ? new HashMap() : projectSessions;
}
public void dispose()
{
for ( Iterator it = projectSessions.values().iterator(); it.hasNext(); )
{
MavenProjectSession session = (MavenProjectSession) it.next();
session.dispose();
}
}
// TODO: Figure out how/when we can shut down all the realms for extensions/plugins connected to each project session...
public MavenProjectSession getProjectSession( MavenProject project )
throws PlexusContainerException

View File

@ -26,6 +26,7 @@ import org.apache.maven.model.Build;
import org.apache.maven.model.Extension;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.plugin.loader.PluginLoader;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.profiles.activation.CustomActivatorAdvice;
import org.apache.maven.project.MavenProject;
@ -66,6 +67,8 @@ public class DefaultBuildExtensionScanner
private ModelInterpolator modelInterpolator;
private PluginLoader pluginLoader;
public void scanForBuildExtensions( List files,
ArtifactRepository localRepository,
ProfileManager globalProfileManager,

View File

@ -35,6 +35,7 @@ import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.DefaultMavenExecutionResult;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.execution.MavenProjectSession;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.ReactorManager;
import org.apache.maven.extension.BuildExtensionScanner;
@ -319,16 +320,9 @@ public class MavenEmbedder
{
PluginManager pluginManager = (PluginManager) container.lookup( PluginManager.ROLE );
MavenSession session = new MavenSession( container, request, null, null, new HashMap() );
MavenSession session = new MavenSession( container, request, null, null, projectSessions );
try
{
pluginManager.verifyPlugin( plugin, project, session );
}
finally
{
session.dispose();
}
}
/** protected for tests only.. */
@ -440,7 +434,7 @@ public class MavenEmbedder
{
getLogger().info( "Scanning for extensions: " + mavenProject );
extensionScanner.scanForBuildExtensions( mavenProject, request.getLocalRepository(), request.getProfileManager(), new HashMap() );
extensionScanner.scanForBuildExtensions( mavenProject, request.getLocalRepository(), request.getProfileManager(), projectSessions );
getLogger().info( "Building MavenProject instance: " + mavenProject );
@ -478,7 +472,7 @@ public class MavenEmbedder
Map handlers = findArtifactTypeHandlers( project );
//TODO: ok this is crappy, now there are active collections so when new artifact handlers
//TODO: ok this is crappy, now there are active collections so when new artifact handlers
// enter the system they should be available.
artifactHandlerManager.addHandlers( handlers );
@ -496,7 +490,7 @@ public class MavenEmbedder
return result.addExtensionScanningException( e );
}
ReactorManager reactorManager = maven.createReactorManager( request, result, new HashMap() );
ReactorManager reactorManager = maven.createReactorManager( request, result, projectSessions );
if ( result.hasExceptions() )
{
@ -624,6 +618,22 @@ public class MavenEmbedder
private MavenExecutionRequest request;
private Map projectSessions;
public void clearProjectSessions()
{
if ( ( projectSessions != null ) && !projectSessions.isEmpty() )
{
for ( Iterator it = projectSessions.values().iterator(); it.hasNext(); )
{
MavenProjectSession session = (MavenProjectSession) it.next();
session.dispose();
}
projectSessions.clear();
}
}
private void start( Configuration configuration )
throws MavenEmbedderException
{
@ -631,6 +641,8 @@ public class MavenEmbedder
logger = configuration.getMavenEmbedderLogger();
projectSessions = new HashMap();
// ----------------------------------------------------------------------------
// Don't override any existing SecurityManager if one has been installed. Our
// SecurityManager just checks to make sure
@ -652,8 +664,8 @@ public class MavenEmbedder
try
{
ContainerConfiguration cc = new DefaultContainerConfiguration()
.addComponentDiscoverer( new MavenPluginDiscoverer() )
ContainerConfiguration cc = new DefaultContainerConfiguration()
.addComponentDiscoverer( new MavenPluginDiscoverer() )
.addComponentDiscoveryListener( new MavenPluginCollector() )
.setClassWorld( classWorld ).setParentContainer( configuration.getParentContainer() ).setName( "embedder" );
@ -889,7 +901,7 @@ public class MavenEmbedder
return result;
}
return maven.execute( request );
return maven.execute( request, projectSessions );
}
finally
{