Author: kenney
Date: Wed Sep  7 07:57:24 2005
New Revision: 279334

URL: http://svn.apache.org/viewcvs?rev=279334&view=rev
Log:
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.



Modified:
    
maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
    
maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/ReactorManager.java
    
maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java

Modified: 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
URL: 
http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java?rev=279334&r1=279333&r2=279334&view=diff
==============================================================================
--- 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
 (original)
+++ 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
 Wed Sep  7 07:57:24 2005
@@ -79,7 +79,7 @@
     // ----------------------------------------------------------------------
 
     protected MavenProjectBuilder projectBuilder;
-    
+
     protected LifecycleExecutor lifecycleExecutor;
 
     protected PlexusContainer container;
@@ -126,9 +126,9 @@
         dispatcher.dispatchStart( event, request.getBaseDirectory() );
 
         ReactorManager rm;
-        
+
         ProfileManager globalProfileManager = 
request.getGlobalProfileManager();
-        
+
         try
         {
             loadSettingsProfiles( globalProfileManager, request.getSettings() 
);
@@ -137,7 +137,7 @@
 
             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 @@
                 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 @@
                     if ( ReactorManager.FAIL_AT_END.equals( 
rm.getFailureBehavior() ) && ( exception instanceof ReactorException ) )
                     {
                         logFailure( response, exception, null );
-                        
+
                         if ( rm.hasMultipleProjects() )
                         {
                             writeReactorSummary( rm );
@@ -262,22 +262,22 @@
         // 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 @@
                 logReactorSummaryLine( project.getName(), "SUCCESS" );
             }
         }
-        
+
         getLogger().info( "" );
         getLogger().info( "" );
     }
@@ -294,20 +294,20 @@
     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 @@
         if ( settingsProfiles != null && !settingsProfiles.isEmpty() )
         {
             List settingsActiveProfileIds = settings.getActiveProfiles();
-            
+
             profileManager.explicitlyActivate( settingsActiveProfileIds );
 
             for ( Iterator it = settings.getProfiles().iterator(); 
it.hasNext(); )
@@ -411,9 +411,9 @@
                 profileManager.addProfile( profile );
             }
         }
-        
+
     }
-    
+
     // ----------------------------------------------------------------------
     // Methods used by all execution request handlers
     // ----------------------------------------------------------------------
@@ -585,7 +585,7 @@
         {
             writeReactorSummary( rm );
         }
-        
+
         line();
 
         getLogger().info( "BUILD SUCCESSFUL" );
@@ -618,7 +618,7 @@
     {
         getLogger().info( 
"----------------------------------------------------------------------------" 
);
     }
-    
+
     protected static String formatTime( long ms )
     {
         long secs = ms / MS_PER_SEC;

Modified: 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/ReactorManager.java
URL: 
http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/ReactorManager.java?rev=279334&r1=279333&r2=279334&view=diff
==============================================================================
--- 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/ReactorManager.java
 (original)
+++ 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/ReactorManager.java
 Wed Sep  7 07:57:24 2005
@@ -20,27 +20,27 @@
 
 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 @@
 
             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 @@
                 + 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 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 @@
         {
             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 @@
             }
         }
     }
-    
+
     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;

Modified: 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
URL: 
http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java?rev=279334&r1=279333&r2=279334&view=diff
==============================================================================
--- 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
 (original)
+++ 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
 Wed Sep  7 07:57:24 2005
@@ -177,7 +177,7 @@
 
             if ( segment.aggregate() )
             {
-                if ( !rm.isBlackListed( project.getId() ) )
+                if ( !rm.isBlackListed( project ) )
                 {
                     line();
 
@@ -246,7 +246,7 @@
                 {
                     MavenProject currentProject = (MavenProject) 
projectIterator.next();
 
-                    if ( !rm.isBlackListed( currentProject.getId() ) )
+                    if ( !rm.isBlackListed( currentProject ) )
                     {
                         line();
 
@@ -335,8 +335,9 @@
         {
             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 )



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to