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.plugin.CycleDetectedInPluginGraphException;
|
import org.apache.maven.plugin.CycleDetectedInPluginGraphException;
|
||||||
import org.apache.maven.plugin.InvalidPluginDescriptorException;
|
import org.apache.maven.plugin.InvalidPluginDescriptorException;
|
||||||
import org.apache.maven.plugin.MojoExecution;
|
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.MojoNotFoundException;
|
||||||
|
import org.apache.maven.plugin.PluginConfigurationException;
|
||||||
import org.apache.maven.plugin.PluginDescriptorParsingException;
|
import org.apache.maven.plugin.PluginDescriptorParsingException;
|
||||||
import org.apache.maven.plugin.PluginManager;
|
import org.apache.maven.plugin.PluginManager;
|
||||||
import org.apache.maven.plugin.PluginManagerException;
|
import org.apache.maven.plugin.PluginManagerException;
|
||||||
|
@ -192,9 +195,8 @@ public void execute( MavenSession session )
|
||||||
|
|
||||||
for ( MojoExecution mojoExecution : executionPlan.getExecutions() )
|
for ( MojoExecution mojoExecution : executionPlan.getExecutions() )
|
||||||
{
|
{
|
||||||
logger.info( executionDescription( mojoExecution, currentProject ) );
|
execute( currentProject, session, mojoExecution );
|
||||||
pluginManager.executeMojo( session, mojoExecution );
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch ( Exception e )
|
catch ( Exception e )
|
||||||
|
@ -229,7 +231,39 @@ else if ( MavenExecutionRequest.REACTOR_FAIL_FAST.equals( session.getReactorFail
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 )
|
public MavenExecutionPlan calculateExecutionPlan( MavenSession session, String... tasks )
|
||||||
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, CycleDetectedInPluginGraphException, MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException, PluginManagerException
|
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, CycleDetectedInPluginGraphException, MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException, PluginManagerException
|
||||||
{
|
{
|
||||||
|
@ -268,19 +302,34 @@ public MavenExecutionPlan calculateExecutionPlan( MavenSession session, String..
|
||||||
pluginDescriptor.setClassRealm( pluginManager.getPluginRealm( session, pluginDescriptor ) );
|
pluginDescriptor.setClassRealm( pluginManager.getPluginRealm( session, pluginDescriptor ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( StringUtils.isNotEmpty( mojoDescriptor.isDependencyResolutionRequired() ) )
|
|
||||||
{
|
|
||||||
requiredDependencyResolutionScopes.add( mojoDescriptor.isDependencyResolutionRequired() );
|
|
||||||
}
|
|
||||||
|
|
||||||
mojoExecution.setMojoDescriptor( mojoDescriptor );
|
mojoExecution.setMojoDescriptor( mojoDescriptor );
|
||||||
|
|
||||||
populateMojoExecutionConfiguration( project, mojoExecution, false );
|
populateMojoExecutionConfiguration( project, mojoExecution, false );
|
||||||
|
|
||||||
|
calculateForkedExecutions( mojoExecution, project, new HashSet<MojoDescriptor>() );
|
||||||
|
|
||||||
|
collectDependencyResolutionScopes( requiredDependencyResolutionScopes, mojoExecution );
|
||||||
}
|
}
|
||||||
|
|
||||||
return new MavenExecutionPlan( lifecyclePlan, requiredDependencyResolutionScopes );
|
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 )
|
private void calculateExecutionForIndividualGoal( MavenSession session, List<MojoExecution> lifecyclePlan, String goal )
|
||||||
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, CycleDetectedInPluginGraphException, MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException
|
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, CycleDetectedInPluginGraphException, MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException
|
||||||
{
|
{
|
||||||
|
@ -452,6 +501,44 @@ private void calculateExecutionForLifecyclePhase( MavenSession session, List<Moj
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 )
|
private String executionDescription( MojoExecution me, MavenProject project )
|
||||||
{
|
{
|
||||||
PluginDescriptor pd = me.getMojoDescriptor().getPluginDescriptor();
|
PluginDescriptor pd = me.getMojoDescriptor().getPluginDescriptor();
|
||||||
|
|
|
@ -19,6 +19,9 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||||
|
@ -41,7 +44,9 @@ public class MojoExecution
|
||||||
* this mojo execution is going to run in.
|
* this mojo execution is going to run in.
|
||||||
*/
|
*/
|
||||||
private String lifecyclePhase;
|
private String lifecyclePhase;
|
||||||
|
|
||||||
|
private List<MojoExecution> forkedExecutions = new ArrayList<MojoExecution>();
|
||||||
|
|
||||||
public MojoExecution( Plugin plugin, String goal, String executionId )
|
public MojoExecution( Plugin plugin, String goal, String executionId )
|
||||||
{
|
{
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
@ -176,4 +181,20 @@ public void setMojoDescriptor( MojoDescriptor mojoDescriptor )
|
||||||
{
|
{
|
||||||
this.mojoDescriptor = mojoDescriptor;
|
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 void writeModel( Writer writer )
|
||||||
* @since 2.0.9
|
* @since 2.0.9
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Object clone()
|
public MavenProject clone()
|
||||||
throws CloneNotSupportedException
|
|
||||||
{
|
{
|
||||||
MavenProject clone = (MavenProject) super.clone();
|
MavenProject clone;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
clone = (MavenProject) super.clone();
|
||||||
|
}
|
||||||
|
catch ( CloneNotSupportedException e )
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException( e );
|
||||||
|
}
|
||||||
|
|
||||||
clone.deepCopy( this );
|
clone.deepCopy( this );
|
||||||
|
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue