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 @@ public class DefaultBuildPlanner
{
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,6 +158,26 @@ public class DefaultBuildPlanner
{
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 )
@ -159,7 +186,7 @@ public class DefaultBuildPlanner
{
DirectInvocationModifier modder = new SimpleDirectInvocationModifier( mojoBinding, reportBindings );
((DirectInvocationOriginElement) planElement).addDirectInvocationModifier( modder );
( (DirectInvocationOriginElement) planElement ).addDirectInvocationModifier( modder );
}
else
{
@ -188,7 +215,7 @@ public class DefaultBuildPlanner
*/
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 @@ public class DefaultBuildPlanner
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,7 +248,7 @@ public class DefaultBuildPlanner
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 )
@ -235,8 +261,7 @@ public class DefaultBuildPlanner
forkingBindings.addLast( invokedBinding );
try
{
findForkModifiers( invokedBinding, pluginDescriptor, forkedPlan, forkedBindings, project,
forkingBindings, tasks );
findForkModifiers( invokedBinding, pluginDescriptor, forkedPlan, forkedBindings, project, forkingBindings );
}
finally
{
@ -264,7 +289,7 @@ public class DefaultBuildPlanner
*/
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 @@ public class DefaultBuildPlanner
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,7 +343,7 @@ public class DefaultBuildPlanner
}
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 );
@ -337,7 +362,7 @@ public class DefaultBuildPlanner
*/
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 @@ public class DefaultBuildPlanner
LifecycleUtils.removeMojoBindings( forkingBindings, cloned, false );
modifyBuildPlanForForkedLifecycle( mojoBinding, pluginDescriptor, planElement, cloned, project, forkingBindings, tasks );
modifyBuildPlanForForkedLifecycle( mojoBinding, pluginDescriptor, planElement, cloned, project, forkingBindings );
}
/**
@ -392,7 +417,7 @@ public class DefaultBuildPlanner
*/
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 @@ public class DefaultBuildPlanner
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.InvalidDependencyVersionException;
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;
@ -162,6 +163,28 @@ public class DefaultPluginManager
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,
MavenSession session )

View File

@ -19,6 +19,7 @@ package org.apache.maven.plugin;
* 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.plugin.version.PluginVersionResolutionException;
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 @@ public interface PluginManager
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 class DefaultPluginVersionManager
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 @@ package org.apache.maven.plugin.version;
* 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;