[MNG-3281] Revisit backwards compat of extensions (IT 0114)

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@815761 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-09-16 13:21:50 +00:00
parent 6b2adee21f
commit b98795ecb9
4 changed files with 25 additions and 20 deletions

View File

@ -154,10 +154,11 @@ public class DefaultBuildPluginManager
Plugin plugin = pluginDescriptor.getPlugin();
MavenProject project = session.getCurrentProject();
ArtifactRepository localRepository = session.getLocalRepository();
List<ArtifactRepository> remoteRepositories = session.getCurrentProject().getPluginArtifactRepositories();
List<ArtifactRepository> remoteRepositories = project.getPluginArtifactRepositories();
PluginCache.CacheRecord cacheRecord = pluginCache.get( plugin, localRepository, remoteRepositories );
PluginCache.CacheRecord cacheRecord = pluginCache.get( plugin, project, localRepository, remoteRepositories );
if ( cacheRecord != null )
{
@ -168,14 +169,14 @@ public class DefaultBuildPluginManager
{
try
{
mavenPluginManager.setupPluginRealm( pluginDescriptor, session, null, null );
mavenPluginManager.setupPluginRealm( pluginDescriptor, session, project.getClassRealm(), null );
}
catch ( PluginResolutionException e )
{
throw new PluginManagerException( plugin, e.getMessage(), e );
}
pluginCache.put( plugin, localRepository, remoteRepositories, pluginDescriptor.getClassRealm(),
pluginCache.put( plugin, project, localRepository, remoteRepositories, pluginDescriptor.getClassRealm(),
pluginDescriptor.getArtifacts() );
}

View File

@ -30,6 +30,7 @@ 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;
@ -46,18 +47,23 @@ public class DefaultPluginCache
private final Plugin plugin;
private final List<ArtifactRepository> repositories = new ArrayList<ArtifactRepository>();
private final ClassRealm projectRealm;
private final int hashCode;
public CacheKey( Plugin plugin, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
public CacheKey( Plugin plugin, MavenProject project, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories )
{
this.plugin = plugin.clone();
this.repositories.add( localRepository );
this.repositories.addAll( remoteRepositories );
this.projectRealm = project.getClassRealm();
int hash = 17;
hash = hash * 31 + pluginHashCode( plugin );
hash = hash * 31 + repositories.hashCode();
hash = hash * 31 + ( projectRealm != null ? projectRealm.hashCode() : 0 );
this.hashCode = hash;
}
@ -82,27 +88,28 @@ public class DefaultPluginCache
CacheKey other = (CacheKey) o;
return pluginEquals( plugin, other.plugin ) && eq(repositories, other.repositories);
return projectRealm == other.projectRealm && pluginEquals( plugin, other.plugin )
&& eq( repositories, other.repositories );
}
}
protected final Map<CacheKey, CacheRecord> cache = new HashMap<CacheKey, CacheRecord>();
public CacheRecord get( Plugin plugin, ArtifactRepository localRepository,
public CacheRecord get( Plugin plugin, MavenProject project, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories )
{
return cache.get( new CacheKey( plugin, localRepository, remoteRepositories ) );
return cache.get( new CacheKey( plugin, project, localRepository, remoteRepositories ) );
}
public void put( Plugin plugin, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories,
ClassRealm pluginRealm, List<Artifact> pluginArtifacts )
public void put( Plugin plugin, MavenProject project, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories, ClassRealm pluginRealm, List<Artifact> pluginArtifacts )
{
if ( pluginRealm == null || pluginArtifacts == null )
{
throw new NullPointerException();
}
CacheKey key = new CacheKey( plugin, localRepository, remoteRepositories );
CacheKey key = new CacheKey( plugin, project, localRepository, remoteRepositories );
if ( cache.containsKey( key ) )
{

View File

@ -116,11 +116,6 @@ public class DefaultPluginDescriptorCache
return clones;
}
private static <T> List<T> clone( List<T> original )
{
return ( original != null ) ? new ArrayList<T>( original ) : null;
}
private static final class CacheKey
implements Key
{

View File

@ -24,6 +24,7 @@ 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;
public interface PluginCache
@ -41,10 +42,11 @@ public interface PluginCache
}
}
CacheRecord get( Plugin plugin, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories );
CacheRecord get( Plugin plugin, MavenProject project, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories );
void put( Plugin plugin, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories,
ClassRealm pluginRealm, List<Artifact> pluginArtifacts );
void put( Plugin plugin, MavenProject project, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories, ClassRealm pluginRealm, List<Artifact> pluginArtifacts );
void flush();
}