Author: bentmann
Date: Fri Aug 28 09:50:29 2009
New Revision: 808828

URL: http://svn.apache.org/viewvc?rev=808828&view=rev
Log:
o Exposed methods to allow the Site Plugin to reuse the forking code for report 
mojos

Modified:
    
maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
    
maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java
    
maven/components/trunk/maven-core/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java

Modified: 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
URL: 
http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java?rev=808828&r1=808827&r2=808828&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
 Fri Aug 28 09:50:29 2009
@@ -438,6 +438,59 @@
             }
         }
 
+        List<MavenProject> forkedProjects = executeForkedExecutions( 
mojoExecution, session, projectIndex );
+
+        fireEvent( session, mojoExecution, LifecycleEventCatapult.MOJO_STARTED 
);
+
+        try
+        {
+            pluginManager.executeMojo( session, mojoExecution );
+
+            fireEvent( session, mojoExecution, 
LifecycleEventCatapult.MOJO_SUCCEEDED );
+        }
+        catch ( MojoFailureException e )
+        {
+            fireEvent( session, mojoExecution, 
LifecycleEventCatapult.MOJO_FAILED );
+
+            throw e;
+        }
+        catch ( MojoExecutionException e )
+        {
+            fireEvent( session, mojoExecution, 
LifecycleEventCatapult.MOJO_FAILED );
+
+            throw e;
+        }
+        catch ( PluginConfigurationException e )
+        {
+            fireEvent( session, mojoExecution, 
LifecycleEventCatapult.MOJO_FAILED );
+
+            throw e;
+        }
+        catch ( PluginManagerException e )
+        {
+            fireEvent( session, mojoExecution, 
LifecycleEventCatapult.MOJO_FAILED );
+
+            throw e;
+        }
+        finally
+        {
+            for ( MavenProject forkedProject : forkedProjects )
+            {
+                forkedProject.setExecutionProject( null );
+            }
+        }
+    }
+
+    public List<MavenProject> executeForkedExecutions( MojoExecution 
mojoExecution, MavenSession session )
+        throws MojoFailureException, MojoExecutionException, 
PluginConfigurationException, PluginManagerException
+    {
+        return executeForkedExecutions( mojoExecution, session, new 
ProjectIndex( session.getProjects() ) );
+    }
+
+    private List<MavenProject> executeForkedExecutions( MojoExecution 
mojoExecution, MavenSession session,
+                                                        ProjectIndex 
projectIndex )
+        throws MojoFailureException, MojoExecutionException, 
PluginConfigurationException, PluginManagerException
+    {
         List<MavenProject> forkedProjects = Collections.emptyList();
 
         Map<String, List<MojoExecution>> forkedExecutions = 
mojoExecution.getForkedExecutions();
@@ -511,45 +564,7 @@
             }
         }
 
-        fireEvent( session, mojoExecution, LifecycleEventCatapult.MOJO_STARTED 
);
-
-        try
-        {
-            pluginManager.executeMojo( session, mojoExecution );
-
-            fireEvent( session, mojoExecution, 
LifecycleEventCatapult.MOJO_SUCCEEDED );
-        }
-        catch ( MojoFailureException e )
-        {
-            fireEvent( session, mojoExecution, 
LifecycleEventCatapult.MOJO_FAILED );
-
-            throw e;
-        }
-        catch ( MojoExecutionException e )
-        {
-            fireEvent( session, mojoExecution, 
LifecycleEventCatapult.MOJO_FAILED );
-
-            throw e;
-        }
-        catch ( PluginConfigurationException e )
-        {
-            fireEvent( session, mojoExecution, 
LifecycleEventCatapult.MOJO_FAILED );
-
-            throw e;
-        }
-        catch ( PluginManagerException e )
-        {
-            fireEvent( session, mojoExecution, 
LifecycleEventCatapult.MOJO_FAILED );
-
-            throw e;
-        }
-        finally
-        {
-            for ( MavenProject forkedProject : forkedProjects )
-            {
-                forkedProject.setExecutionProject( null );
-            }
-        }
+        return forkedProjects;
     }
 
     private static final class ProjectIndex
@@ -945,6 +960,14 @@
         return lifecycleMappings;
     }
 
+    public void calculateForkedExecutions( MojoExecution mojoExecution, 
MavenSession session )
+        throws MojoNotFoundException, PluginNotFoundException, 
PluginResolutionException,
+        PluginDescriptorParsingException, NoPluginFoundForPrefixException, 
InvalidPluginDescriptorException,
+        LifecyclePhaseNotFoundException, LifecycleNotFoundException, 
PluginVersionResolutionException
+    {
+        calculateForkedExecutions( mojoExecution, session, 
session.getCurrentProject(), new HashSet<MojoDescriptor>() );
+    }
+
     private void calculateForkedExecutions( MojoExecution mojoExecution, 
MavenSession session, MavenProject project,
                                             Collection<MojoDescriptor> 
alreadyForkedExecutions )
         throws MojoNotFoundException, PluginNotFoundException, 
PluginResolutionException,

Modified: 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java
URL: 
http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java?rev=808828&r1=808827&r2=808828&view=diff
==============================================================================
--- 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java
 (original)
