o Unified code

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@819871 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-09-29 09:46:01 +00:00
parent 42884072b2
commit 3bcdf432b2
6 changed files with 45 additions and 22 deletions

View File

@ -106,9 +106,9 @@ public class DefaultPluginRealmCache
return cache.get( new CacheKey( plugin, parentRealm, parentImports, localRepository, remoteRepositories ) ); return cache.get( new CacheKey( plugin, parentRealm, parentImports, localRepository, remoteRepositories ) );
} }
public void put( Plugin plugin, ClassLoader parentRealm, List<String> parentImports, public CacheRecord put( Plugin plugin, ClassLoader parentRealm, List<String> parentImports,
ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories,
ClassRealm pluginRealm, List<Artifact> pluginArtifacts ) ClassRealm pluginRealm, List<Artifact> pluginArtifacts )
{ {
if ( pluginRealm == null || pluginArtifacts == null ) if ( pluginRealm == null || pluginArtifacts == null )
{ {
@ -123,7 +123,10 @@ public class DefaultPluginRealmCache
} }
CacheRecord record = new CacheRecord( pluginRealm, pluginArtifacts ); CacheRecord record = new CacheRecord( pluginRealm, pluginArtifacts );
cache.put( key, record ); cache.put( key, record );
return record;
} }
public void flush() public void flush()
@ -234,7 +237,7 @@ public class DefaultPluginRealmCache
return s1 != null ? s1.equals( s2 ) : s2 == null; return s1 != null ? s1.equals( s2 ) : s2 == null;
} }
public void register( MavenProject project, ClassRealm pluginRealm ) public void register( MavenProject project, CacheRecord record )
{ {
// default cache does not track plugin usage // default cache does not track plugin usage
} }

View File

@ -53,19 +53,20 @@ public interface PluginRealmCache
CacheRecord get( Plugin plugin, ClassLoader parentRealm, List<String> parentImports, CacheRecord get( Plugin plugin, ClassLoader parentRealm, List<String> parentImports,
ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories ); ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories );
void put( Plugin plugin, ClassLoader parentRealm, List<String> parentImports, ArtifactRepository localRepository, CacheRecord put( Plugin plugin, ClassLoader parentRealm, List<String> parentImports,
List<ArtifactRepository> remoteRepositories, ClassRealm pluginRealm, List<Artifact> pluginArtifacts ); ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories,
ClassRealm pluginRealm, List<Artifact> pluginArtifacts );
void flush(); void flush();
/** /**
* Registers the specified plugin realm for usage with the given project. Integrators can use the information * Registers the specified cache record for usage with the given project. Integrators can use the information
* collected from this method in combination with a custom cache implementation to dispose unused plugin realms from * collected from this method in combination with a custom cache implementation to dispose unused records from the
* the cache. * cache.
* *
* @param project The project that employs the plugin realm, must not be {@code null}. * @param project The project that employs the plugin realm, must not be {@code null}.
* @param pluginRealm The plugin realm being used for the project, must not be {@code null}. * @param record The cache record being used for the project, must not be {@code null}.
*/ */
void register( MavenProject project, ClassRealm pluginRealm ); void register( MavenProject project, CacheRecord record );
} }

View File

@ -315,12 +315,13 @@ public class DefaultMavenPluginManager
{ {
createPluginRealm( pluginDescriptor, session, parent, imports ); createPluginRealm( pluginDescriptor, session, parent, imports );
pluginRealmCache.put( plugin, parent, imports, session.getLocalRepository(), cacheRecord =
project.getPluginArtifactRepositories(), pluginDescriptor.getClassRealm(), pluginRealmCache.put( plugin, parent, imports, session.getLocalRepository(),
pluginDescriptor.getArtifacts() ); project.getPluginArtifactRepositories(), pluginDescriptor.getClassRealm(),
pluginDescriptor.getArtifacts() );
} }
pluginRealmCache.register( project, pluginDescriptor.getClassRealm() ); pluginRealmCache.register( project, cacheRecord );
} }
private void createPluginRealm( PluginDescriptor pluginDescriptor, MavenSession session, ClassLoader parent, private void createPluginRealm( PluginDescriptor pluginDescriptor, MavenSession session, ClassLoader parent,

View File

@ -362,11 +362,11 @@ public class DefaultProjectBuildingHelper
extensionArtifactFilter = new ExclusionSetFilter( exclusions ); extensionArtifactFilter = new ExclusionSetFilter( exclusions );
} }
projectRealmCache.put( extensionRealms, projectRealm, extensionArtifactFilter ); record = projectRealmCache.put( extensionRealms, projectRealm, extensionArtifactFilter );
record = new ProjectRealmCache.CacheRecord( projectRealm, extensionArtifactFilter );
} }
projectRealmCache.register( project, record );
return record; return record;
} }

View File

@ -83,8 +83,8 @@ public class DefaultProjectRealmCache
return cache.get( new CacheKey( extensionRealms ) ); return cache.get( new CacheKey( extensionRealms ) );
} }
public void put( List<? extends ClassRealm> extensionRealms, ClassRealm projectRealm, public CacheRecord put( List<? extends ClassRealm> extensionRealms, ClassRealm projectRealm,
ArtifactFilter extensionArtifactFilter ) ArtifactFilter extensionArtifactFilter )
{ {
if ( projectRealm == null ) if ( projectRealm == null )
{ {
@ -99,7 +99,10 @@ public class DefaultProjectRealmCache
} }
CacheRecord record = new CacheRecord( projectRealm, extensionArtifactFilter ); CacheRecord record = new CacheRecord( projectRealm, extensionArtifactFilter );
cache.put( key, record ); cache.put( key, record );
return record;
} }
public void flush() public void flush()
@ -107,4 +110,9 @@ public class DefaultProjectRealmCache
cache.clear(); cache.clear();
} }
public void register( MavenProject project, CacheRecord record )
{
// default cache does not track record usage
}
} }

View File

@ -52,9 +52,19 @@ public interface ProjectRealmCache
CacheRecord get( List<? extends ClassRealm> extensionRealms ); CacheRecord get( List<? extends ClassRealm> extensionRealms );
void put( List<? extends ClassRealm> extensionRealms, ClassRealm projectRealm, CacheRecord put( List<? extends ClassRealm> extensionRealms, ClassRealm projectRealm,
ArtifactFilter extensionArtifactFilter ); ArtifactFilter extensionArtifactFilter );
void flush(); void flush();
/**
* Registers the specified cache record for usage with the given project. Integrators can use the information
* collected from this method in combination with a custom cache implementation to dispose unused records from the
* cache.
*
* @param project The project that employs the plugin realm, must not be {@code null}.
* @param record The cache record being used for the project, must not be {@code null}.
*/
void register( MavenProject project, CacheRecord record );
} }