mirror of https://github.com/apache/maven.git
pre-process plugins
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163420 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d5d05a51c5
commit
50759a44cf
|
@ -23,16 +23,15 @@ import org.apache.maven.execution.MavenSession;
|
|||
import org.apache.maven.lifecycle.goal.GoalExecutionException;
|
||||
import org.apache.maven.plugin.PluginExecutionResponse;
|
||||
import org.apache.maven.plugin.PluginManager;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||
|
@ -72,9 +71,10 @@ public class DefaultLifecycleExecutor
|
|||
|
||||
response.setStart( new Date() );
|
||||
|
||||
Set seenPhases = new HashSet();
|
||||
try
|
||||
{
|
||||
preProcessPlugins( tasks, session );
|
||||
|
||||
for ( Iterator i = tasks.iterator(); i.hasNext(); )
|
||||
{
|
||||
String task = (String) i.next();
|
||||
|
@ -97,7 +97,7 @@ public class DefaultLifecycleExecutor
|
|||
}
|
||||
}
|
||||
}
|
||||
catch ( LifecycleExecutionException e )
|
||||
catch ( Exception e )
|
||||
{
|
||||
response.setException( e );
|
||||
}
|
||||
|
@ -109,7 +109,59 @@ public class DefaultLifecycleExecutor
|
|||
return response;
|
||||
}
|
||||
|
||||
protected void executePhase( String phase, MavenSession session, MavenExecutionResponse response )
|
||||
private void preProcessPlugins( 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
|
||||
int index = phases.indexOf( phaseMap.get( task ) );
|
||||
|
||||
for ( int j = 0; j <= index; j++ )
|
||||
{
|
||||
Phase p = (Phase) phases.get( j );
|
||||
|
||||
if ( p.getGoals() != null )
|
||||
{
|
||||
for ( Iterator k = p.getGoals().iterator(); k.hasNext(); )
|
||||
{
|
||||
String goal = (String) k.next();
|
||||
|
||||
verifyMojoPhase( goal, session );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
verifyMojoPhase( task, session );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void verifyMojoPhase( String task, MavenSession session )
|
||||
throws Exception
|
||||
{
|
||||
MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( task );
|
||||
if ( mojoDescriptor == null )
|
||||
{
|
||||
pluginManager.verifyPluginForGoal( task, session );
|
||||
mojoDescriptor = pluginManager.getMojoDescriptor( task );
|
||||
if ( mojoDescriptor.getPhase() != null )
|
||||
{
|
||||
Phase phase = (Phase) phaseMap.get( mojoDescriptor.getPhase() );
|
||||
phase.getGoals().add( task );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void executePhase( String phase, MavenSession session, MavenExecutionResponse response )
|
||||
throws LifecycleExecutionException
|
||||
{
|
||||
// only execute up to the given phase
|
||||
|
|
|
@ -28,8 +28,6 @@ import org.apache.maven.artifact.resolver.ArtifactResolver;
|
|||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||
import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.lifecycle.LifecycleExecutor;
|
||||
import org.apache.maven.lifecycle.Phase;
|
||||
import org.apache.maven.lifecycle.goal.GoalExecutionException;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.apache.maven.plugin.descriptor.Parameter;
|
||||
|
@ -83,9 +81,6 @@ public class DefaultPluginManager
|
|||
|
||||
protected MavenProjectBuilder mavenProjectBuilder;
|
||||
|
||||
// TODO: remove
|
||||
private LifecycleExecutor lifecycleExecutor;
|
||||
|
||||
public DefaultPluginManager()
|
||||
{
|
||||
mojoDescriptors = new HashMap();
|
||||
|
@ -141,24 +136,6 @@ public class DefaultPluginManager
|
|||
|
||||
MojoDescriptor mojoDescriptor = mavenMojoDescriptor.getMojoDescriptor();
|
||||
|
||||
String id = mojoDescriptor.getPhase();
|
||||
|
||||
if ( id != null )
|
||||
{
|
||||
Phase phase = lifecycleExecutor.getPhase( id );
|
||||
|
||||
if ( phase != null )
|
||||
{
|
||||
// TODO: remove debugging
|
||||
System.err.println( "adding " + mavenMojoDescriptor.getId() + " to phase " + phase.getId() );
|
||||
phase.getGoals().add( mavenMojoDescriptor.getId() );
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: this should fail
|
||||
}
|
||||
}
|
||||
|
||||
mojoDescriptors.put( mojoDescriptor.getId(), mojoDescriptor );
|
||||
|
||||
pluginDescriptors.put( pluginDescriptor.getId(), pluginDescriptor );
|
||||
|
@ -239,8 +216,6 @@ public class DefaultPluginManager
|
|||
|
||||
mavenProjectBuilder = (MavenProjectBuilder) container.lookup( MavenProjectBuilder.ROLE );
|
||||
|
||||
lifecycleExecutor = (LifecycleExecutor) container.lookup( LifecycleExecutor.ROLE );
|
||||
|
||||
MavenMetadataSource metadataSource = new MavenMetadataSource( artifactResolver,
|
||||
mavenProjectBuilder );
|
||||
|
||||
|
|
|
@ -34,15 +34,15 @@ public interface PluginManager
|
|||
PluginExecutionResponse executeMojo( MavenSession session, String goalName )
|
||||
throws GoalExecutionException;
|
||||
|
||||
// TODO: not used - needs to be in interface?
|
||||
void processPluginDescriptor( MavenPluginDescriptor pluginDescriptor )
|
||||
throws Exception;
|
||||
|
||||
// TODO: not currently used
|
||||
// TODO: not currently used - needs to be in interface?
|
||||
Map getMojoDescriptors();
|
||||
|
||||
// TODO: not currently used (usages are in the phases that are no longer used)
|
||||
MojoDescriptor getMojoDescriptor( String goalId );
|
||||
|
||||
void verifyPluginForGoal( String pluginId, MavenSession session )
|
||||
void verifyPluginForGoal( String goalName, MavenSession session )
|
||||
throws Exception;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue