mirror of https://github.com/apache/maven.git
o Restored forking to other mojo
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@799083 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2f8d3981f9
commit
6dc7f104e2
|
@ -44,7 +44,10 @@ import org.apache.maven.model.PluginExecution;
|
|||
import org.apache.maven.plugin.CycleDetectedInPluginGraphException;
|
||||
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.PluginManager;
|
||||
import org.apache.maven.plugin.PluginManagerException;
|
||||
|
@ -192,9 +195,8 @@ public class DefaultLifecycleExecutor
|
|||
|
||||
for ( MojoExecution mojoExecution : executionPlan.getExecutions() )
|
||||
{
|
||||
logger.info( executionDescription( mojoExecution, currentProject ) );
|
||||
pluginManager.executeMojo( session, mojoExecution );
|
||||
}
|
||||
execute( currentProject, session, mojoExecution );
|
||||
}
|
||||
|
||||
}
|
||||
catch ( Exception e )
|
||||
|
@ -229,7 +231,39 @@ public class DefaultLifecycleExecutor
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void execute( MavenProject project, MavenSession session, MojoExecution mojoExecution )
|
||||
throws MojoFailureException, MojoExecutionException, PluginConfigurationException, PluginManagerException
|
||||
{
|
||||
MavenProject executionProject = null;
|
||||
|
||||
List<MojoExecution> forkedExecutions = mojoExecution.getForkedExecutions();
|
||||
|
||||
if ( !forkedExecutions.isEmpty() )
|
||||
{
|
||||
executionProject = project.clone();
|
||||
|
||||
session.setCurrentProject( executionProject );
|
||||
try
|
||||
{
|
||||
for ( MojoExecution forkedExecution : forkedExecutions )
|
||||
{
|
||||
execute( executionProject, session, forkedExecution );
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
session.setCurrentProject( project );
|
||||
}
|
||||
}
|
||||
|
||||
project.setExecutionProject( executionProject );
|
||||
|
||||
logger.info( executionDescription( mojoExecution, project ) );
|
||||
|
||||
pluginManager.executeMojo( session, mojoExecution );
|
||||
}
|
||||
|
||||
public MavenExecutionPlan calculateExecutionPlan( MavenSession session, String... tasks )
|
||||
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, CycleDetectedInPluginGraphException, MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException, PluginManagerException
|
||||
{
|
||||
|
@ -268,19 +302,34 @@ public class DefaultLifecycleExecutor
|
|||
pluginDescriptor.setClassRealm( pluginManager.getPluginRealm( session, pluginDescriptor ) );
|
||||
}
|
||||
|
||||
if ( StringUtils.isNotEmpty( mojoDescriptor.isDependencyResolutionRequired() ) )
|
||||
{
|
||||
requiredDependencyResolutionScopes.add( mojoDescriptor.isDependencyResolutionRequired() );
|
||||
}
|
||||
|
||||
mojoExecution.setMojoDescriptor( mojoDescriptor );
|
||||
|
||||
populateMojoExecutionConfiguration( project, mojoExecution, false );
|
||||
|
||||
calculateForkedExecutions( mojoExecution, project, new HashSet<MojoDescriptor>() );
|
||||
|
||||
collectDependencyResolutionScopes( requiredDependencyResolutionScopes, mojoExecution );
|
||||
}
|
||||
|
||||
return new MavenExecutionPlan( lifecyclePlan, requiredDependencyResolutionScopes );
|
||||
}
|
||||
|
||||
|
||||
private void collectDependencyResolutionScopes( Collection<String> requiredDependencyResolutionScopes,
|
||||
MojoExecution mojoExecution )
|
||||
{
|
||||
String requiredDependencyResolutionScope = mojoExecution.getMojoDescriptor().isDependencyResolutionRequired();
|
||||
|
||||
if ( StringUtils.isNotEmpty( requiredDependencyResolutionScope ) )
|
||||
{
|
||||
requiredDependencyResolutionScopes.add( requiredDependencyResolutionScope );
|
||||
}
|
||||
|
||||
for ( MojoExecution forkedExecution : mojoExecution.getForkedExecutions() )
|
||||
{
|
||||
collectDependencyResolutionScopes( requiredDependencyResolutionScopes, forkedExecution );
|
||||
}
|
||||
}
|
||||
|
||||
private void calculateExecutionForIndividualGoal( MavenSession session, List<MojoExecution> lifecyclePlan, String goal )
|
||||
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, CycleDetectedInPluginGraphException, MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException
|
||||
{
|
||||
|
@ -452,6 +501,44 @@ public class DefaultLifecycleExecutor
|
|||
}
|
||||
}
|
||||
|
||||
private void calculateForkedExecutions( MojoExecution mojoExecution, MavenProject project,
|
||||
Collection<MojoDescriptor> alreadyForkedExecutions )
|
||||
throws MojoNotFoundException
|
||||
{
|
||||
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
|
||||
|
||||
if ( !alreadyForkedExecutions.add( mojoDescriptor ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
|
||||
|
||||
if ( StringUtils.isNotEmpty( mojoDescriptor.getExecutePhase() ) )
|
||||
{
|
||||
// TODO
|
||||
|
||||
}
|
||||
else if ( StringUtils.isNotEmpty( mojoDescriptor.getExecuteGoal() ) )
|
||||
{
|
||||
String forkedGoal = mojoDescriptor.getExecuteGoal();
|
||||
|
||||
MojoDescriptor forkedMojoDescriptor = pluginDescriptor.getMojo( forkedGoal );
|
||||
if ( forkedMojoDescriptor == null )
|
||||
{
|
||||
throw new MojoNotFoundException( forkedGoal, pluginDescriptor );
|
||||
}
|
||||
|
||||
MojoExecution forkedExecution = new MojoExecution( forkedMojoDescriptor, forkedGoal );
|
||||
|
||||
populateMojoExecutionConfiguration( project, forkedExecution, true );
|
||||
|
||||
calculateForkedExecutions( forkedExecution, project, alreadyForkedExecutions );
|
||||
|
||||
mojoExecution.addForkedExecution( forkedExecution );
|
||||
}
|
||||
}
|
||||
|
||||
private String executionDescription( MojoExecution me, MavenProject project )
|
||||
{
|
||||
PluginDescriptor pd = me.getMojoDescriptor().getPluginDescriptor();
|
||||
|
|
|
@ -19,6 +19,9 @@ package org.apache.maven.plugin;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||
|
@ -41,7 +44,9 @@ public class MojoExecution
|
|||
* this mojo execution is going to run in.
|
||||
*/
|
||||
private String lifecyclePhase;
|
||||
|
||||
|
||||
private List<MojoExecution> forkedExecutions = new ArrayList<MojoExecution>();
|
||||
|
||||
public MojoExecution( Plugin plugin, String goal, String executionId )
|
||||
{
|
||||
this.plugin = plugin;
|
||||
|
@ -176,4 +181,20 @@ public class MojoExecution
|
|||
{
|
||||
this.mojoDescriptor = mojoDescriptor;
|
||||
}
|
||||
|
||||
public List<MojoExecution> getForkedExecutions()
|
||||
{
|
||||
return forkedExecutions;
|
||||
}
|
||||
|
||||
public void addForkedExecution( MojoExecution forkedExecution )
|
||||
{
|
||||
if ( forkedExecution == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "forked execution missing" );
|
||||
}
|
||||
|
||||
forkedExecutions.add( forkedExecution );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1713,11 +1713,20 @@ public class MavenProject
|
|||
* @since 2.0.9
|
||||
*/
|
||||
@Override
|
||||
public Object clone()
|
||||
throws CloneNotSupportedException
|
||||
public MavenProject clone()
|
||||
{
|
||||
MavenProject clone = (MavenProject) super.clone();
|
||||
MavenProject clone;
|
||||
try
|
||||
{
|
||||
clone = (MavenProject) super.clone();
|
||||
}
|
||||
catch ( CloneNotSupportedException e )
|
||||
{
|
||||
throw new UnsupportedOperationException( e );
|
||||
}
|
||||
|
||||
clone.deepCopy( this );
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue