mirror of https://github.com/apache/maven.git
PR: MNG-167
Add the ability for a mojo to "fork" a phase execution, in a separate iteration of the lifecycle. Add @executePhase generate-sources to idea:idea git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@164930 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b3033fb746
commit
3760f873a1
|
@ -45,8 +45,10 @@ import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @todo there is some duplication between this and the plugin manager
|
||||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
|
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
|
||||||
* @version $Id: DefaultLifecycleExecutor.java,v 1.16 2005/03/04 09:04:25
|
* @version $Id: DefaultLifecycleExecutor.java,v 1.16 2005/03/04 09:04:25
|
||||||
* jdcasey Exp $
|
* jdcasey Exp $
|
||||||
|
@ -404,7 +406,8 @@ public class DefaultLifecycleExecutor
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executePhase( String phase, MavenSession session, Map phaseMap )
|
private void executePhase( String phase, MavenSession session, Map phaseMap )
|
||||||
throws PluginExecutionException, PluginNotFoundException, PluginManagerException, ArtifactResolutionException
|
throws PluginExecutionException, PluginNotFoundException, PluginManagerException, ArtifactResolutionException,
|
||||||
|
LifecycleExecutionException
|
||||||
{
|
{
|
||||||
// only execute up to the given phase
|
// only execute up to the given phase
|
||||||
int index = phases.indexOf( phaseMap.get( phase ) );
|
int index = phases.indexOf( phaseMap.get( phase ) );
|
||||||
|
@ -455,7 +458,8 @@ public class DefaultLifecycleExecutor
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void executeMojo( String id, MavenSession session )
|
protected void executeMojo( String id, MavenSession session )
|
||||||
throws PluginExecutionException, PluginNotFoundException, PluginManagerException, ArtifactResolutionException
|
throws PluginExecutionException, PluginNotFoundException, PluginManagerException, ArtifactResolutionException,
|
||||||
|
LifecycleExecutionException
|
||||||
{
|
{
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// We have something of the form <pluginId>:<mojoId>, so this might be
|
// We have something of the form <pluginId>:<mojoId>, so this might be
|
||||||
|
@ -471,7 +475,22 @@ public class DefaultLifecycleExecutor
|
||||||
logger.debug( "\t{localRepository: " + session.getLocalRepository() + "}" );
|
logger.debug( "\t{localRepository: " + session.getLocalRepository() + "}" );
|
||||||
logger.debug( "\t{remoteRepositories: " + session.getRemoteRepositories() + "}" );
|
logger.debug( "\t{remoteRepositories: " + session.getRemoteRepositories() + "}" );
|
||||||
|
|
||||||
pluginManager.executeMojo( session, id );
|
pluginManager.verifyPluginForGoal( id, session );
|
||||||
|
|
||||||
|
MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( id );
|
||||||
|
|
||||||
|
if ( mojoDescriptor == null )
|
||||||
|
{
|
||||||
|
throw new PluginExecutionException( "Unable to find goal: " + id );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( mojoDescriptor.getExecutePhase() != null )
|
||||||
|
{
|
||||||
|
// TODO: is this too broad to execute?
|
||||||
|
execute( Collections.singletonList( mojoDescriptor.getExecutePhase() ), session );
|
||||||
|
}
|
||||||
|
|
||||||
|
pluginManager.executeMojo( session, mojoDescriptor );
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
|
@ -318,19 +318,11 @@ public class DefaultPluginManager
|
||||||
// Plugin execution
|
// Plugin execution
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
public void executeMojo( MavenSession session, String goalName )
|
public void executeMojo( MavenSession session, MojoDescriptor mojoDescriptor )
|
||||||
throws PluginExecutionException, PluginNotFoundException, PluginManagerException, ArtifactResolutionException
|
throws ArtifactResolutionException, PluginManagerException, PluginExecutionException
|
||||||
{
|
{
|
||||||
verifyPluginForGoal( goalName, session );
|
|
||||||
|
|
||||||
PluginExecutionRequest request = null;
|
PluginExecutionRequest request = null;
|
||||||
|
|
||||||
MojoDescriptor mojoDescriptor = getMojoDescriptor( goalName );
|
|
||||||
if ( mojoDescriptor == null )
|
|
||||||
{
|
|
||||||
throw new PluginExecutionException( "Unable to find goal: " + goalName );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( mojoDescriptor.getRequiresDependencyResolution() != null )
|
if ( mojoDescriptor.getRequiresDependencyResolution() != null )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -365,6 +357,8 @@ public class DefaultPluginManager
|
||||||
|
|
||||||
Plugin plugin = null;
|
Plugin plugin = null;
|
||||||
|
|
||||||
|
String goalName = mojoDescriptor.getId();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
plugin = (Plugin) container.lookup( Plugin.ROLE, goalName );
|
plugin = (Plugin) container.lookup( Plugin.ROLE, goalName );
|
||||||
|
|
|
@ -30,8 +30,8 @@ public interface PluginManager
|
||||||
{
|
{
|
||||||
String ROLE = PluginManager.class.getName();
|
String ROLE = PluginManager.class.getName();
|
||||||
|
|
||||||
void executeMojo( MavenSession session, String goalName )
|
void executeMojo( MavenSession session, MojoDescriptor mojoDescriptor )
|
||||||
throws PluginExecutionException, PluginNotFoundException, PluginManagerException, ArtifactResolutionException;
|
throws PluginExecutionException, PluginManagerException, ArtifactResolutionException;
|
||||||
|
|
||||||
MojoDescriptor getMojoDescriptor( String goalId );
|
MojoDescriptor getMojoDescriptor( String goalId );
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,8 @@ public class MojoDescriptor
|
||||||
|
|
||||||
private String phase;
|
private String phase;
|
||||||
|
|
||||||
|
private String executePhase;
|
||||||
|
|
||||||
private List requirements;
|
private List requirements;
|
||||||
|
|
||||||
private String deprecated;
|
private String deprecated;
|
||||||
|
@ -250,6 +252,16 @@ public class MojoDescriptor
|
||||||
this.goal = goal;
|
this.goal = goal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getExecutePhase()
|
||||||
|
{
|
||||||
|
return executePhase;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExecutePhase( String executePhase )
|
||||||
|
{
|
||||||
|
this.executePhase = executePhase;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean alwaysExecute()
|
public boolean alwaysExecute()
|
||||||
{
|
{
|
||||||
return MULTI_PASS_EXEC_STRATEGY.equals( executionStrategy );
|
return MULTI_PASS_EXEC_STRATEGY.equals( executionStrategy );
|
||||||
|
|
|
@ -109,6 +109,13 @@ public class PluginDescriptorBuilder
|
||||||
mojo.setPhase( phase );
|
mojo.setPhase( phase );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String executePhase = c.getChild( "executePhase" ).getValue();
|
||||||
|
|
||||||
|
if ( executePhase != null )
|
||||||
|
{
|
||||||
|
mojo.setExecutePhase( executePhase );
|
||||||
|
}
|
||||||
|
|
||||||
mojo.setInstantiationStrategy( c.getChild( "instantiationStrategy" ).getValue() );
|
mojo.setInstantiationStrategy( c.getChild( "instantiationStrategy" ).getValue() );
|
||||||
|
|
||||||
mojo.setDescription( c.getChild( "description" ).getValue() );
|
mojo.setDescription( c.getChild( "description" ).getValue() );
|
||||||
|
|
|
@ -119,6 +119,15 @@ public class PluginDescriptorGenerator
|
||||||
//
|
//
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
if ( mojoDescriptor.getExecutePhase() != null )
|
||||||
|
{
|
||||||
|
element( w, "executePhase", mojoDescriptor.getExecutePhase() );
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
w.startElement( "implementation" );
|
w.startElement( "implementation" );
|
||||||
|
|
||||||
w.writeText( mojoDescriptor.getImplementation() );
|
w.writeText( mojoDescriptor.getImplementation() );
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class JavaMojoDescriptorExtractor
|
||||||
|
|
||||||
public static final String PHASE = "phase";
|
public static final String PHASE = "phase";
|
||||||
|
|
||||||
public static final String DISPATCH = "dispatch";
|
public static final String EXECUTE_PHASE = "executePhase";
|
||||||
|
|
||||||
public static final String GOAL_DESCRIPTION = "description";
|
public static final String GOAL_DESCRIPTION = "description";
|
||||||
|
|
||||||
|
@ -172,6 +172,17 @@ public class JavaMojoDescriptorExtractor
|
||||||
mojoDescriptor.setPhase( phase.getValue() );
|
mojoDescriptor.setPhase( phase.getValue() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
// Additional phase to execute first
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
DocletTag executePhase = findInClassHierarchy( javaClass, EXECUTE_PHASE );
|
||||||
|
|
||||||
|
if ( executePhase != null )
|
||||||
|
{
|
||||||
|
mojoDescriptor.setExecutePhase( executePhase.getValue() );
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// Dependency resolution flag
|
// Dependency resolution flag
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
|
@ -38,6 +38,7 @@ import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @goal idea
|
* @goal idea
|
||||||
|
* @executePhase generate-sources
|
||||||
* @requiresDependencyResolution test
|
* @requiresDependencyResolution test
|
||||||
* @description Goal for generating IDEA files from a POM
|
* @description Goal for generating IDEA files from a POM
|
||||||
* @parameter name="project"
|
* @parameter name="project"
|
||||||
|
|
Loading…
Reference in New Issue