Changed ReactorManager's api for blackList and other methods that require

an 'id' to use MavenProject instead. 
In some parts of the code a DAG is constructed using a version-less key,
and in the api what the id should be is unspecified.
This could result in NPE's (it does!) because the code in plexus-utils
assumes a known id (vertex in the DAG) is supplied.

So, moved the project.getId() calls outside of ReactorManager into the
ReactorManager, so that there's just one place where the decision is made on
how to generate an id (DAG vertex label) from a project. This centralizes
that knowledge for increased maintainability and reduced chances on NPE's.




git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@279334 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Kenney Westerhof 2005-09-07 14:57:24 +00:00
parent 7b6f292c73
commit 69c6305347
3 changed files with 71 additions and 63 deletions

View File

@ -79,7 +79,7 @@ public class DefaultMaven
// ----------------------------------------------------------------------
protected MavenProjectBuilder projectBuilder;
protected LifecycleExecutor lifecycleExecutor;
protected PlexusContainer container;
@ -126,9 +126,9 @@ public class DefaultMaven
dispatcher.dispatchStart( event, request.getBaseDirectory() );
ReactorManager rm;
ProfileManager globalProfileManager = request.getGlobalProfileManager();
try
{
loadSettingsProfiles( globalProfileManager, request.getSettings() );
@ -137,7 +137,7 @@ public class DefaultMaven
List projects = collectProjects( files, request.getLocalRepository(), request.isRecursive(),
request.getSettings(), globalProfileManager );
// the reasoning here is that the list is still unsorted according to dependency, so the first project
// SHOULD BE the top-level, or the one we want to start with if we're doing an aggregated build.
@ -146,11 +146,11 @@ public class DefaultMaven
MavenProject superProject = projectBuilder.buildStandaloneSuperProject( request.getLocalRepository() );
projects.add( superProject );
}
rm = new ReactorManager( projects );
String requestFailureBehavior = request.getFailureBehavior();
if ( requestFailureBehavior != null )
{
rm.setFailureBehavior( requestFailureBehavior );
@ -196,7 +196,7 @@ public class DefaultMaven
if ( ReactorManager.FAIL_AT_END.equals( rm.getFailureBehavior() ) && ( exception instanceof ReactorException ) )
{
logFailure( response, exception, null );
if ( rm.hasMultipleProjects() )
{
writeReactorSummary( rm );
@ -262,22 +262,22 @@ public class DefaultMaven
// o project-name...........FAILED
// o project2-name..........SKIPPED (dependency build failed or was skipped)
// o project-3-name.........SUCCESS
line();
getLogger().info( "Reactor Summary:" );
line();
for ( Iterator it = rm.getProjectsSortedByDependency().iterator(); it.hasNext(); )
{
MavenProject project = (MavenProject) it.next();
String id = project.getId();
if ( rm.hasBuildFailure( id ) )
if ( rm.hasBuildFailure( project ) )
{
logReactorSummaryLine( project.getName(), "FAILED" );
}
else if ( rm.isBlackListed( id ) )
else if ( rm.isBlackListed( project ) )
{
logReactorSummaryLine( project.getName(), "SKIPPED (dependency build failed or was skipped)" );
}
@ -286,7 +286,7 @@ public class DefaultMaven
logReactorSummaryLine( project.getName(), "SUCCESS" );
}
}
getLogger().info( "" );
getLogger().info( "" );
}
@ -294,20 +294,20 @@ public class DefaultMaven
private void logReactorSummaryLine( String name, String status )
{
StringBuffer messageBuffer = new StringBuffer();
messageBuffer.append( name );
int dotCount = 65;
dotCount -= name.length();
for ( int i = 0; i < dotCount; i++ )
{
messageBuffer.append( '.' );
}
messageBuffer.append( status );
getLogger().info( messageBuffer.toString() );
}
@ -399,7 +399,7 @@ public class DefaultMaven
if ( settingsProfiles != null && !settingsProfiles.isEmpty() )
{
List settingsActiveProfileIds = settings.getActiveProfiles();
profileManager.explicitlyActivate( settingsActiveProfileIds );
for ( Iterator it = settings.getProfiles().iterator(); it.hasNext(); )
@ -411,9 +411,9 @@ public class DefaultMaven
profileManager.addProfile( profile );
}
}
}
// ----------------------------------------------------------------------
// Methods used by all execution request handlers
// ----------------------------------------------------------------------
@ -585,7 +585,7 @@ public class DefaultMaven
{
writeReactorSummary( rm );
}
line();
getLogger().info( "BUILD SUCCESSFUL" );
@ -618,7 +618,7 @@ public class DefaultMaven
{
getLogger().info( "----------------------------------------------------------------------------" );
}
protected static String formatTime( long ms )
{
long secs = ms / MS_PER_SEC;

View File

@ -20,27 +20,27 @@ import java.util.Map;
public class ReactorManager
{
public static final String FAIL_FAST = "fail-fast";
public static final String FAIL_AT_END = "fail-at-end";
public static final String FAIL_NEVER = "fail-never";
private DAG reactorDag;
private Map projectMap;
private List projectsByDependency;
private List blackList = new ArrayList();
private MavenProject topLevelProject;
private Map buildFailuresByProject = new HashMap();
private String failureBehavior = FAIL_FAST;
public ReactorManager( List projects )
throws CycleDetectedException
{
@ -136,10 +136,10 @@ public class ReactorManager
projectsByDependency.add( projectMap.get( id ) );
}
projectsByDependency = Collections.unmodifiableList( projectsByDependency );
}
public void setFailureBehavior( String failureBehavior )
{
if ( FAIL_FAST.equals( failureBehavior ) || FAIL_AT_END.equals( failureBehavior ) || FAIL_NEVER.equals( failureBehavior ) )
@ -152,33 +152,39 @@ public class ReactorManager
+ FAIL_AT_END + "\', \'" + FAIL_NEVER + "\')." );
}
}
public String getFailureBehavior()
{
return failureBehavior;
}
public List getProjectsSortedByDependency()
{
return projectsByDependency;
}
// TODO: !![jc; 28-jul-2005] check this; if we're using '-r' and there are aggregator tasks, this will result in weirdness.
public MavenProject getTopLevelProject()
{
if ( topLevelProject == null )
{
List projectsByFile = new ArrayList( projectsByDependency );
Collections.sort(projectsByFile, new ByProjectFileComparator() );
topLevelProject = (MavenProject) projectsByFile.get( 0 );
}
return topLevelProject;
}
public void blackList( String id )
public void blackList( MavenProject project )
{
blackList(
ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() ) );
}
private void blackList( String id )
{
if ( !blackList.contains( id ) )
{
@ -197,32 +203,33 @@ public class ReactorManager
}
}
}
public boolean isBlackListed( String id )
public boolean isBlackListed( MavenProject project )
{
return blackList.contains( id );
return blackList.contains(
ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() ) );
}
public void registerBuildFailure( MavenProject project, Exception error, String task )
{
buildFailuresByProject.put( project.getId(), new BuildFailure( error, task ) );
}
public boolean hasBuildFailures()
{
return !buildFailuresByProject.isEmpty();
}
public boolean hasBuildFailure( String id )
public boolean hasBuildFailure( MavenProject project )
{
return buildFailuresByProject.containsKey( id );
return buildFailuresByProject.containsKey( project.getId() );
}
public boolean hasMultipleProjects()
{
return projectsByDependency.size() > 1;
}
private static class ByProjectFileComparator implements Comparator
{
@ -230,12 +237,12 @@ public class ReactorManager
{
MavenProject p1 = (MavenProject) first;
MavenProject p2 = (MavenProject) second;
String p1Path = p1.getFile().getAbsolutePath();
String p2Path = p2.getFile().getAbsolutePath();
int comparison = p1Path.length() - p2Path.length();
if ( comparison > 0 )
{
return 1;
@ -250,23 +257,23 @@ public class ReactorManager
}
}
}
private static class BuildFailure
{
private Exception cause;
private String task;
BuildFailure( Exception cause, String task )
{
this.cause = cause;
this.task = task;
}
String getTask()
{
return task;
}
Exception getCause()
{
return cause;

View File

@ -177,7 +177,7 @@ public class DefaultLifecycleExecutor
if ( segment.aggregate() )
{
if ( !rm.isBlackListed( project.getId() ) )
if ( !rm.isBlackListed( project ) )
{
line();
@ -246,7 +246,7 @@ public class DefaultLifecycleExecutor
{
MavenProject currentProject = (MavenProject) projectIterator.next();
if ( !rm.isBlackListed( currentProject.getId() ) )
if ( !rm.isBlackListed( currentProject ) )
{
line();
@ -335,8 +335,9 @@ public class DefaultLifecycleExecutor
{
rm.registerBuildFailure( project, e, task );
rm.blackList( project.getId() );
rm.blackList( project );
}
// FIXME: how about the other cases?
}
private List segmentTaskListByAggregationNeeds( List tasks, MavenSession session, MavenProject project )