o Extended base plugin manager to allow for caller-supplied exclusions of certain plugin dependencies

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@881793 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-11-18 14:53:55 +00:00
parent 1068ab557c
commit 9e42487829
6 changed files with 47 additions and 24 deletions

View File

@ -182,7 +182,7 @@ public class DefaultBuildPluginManager
}
mavenPluginManager.setupPluginRealm( pluginDescriptor, session, session.getCurrentProject().getClassRealm(),
null );
null, null );
return pluginDescriptor.getClassRealm();
}

View File

@ -28,6 +28,7 @@ import java.util.Map;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Exclusion;
import org.apache.maven.model.Plugin;
@ -53,9 +54,12 @@ public class DefaultPluginRealmCache
private final List<String> parentImports;
private final ArtifactFilter filter;
private final int hashCode;
public CacheKey( Plugin plugin, ClassLoader parentRealm, List<String> parentImports, ArtifactRepository localRepository,
public CacheKey( Plugin plugin, ClassLoader parentRealm, List<String> parentImports,
ArtifactFilter dependencyFilter, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories )
{
this.plugin = plugin.clone();
@ -63,12 +67,14 @@ public class DefaultPluginRealmCache
this.repositories.addAll( remoteRepositories );
this.parentRealm = parentRealm;
this.parentImports = ( parentImports != null ) ? parentImports : Collections.<String> emptyList();
this.filter = dependencyFilter;
int hash = 17;
hash = hash * 31 + pluginHashCode( plugin );
hash = hash * 31 + repositories.hashCode();
hash = hash * 31 + ( parentRealm != null ? parentRealm.hashCode() : 0 );
hash = hash * 31 + this.parentImports.hashCode();
hash = hash * 31 + ( dependencyFilter != null ? dependencyFilter.hashCode() : 0 );
this.hashCode = hash;
}
@ -94,19 +100,22 @@ public class DefaultPluginRealmCache
CacheKey other = (CacheKey) o;
return parentRealm == other.parentRealm && pluginEquals( plugin, other.plugin )
&& eq( repositories, other.repositories );
&& eq( repositories, other.repositories ) && eq( filter, other.filter )
&& eq( parentImports, other.parentImports );
}
}
protected final Map<CacheKey, CacheRecord> cache = new HashMap<CacheKey, CacheRecord>();
public CacheRecord get( Plugin plugin, ClassLoader parentRealm, List<String> parentImports,
ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
ArtifactFilter dependencyFilter, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories )
{
return cache.get( new CacheKey( plugin, parentRealm, parentImports, localRepository, remoteRepositories ) );
return cache.get( new CacheKey( plugin, parentRealm, parentImports, dependencyFilter, localRepository,
remoteRepositories ) );
}
public CacheRecord put( Plugin plugin, ClassLoader parentRealm, List<String> parentImports,
public CacheRecord put( Plugin plugin, ClassLoader parentRealm, List<String> parentImports,ArtifactFilter dependencyFilter,
ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories,
ClassRealm pluginRealm, List<Artifact> pluginArtifacts )
{
@ -115,7 +124,8 @@ public class DefaultPluginRealmCache
throw new NullPointerException();
}
CacheKey key = new CacheKey( plugin, parentRealm, parentImports, localRepository, remoteRepositories );
CacheKey key =
new CacheKey( plugin, parentRealm, parentImports, dependencyFilter, localRepository, remoteRepositories );
if ( cache.containsKey( key ) )
{

View File

@ -22,6 +22,7 @@ package org.apache.maven.plugin;
import java.util.List;
import org.apache.maven.artifact.repository.RepositoryRequest;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
@ -71,9 +72,10 @@ public interface MavenPluginManager
* {@code null}.
* @param parent The parent class realm for the plugin, may be {@code null} to use the Maven core realm.
* @param imports The packages/types to import from the parent realm, may be {@code null}.
* @param filter The filter used to exclude certain plugin dependencies, may be {@code null}.
*/
void setupPluginRealm( PluginDescriptor pluginDescriptor, MavenSession session, ClassLoader parent,
List<String> imports )
List<String> imports, ArtifactFilter filter )
throws PluginResolutionException, PluginContainerException;
/**

View File

@ -23,6 +23,7 @@ import java.util.List;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.model.Plugin;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
@ -51,11 +52,12 @@ public interface PluginRealmCache
}
CacheRecord get( Plugin plugin, ClassLoader parentRealm, List<String> parentImports,
ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories );
ArtifactFilter dependencyFilter, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories );
CacheRecord put( Plugin plugin, ClassLoader parentRealm, List<String> parentImports,
ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories,
ClassRealm pluginRealm, List<Artifact> pluginArtifacts );
ArtifactFilter dependencyFilter, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories, ClassRealm pluginRealm, List<Artifact> pluginArtifacts );
void flush();

View File

@ -290,7 +290,7 @@ public class DefaultMavenPluginManager
}
public synchronized void setupPluginRealm( PluginDescriptor pluginDescriptor, MavenSession session,
ClassLoader parent, List<String> imports )
ClassLoader parent, List<String> imports, ArtifactFilter filter )
throws PluginResolutionException, PluginContainerException
{
Plugin plugin = pluginDescriptor.getPlugin();
@ -298,7 +298,7 @@ public class DefaultMavenPluginManager
MavenProject project = session.getCurrentProject();
PluginRealmCache.CacheRecord cacheRecord =
pluginRealmCache.get( plugin, parent, imports, session.getLocalRepository(),
pluginRealmCache.get( plugin, parent, imports, filter, session.getLocalRepository(),
project.getPluginArtifactRepositories() );
if ( cacheRecord != null )
@ -308,10 +308,10 @@ public class DefaultMavenPluginManager
}
else
{
createPluginRealm( pluginDescriptor, session, parent, imports );
createPluginRealm( pluginDescriptor, session, parent, imports, filter );
cacheRecord =
pluginRealmCache.put( plugin, parent, imports, session.getLocalRepository(),
pluginRealmCache.put( plugin, parent, imports, filter, session.getLocalRepository(),
project.getPluginArtifactRepositories(), pluginDescriptor.getClassRealm(),
pluginDescriptor.getArtifacts() );
}
@ -320,7 +320,7 @@ public class DefaultMavenPluginManager
}
private void createPluginRealm( PluginDescriptor pluginDescriptor, MavenSession session, ClassLoader parent,
List<String> imports )
List<String> imports, ArtifactFilter filter )
throws PluginResolutionException, PluginContainerException
{
Plugin plugin = pluginDescriptor.getPlugin();
@ -346,8 +346,17 @@ public class DefaultMavenPluginManager
request.setOffline( session.isOffline() );
request.setTransferListener( session.getRequest().getTransferListener() );
List<Artifact> pluginArtifacts =
resolvePluginArtifacts( plugin, pluginArtifact, request, project.getExtensionArtifactFilter() );
ArtifactFilter dependencyFilter = project.getExtensionArtifactFilter();
if ( dependencyFilter == null )
{
dependencyFilter = filter;
}
else if ( filter != null )
{
dependencyFilter = new AndArtifactFilter( Arrays.asList( dependencyFilter, filter ) );
}
List<Artifact> pluginArtifacts = resolvePluginArtifacts( plugin, pluginArtifact, request, dependencyFilter );
ClassRealm pluginRealm = classRealmManager.createPluginRealm( plugin, parent, imports );
@ -420,7 +429,7 @@ public class DefaultMavenPluginManager
// FIXME: only exposed to allow workaround for MNG-4194
protected List<Artifact> resolvePluginArtifacts( Plugin plugin, Artifact pluginArtifact,
RepositoryRequest repositoryRequest,
ArtifactFilter extensionArtifactFilter )
ArtifactFilter dependencyFilter )
throws PluginResolutionException
{
Set<Artifact> overrideArtifacts = new LinkedHashSet<Artifact>();
@ -433,9 +442,9 @@ public class DefaultMavenPluginManager
ArtifactFilter resolutionFilter = artifactFilterManager.getCoreArtifactFilter();
if ( extensionArtifactFilter != null )
if ( dependencyFilter != null )
{
resolutionFilter = new AndArtifactFilter( Arrays.asList( resolutionFilter, extensionArtifactFilter ) );
resolutionFilter = new AndArtifactFilter( Arrays.asList( resolutionFilter, dependencyFilter ) );
}
ArtifactResolutionRequest request = new ArtifactResolutionRequest( repositoryRequest );

View File

@ -119,7 +119,7 @@ public class DefaultPluginManager
pluginDescriptor = pluginManager.getPluginDescriptor( plugin, repositoryRequest );
pluginManager.setupPluginRealm( pluginDescriptor, session, null, null );
pluginManager.setupPluginRealm( pluginDescriptor, session, null, null, null );
}
catch ( Exception e )
{
@ -151,7 +151,7 @@ public class DefaultPluginManager
pluginDescriptor = pluginManager.getPluginDescriptor( plugin, repositoryRequest );
pluginManager.setupPluginRealm( pluginDescriptor, session, null, null );
pluginManager.setupPluginRealm( pluginDescriptor, session, null, null, null );
}
catch ( Exception e )
{
@ -231,7 +231,7 @@ public class DefaultPluginManager
try
{
pluginManager.setupPluginRealm( pluginDescriptor, session, null, null );
pluginManager.setupPluginRealm( pluginDescriptor, session, null, null, null );
}
catch ( PluginResolutionException e )
{