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

View File

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

View File

@ -177,7 +177,7 @@ public class DefaultLifecycleExecutor
if ( segment.aggregate() ) if ( segment.aggregate() )
{ {
if ( !rm.isBlackListed( project.getId() ) ) if ( !rm.isBlackListed( project ) )
{ {
line(); line();
@ -246,7 +246,7 @@ public class DefaultLifecycleExecutor
{ {
MavenProject currentProject = (MavenProject) projectIterator.next(); MavenProject currentProject = (MavenProject) projectIterator.next();
if ( !rm.isBlackListed( currentProject.getId() ) ) if ( !rm.isBlackListed( currentProject ) )
{ {
line(); line();
@ -335,8 +335,9 @@ public class DefaultLifecycleExecutor
{ {
rm.registerBuildFailure( project, e, task ); 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 ) private List segmentTaskListByAggregationNeeds( List tasks, MavenSession session, MavenProject project )