Fixing plugin manager/plugin version manager for use with the help plugin...restoring backward compat.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@536027 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2007-05-08 00:06:19 +00:00
parent 11a113d316
commit 44c006ff2a
5 changed files with 120 additions and 45 deletions

View File

@ -94,27 +94,34 @@ private void addForkedLifecycleModifiers( ModifiablePlanElement planElement, Lif
{
MojoBinding mojoBinding = (MojoBinding) it.next();
PluginDescriptor pluginDescriptor;
try
{
pluginDescriptor = pluginLoader.loadPlugin( mojoBinding, project );
}
catch ( PluginLoaderException e )
{
throw new LifecyclePlannerException( e.getMessage(), e );
}
MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( mojoBinding.getGoal() );
if ( mojoDescriptor == null )
{
throw new LifecyclePlannerException( "Mojo: " + mojoBinding.getGoal() + " does not exist in plugin: "
+ pluginDescriptor.getId() + "." );
}
findForkModifiers( mojoBinding, pluginDescriptor, planElement, lifecycleBindings, project, new LinkedList(), tasks );
findForkModifiers( mojoBinding, planElement, lifecycleBindings, project );
}
}
private void findForkModifiers( MojoBinding mojoBinding, ModifiablePlanElement planElement,
LifecycleBindings lifecycleBindings, MavenProject project )
throws LifecyclePlannerException, LifecycleSpecificationException, LifecycleLoaderException
{
PluginDescriptor pluginDescriptor;
try
{
pluginDescriptor = pluginLoader.loadPlugin( mojoBinding, project );
}
catch ( PluginLoaderException e )
{
throw new LifecyclePlannerException( e.getMessage(), e );
}
MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( mojoBinding.getGoal() );
if ( mojoDescriptor == null )
{
throw new LifecyclePlannerException( "Mojo: " + mojoBinding.getGoal() + " does not exist in plugin: "
+ pluginDescriptor.getId() + "." );
}
findForkModifiers( mojoBinding, pluginDescriptor, planElement, lifecycleBindings, project, new LinkedList() );
}
/**
* Traverses all MojoBinding instances discovered from the POM and its packaging-mappings, and
* orchestrates the process of injecting any modifiers that are necessary to accommodate mojos
@ -151,15 +158,35 @@ private void addReportingLifecycleModifiers( ModifiablePlanElement planElement,
{
List reportBindings = lifecycleBindingManager.getReportBindings( project );
// findForkModifiers( mojoBinding, pluginDescriptor, planElement, lifecycleBindings,
// project, forkingBindings, tasks );
for ( Iterator reportBindingIt = reportBindings.iterator(); reportBindingIt.hasNext(); )
{
MojoBinding reportBinding = (MojoBinding) reportBindingIt.next();
PluginDescriptor pd;
try
{
pd = pluginLoader.loadReportPlugin( mojoBinding, project );
}
catch ( PluginLoaderException e )
{
throw new LifecyclePlannerException( "Failed to load report-plugin descriptor for: "
+ MojoBindingUtils.toString( reportBinding ) + ". Reason: " + e.getMessage(), e );
}
// findForkModifiers( reportBinding, planElement, lifecycleBindings, project );
}
Phase phase = LifecycleUtils.findPhaseForMojoBinding( mojoBinding, lifecycleBindings, true );
if ( phase == null )
{
if ( planElement instanceof DirectInvocationOriginElement )
{
DirectInvocationModifier modder = new SimpleDirectInvocationModifier( mojoBinding, reportBindings );
((DirectInvocationOriginElement) planElement).addDirectInvocationModifier( modder );
( (DirectInvocationOriginElement) planElement ).addDirectInvocationModifier( modder );
}
else
{
@ -188,7 +215,7 @@ private void addReportingLifecycleModifiers( ModifiablePlanElement planElement,
*/
private void findForkModifiers( MojoBinding mojoBinding, PluginDescriptor pluginDescriptor,
ModifiablePlanElement planElement, LifecycleBindings mergedBindings, MavenProject project,
LinkedList forkingBindings, List tasks )
LinkedList forkingBindings )
throws LifecyclePlannerException, LifecycleSpecificationException, LifecycleLoaderException
{
forkingBindings.addLast( mojoBinding );
@ -201,12 +228,11 @@ private void findForkModifiers( MojoBinding mojoBinding, PluginDescriptor plugin
if ( mojoDescriptor.getExecuteGoal() != null )
{
recurseSingleMojoFork( mojoBinding, pluginDescriptor, planElement, mergedBindings, project, forkingBindings,
tasks );
recurseSingleMojoFork( mojoBinding, pluginDescriptor, planElement, mergedBindings, project, forkingBindings );
}
else if ( mojoDescriptor.getExecutePhase() != null )
{
recursePhaseMojoFork( mojoBinding, pluginDescriptor, planElement, mergedBindings, project, forkingBindings, tasks );
recursePhaseMojoFork( mojoBinding, pluginDescriptor, planElement, mergedBindings, project, forkingBindings );
}
}
finally
@ -222,27 +248,26 @@ else if ( mojoDescriptor.getExecutePhase() != null )
private void modifyBuildPlanForForkedDirectInvocation( MojoBinding invokedBinding, MojoBinding invokedVia,
PluginDescriptor pluginDescriptor, ModifiablePlanElement planElement,
LifecycleBindings mergedBindings, MavenProject project,
LinkedList forkingBindings, List tasks )
LinkedList forkingBindings )
throws LifecyclePlannerException, LifecycleSpecificationException, LifecycleLoaderException
{
if ( planElement instanceof DirectInvocationOriginElement )
{
List noTasks = Collections.EMPTY_LIST;
LifecycleBindings forkedBindings = new LifecycleBindings();
LifecycleBuildPlan forkedPlan = new LifecycleBuildPlan( noTasks, forkedBindings );
forkingBindings.addLast( invokedBinding );
try
{
findForkModifiers( invokedBinding, pluginDescriptor, forkedPlan, forkedBindings, project,
forkingBindings, tasks );
findForkModifiers( invokedBinding, pluginDescriptor, forkedPlan, forkedBindings, project, forkingBindings );
}
finally
{
forkingBindings.removeLast();
}
List forkedMojos = new ArrayList();
forkedMojos.addAll( lifecycleBindingManager.assembleMojoBindingList( noTasks, forkedBindings, project ) );
forkedMojos.add( invokedBinding );
@ -264,7 +289,7 @@ private void modifyBuildPlanForForkedDirectInvocation( MojoBinding invokedBindin
*/
private void modifyBuildPlanForForkedLifecycle( MojoBinding mojoBinding, PluginDescriptor pluginDescriptor,
ModifiablePlanElement planElement, LifecycleBindings bindings,
MavenProject project, LinkedList forkingBindings, List tasks )
MavenProject project, LinkedList forkingBindings )
throws LifecycleSpecificationException, LifecyclePlannerException, LifecycleLoaderException
{
MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( mojoBinding.getGoal() );
@ -307,7 +332,7 @@ else if ( planElement instanceof BuildPlan )
throw new LifecyclePlannerException( e.getMessage(), e );
}
findForkModifiers( forkedBinding, forkedPluginDescriptor, mpe, bindings, project, forkingBindings, tasks );
findForkModifiers( forkedBinding, forkedPluginDescriptor, mpe, bindings, project, forkingBindings );
}
// now that we've discovered any deeper modifications, add the current MPE to the parent MPE
@ -318,10 +343,10 @@ else if ( planElement instanceof BuildPlan )
}
else if ( planElement instanceof DirectInvocationOriginElement )
{
List planMojoBindings = ((BuildPlan) mpe).getPlanMojoBindings( project, lifecycleBindingManager );
List planMojoBindings = ( (BuildPlan) mpe ).getPlanMojoBindings( project, lifecycleBindingManager );
ForkedDirectInvocationModifier modifier = new ForkedDirectInvocationModifier( mojoBinding, planMojoBindings );
( (DirectInvocationOriginElement) planElement ).addDirectInvocationModifier( modifier );
}
}
@ -337,7 +362,7 @@ else if ( planElement instanceof DirectInvocationOriginElement )
*/
private void recursePhaseMojoFork( MojoBinding mojoBinding, PluginDescriptor pluginDescriptor,
ModifiablePlanElement planElement, LifecycleBindings mergedBindings, MavenProject project,
LinkedList forkingBindings, List tasks )
LinkedList forkingBindings )
throws LifecyclePlannerException, LifecycleSpecificationException, LifecycleLoaderException
{
String referencingGoal = mojoBinding.getGoal();
@ -382,7 +407,7 @@ private void recursePhaseMojoFork( MojoBinding mojoBinding, PluginDescriptor plu
LifecycleUtils.removeMojoBindings( forkingBindings, cloned, false );
modifyBuildPlanForForkedLifecycle( mojoBinding, pluginDescriptor, planElement, cloned, project, forkingBindings, tasks );
modifyBuildPlanForForkedLifecycle( mojoBinding, pluginDescriptor, planElement, cloned, project, forkingBindings );
}
/**
@ -392,7 +417,7 @@ private void recursePhaseMojoFork( MojoBinding mojoBinding, PluginDescriptor plu
*/
private void recurseSingleMojoFork( MojoBinding mojoBinding, PluginDescriptor pluginDescriptor,
ModifiablePlanElement planElement, LifecycleBindings mergedBindings,
MavenProject project, LinkedList forkingBindings, List tasks )
MavenProject project, LinkedList forkingBindings )
throws LifecyclePlannerException, LifecycleSpecificationException, LifecycleLoaderException
{
String referencingGoal = mojoBinding.getGoal();
@ -422,7 +447,7 @@ private void recurseSingleMojoFork( MojoBinding mojoBinding, PluginDescriptor pl
if ( !LifecycleUtils.isMojoBindingPresent( binding, forkingBindings, false ) )
{
modifyBuildPlanForForkedDirectInvocation( binding, mojoBinding, pluginDescriptor, planElement, mergedBindings,
project, forkingBindings, tasks );
project, forkingBindings );
}
}

