mirror of https://github.com/apache/maven.git
configure phases based on configuration
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163422 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f793423baf
commit
236dc52410
|
@ -21,9 +21,12 @@ import org.apache.maven.artifact.resolver.ArtifactResolver;
|
|||
import org.apache.maven.execution.MavenExecutionResponse;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.lifecycle.goal.GoalExecutionException;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.plugin.PluginExecutionResponse;
|
||||
import org.apache.maven.plugin.PluginManager;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
|
||||
|
||||
|
@ -73,7 +76,9 @@ public class DefaultLifecycleExecutor
|
|||
|
||||
try
|
||||
{
|
||||
preProcessPlugins( tasks, session );
|
||||
processPluginConfiguration( session.getProject(), session );
|
||||
|
||||
processGoalChain( tasks, session );
|
||||
|
||||
for ( Iterator i = tasks.iterator(); i.hasNext(); )
|
||||
{
|
||||
|
@ -109,15 +114,37 @@ public class DefaultLifecycleExecutor
|
|||
return response;
|
||||
}
|
||||
|
||||
private void preProcessPlugins( List tasks, MavenSession session )
|
||||
private void processPluginConfiguration( MavenProject project, MavenSession mavenSession )
|
||||
throws Exception
|
||||
{
|
||||
for ( Iterator i = project.getPlugins().iterator(); i.hasNext(); )
|
||||
{
|
||||
Plugin plugin = (Plugin) i.next();
|
||||
|
||||
if ( pluginManager.verifyPlugin( plugin.getId(), mavenSession ) )
|
||||
{
|
||||
PluginDescriptor pluginDescriptor = pluginManager.getPluginDescriptor( plugin.getId() );
|
||||
for ( Iterator j = pluginDescriptor.getMojos().iterator(); j.hasNext(); )
|
||||
{
|
||||
MojoDescriptor mojoDescriptor = (MojoDescriptor) j.next();
|
||||
|
||||
if ( mojoDescriptor.getPhase() != null )
|
||||
{
|
||||
Phase phase = (Phase) phaseMap.get( mojoDescriptor.getPhase() );
|
||||
phase.getGoals().add( mojoDescriptor.getId() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void processGoalChain( List tasks, MavenSession session )
|
||||
throws Exception
|
||||
{
|
||||
for ( Iterator i = tasks.iterator(); i.hasNext(); )
|
||||
{
|
||||
String task = (String) i.next();
|
||||
|
||||
PluginExecutionResponse pluginResponse;
|
||||
|
||||
if ( phaseMap.containsKey( task ) )
|
||||
{
|
||||
// only execute up to the given phase
|
||||
|
|
|
@ -112,6 +112,11 @@ public class DefaultPluginManager
|
|||
return (MojoDescriptor) mojoDescriptors.get( name );
|
||||
}
|
||||
|
||||
public PluginDescriptor getPluginDescriptor( String pluginId )
|
||||
{
|
||||
return (PluginDescriptor) pluginDescriptors.get( pluginId );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
|
@ -186,11 +191,17 @@ public class DefaultPluginManager
|
|||
return goalName;
|
||||
}
|
||||
|
||||
public void verifyPluginForGoal( String goalName, MavenSession session )
|
||||
public boolean verifyPluginForGoal( String goalName, MavenSession session )
|
||||
throws Exception
|
||||
{
|
||||
String pluginId = getPluginId( goalName );
|
||||
|
||||
return verifyPlugin( pluginId, session );
|
||||
}
|
||||
|
||||
public boolean verifyPlugin( String pluginId, MavenSession session )
|
||||
throws Exception
|
||||
{
|
||||
if ( !isPluginInstalled( pluginId ) )
|
||||
{
|
||||
//!! This is entirely crappy. We need a better naming for plugin
|
||||
|
@ -204,6 +215,12 @@ public class DefaultPluginManager
|
|||
Artifact pluginArtifact = new DefaultArtifact( "maven", artifactId, version, "plugin", "jar" );
|
||||
|
||||
addPlugin( pluginArtifact, session );
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.maven.plugin;
|
|||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.lifecycle.goal.GoalExecutionException;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -43,6 +44,11 @@ public interface PluginManager
|
|||
|
||||
MojoDescriptor getMojoDescriptor( String goalId );
|
||||
|
||||
void verifyPluginForGoal( String goalName, MavenSession session )
|
||||
boolean verifyPluginForGoal( String goalName, MavenSession session )
|
||||
throws Exception;
|
||||
|
||||
boolean verifyPlugin( String pluginId, MavenSession session )
|
||||
throws Exception;
|
||||
|
||||
PluginDescriptor getPluginDescriptor( String pluginId );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue