new SimpleDateFormat( "yyyyMMdd-hhmm" ).format( request.getStartTime() ) );
}
request.setStartTime( new Date() );
MavenExecutionResult result = new DefaultMavenExecutionResult();
try
{
validateLocalRepository( request );
}
catch ( LocalRepositoryNotAccessibleException e )
{
return addExceptionToResult( result, e );
}
DelegatingLocalArtifactRepository delegatingLocalArtifactRepository =
new DelegatingLocalArtifactRepository( request.getLocalRepository() );
request.setLocalRepository( delegatingLocalArtifactRepository );
DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) newRepositorySession( request );
MavenSession session = new MavenSession( container, repoSession, request, result );
legacySupport.setSession( session );
try
{
for ( AbstractMavenLifecycleParticipant listener : getLifecycleParticipants( Collections.<MavenProject> emptyList() ) )
{
listener.afterSessionStart( session );
}
}
catch ( MavenExecutionException e )
{
return addExceptionToResult( result, e );
}
eventCatapult.fire( ExecutionEvent.Type.ProjectDiscoveryStarted, session, null );
request.getProjectBuildingRequest().setRepositorySession( session.getRepositorySession() );
//TODO: optimize for the single project or no project
List<MavenProject> projects;
try
{
projects = getProjectsForMavenReactor( request );
}
catch ( ProjectBuildingException e )
{
return addExceptionToResult( result, e );
}
session.setProjects( projects );
result.setTopologicallySortedProjects( session.getProjects() );
result.setProject( session.getTopLevelProject() );
try
{
Map<String, MavenProject> projectMap;
projectMap = getProjectMap( session.getProjects() );
// Desired order of precedence for local artifact repositories
//
// Reactor
// Workspace
// User Local Repository
ReactorReader reactorRepository = new ReactorReader( projectMap );
repoSession.setWorkspaceReader( ChainedWorkspaceReader.newInstance( reactorRepository,
repoSession.getWorkspaceReader() ) );
}
catch ( org.apache.maven.DuplicateProjectException e )
{
return addExceptionToResult( result, e );
}
repoSession.setReadOnly();
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
try
{
for ( AbstractMavenLifecycleParticipant listener : getLifecycleParticipants( projects ) )
{
Thread.currentThread().setContextClassLoader( listener.getClass().getClassLoader() );
listener.afterProjectsRead( session );
}
}
catch ( MavenExecutionException e )
{
return addExceptionToResult( result, e );
}
finally
{
Thread.currentThread().setContextClassLoader( originalClassLoader );
}
try
{
ProjectSorter projectSorter = new ProjectSorter( session.getProjects() );
ProjectDependencyGraph projectDependencyGraph = createDependencyGraph( projectSorter, request );
session.setProjects( projectDependencyGraph.getSortedProjects() );
session.setProjectDependencyGraph( projectDependencyGraph );
}
catch ( CycleDetectedException e )
{
String message = "The projects in the reactor contain a cyclic reference: " + e.getMessage();
ProjectCycleException error = new ProjectCycleException( message, e );
return addExceptionToResult( result, error );
}
catch ( DuplicateProjectException e )
{
return addExceptionToResult( result, e );
}
catch ( MavenExecutionException e )
{
return addExceptionToResult( result, e );
}
result.setTopologicallySortedProjects( session.getProjects() );
if ( result.hasExceptions() )
{
return result;
}
lifecycleStarter.execute( session );