o Fixed project realm handling to be more embedder friendly

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@795206 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-07-17 19:48:57 +00:00
parent 8efe10c89e
commit ef13f229e8
4 changed files with 28 additions and 9 deletions

View File

@ -97,12 +97,15 @@ class DefaultModelBuildingListener
projectBuildingHelper.createProjectRealm( model, projectBuildingRequest.getLocalRepository(),
pluginRepositories );
/*
* Update the context class loader so that the container will search the project realm when the model
* builder injects the lifecycle bindings from the packaging next. The class loader is reset by the project
* builder when the project is fully assembled.
*/
Thread.currentThread().setContextClassLoader( projectRealm );
if ( projectRealm != null )
{
/*
* Update the context class loader such that the container will search the project realm when the model
* builder injects the lifecycle bindings from the packaging in the next step. The context class loader
* will be reset by the project builder when the project is fully assembled.
*/
Thread.currentThread().setContextClassLoader( projectRealm );
}
}
}

View File

@ -302,7 +302,23 @@ public class DefaultProjectBuilder
.setRemoteRepostories( project.getRemoteArtifactRepositories() )
.setManagedVersionMap( project.getManagedVersionMap() );
ArtifactResolutionResult result = repositorySystem.resolve( artifactRequest );
ArtifactResolutionResult result;
ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
try
{
if ( project.getClassRealm() != null )
{
Thread.currentThread().setContextClassLoader( project.getClassRealm() );
}
result = repositorySystem.resolve( artifactRequest );
}
finally
{
Thread.currentThread().setContextClassLoader( oldContextClassLoader );
}
if ( result.hasExceptions() )
{

View File

@ -98,7 +98,7 @@ public class DefaultProjectBuildingHelper
List<ArtifactRepository> remoteRepositories )
throws ArtifactResolutionException
{
ClassRealm projectRealm = container.getContainerRealm();
ClassRealm projectRealm = null;
Build build = model.getBuild();

View File

@ -55,7 +55,7 @@ public interface ProjectBuildingHelper
* @param model The model to create the project realm for, must not be {@code null}
* @param localRepository The local repository to use for artifact resolution, must not be {@code null}.
* @param remoteRepositories The remote repositories to use for artifact resolution, must not be {@code null}.
* @return The project realm, never {@code null}.
* @return The project realm or {@code null} if the project uses no extensions.
* @throws ArtifactResolutionException If any build extension could not be resolved.
*/
ClassRealm createProjectRealm( Model model, ArtifactRepository localRepository,