From bc314e68aa6f2213c5541d2dedbf9474b1788854 Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Thu, 18 Feb 2010 23:19:48 +0000 Subject: [PATCH] o Concentrated all plugin artifact resolution in one component git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@911645 13f79535-47bb-0310-9956-ffa450edef68 --- .../internal/DefaultMavenPluginManager.java | 53 ++----------------- .../DefaultPluginDependenciesResolver.java | 23 ++++++++ .../internal/PluginDependenciesResolver.java | 14 ++++- 3 files changed, 40 insertions(+), 50 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java index 8be40338d7..3e9dd50c9e 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java @@ -36,10 +36,7 @@ import java.util.zip.ZipEntry; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.RepositoryRequest; -import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; -import org.apache.maven.artifact.resolver.ArtifactResolutionResult; -import org.apache.maven.artifact.resolver.ResolutionErrorHandler; import org.apache.maven.artifact.resolver.filter.AndArtifactFilter; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.classrealm.ClassRealmManager; @@ -65,7 +62,6 @@ import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder; import org.apache.maven.project.MavenProject; -import org.apache.maven.repository.RepositorySystem; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.annotations.Component; @@ -108,12 +104,6 @@ public class DefaultMavenPluginManager @Requirement private ClassRealmManager classRealmManager; - @Requirement - protected RepositorySystem repositorySystem; - - @Requirement - private ResolutionErrorHandler resolutionErrorHandler; - @Requirement private PluginDescriptorCache pluginDescriptorCache; @@ -134,7 +124,8 @@ public class DefaultMavenPluginManager if ( pluginDescriptor == null ) { - Artifact pluginArtifact = resolvePluginArtifact( plugin, repositoryRequest ); + Artifact pluginArtifact = + pluginDependenciesResolver.resolve( plugin, new ArtifactResolutionRequest( repositoryRequest ) ); pluginDescriptor = extractPluginDescriptor( pluginArtifact, plugin ); @@ -146,29 +137,6 @@ public class DefaultMavenPluginManager return pluginDescriptor; } - private Artifact resolvePluginArtifact( Plugin plugin, RepositoryRequest repositoryRequest ) - throws PluginResolutionException - { - Artifact pluginArtifact = repositorySystem.createPluginArtifact( plugin ); - - ArtifactResolutionRequest request = new ArtifactResolutionRequest( repositoryRequest ); - request.setArtifact( pluginArtifact ); - request.setResolveTransitively( false ); - - ArtifactResolutionResult result = repositorySystem.resolve( request ); - - try - { - resolutionErrorHandler.throwErrors( request, result ); - } - catch ( ArtifactResolutionException e ) - { - throw new PluginResolutionException( plugin, e ); - } - - return pluginArtifact; - } - private PluginDescriptor extractPluginDescriptor( Artifact pluginArtifact, Plugin plugin ) throws PluginDescriptorParsingException, InvalidPluginDescriptorException { @@ -353,7 +321,8 @@ public class DefaultMavenPluginManager dependencyFilter = new AndArtifactFilter( Arrays.asList( dependencyFilter, filter ) ); } - List pluginArtifacts = resolvePluginArtifacts( plugin, pluginArtifact, request, dependencyFilter ); + List pluginArtifacts = + pluginDependenciesResolver.resolve( plugin, pluginArtifact, request, dependencyFilter ); ClassRealm pluginRealm = classRealmManager.createPluginRealm( plugin, parent, imports, pluginArtifacts ); @@ -392,20 +361,6 @@ public class DefaultMavenPluginManager } } - /** - * Gets all artifacts required for the class realm of the specified plugin. An artifact in the result list that has - * no file set is meant to be excluded from the plugin realm in favor of the equivalent library from the current - * core distro. - */ - // FIXME: only exposed to allow workaround for MNG-4194 - protected List resolvePluginArtifacts( Plugin plugin, Artifact pluginArtifact, - ArtifactResolutionRequest request, - ArtifactFilter dependencyFilter ) - throws PluginResolutionException - { - return pluginDependenciesResolver.resolve( plugin, pluginArtifact, request, dependencyFilter ); - } - public T getConfiguredMojo( Class mojoInterface, MavenSession session, MojoExecution mojoExecution ) throws PluginConfigurationException, PluginContainerException { diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java index b5874550b0..edd389e378 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java @@ -63,6 +63,29 @@ public class DefaultPluginDependenciesResolver @Requirement private ArtifactFilterManager artifactFilterManager; + public Artifact resolve( Plugin plugin, ArtifactResolutionRequest request ) + throws PluginResolutionException + { + Artifact pluginArtifact = repositorySystem.createPluginArtifact( plugin ); + + request.setArtifact( pluginArtifact ); + request.setResolveRoot( true ); + request.setResolveTransitively( false ); + + ArtifactResolutionResult result = repositorySystem.resolve( request ); + + try + { + resolutionErrorHandler.throwErrors( request, result ); + } + catch ( ArtifactResolutionException e ) + { + throw new PluginResolutionException( plugin, e ); + } + + return pluginArtifact; + } + public List resolve( Plugin plugin, Artifact pluginArtifact, ArtifactResolutionRequest request, ArtifactFilter dependencyFilter ) throws PluginResolutionException diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/PluginDependenciesResolver.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/PluginDependenciesResolver.java index 341a9dfa51..7a48cab7cc 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/internal/PluginDependenciesResolver.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/PluginDependenciesResolver.java @@ -37,6 +37,18 @@ import org.apache.maven.plugin.PluginResolutionException; public interface PluginDependenciesResolver { + /** + * Resolves the main artifact of the specified plugin. + * + * @param plugin The plugin for which to resolve the main artifact, must not be {@code null}. + * @param request A prepopulated resolution request that will be completed and used for the resolution, must not be + * {@code null}. + * @return The resolved plugin artifact, never {@code null}. + * @throws PluginResolutionException If the plugin artifact could not be resolved. + */ + public Artifact resolve( Plugin plugin, ArtifactResolutionRequest request ) + throws PluginResolutionException; + /** * Resolves the runtime dependencies of the specified plugin. * @@ -49,7 +61,7 @@ public interface PluginDependenciesResolver * @throws PluginResolutionException If any dependency could not be resolved. */ List resolve( Plugin plugin, Artifact pluginArtifact, ArtifactResolutionRequest request, - ArtifactFilter dependencyFilter ) + ArtifactFilter dependencyFilter ) throws PluginResolutionException; }