public void execute( MavenSession session )
{
fireEvent( session, null, LifecycleEventCatapult.SESSION_STARTED );
MavenExecutionResult result = session.getResult();
List<ProjectBuild> projectBuilds;
ProjectIndex projectIndex;
try
{
projectBuilds = calculateProjectBuilds( session );
projectIndex = new ProjectIndex( session.getProjects() );
}
catch ( Exception e )
{
result.addException( e );
fireEvent( session, null, LifecycleEventCatapult.SESSION_ENDED );
return;
}
if ( logger.isDebugEnabled() )
{
debugReactorPlan( projectBuilds );
}
ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
for ( ProjectBuild projectBuild : projectBuilds )
{
MavenProject currentProject = projectBuild.project;
long buildStartTime = System.currentTimeMillis();
try
{
session.setCurrentProject( currentProject );
if ( session.isBlackListed( currentProject ) )
{
fireEvent( session, null, LifecycleEventCatapult.PROJECT_SKIPPED );
continue;
}
fireEvent( session, null, LifecycleEventCatapult.PROJECT_STARTED );
ClassRealm projectRealm = currentProject.getClassRealm();
if ( projectRealm != null )
{
Thread.currentThread().setContextClassLoader( projectRealm );
}
MavenExecutionPlan executionPlan =
calculateExecutionPlan( session, currentProject, projectBuild.taskSegment );
if ( logger.isDebugEnabled() )
{
debugProjectPlan( currentProject, executionPlan );
}
// TODO: once we have calculated the build plan then we should accurately be able to download
// the project dependencies. Having it happen in the plugin manager is a tangled mess. We can optimize
// this later by looking at the build plan. Would be better to just batch download everything required
// by the reactor.
List<MavenProject> projectsToResolve;
if ( projectBuild.taskSegment.aggregating )
{
projectsToResolve = session.getProjects();
}
else
{
projectsToResolve = Collections.singletonList( currentProject );
}
for ( MavenProject project : projectsToResolve )
{
resolveProjectDependencies( project, executionPlan.getRequiredCollectionScopes(),
executionPlan.getRequiredResolutionScopes(), session,
projectBuild.taskSegment.aggregating );
}
DependencyContext dependencyContext =
new DependencyContext( executionPlan, projectBuild.taskSegment.aggregating );
for ( MojoExecution mojoExecution : executionPlan.getExecutions() )
{
execute( session, mojoExecution, projectIndex, dependencyContext );
}
long buildEndTime = System.currentTimeMillis();
result.addBuildSummary( new BuildSuccess( currentProject, buildEndTime - buildStartTime ) );
fireEvent( session, null, LifecycleEventCatapult.PROJECT_SUCCEEDED );
}
catch ( Exception e )
{
result.addException( e );
long buildEndTime = System.currentTimeMillis();
result.addBuildSummary( new BuildFailure( currentProject, buildEndTime - buildStartTime, e ) );
fireEvent( session, null, LifecycleEventCatapult.PROJECT_FAILED );
if ( MavenExecutionRequest.REACTOR_FAIL_NEVER.equals( session.getReactorFailureBehavior() ) )
{