+++ 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java
 Fri Aug 28 09:50:29 2009
@@ -20,19 +20,25 @@
  */
 
 import java.util.Collection;
+import java.util.List;
 import java.util.Set;
 
 import org.apache.maven.artifact.repository.RepositoryRequest;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.model.Plugin;
 import org.apache.maven.plugin.InvalidPluginDescriptorException;
+import org.apache.maven.plugin.MojoExecution;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugin.MojoNotFoundException;
+import org.apache.maven.plugin.PluginConfigurationException;
 import org.apache.maven.plugin.PluginDescriptorParsingException;
 import org.apache.maven.plugin.PluginManagerException;
 import org.apache.maven.plugin.PluginNotFoundException;
 import org.apache.maven.plugin.PluginResolutionException;
 import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
 import org.apache.maven.plugin.version.PluginVersionResolutionException;
+import org.apache.maven.project.MavenProject;
 
 /**
  * @author Jason van  Zyl
@@ -79,4 +85,34 @@
         throws LifecycleExecutionException;
     
     void execute( MavenSession session );
+
+    /**
+     * Calculates the forked mojo executions requested by the mojo associated 
with the specified mojo execution.
+     * 
+     * @param mojoExecution The mojo execution for which to calculate the 
forked mojo executions, must not be {...@code
+     *            null}.
+     * @param session The current build session that holds the projects and 
further settings, must not be {...@code null}.
+     */
+    void calculateForkedExecutions( MojoExecution mojoExecution, MavenSession 
session )
+        throws MojoNotFoundException, PluginNotFoundException, 
PluginResolutionException,
+        PluginDescriptorParsingException, NoPluginFoundForPrefixException, 
InvalidPluginDescriptorException,
+        LifecyclePhaseNotFoundException, LifecycleNotFoundException, 
PluginVersionResolutionException;
+
+    /**
+     * Executes the previously calculated forked mojo executions of the given 
mojo execution. If the specified mojo
+     * execution requires no forking, this method does nothing. The return 
value denotes a subset of the projects from
+     * the session that have been forked. The method {...@link 
MavenProject#getExecutionProject()} of those projects
+     * returns the project clone on which the forked execution were performed. 
It is the responsibility of the caller to
+     * reset those execution projects to {...@code null} once they are no 
longer needed to free memory and to avoid
+     * accidental usage by unrelated mojos.
+     * 
+     * @param mojoExecution The mojo execution whose forked mojo executions 
should be processed, must not be {...@code
+     *            null}.
+     * @param session The current build session that holds the projects and 
further settings, must not be {...@code null}.
+     * @return The (unmodifiable) list of projects that have been forked, can 
be empty if no forking was required but
+     *         will never be {...@code null}.
+     */
+    List<MavenProject> executeForkedExecutions( MojoExecution mojoExecution, 
MavenSession session )
+        throws MojoFailureException, MojoExecutionException, 
PluginConfigurationException, PluginManagerException;
+
 }

Modified: 
maven/components/trunk/maven-core/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java
URL: 
http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java?rev=808828&r1=808827&r2=808828&view=diff
==============================================================================
--- 
maven/components/trunk/maven-core/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java
 (original)
+++ 
maven/components/trunk/maven-core/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java
 Fri Aug 28 09:50:29 2009
@@ -30,13 +30,22 @@
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.lifecycle.LifecycleExecutionException;
 import org.apache.maven.lifecycle.LifecycleExecutor;
+import org.apache.maven.lifecycle.LifecycleNotFoundException;
+import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException;
 import org.apache.maven.lifecycle.MavenExecutionPlan;
 import org.apache.maven.model.Plugin;
+import org.apache.maven.plugin.InvalidPluginDescriptorException;
 import org.apache.maven.plugin.MojoExecution;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugin.MojoNotFoundException;
+import org.apache.maven.plugin.PluginConfigurationException;
 import org.apache.maven.plugin.PluginDescriptorParsingException;
+import org.apache.maven.plugin.PluginManagerException;
 import org.apache.maven.plugin.PluginNotFoundException;
 import org.apache.maven.plugin.PluginResolutionException;
+import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
+import org.apache.maven.plugin.version.PluginVersionResolutionException;
 import org.codehaus.plexus.util.xml.Xpp3Dom;
 
 /**
@@ -121,4 +130,17 @@
     {
     }
 
+    public void calculateForkedExecutions( MojoExecution mojoExecution, 
MavenSession session )
+        throws MojoNotFoundException, PluginNotFoundException, 
PluginResolutionException,
+        PluginDescriptorParsingException, NoPluginFoundForPrefixException, 
InvalidPluginDescriptorException,
+        LifecyclePhaseNotFoundException, LifecycleNotFoundException, 
PluginVersionResolutionException
+    {
+    }
+
+    public List<MavenProject> executeForkedExecutions( MojoExecution 
mojoExecution, MavenSession session )
+        throws MojoFailureException, MojoExecutionException, 
PluginConfigurationException, PluginManagerException
+    {
+        return Collections.emptyList();
+    }
+
 }


Reply via email to