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.List;
|
||||
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>
|
||||
* @version $Id: DefaultLifecycleExecutor.java,v 1.16 2005/03/04 09:04:25
|
||||
* jdcasey Exp $
|
||||
|
@ -404,7 +406,8 @@ public class DefaultLifecycleExecutor
|
|||
}
|
||||
|
||||
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
|
||||
int index = phases.indexOf( phaseMap.get( phase ) );
|
||||
|
@ -455,7 +458,8 @@ public class DefaultLifecycleExecutor
|
|||
}
|
||||
|
||||
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
|
||||
|
@ -471,7 +475,22 @@ public class DefaultLifecycleExecutor
|
|||
logger.debug( "\t{localRepository: " + session.getLocalRepository() + "}" );
|
||||
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
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public void executeMojo( MavenSession session, String goalName )
|
||||
throws PluginExecutionException, PluginNotFoundException, PluginManagerException, ArtifactResolutionException
|
||||
public void executeMojo( MavenSession session, MojoDescriptor mojoDescriptor )
|
||||
throws ArtifactResolutionException, PluginManagerException, PluginExecutionException
|
||||
{
|
||||
verifyPluginForGoal( goalName, session );
|
||||
|
||||
PluginExecutionRequest request = null;
|
||||
|
||||
MojoDescriptor mojoDescriptor = getMojoDescriptor( goalName );
|
||||
if ( mojoDescriptor == null )
|
||||
{
|
||||
throw new PluginExecutionException( "Unable to find goal: " + goalName );
|
||||
}
|
||||
|
||||
if ( mojoDescriptor.getRequiresDependencyResolution() != null )
|
||||
{
|
||||
|
||||
|
@ -365,6 +357,8 @@ public class DefaultPluginManager
|
|||
|
||||
Plugin plugin = null;
|
||||
|
||||
String goalName = mojoDescriptor.getId();
|
||||
|
||||
try
|
||||
{
|
||||
plugin = (Plugin) container.lookup( Plugin.ROLE, goalName );
|
||||
|
|
|
@ -30,8 +30,8 @@ public interface PluginManager
|
|||
{
|
||||
String ROLE = PluginManager.class.getName();
|
||||
|
||||
void executeMojo( MavenSession session, String goalName )
|
||||
throws PluginExecutionException, PluginNotFoundException, PluginManagerException, ArtifactResolutionException;
|
||||
void executeMojo( MavenSession session, MojoDescriptor mojoDescriptor )
|
||||
throws PluginExecutionException, PluginManagerException, ArtifactResolutionException;
|
||||
|
||||
MojoDescriptor getMojoDescriptor( String goalId );
|
||||
|
||||
|
|
|
@ -57,6 +57,8 @@ public class MojoDescriptor
|
|||
|
||||
private String phase;
|
||||
|
||||
private String executePhase;
|
||||
|
||||
private List requirements;
|
||||
|
||||
private String deprecated;
|
||||
|
@ -250,6 +252,16 @@ public class MojoDescriptor
|
|||
this.goal = goal;
|
||||
}
|
||||
|
||||
public String getExecutePhase()
|
||||
{
|
||||
return executePhase;
|
||||
}
|
||||
|
||||
public void setExecutePhase( String executePhase )
|
||||
{
|
||||
this.executePhase = executePhase;
|
||||
}
|
||||
|
||||
public boolean alwaysExecute()
|
||||
{
|
||||
return MULTI_PASS_EXEC_STRATEGY.equals( executionStrategy );
|
||||
|
|
|
@ -109,6 +109,13 @@ public class PluginDescriptorBuilder
|
|||
mojo.setPhase( phase );
|
||||
}
|
||||
|
||||
String executePhase = c.getChild( "executePhase" ).getValue();
|
||||
|
||||
if ( executePhase != null )
|
||||
{
|
||||
mojo.setExecutePhase( executePhase );
|
||||
}
|
||||
|
||||
mojo.setInstantiationStrategy( c.getChild( "instantiationStrategy" ).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.writeText( mojoDescriptor.getImplementation() );
|
||||
|
|
|
@ -62,7 +62,7 @@ public class JavaMojoDescriptorExtractor
|
|||
|
||||
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";
|
||||
|
||||
|
@ -172,6 +172,17 @@ public class JavaMojoDescriptorExtractor
|
|||
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
|
||||
// ----------------------------------------------------------------------
|
||||
|
|
|
@ -38,6 +38,7 @@ import java.util.Iterator;
|
|||
|
||||
/**
|
||||
* @goal idea
|
||||
* @executePhase generate-sources
|
||||
* @requiresDependencyResolution test
|
||||
* @description Goal for generating IDEA files from a POM
|
||||
* @parameter name="project"
|
||||
|
|
Loading…
Reference in New Issue