mirror of https://github.com/apache/maven.git
o Used project realm during dependency resolution
o Fixed NPEs git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@793871 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2caa6b5112
commit
42340c1b92
|
@ -57,6 +57,7 @@ import org.apache.maven.project.MavenProject;
|
|||
import org.apache.maven.repository.RepositorySystem;
|
||||
import org.apache.maven.wagon.ResourceDoesNotExistException;
|
||||
import org.apache.maven.wagon.TransferFailedException;
|
||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||
import org.codehaus.plexus.component.annotations.Requirement;
|
||||
import org.codehaus.plexus.configuration.PlexusConfiguration;
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
|
@ -140,6 +141,8 @@ public class DefaultLifecycleExecutor
|
|||
goals = Collections.singletonList( goal );
|
||||
}
|
||||
}
|
||||
|
||||
ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
for ( MavenProject currentProject : session.getProjects() )
|
||||
{
|
||||
|
@ -157,6 +160,12 @@ public class DefaultLifecycleExecutor
|
|||
{
|
||||
session.setCurrentProject( currentProject );
|
||||
|
||||
ClassRealm projectRealm = currentProject.getClassRealm();
|
||||
if ( projectRealm != null )
|
||||
{
|
||||
Thread.currentThread().setContextClassLoader( projectRealm );
|
||||
}
|
||||
|
||||
MavenExecutionPlan executionPlan = calculateExecutionPlan( session, goals.toArray( new String[] {} ) );
|
||||
|
||||
//TODO: once we have calculated the build plan then we should accurately be able to download
|
||||
|
@ -215,6 +224,8 @@ public class DefaultLifecycleExecutor
|
|||
finally
|
||||
{
|
||||
session.setCurrentProject( null );
|
||||
|
||||
Thread.currentThread().setContextClassLoader( oldContextClassLoader );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,8 +72,6 @@ public class DefaultProjectBuilder
|
|||
|
||||
@Requirement
|
||||
private ResolutionErrorHandler resolutionErrorHandler;
|
||||
|
||||
private MavenProject standaloneProject;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// MavenProjectBuilder Implementation
|
||||
|
@ -143,6 +141,8 @@ public class DefaultProjectBuilder
|
|||
project.setRemoteArtifactRepositories( listener.getRemoteRepositories() );
|
||||
project.setPluginArtifactRepositories( listener.getPluginRepositories() );
|
||||
|
||||
project.setClassRealm( listener.getProjectRealm() );
|
||||
|
||||
try
|
||||
{
|
||||
if ( configuration.isProcessPlugins() )
|
||||
|
@ -252,11 +252,6 @@ public class DefaultProjectBuilder
|
|||
public MavenProject buildStandaloneSuperProject( ProjectBuildingRequest config )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
if ( standaloneProject != null )
|
||||
{
|
||||
return standaloneProject;
|
||||
}
|
||||
|
||||
ModelBuildingRequest request = getModelBuildingRequest( config );
|
||||
|
||||
ModelBuildingResult result;
|
||||
|
@ -269,15 +264,20 @@ public class DefaultProjectBuilder
|
|||
throw new ProjectBuildingException( "[standalone]", "Failed to build standalone project", e );
|
||||
}
|
||||
|
||||
MavenProject standaloneProject;
|
||||
|
||||
try
|
||||
{
|
||||
standaloneProject = new MavenProject( result.getEffectiveModel(), repositorySystem, this, config );
|
||||
}
|
||||
catch ( InvalidRepositoryException e )
|
||||
{
|
||||
// Not going to happen.
|
||||
throw new IllegalStateException( e );
|
||||
}
|
||||
|
||||
standaloneProject.setActiveProfiles( result.getActiveExternalProfiles() );
|
||||
standaloneProject.setInjectedProfileIds( "external", getProfileIds( result.getActiveExternalProfiles() ) );
|
||||
|
||||
standaloneProject.setExecutionRoot( true );
|
||||
|
||||
return standaloneProject;
|
||||
|
|
|
@ -98,11 +98,13 @@ public class DefaultProjectBuildingHelper
|
|||
List<ArtifactRepository> remoteRepositories )
|
||||
throws ArtifactResolutionException
|
||||
{
|
||||
ClassRealm projectRealm = container.getContainerRealm();
|
||||
|
||||
Build build = model.getBuild();
|
||||
|
||||
if ( build == null )
|
||||
{
|
||||
return null;
|
||||
return projectRealm;
|
||||
}
|
||||
|
||||
List<Plugin> extensionPlugins = new ArrayList<Plugin>();
|
||||
|
@ -117,7 +119,7 @@ public class DefaultProjectBuildingHelper
|
|||
|
||||
if ( build.getExtensions().isEmpty() && extensionPlugins.isEmpty() )
|
||||
{
|
||||
return null;
|
||||
return projectRealm;
|
||||
}
|
||||
|
||||
String realmId = model.getGroupId() + ':' + model.getArtifactId() + ':' + model.getVersion();
|
||||
|
@ -129,8 +131,6 @@ public class DefaultProjectBuildingHelper
|
|||
|
||||
ClassWorld world = ( (MutablePlexusContainer) container ).getClassWorld();
|
||||
|
||||
ClassRealm projectRealm;
|
||||
|
||||
synchronized ( world )
|
||||
{
|
||||
projectRealm = world.getClassRealm( realmId );
|
||||
|
|
|
@ -68,6 +68,7 @@ import org.apache.maven.model.Scm;
|
|||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
|
||||
import org.apache.maven.repository.RepositorySystem;
|
||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||
|
||||
|
@ -167,6 +168,8 @@ public class MavenProject
|
|||
|
||||
private Map<String, Object> context;
|
||||
|
||||
private ClassRealm classRealm;
|
||||
|
||||
//
|
||||
|
||||
public MavenProject()
|
||||
|
@ -380,16 +383,6 @@ public class MavenProject
|
|||
{
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public void setRemoteArtifactRepositories( List<ArtifactRepository> remoteArtifactRepositories )
|
||||
{
|
||||
this.remoteArtifactRepositories = remoteArtifactRepositories;
|
||||
}
|
||||
|
||||
public List<ArtifactRepository> getRemoteArtifactRepositories()
|
||||
{
|
||||
return remoteArtifactRepositories;
|
||||
}
|
||||
|
||||
public boolean hasParent()
|
||||
{
|
||||
|
@ -1346,6 +1339,21 @@ public class MavenProject
|
|||
return build;
|
||||
}
|
||||
|
||||
public void setRemoteArtifactRepositories( List<ArtifactRepository> remoteArtifactRepositories )
|
||||
{
|
||||
this.remoteArtifactRepositories = remoteArtifactRepositories;
|
||||
}
|
||||
|
||||
public List<ArtifactRepository> getRemoteArtifactRepositories()
|
||||
{
|
||||
if ( remoteArtifactRepositories == null )
|
||||
{
|
||||
remoteArtifactRepositories = new ArrayList<ArtifactRepository>();
|
||||
}
|
||||
|
||||
return remoteArtifactRepositories;
|
||||
}
|
||||
|
||||
public void setPluginArtifactRepositories( List<ArtifactRepository> pluginArtifactRepositories )
|
||||
{
|
||||
this.pluginArtifactRepositories = pluginArtifactRepositories;
|
||||
|
@ -1357,6 +1365,11 @@ public class MavenProject
|
|||
*/
|
||||
public List<ArtifactRepository> getPluginArtifactRepositories()
|
||||
{
|
||||
if ( pluginArtifactRepositories == null )
|
||||
{
|
||||
pluginArtifactRepositories = new ArrayList<ArtifactRepository>();
|
||||
}
|
||||
|
||||
return pluginArtifactRepositories;
|
||||
}
|
||||
|
||||
|
@ -1969,4 +1982,25 @@ public class MavenProject
|
|||
}
|
||||
return context.get( key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the project's class realm.
|
||||
*
|
||||
* @param classRealm The class realm hosting the build extensions of this project, may be {@code null}.
|
||||
*/
|
||||
public void setClassRealm( ClassRealm classRealm )
|
||||
{
|
||||
this.classRealm = classRealm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the project's class realm. This class realm hosts the build extensions of the project.
|
||||
*
|
||||
* @return The project's class realm or {@code null}.
|
||||
*/
|
||||
public ClassRealm getClassRealm()
|
||||
{
|
||||
return classRealm;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 or {@code null} if no build extensions are present.
|
||||
* @return The project realm, never {@code null}.
|
||||
* @throws ArtifactResolutionException If any build extension could not be resolved.
|
||||
*/
|
||||
ClassRealm createProjectRealm( Model model, ArtifactRepository localRepository,
|
||||
|
|
Loading…
Reference in New Issue