You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by jd...@apache.org on 2005/08/17 04:05:07 UTC

svn commit: r233104 - /maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java

Author: jdcasey
Date: Tue Aug 16 19:05:04 2005
New Revision: 233104

URL: http://svn.apache.org/viewcvs?rev=233104&view=rev
Log:
Throwing exception if infinite loop detected in phase vs. executePhase...this is probably not optimal, but it's a start.

Modified:
    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/lifecycle/DefaultLifecycleExecutor.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java?rev=233104&r1=233103&r2=233104&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 Tue Aug 16 19:05:04 2005
@@ -524,12 +524,51 @@
                 }
             }
         }
+        
+        String mojoPhase = findFirstPhaseBindingForMojo( mojoDescriptor, lifecycleMappings );
+        
+        int mojoPhaseIdx = phases.indexOf( mojoPhase );
+        int execPhaseIdx = phases.indexOf( task );
+        
+        if ( mojoPhaseIdx > -1 && mojoPhaseIdx <= execPhaseIdx )
+        {
+            throw new LifecycleExecutionException( "Infinite loop detected in build process. Mojo: \'"
+                + mojoDescriptor.getGoal() + "\' declares executePhase of: \'" + task
+                + "\' but is itself bound to phase: \'" + mojoPhase
+                + "\'. This will result in infinite forking of build execution." );
+        }
 
         MavenProject executionProject = new MavenProject( project );
         executeGoalWithLifecycle( task, session, lifecycleMappings, executionProject );
         project.setExecutionProject( executionProject );
     }
 
+    private String findFirstPhaseBindingForMojo( MojoDescriptor mojoDescriptor, Map lifecycleMappings )
+    {
+        PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
+        
+        String mojoIdWithVersion = pluginDescriptor.getGroupId() + ":" + pluginDescriptor.getArtifactId() + ":"
+            + pluginDescriptor.getVersion() + ":" + mojoDescriptor.getGoal();
+        
+        String mojoIdWithoutVersion = pluginDescriptor.getGroupId() + ":" + pluginDescriptor.getArtifactId() + ":"
+            + mojoDescriptor.getGoal();
+            
+        for ( Iterator it = lifecycleMappings.entrySet().iterator(); it.hasNext(); )
+        {
+            Map.Entry entry = (Map.Entry) it.next();
+            
+            String phase = (String) entry.getKey();
+            List tasks = (List) entry.getValue();
+            
+            if ( tasks.contains( mojoIdWithVersion ) || tasks.contains( mojoIdWithoutVersion ) )
+            {
+                return phase;
+            }
+        }
+        
+        return null;
+    }
+
     private Map constructLifecycleMappings( MavenSession session, String selectedPhase, MavenProject project )
         throws ArtifactResolutionException, LifecycleExecutionException
     {
@@ -792,14 +831,23 @@
             if ( execution.isInheritanceApplied() || mojoDescriptor.isInheritedByDefault() )
             {
                 MojoExecution mojoExecution = new MojoExecution( mojoDescriptor, execution.getId() );
-                if ( execution.getPhase() != null )
+                
+                String phase = execution.getPhase();
+                
+                if ( phase == null )
                 {
-                    addToLifecycleMappings( phaseMap, execution.getPhase(), mojoExecution, settings );
+                    // if the phase was not in the configuration, use the phase in the descriptor
+                    phase = mojoDescriptor.getPhase();
                 }
-                else if ( mojoDescriptor.getPhase() != null )
+                
+                if ( phase != null )
                 {
-                    // if the phase was not in the configuration, use the phase in the descriptor
-                    addToLifecycleMappings( phaseMap, mojoDescriptor.getPhase(), mojoExecution, settings );
+                    if ( mojoDescriptor.isDirectInvocationOnly() )
+                    {
+                        throw new LifecycleExecutionException( "Mojo: \'" + goal + "\' requires direct invocation. It cannot be used as part of the lifecycle (it was included via the POM)." );
+                    }
+                    
+                    addToLifecycleMappings( phaseMap, phase, mojoExecution, settings );
                 }
             }
         }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org