View File

@ -1,4 +1,4 @@
package org.apache.maven.plugin;
package org.apache.maven.plugin;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@ -61,6 +61,7 @@
import org.apache.maven.project.artifact.MavenMetadataSource;
import org.apache.maven.project.path.PathTranslator;
import org.apache.maven.reporting.MavenReport;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.PlexusContainerException;
@ -161,6 +162,28 @@ public Plugin getPluginDefinitionForPrefix( String prefix,
project.getPluginArtifactRepositories(),
session.getLocalRepository() );
}
/**
* @deprecated
*/
public PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings,
ArtifactRepository localRepository )
throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException,
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException,
PluginVersionNotFoundException
{
// TODO: this should be possibly outside
// All version-resolution logic has been moved to DefaultPluginVersionManager.
if ( plugin.getVersion() == null )
{
getLogger().debug( "Resolving version for plugin: " + plugin.getKey() );
String version = pluginVersionManager.resolvePluginVersion( plugin.getGroupId(), plugin.getArtifactId(),
project, localRepository );
plugin.setVersion( version );
}
return verifyVersionedPlugin( plugin, project, localRepository );
}
public PluginDescriptor verifyPlugin( Plugin plugin,
MavenProject project,

View File

@ -19,6 +19,7 @@
* under the License.
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
@ -31,6 +32,7 @@
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.reporting.MavenReport;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import java.util.Map;
@ -61,6 +63,17 @@ Plugin getPluginDefinitionForPrefix( String prefix,
MavenSession session,
MavenProject project );
/**
* @deprecated
*/
PluginDescriptor verifyPlugin( Plugin plugin,
MavenProject project,
Settings settings,
ArtifactRepository localRepository )
throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException,
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException,
PluginVersionNotFoundException;
PluginDescriptor verifyPlugin( Plugin plugin,
MavenProject project,
MavenSession session )

View File

@ -61,13 +61,22 @@ public class DefaultPluginVersionManager
// TODO: Revisit to remove this piece of state. PLUGIN REGISTRY MAY BE UPDATED ON DISK OUT-OF-PROCESS!
private Map resolvedMetaVersions = new HashMap();
/**
* @deprecated
*/
public String resolvePluginVersion( String groupId, String artifactId, MavenProject project, ArtifactRepository localRepository )
throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException
{
return resolvePluginVersion( groupId, artifactId, project, localRepository, false );
}
public String resolvePluginVersion( String groupId,
String artifactId,
MavenProject project,
MavenSession session )
throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException
{
return resolvePluginVersion( groupId, artifactId, project, session, false );
return resolvePluginVersion( groupId, artifactId, project, session.getLocalRepository(), false );
}
public String resolveReportPluginVersion( String groupId,
@ -76,18 +85,16 @@ public String resolveReportPluginVersion( String groupId,
MavenSession session )
throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException
{
return resolvePluginVersion( groupId, artifactId, project, session, true );
return resolvePluginVersion( groupId, artifactId, project, session.getLocalRepository(), true );
}
private String resolvePluginVersion( String groupId,
String artifactId,
MavenProject project,
MavenSession session,
ArtifactRepository localRepository,
boolean resolveAsReportPlugin )
throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException
{
ArtifactRepository localRepository = session.getLocalRepository();
// first pass...if the plugin is specified in the pom, try to retrieve the version from there.
String version = getVersionFromPluginConfig( groupId, artifactId, project, resolveAsReportPlugin );
getLogger().debug( "Version from POM: " + version );

View File

@ -19,6 +19,7 @@
* under the License.
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.InvalidPluginException;
import org.apache.maven.project.MavenProject;
@ -27,6 +28,12 @@ public interface PluginVersionManager
{
String ROLE = PluginVersionManager.class.getName();
/**
* @deprecated
*/
String resolvePluginVersion( String groupId, String artifactId, MavenProject project, ArtifactRepository localRepository )
throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException;
String resolvePluginVersion( String groupId, String artifactId, MavenProject project, MavenSession session )
throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException;