diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java index 1301be8586..a30e9d60f9 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java @@ -154,10 +154,11 @@ public class DefaultBuildPluginManager Plugin plugin = pluginDescriptor.getPlugin(); + MavenProject project = session.getCurrentProject(); ArtifactRepository localRepository = session.getLocalRepository(); - List remoteRepositories = session.getCurrentProject().getPluginArtifactRepositories(); + List 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() ); } diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginCache.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginCache.java index bd7793d626..e959544662 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginCache.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginCache.java @@ -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 repositories = new ArrayList(); - + + private final ClassRealm projectRealm; + private final int hashCode; - public CacheKey( Plugin plugin, ArtifactRepository localRepository, List remoteRepositories ) + public CacheKey( Plugin plugin, MavenProject project, ArtifactRepository localRepository, + List 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 cache = new HashMap(); - public CacheRecord get( Plugin plugin, ArtifactRepository localRepository, + public CacheRecord get( Plugin plugin, MavenProject project, ArtifactRepository localRepository, List 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 remoteRepositories, - ClassRealm pluginRealm, List pluginArtifacts ) + public void put( Plugin plugin, MavenProject project, ArtifactRepository localRepository, + List remoteRepositories, ClassRealm pluginRealm, List 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 ) ) { diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginDescriptorCache.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginDescriptorCache.java index f8ee0e7ba6..99c111e60f 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginDescriptorCache.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginDescriptorCache.java @@ -116,11 +116,6 @@ public class DefaultPluginDescriptorCache return clones; } - private static List clone( List original ) - { - return ( original != null ) ? new ArrayList( original ) : null; - } - private static final class CacheKey implements Key { diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginCache.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginCache.java index 29313260ba..fd3ac7f9fe 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/PluginCache.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginCache.java @@ -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 remoteRepositories ); + CacheRecord get( Plugin plugin, MavenProject project, ArtifactRepository localRepository, + List remoteRepositories ); - void put( Plugin plugin, ArtifactRepository localRepository, List remoteRepositories, - ClassRealm pluginRealm, List pluginArtifacts ); + void put( Plugin plugin, MavenProject project, ArtifactRepository localRepository, + List remoteRepositories, ClassRealm pluginRealm, List pluginArtifacts ); void flush(); }