mirror of https://github.com/apache/maven.git
o Generalized plugin realm cache
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@817669 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3646d923a9
commit
341f030f5c
|
@ -46,9 +46,6 @@ public class DefaultBuildPluginManager
|
|||
@Requirement
|
||||
private PlexusContainer container;
|
||||
|
||||
@Requirement
|
||||
private PluginRealmCache pluginCache;
|
||||
|
||||
@Requirement
|
||||
private MavenPluginManager mavenPluginManager;
|
||||
|
||||
|
@ -154,30 +151,14 @@ public class DefaultBuildPluginManager
|
|||
|
||||
Plugin plugin = pluginDescriptor.getPlugin();
|
||||
|
||||
MavenProject project = session.getCurrentProject();
|
||||
ArtifactRepository localRepository = session.getLocalRepository();
|
||||
List<ArtifactRepository> remoteRepositories = project.getPluginArtifactRepositories();
|
||||
|
||||
PluginRealmCache.CacheRecord cacheRecord = pluginCache.get( plugin, project, localRepository, remoteRepositories );
|
||||
|
||||
if ( cacheRecord != null )
|
||||
try
|
||||
{
|
||||
pluginDescriptor.setClassRealm( cacheRecord.realm );
|
||||
pluginDescriptor.setArtifacts( new ArrayList<Artifact>( cacheRecord.artifacts ) );
|
||||
mavenPluginManager.setupPluginRealm( pluginDescriptor, session,
|
||||
session.getCurrentProject().getClassRealm(), null );
|
||||
}
|
||||
else
|
||||
catch ( PluginResolutionException e )
|
||||
{
|
||||
try
|
||||
{
|
||||
mavenPluginManager.setupPluginRealm( pluginDescriptor, session, project.getClassRealm(), null );
|
||||
}
|
||||
catch ( PluginResolutionException e )
|
||||
{
|
||||
throw new PluginManagerException( plugin, e.getMessage(), e );
|
||||
}
|
||||
|
||||
pluginCache.put( plugin, project, localRepository, remoteRepositories, pluginDescriptor.getClassRealm(),
|
||||
pluginDescriptor.getArtifacts() );
|
||||
throw new PluginManagerException( plugin, e.getMessage(), e );
|
||||
}
|
||||
|
||||
return pluginDescriptor.getClassRealm();
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.maven.plugin;
|
|||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
@ -30,7 +31,6 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
|
|||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Exclusion;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
|
||||
|
@ -48,22 +48,26 @@ public class DefaultPluginRealmCache
|
|||
|
||||
private final List<ArtifactRepository> repositories = new ArrayList<ArtifactRepository>();
|
||||
|
||||
private final ClassRealm projectRealm;
|
||||
private final ClassLoader parentRealm;
|
||||
|
||||
private final List<String> parentImports;
|
||||
|
||||
private final int hashCode;
|
||||
|
||||
public CacheKey( Plugin plugin, MavenProject project, ArtifactRepository localRepository,
|
||||
public CacheKey( Plugin plugin, ClassLoader parentRealm, List<String> parentImports, ArtifactRepository localRepository,
|
||||
List<ArtifactRepository> remoteRepositories )
|
||||
{
|
||||
this.plugin = plugin.clone();
|
||||
this.repositories.add( localRepository );
|
||||
this.repositories.addAll( remoteRepositories );
|
||||
this.projectRealm = project.getClassRealm();
|
||||
this.parentRealm = parentRealm;
|
||||
this.parentImports = ( parentImports != null ) ? parentImports : Collections.<String> emptyList();
|
||||
|
||||
int hash = 17;
|
||||
hash = hash * 31 + pluginHashCode( plugin );
|
||||
hash = hash * 31 + repositories.hashCode();
|
||||
hash = hash * 31 + ( projectRealm != null ? projectRealm.hashCode() : 0 );
|
||||
hash = hash * 31 + ( parentRealm != null ? parentRealm.hashCode() : 0 );
|
||||
hash = hash * 31 + this.parentImports.hashCode();
|
||||
this.hashCode = hash;
|
||||
}
|
||||
|
||||
|
@ -88,32 +92,33 @@ public class DefaultPluginRealmCache
|
|||
|
||||
CacheKey other = (CacheKey) o;
|
||||
|
||||
return projectRealm == other.projectRealm && pluginEquals( plugin, other.plugin )
|
||||
return parentRealm == other.parentRealm && pluginEquals( plugin, other.plugin )
|
||||
&& eq( repositories, other.repositories );
|
||||
}
|
||||
}
|
||||
|
||||
protected final Map<CacheKey, CacheRecord> cache = new HashMap<CacheKey, CacheRecord>();
|
||||
|
||||
public CacheRecord get( Plugin plugin, MavenProject project, ArtifactRepository localRepository,
|
||||
List<ArtifactRepository> remoteRepositories )
|
||||
public CacheRecord get( Plugin plugin, ClassLoader parentRealm, List<String> parentImports,
|
||||
ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
|
||||
{
|
||||
return cache.get( new CacheKey( plugin, project, localRepository, remoteRepositories ) );
|
||||
return cache.get( new CacheKey( plugin, parentRealm, parentImports, localRepository, remoteRepositories ) );
|
||||
}
|
||||
|
||||
public void put( Plugin plugin, MavenProject project, ArtifactRepository localRepository,
|
||||
List<ArtifactRepository> remoteRepositories, ClassRealm pluginRealm, List<Artifact> pluginArtifacts )
|
||||
public void put( Plugin plugin, ClassLoader parentRealm, List<String> parentImports,
|
||||
ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories,
|
||||
ClassRealm pluginRealm, List<Artifact> pluginArtifacts )
|
||||
{
|
||||
if ( pluginRealm == null || pluginArtifacts == null )
|
||||
{
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
CacheKey key = new CacheKey( plugin, project, localRepository, remoteRepositories );
|
||||
CacheKey key = new CacheKey( plugin, parentRealm, parentImports, localRepository, remoteRepositories );
|
||||
|
||||
if ( cache.containsKey( key ) )
|
||||
{
|
||||
throw new IllegalStateException( "Duplicate plugin realm for plugin " + plugin );
|
||||
throw new IllegalStateException( "Duplicate plugin realm for plugin " + plugin.getId() );
|
||||
}
|
||||
|
||||
CacheRecord record = new CacheRecord( pluginRealm, pluginArtifacts );
|
||||
|
|
|
@ -24,9 +24,16 @@ import java.util.List;
|
|||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||
|
||||
/**
|
||||
* Caches plugin class realms. <strong>Warning:</strong> This is an internal utility interface that is only public for
|
||||
* technical reasons, it is not part of the public API. In particular, this interface can be changed or deleted without
|
||||
* prior notice.
|
||||
*
|
||||
* @author Igor Fedorenko
|
||||
* @author Benjamin Bentmann
|
||||
*/
|
||||
public interface PluginRealmCache
|
||||
{
|
||||
|
||||
|
@ -42,11 +49,12 @@ public interface PluginRealmCache
|
|||
}
|
||||
}
|
||||
|
||||
CacheRecord get( Plugin plugin, MavenProject project, ArtifactRepository localRepository,
|
||||
List<ArtifactRepository> remoteRepositories );
|
||||
CacheRecord get( Plugin plugin, ClassLoader parentRealm, List<String> parentImports,
|
||||
ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories );
|
||||
|
||||
void put( Plugin plugin, MavenProject project, ArtifactRepository localRepository,
|
||||
void put( Plugin plugin, ClassLoader parentRealm, List<String> parentImports, ArtifactRepository localRepository,
|
||||
List<ArtifactRepository> remoteRepositories, ClassRealm pluginRealm, List<Artifact> pluginArtifacts );
|
||||
|
||||
void flush();
|
||||
|
||||
}
|
||||
|
|
|
@ -63,6 +63,7 @@ import org.apache.maven.plugin.PluginDescriptorCache;
|
|||
import org.apache.maven.plugin.PluginDescriptorParsingException;
|
||||
import org.apache.maven.plugin.PluginManagerException;
|
||||
import org.apache.maven.plugin.PluginParameterExpressionEvaluator;
|
||||
import org.apache.maven.plugin.PluginRealmCache;
|
||||
import org.apache.maven.plugin.PluginResolutionException;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
|
@ -125,6 +126,9 @@ public class DefaultMavenPluginManager
|
|||
@Requirement
|
||||
private PluginDescriptorCache pluginDescriptorCache;
|
||||
|
||||
@Requirement
|
||||
private PluginRealmCache pluginRealmCache;
|
||||
|
||||
private PluginDescriptorBuilder builder = new PluginDescriptorBuilder();
|
||||
|
||||
public synchronized PluginDescriptor getPluginDescriptor( Plugin plugin, RepositoryRequest repositoryRequest )
|
||||
|
@ -293,6 +297,31 @@ public class DefaultMavenPluginManager
|
|||
{
|
||||
Plugin plugin = pluginDescriptor.getPlugin();
|
||||
|
||||
PluginRealmCache.CacheRecord cacheRecord =
|
||||
pluginRealmCache.get( plugin, parent, imports, session.getLocalRepository(),
|
||||
session.getCurrentProject().getPluginArtifactRepositories() );
|
||||
|
||||
if ( cacheRecord != null )
|
||||
{
|
||||
pluginDescriptor.setClassRealm( cacheRecord.realm );
|
||||
pluginDescriptor.setArtifacts( new ArrayList<Artifact>( cacheRecord.artifacts ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
createPluginRealm( pluginDescriptor, session, parent, imports );
|
||||
|
||||
pluginRealmCache.put( plugin, parent, imports, session.getLocalRepository(),
|
||||
session.getCurrentProject().getPluginArtifactRepositories(),
|
||||
pluginDescriptor.getClassRealm(), pluginDescriptor.getArtifacts() );
|
||||
}
|
||||
}
|
||||
|
||||
private void createPluginRealm( PluginDescriptor pluginDescriptor, MavenSession session, ClassLoader parent,
|
||||
List<String> imports )
|
||||
throws PluginResolutionException, PluginManagerException
|
||||
{
|
||||
Plugin plugin = pluginDescriptor.getPlugin();
|
||||
|
||||
if ( plugin == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "incomplete plugin descriptor, plugin missing" );
|
||||
|
|
Loading…
Reference in New Issue