recognise prefix of plugins already loaded

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@168605 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-05-06 14:21:00 +00:00
parent d9ac5ea1e5
commit 216a640dd0
3 changed files with 68 additions and 21 deletions

View File

@ -343,14 +343,22 @@ public class DefaultLifecycleExecutor
String version = null;
String goal = null;
PluginDescriptor pluginDescriptor = null;
StringTokenizer tok = new StringTokenizer( task, ":" );
int numTokens = tok.countTokens();
if ( numTokens == 2 )
{
// TODO: look up registered aliases in plugin manager instead
groupId = PluginDescriptor.getDefaultPluginGroupId();
artifactId = PluginDescriptor.getDefaultPluginArtifactId( tok.nextToken() );
String prefix = tok.nextToken();
goal = tok.nextToken();
pluginDescriptor = pluginManager.verifyPlugin( prefix );
if ( pluginDescriptor == null )
{
groupId = PluginDescriptor.getDefaultPluginGroupId();
artifactId = PluginDescriptor.getDefaultPluginArtifactId( prefix );
}
}
else if ( numTokens == 4 )
{
@ -366,28 +374,37 @@ public class DefaultLifecycleExecutor
throw new LifecycleExecutionException( message );
}
// TODO: this shouldn't be necessary all the time.
injectHandlerPluginConfiguration( session.getProject(), groupId, artifactId, version );
try
if ( pluginDescriptor == null )
{
PluginDescriptor pluginDescriptor = pluginManager.verifyPlugin( groupId, artifactId, version, session );
// TODO: should be able to create a Map from this
for ( Iterator i = pluginDescriptor.getMojos().iterator(); i.hasNext(); )
injectHandlerPluginConfiguration( session.getProject(), groupId, artifactId, version );
try
{
MojoDescriptor mojoDescriptor = (MojoDescriptor) i.next();
if ( mojoDescriptor.getGoal().equals( goal ) )
{
return mojoDescriptor;
}
pluginDescriptor = pluginManager.verifyPlugin( groupId, artifactId, version, session );
}
catch ( PluginManagerException e )
{
throw new LifecycleExecutionException( "Internal error in the plugin manager", e );
}
}
catch ( PluginManagerException e )
MojoDescriptor mojoDescriptor = null;
// TODO: should be able to create a Map from this
for ( Iterator i = pluginDescriptor.getMojos().iterator(); i.hasNext() && mojoDescriptor == null; )
{
throw new LifecycleExecutionException( "Internal error in the plugin manager", e );
MojoDescriptor desc = (MojoDescriptor) i.next();
if ( desc.getGoal().equals( goal ) )
{
mojoDescriptor = desc;
}
}
throw new LifecycleExecutionException( "Required goal not found: " + task );
if ( mojoDescriptor == null )
{
throw new LifecycleExecutionException( "Required goal not found: " + task );
}
return mojoDescriptor;
}
public List getPhases()

View File

@ -73,6 +73,8 @@ public class DefaultPluginManager
protected Map pluginDescriptors;
protected Map pluginDescriptorsByPrefix;
protected PlexusContainer container;
protected PluginDescriptorBuilder pluginDescriptorBuilder;
@ -87,6 +89,8 @@ public class DefaultPluginManager
{
pluginDescriptors = new HashMap();
pluginDescriptorsByPrefix = new HashMap();
pluginDescriptorBuilder = new PluginDescriptorBuilder();
}
@ -96,6 +100,11 @@ public class DefaultPluginManager
PluginDescriptor.constructPluginKey( groupId, artifactId, version ) );
}
private PluginDescriptor getPluginDescriptor( String prefix )
{
return (PluginDescriptor) pluginDescriptorsByPrefix.get( prefix );
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
@ -117,9 +126,8 @@ public class DefaultPluginManager
if ( pluginDescriptor.getVersion() == null )
{
// TODO: temporary - until we're done testing that version is always written
throw new NullPointerException(
"Version was null - check your plugin '" + pluginDescriptor.getId() +
"' was built with Maven 2.0 Alpha 2" );
throw new NullPointerException( "Version was null - check your plugin '" + pluginDescriptor.getId() +
"' was built with Maven 2.0 Alpha 2" );
}
String key = pluginDescriptor.getId();
@ -129,6 +137,12 @@ public class DefaultPluginManager
pluginsInProcess.add( key );
pluginDescriptors.put( key, pluginDescriptor );
// TODO: throw an (not runtime) exception if there is a prefix overlap - means doing so elsewhere
if ( !pluginDescriptorsByPrefix.containsKey( pluginDescriptor.getGoalPrefix() ) )
{
pluginDescriptorsByPrefix.put( pluginDescriptor.getGoalPrefix(), pluginDescriptor );
}
}
}
}
@ -142,6 +156,20 @@ public class DefaultPluginManager
return pluginDescriptors.containsKey( PluginDescriptor.constructPluginKey( groupId, artifactId, version ) );
}
private boolean isPluginInstalled( String prefix )
{
return pluginDescriptorsByPrefix.containsKey( prefix );
}
public PluginDescriptor verifyPlugin( String prefix )
{
if ( !isPluginInstalled( prefix ) )
{
// TODO: lookup remotely
}
return getPluginDescriptor( prefix );
}
public PluginDescriptor verifyPlugin( String groupId, String artifactId, String version, MavenSession session )
throws ArtifactResolutionException, PluginManagerException
{

View File

@ -33,6 +33,8 @@ public interface PluginManager
void executeMojo( MavenSession session, MojoDescriptor mojoDescriptor )
throws MojoExecutionException, PluginManagerException, ArtifactResolutionException;
PluginDescriptor verifyPlugin( String prefix );
PluginDescriptor verifyPlugin( String groupId, String artifactId, String version, MavenSession session )
throws ArtifactResolutionException, PluginManagerException;
}