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,6 +94,14 @@ public class DefaultBuildPlanner
{ {
MojoBinding mojoBinding = (MojoBinding) it.next(); MojoBinding mojoBinding = (MojoBinding) it.next();
findForkModifiers( mojoBinding, planElement, lifecycleBindings, project );
}
}
private void findForkModifiers( MojoBinding mojoBinding, ModifiablePlanElement planElement,
LifecycleBindings lifecycleBindings, MavenProject project )
throws LifecyclePlannerException, LifecycleSpecificationException, LifecycleLoaderException
{
PluginDescriptor pluginDescriptor; PluginDescriptor pluginDescriptor;
try try
{ {
@ -111,8 +119,7 @@ public class DefaultBuildPlanner
+ pluginDescriptor.getId() + "." ); + pluginDescriptor.getId() + "." );
} }
findForkModifiers( mojoBinding, pluginDescriptor, planElement, lifecycleBindings, project, new LinkedList(), tasks ); findForkModifiers( mojoBinding, pluginDescriptor, planElement, lifecycleBindings, project, new LinkedList() );
}
} }
/** /**
@ -151,6 +158,26 @@ public class DefaultBuildPlanner
{ {
List reportBindings = lifecycleBindingManager.getReportBindings( project ); 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 ); Phase phase = LifecycleUtils.findPhaseForMojoBinding( mojoBinding, lifecycleBindings, true );
if ( phase == null ) if ( phase == null )
@ -159,7 +186,7 @@ public class DefaultBuildPlanner
{ {
DirectInvocationModifier modder = new SimpleDirectInvocationModifier( mojoBinding, reportBindings ); DirectInvocationModifier modder = new SimpleDirectInvocationModifier( mojoBinding, reportBindings );
((DirectInvocationOriginElement) planElement).addDirectInvocationModifier( modder ); ( (DirectInvocationOriginElement) planElement ).addDirectInvocationModifier( modder );
} }
else else
{ {
@ -188,7 +215,7 @@ public class DefaultBuildPlanner
*/ */
private void findForkModifiers( MojoBinding mojoBinding, PluginDescriptor pluginDescriptor, private void findForkModifiers( MojoBinding mojoBinding, PluginDescriptor pluginDescriptor,
ModifiablePlanElement planElement, LifecycleBindings mergedBindings, MavenProject project, ModifiablePlanElement planElement, LifecycleBindings mergedBindings, MavenProject project,
LinkedList forkingBindings, List tasks ) LinkedList forkingBindings )
throws LifecyclePlannerException, LifecycleSpecificationException, LifecycleLoaderException throws LifecyclePlannerException, LifecycleSpecificationException, LifecycleLoaderException
{ {
forkingBindings.addLast( mojoBinding ); forkingBindings.addLast( mojoBinding );
@ -201,12 +228,11 @@ public class DefaultBuildPlanner
if ( mojoDescriptor.getExecuteGoal() != null ) if ( mojoDescriptor.getExecuteGoal() != null )
{ {
recurseSingleMojoFork( mojoBinding, pluginDescriptor, planElement, mergedBindings, project, forkingBindings, recurseSingleMojoFork( mojoBinding, pluginDescriptor, planElement, mergedBindings, project, forkingBindings );
tasks );
} }
else if ( mojoDescriptor.getExecutePhase() != null ) else if ( mojoDescriptor.getExecutePhase() != null )
{ {
recursePhaseMojoFork( mojoBinding, pluginDescriptor, planElement, mergedBindings, project, forkingBindings, tasks ); recursePhaseMojoFork( mojoBinding, pluginDescriptor, planElement, mergedBindings, project, forkingBindings );
} }
} }
finally finally
@ -222,7 +248,7 @@ public class DefaultBuildPlanner
private void modifyBuildPlanForForkedDirectInvocation( MojoBinding invokedBinding, MojoBinding invokedVia, private void modifyBuildPlanForForkedDirectInvocation( MojoBinding invokedBinding, MojoBinding invokedVia,
PluginDescriptor pluginDescriptor, ModifiablePlanElement planElement, PluginDescriptor pluginDescriptor, ModifiablePlanElement planElement,
LifecycleBindings mergedBindings, MavenProject project, LifecycleBindings mergedBindings, MavenProject project,
LinkedList forkingBindings, List tasks ) LinkedList forkingBindings )
throws LifecyclePlannerException, LifecycleSpecificationException, LifecycleLoaderException throws LifecyclePlannerException, LifecycleSpecificationException, LifecycleLoaderException
{ {
if ( planElement instanceof DirectInvocationOriginElement ) if ( planElement instanceof DirectInvocationOriginElement )
@ -235,8 +261,7 @@ public class DefaultBuildPlanner
forkingBindings.addLast( invokedBinding ); forkingBindings.addLast( invokedBinding );
try try
{ {
findForkModifiers( invokedBinding, pluginDescriptor, forkedPlan, forkedBindings, project, findForkModifiers( invokedBinding, pluginDescriptor, forkedPlan, forkedBindings, project, forkingBindings );
forkingBindings, tasks );
} }
finally finally
{ {
@ -264,7 +289,7 @@ public class DefaultBuildPlanner
*/ */
private void modifyBuildPlanForForkedLifecycle( MojoBinding mojoBinding, PluginDescriptor pluginDescriptor, private void modifyBuildPlanForForkedLifecycle( MojoBinding mojoBinding, PluginDescriptor pluginDescriptor,
ModifiablePlanElement planElement, LifecycleBindings bindings, ModifiablePlanElement planElement, LifecycleBindings bindings,
MavenProject project, LinkedList forkingBindings, List tasks ) MavenProject project, LinkedList forkingBindings )
throws LifecycleSpecificationException, LifecyclePlannerException, LifecycleLoaderException throws LifecycleSpecificationException, LifecyclePlannerException, LifecycleLoaderException
{ {
MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( mojoBinding.getGoal() ); MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( mojoBinding.getGoal() );
@ -307,7 +332,7 @@ public class DefaultBuildPlanner
throw new LifecyclePlannerException( e.getMessage(), e ); 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 // 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 ) 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 ); ForkedDirectInvocationModifier modifier = new ForkedDirectInvocationModifier( mojoBinding, planMojoBindings );
@ -337,7 +362,7 @@ public class DefaultBuildPlanner
*/ */
private void recursePhaseMojoFork( MojoBinding mojoBinding, PluginDescriptor pluginDescriptor, private void recursePhaseMojoFork( MojoBinding mojoBinding, PluginDescriptor pluginDescriptor,
ModifiablePlanElement planElement, LifecycleBindings mergedBindings, MavenProject project, ModifiablePlanElement planElement, LifecycleBindings mergedBindings, MavenProject project,
LinkedList forkingBindings, List tasks ) LinkedList forkingBindings )
throws LifecyclePlannerException, LifecycleSpecificationException, LifecycleLoaderException throws LifecyclePlannerException, LifecycleSpecificationException, LifecycleLoaderException
{ {
String referencingGoal = mojoBinding.getGoal(); String referencingGoal = mojoBinding.getGoal();
@ -382,7 +407,7 @@ public class DefaultBuildPlanner
LifecycleUtils.removeMojoBindings( forkingBindings, cloned, false ); 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, private void recurseSingleMojoFork( MojoBinding mojoBinding, PluginDescriptor pluginDescriptor,
ModifiablePlanElement planElement, LifecycleBindings mergedBindings, ModifiablePlanElement planElement, LifecycleBindings mergedBindings,
MavenProject project, LinkedList forkingBindings, List tasks ) MavenProject project, LinkedList forkingBindings )
throws LifecyclePlannerException, LifecycleSpecificationException, LifecycleLoaderException throws LifecyclePlannerException, LifecycleSpecificationException, LifecycleLoaderException
{ {
String referencingGoal = mojoBinding.getGoal(); String referencingGoal = mojoBinding.getGoal();
@ -422,7 +447,7 @@ public class DefaultBuildPlanner
if ( !LifecycleUtils.isMojoBindingPresent( binding, forkingBindings, false ) ) if ( !LifecycleUtils.isMojoBindingPresent( binding, forkingBindings, false ) )
{ {
modifyBuildPlanForForkedDirectInvocation( binding, mojoBinding, pluginDescriptor, planElement, mergedBindings, 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 * 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.artifact.MavenMetadataSource;
import org.apache.maven.project.path.PathTranslator; import org.apache.maven.project.path.PathTranslator;
import org.apache.maven.reporting.MavenReport; import org.apache.maven.reporting.MavenReport;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.PlexusContainerException; import org.codehaus.plexus.PlexusContainerException;
@ -162,6 +163,28 @@ public class DefaultPluginManager
session.getLocalRepository() ); 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, public PluginDescriptor verifyPlugin( Plugin plugin,
MavenProject project, MavenProject project,
MavenSession session ) MavenSession session )

View File

@ -19,6 +19,7 @@ package org.apache.maven.plugin;
* under the License. * under the License.
*/ */
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; 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.MavenProject;
import org.apache.maven.project.artifact.InvalidDependencyVersionException; import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.reporting.MavenReport; import org.apache.maven.reporting.MavenReport;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import java.util.Map; import java.util.Map;
@ -61,6 +63,17 @@ public interface PluginManager
MavenSession session, MavenSession session,
MavenProject project ); 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, PluginDescriptor verifyPlugin( Plugin plugin,
MavenProject project, MavenProject project,
MavenSession session ) 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! // TODO: Revisit to remove this piece of state. PLUGIN REGISTRY MAY BE UPDATED ON DISK OUT-OF-PROCESS!
private Map resolvedMetaVersions = new HashMap(); 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, public String resolvePluginVersion( String groupId,
String artifactId, String artifactId,
MavenProject project, MavenProject project,
MavenSession session ) MavenSession session )
throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException
{ {
return resolvePluginVersion( groupId, artifactId, project, session, false ); return resolvePluginVersion( groupId, artifactId, project, session.getLocalRepository(), false );
} }
public String resolveReportPluginVersion( String groupId, public String resolveReportPluginVersion( String groupId,
@ -76,18 +85,16 @@ public class DefaultPluginVersionManager
MavenSession session ) MavenSession session )
throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException
{ {
return resolvePluginVersion( groupId, artifactId, project, session, true ); return resolvePluginVersion( groupId, artifactId, project, session.getLocalRepository(), true );
} }
private String resolvePluginVersion( String groupId, private String resolvePluginVersion( String groupId,
String artifactId, String artifactId,
MavenProject project, MavenProject project,
MavenSession session, ArtifactRepository localRepository,
boolean resolveAsReportPlugin ) boolean resolveAsReportPlugin )
throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException 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. // first pass...if the plugin is specified in the pom, try to retrieve the version from there.
String version = getVersionFromPluginConfig( groupId, artifactId, project, resolveAsReportPlugin ); String version = getVersionFromPluginConfig( groupId, artifactId, project, resolveAsReportPlugin );
getLogger().debug( "Version from POM: " + version ); getLogger().debug( "Version from POM: " + version );

View File

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