o Exposed methods to allow the Site Plugin to reuse the forking code for report mojos

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@808828 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-08-28 09:50:29 +00:00
parent b2e6f787f6
commit 023afe0dec
3 changed files with 120 additions and 39 deletions

View File

@ -438,6 +438,59 @@ public class DefaultLifecycleExecutor
}
}
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 @@ 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<MojoDescriptor>() );
}
private void calculateForkedExecutions( MojoExecution mojoExecution, MavenSession session, MavenProject project,
Collection<MojoDescriptor> alreadyForkedExecutions )
throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException,

View File

@ -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<MavenProject> executeForkedExecutions( MojoExecution mojoExecution, MavenSession session )
throws MojoFailureException, MojoExecutionException, PluginConfigurationException, PluginManagerException;
}

View File

@ -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<MavenProject> executeForkedExecutions( MojoExecution mojoExecution, MavenSession session )
throws MojoFailureException, MojoExecutionException, PluginConfigurationException, PluginManagerException
{
return Collections.emptyList();
}
}