mirror of https://github.com/apache/maven.git
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
This commit is contained in:
parent
862e8875d1
commit
bc314e68aa
|
@ -36,10 +36,7 @@ import java.util.zip.ZipEntry;
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
import org.apache.maven.artifact.repository.RepositoryRequest;
|
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.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.AndArtifactFilter;
|
||||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||||
import org.apache.maven.classrealm.ClassRealmManager;
|
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.PluginDescriptor;
|
||||||
import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
|
import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
import org.apache.maven.repository.RepositorySystem;
|
|
||||||
import org.codehaus.plexus.PlexusContainer;
|
import org.codehaus.plexus.PlexusContainer;
|
||||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.codehaus.plexus.component.annotations.Component;
|
||||||
|
@ -108,12 +104,6 @@ public class DefaultMavenPluginManager
|
||||||
@Requirement
|
@Requirement
|
||||||
private ClassRealmManager classRealmManager;
|
private ClassRealmManager classRealmManager;
|
||||||
|
|
||||||
@Requirement
|
|
||||||
protected RepositorySystem repositorySystem;
|
|
||||||
|
|
||||||
@Requirement
|
|
||||||
private ResolutionErrorHandler resolutionErrorHandler;
|
|
||||||
|
|
||||||
@Requirement
|
@Requirement
|
||||||
private PluginDescriptorCache pluginDescriptorCache;
|
private PluginDescriptorCache pluginDescriptorCache;
|
||||||
|
|
||||||
|
@ -134,7 +124,8 @@ public class DefaultMavenPluginManager
|
||||||
|
|
||||||
if ( pluginDescriptor == null )
|
if ( pluginDescriptor == null )
|
||||||
{
|
{
|
||||||
Artifact pluginArtifact = resolvePluginArtifact( plugin, repositoryRequest );
|
Artifact pluginArtifact =
|
||||||
|
pluginDependenciesResolver.resolve( plugin, new ArtifactResolutionRequest( repositoryRequest ) );
|
||||||
|
|
||||||
pluginDescriptor = extractPluginDescriptor( pluginArtifact, plugin );
|
pluginDescriptor = extractPluginDescriptor( pluginArtifact, plugin );
|
||||||
|
|
||||||
|
@ -146,29 +137,6 @@ public class DefaultMavenPluginManager
|
||||||
return pluginDescriptor;
|
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 )
|
private PluginDescriptor extractPluginDescriptor( Artifact pluginArtifact, Plugin plugin )
|
||||||
throws PluginDescriptorParsingException, InvalidPluginDescriptorException
|
throws PluginDescriptorParsingException, InvalidPluginDescriptorException
|
||||||
{
|
{
|
||||||
|
@ -353,7 +321,8 @@ public class DefaultMavenPluginManager
|
||||||
dependencyFilter = new AndArtifactFilter( Arrays.asList( dependencyFilter, filter ) );
|
dependencyFilter = new AndArtifactFilter( Arrays.asList( dependencyFilter, filter ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Artifact> pluginArtifacts = resolvePluginArtifacts( plugin, pluginArtifact, request, dependencyFilter );
|
List<Artifact> pluginArtifacts =
|
||||||
|
pluginDependenciesResolver.resolve( plugin, pluginArtifact, request, dependencyFilter );
|
||||||
|
|
||||||
ClassRealm pluginRealm = classRealmManager.createPluginRealm( plugin, parent, imports, pluginArtifacts );
|
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<Artifact> resolvePluginArtifacts( Plugin plugin, Artifact pluginArtifact,
|
|
||||||
ArtifactResolutionRequest request,
|
|
||||||
ArtifactFilter dependencyFilter )
|
|
||||||
throws PluginResolutionException
|
|
||||||
{
|
|
||||||
return pluginDependenciesResolver.resolve( plugin, pluginArtifact, request, dependencyFilter );
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> T getConfiguredMojo( Class<T> mojoInterface, MavenSession session, MojoExecution mojoExecution )
|
public <T> T getConfiguredMojo( Class<T> mojoInterface, MavenSession session, MojoExecution mojoExecution )
|
||||||
throws PluginConfigurationException, PluginContainerException
|
throws PluginConfigurationException, PluginContainerException
|
||||||
{
|
{
|
||||||
|
|
|
@ -63,6 +63,29 @@ public class DefaultPluginDependenciesResolver
|
||||||
@Requirement
|
@Requirement
|
||||||
private ArtifactFilterManager artifactFilterManager;
|
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<Artifact> resolve( Plugin plugin, Artifact pluginArtifact, ArtifactResolutionRequest request,
|
public List<Artifact> resolve( Plugin plugin, Artifact pluginArtifact, ArtifactResolutionRequest request,
|
||||||
ArtifactFilter dependencyFilter )
|
ArtifactFilter dependencyFilter )
|
||||||
throws PluginResolutionException
|
throws PluginResolutionException
|
||||||
|
|
|
@ -37,6 +37,18 @@ import org.apache.maven.plugin.PluginResolutionException;
|
||||||
public interface PluginDependenciesResolver
|
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.
|
* Resolves the runtime dependencies of the specified plugin.
|
||||||
*
|
*
|
||||||
|
@ -49,7 +61,7 @@ public interface PluginDependenciesResolver
|
||||||
* @throws PluginResolutionException If any dependency could not be resolved.
|
* @throws PluginResolutionException If any dependency could not be resolved.
|
||||||
*/
|
*/
|
||||||
List<Artifact> resolve( Plugin plugin, Artifact pluginArtifact, ArtifactResolutionRequest request,
|
List<Artifact> resolve( Plugin plugin, Artifact pluginArtifact, ArtifactResolutionRequest request,
|
||||||
ArtifactFilter dependencyFilter )
|
ArtifactFilter dependencyFilter )
|
||||||
throws PluginResolutionException;
|
throws PluginResolutionException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue