[MNG-5019] [regression] String-based component lookups performed by report mojos fail with ClassCastException

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1074184 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2011-02-24 15:12:30 +00:00
parent 3279b97102
commit b6ee02c3df
3 changed files with 9 additions and 13 deletions

View File

@ -24,7 +24,6 @@ import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.component.annotations.Requirement;
@ -39,9 +38,6 @@ public class DefaultBuildPluginManager
implements BuildPluginManager implements BuildPluginManager
{ {
@Requirement
private PlexusContainer container;
@Requirement @Requirement
private MavenPluginManager mavenPluginManager; private MavenPluginManager mavenPluginManager;
@ -86,8 +82,6 @@ public class DefaultBuildPluginManager
throw new PluginExecutionException( mojoExecution, project, e ); throw new PluginExecutionException( mojoExecution, project, e );
} }
ClassRealm oldLookupRealm = container.setLookupRealm( pluginRealm );
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader( pluginRealm ); Thread.currentThread().setContextClassLoader( pluginRealm );
@ -159,7 +153,6 @@ public class DefaultBuildPluginManager
mavenPluginManager.releaseMojo( mojo, mojoExecution ); mavenPluginManager.releaseMojo( mojo, mojoExecution );
Thread.currentThread().setContextClassLoader( oldClassLoader ); Thread.currentThread().setContextClassLoader( oldClassLoader );
container.setLookupRealm( oldLookupRealm );
legacySupport.setSession( oldSession ); legacySupport.setSession( oldSession );
} }

View File

@ -109,16 +109,16 @@ public class DefaultPluginManager
throw new PluginManagerException( plugin, e.getMessage(), e ); throw new PluginManagerException( plugin, e.getMessage(), e );
} }
ClassRealm oldRealm = container.getLookupRealm(); ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
try try
{ {
container.setLookupRealm( pluginDescriptor.getClassRealm() ); Thread.currentThread().setContextClassLoader( pluginDescriptor.getClassRealm() );
return container.lookup( role, roleHint ); return container.lookup( role, roleHint );
} }
finally finally
{ {
container.setLookupRealm( oldRealm ); Thread.currentThread().setContextClassLoader( oldClassLoader );
} }
} }
@ -141,16 +141,16 @@ public class DefaultPluginManager
throw new PluginManagerException( plugin, e.getMessage(), e ); throw new PluginManagerException( plugin, e.getMessage(), e );
} }
ClassRealm oldRealm = container.getLookupRealm(); ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
try try
{ {
container.setLookupRealm( pluginDescriptor.getClassRealm() ); Thread.currentThread().setContextClassLoader( pluginDescriptor.getClassRealm() );
return container.lookupMap( role ); return container.lookupMap( role );
} }
finally finally
{ {
container.setLookupRealm( oldRealm ); Thread.currentThread().setContextClassLoader( oldClassLoader );
} }
} }

View File

@ -374,6 +374,9 @@ public class MavenCli
container = new DefaultPlexusContainer( cc ); container = new DefaultPlexusContainer( cc );
// NOTE: To avoid inconsistencies, we'll use the TCCL exclusively for lookups
container.setLookupRealm( null );
container.setLoggerManager( new MavenLoggerManager( logger ) ); container.setLoggerManager( new MavenLoggerManager( logger ) );
customizeContainer( container ); customizeContainer( container );