PR: MNG-1057

look for command line goals in the project declared plugins

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@292935 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-10-01 07:10:39 +00:00
parent 39cd577f77
commit 76f82eefc9
3 changed files with 46 additions and 27 deletions

View File

@ -1144,14 +1144,14 @@ private MojoDescriptor getMojoDescriptor( String task, MavenSession session, Mav
StringTokenizer tok = new StringTokenizer( task, ":" );
int numTokens = tok.countTokens();
// TODO: Add "&& canUsePrefix" to this boolean expression, and remove deprecation warning in next release.
if ( numTokens == 2 )
{
if ( !canUsePrefix )
{
getLogger().warn(
"DEPRECATED: Mapped-prefix lookup of mojos are only supported from direct invocation. Please use specification of the form groupId:artifactId[:version]:goal instead. (Offending mojo: \'" +
task + "\', invoked via: \'" + invokedVia + "\')" );
String msg = "DEPRECATED: Mapped-prefix lookup of mojos are only supported from direct invocation. " +
"Please use specification of the form groupId:artifactId[:version]:goal instead. " +
"(Offending mojo: \'" + task + "\', invoked via: \'" + invokedVia + "\')";
throw new LifecycleExecutionException( msg );
}
String prefix = tok.nextToken();
@ -1159,16 +1159,9 @@ private MojoDescriptor getMojoDescriptor( String task, MavenSession session, Mav
// Steps for retrieving the plugin model instance:
// 1. request directly from the plugin collector by prefix
try
{
pluginDescriptor = pluginManager.getPluginDescriptorForPrefix( prefix );
}
catch ( PluginManagerException e )
{
throw new LifecycleExecutionException(
"Cannot resolve plugin-prefix: \'" + prefix + "\' from plugin collector.", e );
}
pluginDescriptor = pluginManager.getPluginDescriptorForPrefix( prefix );
// 2. look in the repository via search groups
if ( pluginDescriptor == null )
{
try
@ -1181,8 +1174,7 @@ private MojoDescriptor getMojoDescriptor( String task, MavenSession session, Mav
"Cannot resolve plugin-prefix: \'" + prefix + "\' from plugin mappings metadata.", e );
}
}
if ( pluginDescriptor != null )
else
{
plugin = new Plugin();
@ -1191,7 +1183,34 @@ private MojoDescriptor getMojoDescriptor( String task, MavenSession session, Mav
plugin.setVersion( pluginDescriptor.getVersion() );
}
// 2. default to o.a.m.plugins and maven-<prefix>-plugin
// 3. search plugins in the current POM
if ( plugin == null )
{
for ( Iterator i = project.getBuildPlugins().iterator(); i.hasNext(); )
{
Plugin buildPlugin = (Plugin) i.next();
try
{
PluginDescriptor desc = pluginManager.verifyPlugin( buildPlugin, project, session.getSettings(),
session.getLocalRepository() );
if ( prefix.equals( desc.getGoalPrefix() ) )
{
plugin = buildPlugin;
}
}
catch ( PluginManagerException e )
{
throw new LifecycleExecutionException( "Internal error in the plugin manager", e );
}
catch ( PluginVersionResolutionException e )
{
throw new LifecycleExecutionException( "Error resolving plugin version", e );
}
}
}
// 4. default to o.a.m.plugins and maven-<prefix>-plugin
if ( plugin == null )
{
plugin = new Plugin();

View File

@ -131,7 +131,6 @@ public DefaultPluginManager()
// ----------------------------------------------------------------------
public PluginDescriptor getPluginDescriptorForPrefix( String prefix )
throws PluginManagerException
{
return pluginCollector.getPluginDescriptorForPrefix( prefix );
}
@ -310,18 +309,20 @@ public void executeMojo( MavenProject project, MojoExecution mojoExecution, Mave
throws ArtifactResolutionException, PluginManagerException, MojoExecutionException
{
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
// NOTE: I'm putting these checks in here, since this is the central point of access for
// anything that wants to execute a mojo.
if( mojoDescriptor.isProjectRequired() && !session.isUsingPOMsFromFilesystem() )
if ( mojoDescriptor.isProjectRequired() && !session.isUsingPOMsFromFilesystem() )
{
throw new MojoExecutionException( "Cannot execute mojo: " + mojoDescriptor.getGoal() + ". It requires a project, but the build is not using one." );
throw new MojoExecutionException( "Cannot execute mojo: " + mojoDescriptor.getGoal() +
". It requires a project, but the build is not using one." );
}
if ( mojoDescriptor.isOnlineRequired() && session.getSettings().isOffline() )
{
// TODO: Should we error out, or simply warn and skip??
throw new MojoExecutionException( "Mojo: " + mojoDescriptor.getGoal() + " requires online mode for execution. Maven is currently offline." );
throw new MojoExecutionException( "Mojo: " + mojoDescriptor.getGoal() +
" requires online mode for execution. Maven is currently offline." );
}
if ( mojoDescriptor.isDependencyResolutionRequired() != null )
@ -503,7 +504,7 @@ private Mojo getConfiguredMojo( MavenSession session, Xpp3Dom dom, MavenProject
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
PlexusContainer pluginContainer = getPluginContainer( pluginDescriptor );
// if this is the first time this plugin has been used, the plugin's container will only
// contain the plugin's artifact in isolation; we need to finish resolving the plugin's
// dependencies, and add them to the container.
@ -519,10 +520,10 @@ private Mojo getConfiguredMojo( MavenSession session, Xpp3Dom dom, MavenProject
if ( plugin instanceof ContextEnabled )
{
Map pluginContext = session.getPluginContext( pluginDescriptor, project );
( (ContextEnabled) plugin ).setPluginContext( pluginContext );
}
plugin.setLog( mojoLogger );
XmlPlexusConfiguration pomConfiguration;

View File

@ -44,8 +44,7 @@ void executeMojo( MavenProject project, MojoExecution execution, MavenSession se
MavenReport getReport( MavenProject project, MojoExecution mojoExecution, MavenSession session )
throws PluginManagerException;
PluginDescriptor getPluginDescriptorForPrefix( String prefix )
throws PluginManagerException;
PluginDescriptor getPluginDescriptorForPrefix( String prefix );
Plugin getPluginDefinitionForPrefix( String prefix, MavenSession session, MavenProject project )
throws PluginManagerException;