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:
Brett Leslie Porter 2005-02-27 06:19:13 +00:00
parent d5d05a51c5
commit 50759a44cf
3 changed files with 60 additions and 33 deletions

View File

@ -23,16 +23,15 @@ import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.goal.GoalExecutionException; import org.apache.maven.lifecycle.goal.GoalExecutionException;
import org.apache.maven.plugin.PluginExecutionResponse; import org.apache.maven.plugin.PluginExecutionResponse;
import org.apache.maven.plugin.PluginManager; import org.apache.maven.plugin.PluginManager;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.project.MavenProjectBuilder;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
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.Set;
/** /**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a> * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@ -72,9 +71,10 @@ public class DefaultLifecycleExecutor
response.setStart( new Date() ); response.setStart( new Date() );
Set seenPhases = new HashSet();
try try
{ {
preProcessPlugins( tasks, session );
for ( Iterator i = tasks.iterator(); i.hasNext(); ) for ( Iterator i = tasks.iterator(); i.hasNext(); )
{ {
String task = (String) i.next(); String task = (String) i.next();
@ -97,7 +97,7 @@ public class DefaultLifecycleExecutor
} }
} }
} }
catch ( LifecycleExecutionException e ) catch ( Exception e )
{ {
response.setException( e ); response.setException( e );
} }
@ -109,7 +109,59 @@ public class DefaultLifecycleExecutor
return response; 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 throws LifecycleExecutionException
{ {
// only execute up to the given phase // only execute up to the given phase

View File

@ -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.ArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter; import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
import org.apache.maven.execution.MavenSession; 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.lifecycle.goal.GoalExecutionException;
import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.Parameter; import org.apache.maven.plugin.descriptor.Parameter;
@ -83,9 +81,6 @@ public class DefaultPluginManager
protected MavenProjectBuilder mavenProjectBuilder; protected MavenProjectBuilder mavenProjectBuilder;
// TODO: remove
private LifecycleExecutor lifecycleExecutor;
public DefaultPluginManager() public DefaultPluginManager()
{ {
mojoDescriptors = new HashMap(); mojoDescriptors = new HashMap();
@ -141,24 +136,6 @@ public class DefaultPluginManager
MojoDescriptor mojoDescriptor = mavenMojoDescriptor.getMojoDescriptor(); 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 ); mojoDescriptors.put( mojoDescriptor.getId(), mojoDescriptor );
pluginDescriptors.put( pluginDescriptor.getId(), pluginDescriptor ); pluginDescriptors.put( pluginDescriptor.getId(), pluginDescriptor );
@ -239,8 +216,6 @@ public class DefaultPluginManager
mavenProjectBuilder = (MavenProjectBuilder) container.lookup( MavenProjectBuilder.ROLE ); mavenProjectBuilder = (MavenProjectBuilder) container.lookup( MavenProjectBuilder.ROLE );
lifecycleExecutor = (LifecycleExecutor) container.lookup( LifecycleExecutor.ROLE );
MavenMetadataSource metadataSource = new MavenMetadataSource( artifactResolver, MavenMetadataSource metadataSource = new MavenMetadataSource( artifactResolver,
mavenProjectBuilder ); mavenProjectBuilder );

View File

@ -34,15 +34,15 @@ public interface PluginManager
PluginExecutionResponse executeMojo( MavenSession session, String goalName ) PluginExecutionResponse executeMojo( MavenSession session, String goalName )
throws GoalExecutionException; throws GoalExecutionException;
// TODO: not used - needs to be in interface?
void processPluginDescriptor( MavenPluginDescriptor pluginDescriptor ) void processPluginDescriptor( MavenPluginDescriptor pluginDescriptor )
throws Exception; throws Exception;
// TODO: not currently used // TODO: not currently used - needs to be in interface?
Map getMojoDescriptors(); Map getMojoDescriptors();
// TODO: not currently used (usages are in the phases that are no longer used)
MojoDescriptor getMojoDescriptor( String goalId ); MojoDescriptor getMojoDescriptor( String goalId );
void verifyPluginForGoal( String pluginId, MavenSession session ) void verifyPluginForGoal( String goalName, MavenSession session )
throws Exception; throws Exception;
} }