mirror of https://github.com/apache/maven.git
o the dispatcher is available in the session so remove the dispatcher from the signature of the lifecycle executor, now the
lifecycle execution only requires a session. git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@757426 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6e199c648b
commit
0a18feb00e
|
@ -39,7 +39,6 @@ import org.apache.maven.execution.RuntimeInformation;
|
|||
import org.apache.maven.lifecycle.Lifecycle;
|
||||
import org.apache.maven.lifecycle.LifecycleExecutionException;
|
||||
import org.apache.maven.lifecycle.LifecycleExecutor;
|
||||
import org.apache.maven.lifecycle.TaskValidationResult;
|
||||
import org.apache.maven.monitor.event.DeprecationEventDispatcher;
|
||||
import org.apache.maven.monitor.event.EventDispatcher;
|
||||
import org.apache.maven.monitor.event.MavenEvents;
|
||||
|
@ -115,48 +114,21 @@ public class DefaultMaven
|
|||
|
||||
MavenSession session = createSession( request, reactorManager, dispatcher );
|
||||
|
||||
if ( request.getGoals() != null )
|
||||
{
|
||||
for ( Iterator i = request.getGoals().iterator(); i.hasNext(); )
|
||||
{
|
||||
String goal = (String) i.next();
|
||||
|
||||
if ( goal == null )
|
||||
{
|
||||
i.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
TaskValidationResult tvr = lifecycleExecutor.isTaskValid( goal, session, reactorManager.getTopLevelProject() );
|
||||
|
||||
if ( !tvr.isTaskValid() )
|
||||
{
|
||||
Exception e = tvr.generateInvalidTaskException();
|
||||
result.addException( e );
|
||||
dispatcher.dispatchError( event, request.getBaseDirectory(), e );
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.info( "Scanning for projects..." );
|
||||
|
||||
if ( reactorManager.hasMultipleProjects() )
|
||||
{
|
||||
logger.info( "Reactor build order: " );
|
||||
|
||||
for ( Iterator i = reactorManager.getSortedProjects().iterator(); i.hasNext(); )
|
||||
for( MavenProject project : reactorManager.getSortedProjects() )
|
||||
{
|
||||
MavenProject project = (MavenProject) i.next();
|
||||
|
||||
logger.info( " " + project.getName() );
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
lifecycleExecutor.execute( session, reactorManager, dispatcher );
|
||||
lifecycleExecutor.execute( session );
|
||||
}
|
||||
catch ( LifecycleExecutionException e )
|
||||
{
|
||||
|
|
|
@ -52,14 +52,10 @@ public class MavenSession
|
|||
|
||||
private ReactorManager reactorManager;
|
||||
|
||||
private boolean usingPOMsFromFilesystem = true;
|
||||
|
||||
private MavenExecutionRequest request;
|
||||
|
||||
private MavenProject currentProject;
|
||||
|
||||
private Stack forkedProjectStack = new Stack();
|
||||
|
||||
private Map reports = new LinkedHashMap();
|
||||
|
||||
//For testing
|
||||
|
@ -197,33 +193,6 @@ public class MavenSession
|
|||
return request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push the existing currentProject onto the forked-project stack, and set the specified project
|
||||
* as the new current project. This signifies the beginning of a new forked-execution context.
|
||||
*/
|
||||
public void addForkedProject( MavenProject project )
|
||||
{
|
||||
forkedProjectStack.push( currentProject );
|
||||
currentProject = project;
|
||||
}
|
||||
|
||||
/**
|
||||
* Peel off the last forked project from the stack, and restore it as the currentProject. This
|
||||
* signifies the cleanup of a completed forked-execution context.
|
||||
*/
|
||||
public MavenProject removeForkedProject()
|
||||
{
|
||||
if ( !forkedProjectStack.isEmpty() )
|
||||
{
|
||||
MavenProject lastCurrent = currentProject;
|
||||
currentProject = (MavenProject) forkedProjectStack.pop();
|
||||
|
||||
return lastCurrent;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setCurrentProject( MavenProject currentProject )
|
||||
{
|
||||
this.currentProject = currentProject;
|
||||
|
@ -297,4 +266,9 @@ public class MavenSession
|
|||
{
|
||||
return request.isOffline();
|
||||
}
|
||||
|
||||
public ReactorManager getReactorManager()
|
||||
{
|
||||
return reactorManager;
|
||||
}
|
||||
}
|
|
@ -29,9 +29,7 @@ import org.apache.maven.execution.ReactorManager;
|
|||
import org.apache.maven.lifecycle.mapping.LifecycleMapping;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.PluginExecution;
|
||||
import org.apache.maven.monitor.event.EventDispatcher;
|
||||
import org.apache.maven.monitor.event.MavenEvents;
|
||||
import org.apache.maven.plugin.InvalidPluginException;
|
||||
import org.apache.maven.plugin.PluginLoaderException;
|
||||
import org.apache.maven.plugin.PluginManager;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
|
@ -61,19 +59,12 @@ public class DefaultLifecycleExecutor
|
|||
@Requirement
|
||||
private Map<String, LifecycleMapping> lifecycleMappings;
|
||||
|
||||
/**
|
||||
* Execute a task. Each task may be a phase in the lifecycle or the execution of a mojo.
|
||||
*
|
||||
* @param session
|
||||
* @param rm
|
||||
* @param dispatcher
|
||||
*/
|
||||
public void execute( MavenSession session, ReactorManager rm, EventDispatcher dispatcher )
|
||||
public void execute( MavenSession session )
|
||||
throws BuildFailureException, LifecycleExecutionException
|
||||
{
|
||||
// TODO: This is dangerous, particularly when it's just a collection of loose-leaf projects being built
|
||||
// within the same reactor (using an inclusion pattern to gather them up)...
|
||||
MavenProject rootProject = rm.getTopLevelProject();
|
||||
MavenProject rootProject = session.getReactorManager().getTopLevelProject();
|
||||
|
||||
List<String> goals = session.getGoals();
|
||||
|
||||
|
@ -92,7 +83,7 @@ public class DefaultLifecycleExecutor
|
|||
throw new BuildFailureException( "\n\nYou must specify at least one goal. Try 'mvn install' to build or 'mvn --help' for options \nSee http://maven.apache.org for more information.\n\n" );
|
||||
}
|
||||
|
||||
executeTaskSegments( goals, rm, session, rootProject, dispatcher );
|
||||
executeTaskSegments( goals, session, rootProject );
|
||||
}
|
||||
|
||||
public List<String> getLifecyclePhases()
|
||||
|
@ -108,86 +99,14 @@ public class DefaultLifecycleExecutor
|
|||
return null;
|
||||
}
|
||||
|
||||
public static boolean isValidPhaseName( final String phaseName )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public TaskValidationResult isTaskValid( String task, MavenSession session, MavenProject rootProject )
|
||||
{
|
||||
//jvz: have to investigate plugins that are run without a root project or using Maven in reactor mode. Looks like we
|
||||
// were never validating these anyway if you look in the execution code.
|
||||
|
||||
if ( rootProject != null )
|
||||
{
|
||||
if ( !isValidPhaseName( task ) )
|
||||
{
|
||||
// definitely a CLI goal, can use prefix
|
||||
try
|
||||
{
|
||||
getMojoDescriptorForDirectInvocation( task, session, rootProject );
|
||||
|
||||
return new TaskValidationResult();
|
||||
}
|
||||
catch ( PluginLoaderException e )
|
||||
{
|
||||
// TODO: shouldn't hit this, investigate using the same resolution logic as
|
||||
// others for plugins in the reactor
|
||||
|
||||
return new TaskValidationResult( task, "Cannot find mojo descriptor for: \'" + task + "\' - Treating as non-aggregator.", e );
|
||||
}
|
||||
catch ( LifecycleExecutionException e )
|
||||
{
|
||||
String message = "Invalid task '" + task + "': you must specify a valid lifecycle phase, or"
|
||||
+ " a goal in the format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal";
|
||||
|
||||
return new TaskValidationResult( task, message, e );
|
||||
}
|
||||
catch ( InvalidPluginException e )
|
||||
{
|
||||
return new TaskValidationResult( task, e.getMessage(), e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new TaskValidationResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the {@link MojoDescriptor} that corresponds to a given direct mojo invocation. This
|
||||
* is used during the fail-fast method isTaskValid(..), and also during task-segmentation, to
|
||||
* allow the lifecycle executor to determine whether the mojo is an aggregator.
|
||||
*
|
||||
* @throws PluginLoaderException
|
||||
*/
|
||||
private MojoDescriptor getMojoDescriptorForDirectInvocation( String task, MavenSession session, MavenProject project )
|
||||
throws InvalidPluginException, PluginLoaderException, LifecycleExecutionException
|
||||
{
|
||||
MojoDescriptor descriptor;
|
||||
|
||||
try
|
||||
{
|
||||
descriptor = getMojoDescriptor( task, session, project );
|
||||
}
|
||||
catch ( LifecycleExecutionException e )
|
||||
{
|
||||
throw new LifecycleExecutionException( "Cannot find the specified goal.", e );
|
||||
}
|
||||
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
private void executeTaskSegments( List<String> goals, ReactorManager rm, MavenSession session, MavenProject rootProject, EventDispatcher dispatcher )
|
||||
private void executeTaskSegments( List<String> goals, MavenSession session, MavenProject rootProject )
|
||||
throws LifecycleExecutionException, BuildFailureException
|
||||
{
|
||||
List<MavenProject> sortedProjects = session.getSortedProjects();
|
||||
|
||||
for ( MavenProject currentProject : sortedProjects )
|
||||
{
|
||||
if ( !rm.isBlackListed( currentProject ) )
|
||||
if ( !session.getReactorManager().isBlackListed( currentProject ) )
|
||||
{
|
||||
line();
|
||||
|
||||
|
@ -208,9 +127,9 @@ public class DefaultLifecycleExecutor
|
|||
for ( String goal : goals )
|
||||
{
|
||||
String target = currentProject.getId() + " ( " + goal + " )";
|
||||
dispatcher.dispatchStart( event, target );
|
||||
executeGoalAndHandleFailures( goal, session, currentProject, dispatcher, event, rm, buildStartTime, target );
|
||||
dispatcher.dispatchEnd( event, target );
|
||||
session.getEventDispatcher().dispatchStart( event, target );
|
||||
executeGoalAndHandleFailures( goal, session, currentProject, event, session.getReactorManager(), buildStartTime, target );
|
||||
session.getEventDispatcher().dispatchEnd( event, target );
|
||||
}
|
||||
}
|
||||
finally
|
||||
|
@ -218,12 +137,12 @@ public class DefaultLifecycleExecutor
|
|||
session.setCurrentProject( null );
|
||||
}
|
||||
|
||||
rm.registerBuildSuccess( currentProject, System.currentTimeMillis() - buildStartTime );
|
||||
session.getReactorManager().registerBuildSuccess( currentProject, System.currentTimeMillis() - buildStartTime );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void executeGoalAndHandleFailures( String task, MavenSession session, MavenProject project, EventDispatcher dispatcher, String event, ReactorManager rm, long buildStartTime, String target )
|
||||
private void executeGoalAndHandleFailures( String task, MavenSession session, MavenProject project, String event, ReactorManager rm, long buildStartTime, String target )
|
||||
throws BuildFailureException, LifecycleExecutionException
|
||||
{
|
||||
try
|
||||
|
@ -232,7 +151,7 @@ public class DefaultLifecycleExecutor
|
|||
}
|
||||
catch ( LifecycleExecutionException e )
|
||||
{
|
||||
dispatcher.dispatchError( event, target, e );
|
||||
session.getEventDispatcher().dispatchError( event, target, e );
|
||||
|
||||
if ( handleExecutionFailure( rm, project, e, task, buildStartTime ) )
|
||||
{
|
||||
|
@ -241,7 +160,7 @@ public class DefaultLifecycleExecutor
|
|||
}
|
||||
catch ( BuildFailureException e )
|
||||
{
|
||||
dispatcher.dispatchError( event, target, e );
|
||||
session.getEventDispatcher().dispatchError( event, target, e );
|
||||
|
||||
if ( handleExecutionFailure( rm, project, e, task, buildStartTime ) )
|
||||
{
|
||||
|
|
|
@ -33,9 +33,7 @@ import org.apache.maven.project.MavenProject;
|
|||
public interface LifecycleExecutor
|
||||
{
|
||||
List<String> getLifecyclePhases();
|
||||
|
||||
TaskValidationResult isTaskValid( String task, MavenSession session, MavenProject rootProject );
|
||||
|
||||
void execute( MavenSession session, ReactorManager rm, EventDispatcher dispatcher )
|
||||
|
||||
void execute( MavenSession session )
|
||||
throws LifecycleExecutionException, BuildFailureException;
|
||||
}
|
||||
|
|
|
@ -110,13 +110,14 @@ public class LifecycleExecutorTest
|
|||
|
||||
ReactorManager reactorManager = new ReactorManager( projects, request.getReactorFailureBehavior() );
|
||||
|
||||
MavenSession session = new MavenSession( getContainer(), request, reactorManager );
|
||||
EventDispatcher dispatcher = new DeprecationEventDispatcher( MavenEvents.DEPRECATIONS, request.getEventMonitors() );
|
||||
|
||||
MavenSession session = new MavenSession( getContainer(), request, reactorManager, dispatcher );
|
||||
//!!jvz This is not really quite right, take a look at how this actually works.
|
||||
session.setCurrentProject( project );
|
||||
|
||||
EventDispatcher dispatcher = new DeprecationEventDispatcher( MavenEvents.DEPRECATIONS, request.getEventMonitors() );
|
||||
|
||||
lifecycleExecutor.execute( session, reactorManager, dispatcher );
|
||||
lifecycleExecutor.execute( session );
|
||||
}
|
||||
|
||||
public void testRemoteResourcesPlugin()
|
||||
|
|
Loading…
Reference in New Issue