cleanup of the class realm purging

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1413287 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2012-11-25 03:12:49 +00:00
parent 1d4d1df865
commit 451c43152b
2 changed files with 24 additions and 15 deletions

View File

@ -29,7 +29,9 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Plugin; import org.apache.maven.model.Plugin;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Disposable;
import org.sonatype.aether.RepositorySystemSession; import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.graph.DependencyFilter; import org.sonatype.aether.graph.DependencyFilter;
import org.sonatype.aether.repository.LocalRepository; import org.sonatype.aether.repository.LocalRepository;
@ -41,7 +43,7 @@ import org.sonatype.aether.repository.WorkspaceRepository;
*/ */
@Component( role = PluginRealmCache.class ) @Component( role = PluginRealmCache.class )
public class DefaultPluginRealmCache public class DefaultPluginRealmCache
implements PluginRealmCache implements PluginRealmCache, Disposable
{ {
protected static class CacheKey protected static class CacheKey
@ -179,6 +181,18 @@ public class DefaultPluginRealmCache
public void flush() public void flush()
{ {
for ( CacheRecord record : cache.values() )
{
ClassRealm realm = record.realm;
try
{
realm.getWorld().disposeRealm( realm.getId() );
}
catch ( NoSuchRealmException e )
{
// ignore
}
}
cache.clear(); cache.clear();
} }
@ -197,4 +211,9 @@ public class DefaultPluginRealmCache
// default cache does not track plugin usage // default cache does not track plugin usage
} }
public void dispose()
{
flush();
}
} }

View File

@ -55,6 +55,7 @@ import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.lifecycle.LifecycleExecutionException; import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.lifecycle.internal.LifecycleWeaveBuilder; import org.apache.maven.lifecycle.internal.LifecycleWeaveBuilder;
import org.apache.maven.model.building.ModelProcessor; import org.apache.maven.model.building.ModelProcessor;
import org.apache.maven.plugin.PluginRealmCache;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.properties.internal.EnvironmentUtils; import org.apache.maven.properties.internal.EnvironmentUtils;
import org.apache.maven.settings.building.DefaultSettingsBuildingRequest; import org.apache.maven.settings.building.DefaultSettingsBuildingRequest;
@ -112,9 +113,6 @@ public class MavenCli
private ClassWorld classWorld; private ClassWorld classWorld;
// Per-instance container supports fast embedded execution of core ITs
private DefaultPlexusContainer container;
private LoggerManager plexusLoggerManager; private LoggerManager plexusLoggerManager;
private ILoggerFactory slf4jLoggerFactory; private ILoggerFactory slf4jLoggerFactory;
@ -197,7 +195,7 @@ public class MavenCli
// TODO: need to externalize CliRequest // TODO: need to externalize CliRequest
public int doMain( CliRequest cliRequest ) public int doMain( CliRequest cliRequest )
{ {
PlexusContainer localContainer = this.container; PlexusContainer localContainer = null;
try try
{ {
initialize( cliRequest ); initialize( cliRequest );
@ -235,7 +233,7 @@ public class MavenCli
} }
finally finally
{ {
if ( localContainer != this.container ) if (localContainer != null)
{ {
localContainer.dispose(); localContainer.dispose();
} }
@ -377,10 +375,8 @@ public class MavenCli
cliRequest.classWorld = new ClassWorld( "plexus.core", Thread.currentThread().getContextClassLoader() ); cliRequest.classWorld = new ClassWorld( "plexus.core", Thread.currentThread().getContextClassLoader() );
} }
DefaultPlexusContainer container = this.container; DefaultPlexusContainer container = null;
if ( container == null )
{
ContainerConfiguration cc = new DefaultContainerConfiguration() ContainerConfiguration cc = new DefaultContainerConfiguration()
.setClassWorld( cliRequest.classWorld ) .setClassWorld( cliRequest.classWorld )
.setRealm( setupContainerRealm( cliRequest ) ) .setRealm( setupContainerRealm( cliRequest ) )
@ -405,12 +401,6 @@ public class MavenCli
customizeContainer( container ); customizeContainer( container );
if ( cliRequest.classWorld == classWorld )
{
this.container = container;
}
}
container.getLoggerManager().setThresholds( cliRequest.request.getLoggingLevel() ); container.getLoggerManager().setThresholds( cliRequest.request.getLoggingLevel() );
Thread.currentThread().setContextClassLoader( container.getContainerRealm() ); Thread.currentThread().setContextClassLoader( container.getContainerRealm() );