diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
index 9d7b615b31..6dadf1f9ac 100644
--- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
+++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
@@ -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 Jason van Zyl
* @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 :, 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 );
}
// ----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
index 2c9699040b..6c85fefbf7 100644
--- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
+++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
@@ -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 );
diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java
index eb907a67e0..01ef8d0f72 100644
--- a/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java
+++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java
@@ -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 );
diff --git a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java
index e694247e2b..df70ef3084 100755
--- a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java
+++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java
@@ -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 );
diff --git a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java
index 33b5c9ab1e..02e7c8b7d4 100755
--- a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java
+++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java
@@ -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() );
diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java
index e7bdd2a5ad..719f92b85d 100644
--- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java
+++ b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java
@@ -119,6 +119,15 @@ public class PluginDescriptorGenerator
//
// ----------------------------------------------------------------------
+ if ( mojoDescriptor.getExecutePhase() != null )
+ {
+ element( w, "executePhase", mojoDescriptor.getExecutePhase() );
+ }
+
+ // ----------------------------------------------------------------------
+ //
+ // ----------------------------------------------------------------------
+
w.startElement( "implementation" );
w.writeText( mojoDescriptor.getImplementation() );
diff --git a/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java b/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java
index 68b8d6fa63..8ed605ce7e 100644
--- a/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java
+++ b/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java
@@ -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
// ----------------------------------------------------------------------
diff --git a/maven-plugins/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaMojo.java b/maven-plugins/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaMojo.java
index 1ba1dabb5d..89f825f9b6 100644
--- a/maven-plugins/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaMojo.java
+++ b/maven-plugins/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaMojo.java
@@ -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"