From 44c006ff2a0d9a928158d6caadf153947eacdd66 Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Tue, 8 May 2007 00:06:19 +0000 Subject: [PATCH] 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 --- .../lifecycle/plan/DefaultBuildPlanner.java | 103 +++++++++++------- .../maven/plugin/DefaultPluginManager.java | 25 ++++- .../apache/maven/plugin/PluginManager.java | 13 +++ .../version/DefaultPluginVersionManager.java | 17 ++- .../plugin/version/PluginVersionManager.java | 7 ++ 5 files changed, 120 insertions(+), 45 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/plan/DefaultBuildPlanner.java b/maven-core/src/main/java/org/apache/maven/lifecycle/plan/DefaultBuildPlanner.java index 332ee01bbf..525ca6a55d 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/plan/DefaultBuildPlanner.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/plan/DefaultBuildPlanner.java @@ -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,15 +158,35 @@ 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 ) { if ( planElement instanceof DirectInvocationOriginElement ) { 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,27 +248,26 @@ 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 ) { 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 @@ 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,10 +343,10 @@ 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 ); - + ( (DirectInvocationOriginElement) planElement ).addDirectInvocationModifier( modifier ); } } @@ -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 ); } } diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java index df4edcf380..235dc552f4 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java @@ -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; @@ -161,6 +162,28 @@ public class DefaultPluginManager 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, diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java index ac538e893d..b93fb298c2 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java @@ -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 ) diff --git a/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java b/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java index 6822241734..741076e0b6 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java @@ -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 ); diff --git a/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionManager.java b/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionManager.java index 9e3f036c35..9e636025b2 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionManager.java @@ -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;