[MNG-4925] Mismanagement of container lookup realm can cause type incompatibilities for plugins looking up components by string

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1042237 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2010-12-04 20:49:18 +00:00
parent 5f05f63b1e
commit 51a0476667
1 changed files with 4 additions and 8 deletions

View File

@ -86,8 +86,10 @@ public class DefaultBuildPluginManager
throw new PluginExecutionException( mojoExecution, project, e ); throw new PluginExecutionException( mojoExecution, project, e );
} }
ClassRealm oldLookupRealm = container.getLookupRealm(); ClassRealm oldLookupRealm = container.setLookupRealm( pluginRealm );
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader( pluginRealm );
MavenSession oldSession = legacySupport.getSession(); MavenSession oldSession = legacySupport.getSession();
@ -95,8 +97,6 @@ public class DefaultBuildPluginManager
{ {
mojo = mavenPluginManager.getConfiguredMojo( Mojo.class, session, mojoExecution ); mojo = mavenPluginManager.getConfiguredMojo( Mojo.class, session, mojoExecution );
Thread.currentThread().setContextClassLoader( pluginRealm );
legacySupport.setSession( session ); legacySupport.setSession( session );
// NOTE: DuplicateArtifactAttachmentException is currently unchecked, so be careful removing this try/catch! // NOTE: DuplicateArtifactAttachmentException is currently unchecked, so be careful removing this try/catch!
@ -158,12 +158,8 @@ public class DefaultBuildPluginManager
{ {
mavenPluginManager.releaseMojo( mojo, mojoExecution ); mavenPluginManager.releaseMojo( mojo, mojoExecution );
if ( oldLookupRealm != null )
{
container.setLookupRealm( null );
}
Thread.currentThread().setContextClassLoader( oldClassLoader ); Thread.currentThread().setContextClassLoader( oldClassLoader );
container.setLookupRealm( oldLookupRealm );
legacySupport.setSession( oldSession ); legacySupport.setSession( oldSession );
} }