diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java index e4f3b8f786..8cfc9afa71 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java @@ -438,6 +438,59 @@ public class DefaultLifecycleExecutor } } + List 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 executeForkedExecutions( MojoExecution mojoExecution, MavenSession session ) + throws MojoFailureException, MojoExecutionException, PluginConfigurationException, PluginManagerException + { + return executeForkedExecutions( mojoExecution, session, new ProjectIndex( session.getProjects() ) ); + } + + private List executeForkedExecutions( MojoExecution mojoExecution, MavenSession session, + ProjectIndex projectIndex ) + throws MojoFailureException, MojoExecutionException, PluginConfigurationException, PluginManagerException + { List forkedProjects = Collections.emptyList(); Map> forkedExecutions = mojoExecution.getForkedExecutions(); @@ -511,45 +564,7 @@ public class DefaultLifecycleExecutor } } - 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 @@ public class DefaultLifecycleExecutor 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() ); + } + private void calculateForkedExecutions( MojoExecution mojoExecution, MavenSession session, MavenProject project, Collection alreadyForkedExecutions ) throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException, diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java index 2acfa8978e..2842114078 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java @@ -20,19 +20,25 @@ package org.apache.maven.lifecycle; */ 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 @@ public interface LifecycleExecutor 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 executeForkedExecutions( MojoExecution mojoExecution, MavenSession session ) + throws MojoFailureException, MojoExecutionException, PluginConfigurationException, PluginManagerException; + } diff --git a/maven-core/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java b/maven-core/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java index 43b74e23ac..5eb9e682dc 100644 --- a/maven-core/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java +++ b/maven-core/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java @@ -30,13 +30,22 @@ import org.apache.maven.artifact.repository.RepositoryRequest; 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 class EmptyLifecycleExecutor { } + public void calculateForkedExecutions( MojoExecution mojoExecution, MavenSession session ) + throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException, + PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException, + LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException + { + } + + public List executeForkedExecutions( MojoExecution mojoExecution, MavenSession session ) + throws MojoFailureException, MojoExecutionException, PluginConfigurationException, PluginManagerException + { + return Collections.emptyList(); + } + }