mirror of https://github.com/apache/maven.git
disable project-specific loading of extensions and plugins until we can figure out how to do it without causing OOME's.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@589904 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b97533f845
commit
00a1edc008
|
@ -65,7 +65,6 @@ import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jason van zyl
|
* @author jason van zyl
|
||||||
|
@ -184,8 +183,7 @@ public class DefaultMaven
|
||||||
MavenSession session = createSession(
|
MavenSession session = createSession(
|
||||||
request,
|
request,
|
||||||
reactorManager,
|
reactorManager,
|
||||||
dispatcher,
|
dispatcher );
|
||||||
request.getProjectSessions() );
|
|
||||||
|
|
||||||
for ( Iterator i = request.getGoals().iterator(); i.hasNext(); )
|
for ( Iterator i = request.getGoals().iterator(); i.hasNext(); )
|
||||||
{
|
{
|
||||||
|
@ -281,7 +279,7 @@ public class DefaultMaven
|
||||||
// instances just-in-time.
|
// instances just-in-time.
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
buildExtensionScanner.scanForBuildExtensions( files, request.getLocalRepository(), request.getProfileManager(), request.getProjectSessions() );
|
buildExtensionScanner.scanForBuildExtensions( files, request.getLocalRepository(), request.getProfileManager() );
|
||||||
}
|
}
|
||||||
catch ( ExtensionScanningException e )
|
catch ( ExtensionScanningException e )
|
||||||
{
|
{
|
||||||
|
@ -417,15 +415,13 @@ public class DefaultMaven
|
||||||
|
|
||||||
protected MavenSession createSession( MavenExecutionRequest request,
|
protected MavenSession createSession( MavenExecutionRequest request,
|
||||||
ReactorManager reactorManager,
|
ReactorManager reactorManager,
|
||||||
EventDispatcher dispatcher,
|
EventDispatcher dispatcher )
|
||||||
Map projectSessions )
|
|
||||||
{
|
{
|
||||||
MavenSession session = new MavenSession(
|
MavenSession session = new MavenSession(
|
||||||
container,
|
container,
|
||||||
request,
|
request,
|
||||||
dispatcher,
|
dispatcher,
|
||||||
reactorManager,
|
reactorManager );
|
||||||
projectSessions );
|
|
||||||
|
|
||||||
SessionContext ctx = new SessionContext( session );
|
SessionContext ctx = new SessionContext( session );
|
||||||
ctx.store( buildContextManager );
|
ctx.store( buildContextManager );
|
||||||
|
|
|
@ -28,9 +28,7 @@ import org.apache.maven.wagon.events.TransferListener;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,13 +60,6 @@ public class DefaultMavenExecutionRequest
|
||||||
|
|
||||||
private boolean isProjectPresent = true;
|
private boolean isProjectPresent = true;
|
||||||
|
|
||||||
/**
|
|
||||||
* These are {@link MavenProjectSession} instances, keyed by
|
|
||||||
* groupId:artifactId:version of the project, and used to lookup and store
|
|
||||||
* extension and plugin realms specific to that project.
|
|
||||||
*/
|
|
||||||
private Map projectSessions;
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// We need to allow per execution user and global settings as the embedder
|
// We need to allow per execution user and global settings as the embedder
|
||||||
// might be running in a mode where its executing many threads with totally
|
// might be running in a mode where its executing many threads with totally
|
||||||
|
@ -612,20 +603,4 @@ public class DefaultMavenExecutionRequest
|
||||||
{
|
{
|
||||||
return remoteRepositories;
|
return remoteRepositories;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map getProjectSessions()
|
|
||||||
{
|
|
||||||
if ( projectSessions == null )
|
|
||||||
{
|
|
||||||
projectSessions = new HashMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
return projectSessions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MavenExecutionRequest setProjectSessions( Map projectSessions )
|
|
||||||
{
|
|
||||||
this.projectSessions = projectSessions;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@ import org.codehaus.plexus.logging.Logger;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -203,7 +202,4 @@ public interface MavenExecutionRequest
|
||||||
|
|
||||||
MavenExecutionRequest addRemoteRepository( ArtifactRepository repository );
|
MavenExecutionRequest addRemoteRepository( ArtifactRepository repository );
|
||||||
List getRemoteRepositories();
|
List getRemoteRepositories();
|
||||||
|
|
||||||
MavenExecutionRequest setProjectSessions( Map projectSessions );
|
|
||||||
Map getProjectSessions();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,11 +25,9 @@ import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
import org.apache.maven.settings.Settings;
|
import org.apache.maven.settings.Settings;
|
||||||
import org.codehaus.plexus.PlexusContainer;
|
import org.codehaus.plexus.PlexusContainer;
|
||||||
import org.codehaus.plexus.PlexusContainerException;
|
|
||||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -53,13 +51,10 @@ public class MavenSession
|
||||||
|
|
||||||
private Map reports = new LinkedHashMap();
|
private Map reports = new LinkedHashMap();
|
||||||
|
|
||||||
private final Map projectSessions;
|
|
||||||
|
|
||||||
public MavenSession( PlexusContainer container,
|
public MavenSession( PlexusContainer container,
|
||||||
MavenExecutionRequest request,
|
MavenExecutionRequest request,
|
||||||
EventDispatcher eventDispatcher,
|
EventDispatcher eventDispatcher,
|
||||||
ReactorManager reactorManager,
|
ReactorManager reactorManager )
|
||||||
Map projectSessions )
|
|
||||||
{
|
{
|
||||||
this.container = container;
|
this.container = container;
|
||||||
|
|
||||||
|
@ -68,24 +63,6 @@ public class MavenSession
|
||||||
this.eventDispatcher = eventDispatcher;
|
this.eventDispatcher = eventDispatcher;
|
||||||
|
|
||||||
this.reactorManager = reactorManager;
|
this.reactorManager = reactorManager;
|
||||||
|
|
||||||
this.projectSessions = projectSessions == null ? new HashMap() : projectSessions;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Figure out how/when we can shut down all the realms for extensions/plugins connected to each project session...
|
|
||||||
public MavenProjectSession getProjectSession( MavenProject project )
|
|
||||||
throws PlexusContainerException
|
|
||||||
{
|
|
||||||
String id = MavenProjectSession.createProjectId( project.getGroupId(), project.getArtifactId(), project.getVersion() );
|
|
||||||
|
|
||||||
MavenProjectSession projectSession = (MavenProjectSession) projectSessions.get( id );
|
|
||||||
if ( projectSession == null )
|
|
||||||
{
|
|
||||||
projectSession = new MavenProjectSession( id, container );
|
|
||||||
projectSessions.put( id, projectSession );
|
|
||||||
}
|
|
||||||
|
|
||||||
return projectSession;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map getPluginContext( PluginDescriptor pluginDescriptor,
|
public Map getPluginContext( PluginDescriptor pluginDescriptor,
|
||||||
|
|
|
@ -24,7 +24,6 @@ import org.apache.maven.profiles.ProfileManager;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public interface BuildExtensionScanner
|
public interface BuildExtensionScanner
|
||||||
{
|
{
|
||||||
|
@ -33,14 +32,12 @@ public interface BuildExtensionScanner
|
||||||
|
|
||||||
void scanForBuildExtensions( List files,
|
void scanForBuildExtensions( List files,
|
||||||
ArtifactRepository localRepository,
|
ArtifactRepository localRepository,
|
||||||
ProfileManager globalProfileManager,
|
ProfileManager globalProfileManager )
|
||||||
Map projectSessions )
|
|
||||||
throws ExtensionScanningException;
|
throws ExtensionScanningException;
|
||||||
|
|
||||||
void scanForBuildExtensions( File pom,
|
void scanForBuildExtensions( File pom,
|
||||||
ArtifactRepository localRepository,
|
ArtifactRepository localRepository,
|
||||||
ProfileManager globalProfileManager,
|
ProfileManager globalProfileManager )
|
||||||
Map projectSessions )
|
|
||||||
throws ExtensionScanningException;
|
throws ExtensionScanningException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,8 +71,7 @@ public class DefaultBuildExtensionScanner
|
||||||
|
|
||||||
public void scanForBuildExtensions( List files,
|
public void scanForBuildExtensions( List files,
|
||||||
ArtifactRepository localRepository,
|
ArtifactRepository localRepository,
|
||||||
ProfileManager globalProfileManager,
|
ProfileManager globalProfileManager )
|
||||||
Map projectSessions )
|
|
||||||
throws ExtensionScanningException
|
throws ExtensionScanningException
|
||||||
{
|
{
|
||||||
List visited = new ArrayList();
|
List visited = new ArrayList();
|
||||||
|
@ -81,17 +80,16 @@ public class DefaultBuildExtensionScanner
|
||||||
{
|
{
|
||||||
File pom = (File) it.next();
|
File pom = (File) it.next();
|
||||||
|
|
||||||
scanInternal( pom, localRepository, globalProfileManager, visited, files, projectSessions );
|
scanInternal( pom, localRepository, globalProfileManager, visited, files );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scanForBuildExtensions( File pom,
|
public void scanForBuildExtensions( File pom,
|
||||||
ArtifactRepository localRepository,
|
ArtifactRepository localRepository,
|
||||||
ProfileManager globalProfileManager,
|
ProfileManager globalProfileManager )
|
||||||
Map projectSessions )
|
|
||||||
throws ExtensionScanningException
|
throws ExtensionScanningException
|
||||||
{
|
{
|
||||||
scanInternal( pom, localRepository, globalProfileManager, new ArrayList(), Collections.singletonList( pom ), projectSessions );
|
scanInternal( pom, localRepository, globalProfileManager, new ArrayList(), Collections.singletonList( pom ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Use a build-context cache object for visitedModelIdx and reactorFiles,
|
// TODO: Use a build-context cache object for visitedModelIdx and reactorFiles,
|
||||||
|
@ -100,8 +98,7 @@ public class DefaultBuildExtensionScanner
|
||||||
ArtifactRepository localRepository,
|
ArtifactRepository localRepository,
|
||||||
ProfileManager globalProfileManager,
|
ProfileManager globalProfileManager,
|
||||||
List visitedModelIds,
|
List visitedModelIds,
|
||||||
List reactorFiles,
|
List reactorFiles )
|
||||||
Map projectSessions )
|
|
||||||
throws ExtensionScanningException
|
throws ExtensionScanningException
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -158,7 +155,7 @@ public class DefaultBuildExtensionScanner
|
||||||
|
|
||||||
model = modelInterpolator.interpolate( model, inheritedInterpolationValues, false );
|
model = modelInterpolator.interpolate( model, inheritedInterpolationValues, false );
|
||||||
|
|
||||||
checkModelBuildForExtensions( model, localRepository, inheritedRemoteRepositories, projectSessions );
|
checkModelBuildForExtensions( model, localRepository, inheritedRemoteRepositories );
|
||||||
|
|
||||||
if ( !reactorFiles.contains( modelPom ) )
|
if ( !reactorFiles.contains( modelPom ) )
|
||||||
{
|
{
|
||||||
|
@ -174,8 +171,7 @@ public class DefaultBuildExtensionScanner
|
||||||
originalRemoteRepositories,
|
originalRemoteRepositories,
|
||||||
globalProfileManager,
|
globalProfileManager,
|
||||||
visitedModelIds,
|
visitedModelIds,
|
||||||
reactorFiles,
|
reactorFiles );
|
||||||
projectSessions );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Properties modelProps = model.getProperties();
|
Properties modelProps = model.getProperties();
|
||||||
|
@ -187,7 +183,7 @@ public class DefaultBuildExtensionScanner
|
||||||
|
|
||||||
getLogger().debug( "Finished pre-scanning: " + pom + " for build extensions." );
|
getLogger().debug( "Finished pre-scanning: " + pom + " for build extensions." );
|
||||||
|
|
||||||
extensionManager.registerWagons( projectSessions );
|
extensionManager.registerWagons();
|
||||||
}
|
}
|
||||||
catch ( ModelInterpolationException e )
|
catch ( ModelInterpolationException e )
|
||||||
{
|
{
|
||||||
|
@ -222,8 +218,7 @@ public class DefaultBuildExtensionScanner
|
||||||
List originalRemoteRepositories,
|
List originalRemoteRepositories,
|
||||||
ProfileManager globalProfileManager,
|
ProfileManager globalProfileManager,
|
||||||
List visitedModelIds,
|
List visitedModelIds,
|
||||||
List reactorFiles,
|
List reactorFiles )
|
||||||
Map projectSessions )
|
|
||||||
throws ExtensionScanningException
|
throws ExtensionScanningException
|
||||||
{
|
{
|
||||||
// FIXME: This gets a little sticky, because modules can be added by profiles that require
|
// FIXME: This gets a little sticky, because modules can be added by profiles that require
|
||||||
|
@ -289,12 +284,12 @@ public class DefaultBuildExtensionScanner
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
scanInternal( modulePomDirectory, localRepository, globalProfileManager, visitedModelIds, reactorFiles, projectSessions );
|
scanInternal( modulePomDirectory, localRepository, globalProfileManager, visitedModelIds, reactorFiles );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkModelBuildForExtensions( Model model, ArtifactRepository localRepository, List remoteRepositories, Map projectSessions )
|
private void checkModelBuildForExtensions( Model model, ArtifactRepository localRepository, List remoteRepositories )
|
||||||
throws ExtensionScanningException
|
throws ExtensionScanningException
|
||||||
{
|
{
|
||||||
Build build = model.getBuild();
|
Build build = model.getBuild();
|
||||||
|
@ -318,7 +313,7 @@ public class DefaultBuildExtensionScanner
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
extensionManager.addExtension( extension, model, remoteRepositories, localRepository, projectSessions );
|
extensionManager.addExtension( extension, model, remoteRepositories, localRepository );
|
||||||
}
|
}
|
||||||
catch ( ExtensionManagerException e )
|
catch ( ExtensionManagerException e )
|
||||||
{
|
{
|
||||||
|
|
|
@ -43,7 +43,6 @@ import org.apache.maven.plugin.DefaultPluginManager;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
import org.codehaus.plexus.MutablePlexusContainer;
|
import org.codehaus.plexus.MutablePlexusContainer;
|
||||||
import org.codehaus.plexus.PlexusConstants;
|
import org.codehaus.plexus.PlexusConstants;
|
||||||
import org.codehaus.plexus.PlexusContainerException;
|
|
||||||
import org.codehaus.plexus.classworlds.ClassWorld;
|
import org.codehaus.plexus.classworlds.ClassWorld;
|
||||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||||
import org.codehaus.plexus.classworlds.realm.DuplicateRealmException;
|
import org.codehaus.plexus.classworlds.realm.DuplicateRealmException;
|
||||||
|
@ -117,8 +116,7 @@ public class DefaultExtensionManager
|
||||||
public void addExtension( Extension extension,
|
public void addExtension( Extension extension,
|
||||||
Model originatingModel,
|
Model originatingModel,
|
||||||
List remoteRepositories,
|
List remoteRepositories,
|
||||||
ArtifactRepository localRepository,
|
ArtifactRepository localRepository )
|
||||||
Map projectSessions )
|
|
||||||
throws ExtensionManagerException
|
throws ExtensionManagerException
|
||||||
{
|
{
|
||||||
Artifact extensionArtifact = artifactFactory.createBuildArtifact( extension.getGroupId(),
|
Artifact extensionArtifact = artifactFactory.createBuildArtifact( extension.getGroupId(),
|
||||||
|
@ -150,14 +148,12 @@ public class DefaultExtensionManager
|
||||||
remoteRepositories,
|
remoteRepositories,
|
||||||
localRepository,
|
localRepository,
|
||||||
null,
|
null,
|
||||||
projectSessions,
|
|
||||||
MavenProjectSession.createProjectId( groupId, artifactId, version ) );
|
MavenProjectSession.createProjectId( groupId, artifactId, version ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addExtension( Extension extension,
|
public void addExtension( Extension extension,
|
||||||
MavenProject project,
|
MavenProject project,
|
||||||
ArtifactRepository localRepository,
|
ArtifactRepository localRepository )
|
||||||
Map projectSessions )
|
|
||||||
throws ExtensionManagerException
|
throws ExtensionManagerException
|
||||||
{
|
{
|
||||||
String extensionId = ArtifactUtils.versionlessKey( extension.getGroupId(), extension.getArtifactId() );
|
String extensionId = ArtifactUtils.versionlessKey( extension.getGroupId(), extension.getArtifactId() );
|
||||||
|
@ -171,40 +167,24 @@ public class DefaultExtensionManager
|
||||||
project.getRemoteArtifactRepositories(),
|
project.getRemoteArtifactRepositories(),
|
||||||
localRepository,
|
localRepository,
|
||||||
new ActiveArtifactResolver( project ),
|
new ActiveArtifactResolver( project ),
|
||||||
projectSessions,
|
|
||||||
MavenProjectSession.createProjectId( project.getGroupId(), project.getArtifactId(), project.getVersion() ) );
|
MavenProjectSession.createProjectId( project.getGroupId(), project.getArtifactId(), project.getVersion() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String createExtensionRealmId( Artifact realmArtifact )
|
||||||
|
{
|
||||||
|
return "/extensions/" + ArtifactUtils.versionlessKey( realmArtifact );
|
||||||
|
}
|
||||||
|
|
||||||
private void addExtension( Artifact extensionArtifact,
|
private void addExtension( Artifact extensionArtifact,
|
||||||
Artifact projectArtifact,
|
Artifact projectArtifact,
|
||||||
List remoteRepositories,
|
List remoteRepositories,
|
||||||
ArtifactRepository localRepository,
|
ArtifactRepository localRepository,
|
||||||
ActiveArtifactResolver activeArtifactResolver,
|
ActiveArtifactResolver activeArtifactResolver,
|
||||||
Map projectSessions,
|
|
||||||
String projectId )
|
String projectId )
|
||||||
throws ExtensionManagerException
|
throws ExtensionManagerException
|
||||||
{
|
{
|
||||||
getLogger().debug( "Starting extension-addition process for: " + extensionArtifact );
|
getLogger().debug( "Starting extension-addition process for: " + extensionArtifact );
|
||||||
|
|
||||||
// create a new MavenProjectSession instance for the current project.
|
|
||||||
// This session instance will house the plugin and extension realms that
|
|
||||||
// pertain to this specific project, along with containing the project-level
|
|
||||||
// realm to use as a lookupRealm in the lifecycle executor and plugin manager.
|
|
||||||
MavenProjectSession projectSession = (MavenProjectSession) projectSessions.get( projectId );
|
|
||||||
if ( projectSession == null )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
projectSession = new MavenProjectSession( projectId, container );
|
|
||||||
}
|
|
||||||
catch ( PlexusContainerException e )
|
|
||||||
{
|
|
||||||
throw new ExtensionManagerException( "Failed to create project realm for: " + projectId, projectId, e );
|
|
||||||
}
|
|
||||||
|
|
||||||
projectSessions.put( projectId, projectSession );
|
|
||||||
}
|
|
||||||
|
|
||||||
ArtifactFilter coreFilter = artifactFilterManager.getArtifactFilter();
|
ArtifactFilter coreFilter = artifactFilterManager.getArtifactFilter();
|
||||||
|
|
||||||
// if the extension is null,
|
// if the extension is null,
|
||||||
|
@ -213,9 +193,21 @@ public class DefaultExtensionManager
|
||||||
//
|
//
|
||||||
// skip it.
|
// skip it.
|
||||||
if ( ( extensionArtifact != null )
|
if ( ( extensionArtifact != null )
|
||||||
&& !projectSession.containsExtensionRealm( extensionArtifact )
|
|
||||||
&& coreFilter.include( extensionArtifact ) )
|
&& coreFilter.include( extensionArtifact ) )
|
||||||
{
|
{
|
||||||
|
String realmId = createExtensionRealmId( extensionArtifact );
|
||||||
|
try
|
||||||
|
{
|
||||||
|
container.getClassWorld().getRealm( realmId );
|
||||||
|
|
||||||
|
// if we find the realm, we don't need to proceed, we've already added this extension.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
catch ( NoSuchRealmException e )
|
||||||
|
{
|
||||||
|
// proceed.
|
||||||
|
}
|
||||||
|
|
||||||
ArtifactFilter filter =
|
ArtifactFilter filter =
|
||||||
new ProjectArtifactExceptionFilter( coreFilter, projectArtifact );
|
new ProjectArtifactExceptionFilter( coreFilter, projectArtifact );
|
||||||
|
|
||||||
|
@ -266,7 +258,7 @@ public class DefaultExtensionManager
|
||||||
ClassRealm extensionRealm;
|
ClassRealm extensionRealm;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
extensionRealm = projectSession.createExtensionRealm( extensionArtifact );
|
extensionRealm = container.getContainerRealm().createChildRealm( realmId );
|
||||||
}
|
}
|
||||||
catch ( DuplicateRealmException e )
|
catch ( DuplicateRealmException e )
|
||||||
{
|
{
|
||||||
|
@ -294,17 +286,15 @@ public class DefaultExtensionManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
importLocalExtensionComponents( extensionRealm, projectSession, extensionArtifact );
|
importLocalExtensionComponents( extensionRealm, projectId, extensionArtifact );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void importLocalExtensionComponents( ClassRealm extensionRealm,
|
private void importLocalExtensionComponents( ClassRealm extensionRealm,
|
||||||
MavenProjectSession projectSession,
|
String projectId,
|
||||||
Artifact extensionArtifact )
|
Artifact extensionArtifact )
|
||||||
throws ExtensionManagerException
|
throws ExtensionManagerException
|
||||||
{
|
{
|
||||||
String projectId = projectSession.getProjectId();
|
|
||||||
|
|
||||||
ClassWorld discoveryWorld = new ClassWorld();
|
ClassWorld discoveryWorld = new ClassWorld();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -324,7 +314,7 @@ public class DefaultExtensionManager
|
||||||
ComponentDiscoverer discoverer = new DefaultComponentDiscoverer();
|
ComponentDiscoverer discoverer = new DefaultComponentDiscoverer();
|
||||||
discoverer.setManager( new DummyDiscovererManager() );
|
discoverer.setManager( new DummyDiscovererManager() );
|
||||||
|
|
||||||
ClassRealm projectRealm = projectSession.getProjectRealm();
|
ClassRealm realm = container.getContainerRealm();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Find the extension component descriptors that exist ONLY in the immediate extension
|
// Find the extension component descriptors that exist ONLY in the immediate extension
|
||||||
|
@ -342,18 +332,18 @@ public class DefaultExtensionManager
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
getLogger().debug( "Importing: " + implementation + "\nwith role: " + comp.getRole() + "\nand hint: " + comp.getRoleHint() + "\nfrom extension realm: " + extensionRealm.getId() + "\nto project realm: " + projectRealm.getId() );
|
getLogger().debug( "Importing: " + implementation + "\nwith role: " + comp.getRole() + "\nand hint: " + comp.getRoleHint() + "\nfrom extension realm: " + extensionRealm.getId() + "\nto container realm: " + realm.getId() );
|
||||||
|
|
||||||
// Import the extension component's implementation class into the project-level
|
// Import the extension component's implementation class into the project-level
|
||||||
// realm.
|
// realm.
|
||||||
projectRealm.importFrom( extensionRealm.getId(), implementation );
|
realm.importFrom( extensionRealm.getId(), implementation );
|
||||||
|
|
||||||
// Set the realmId to be used in looking up this extension component to the
|
// Set the realmId to be used in looking up this extension component to the
|
||||||
// project-level realm, since we now have a restricted import
|
// project-level realm, since we now have a restricted import
|
||||||
// that allows most of the extension to stay hidden, and the
|
// that allows most of the extension to stay hidden, and the
|
||||||
// specific local extension components are still accessible
|
// specific local extension components are still accessible
|
||||||
// from the project-level realm.
|
// from the project-level realm.
|
||||||
comp.setRealmId( projectRealm.getId() );
|
comp.setRealmId( realm.getId() );
|
||||||
|
|
||||||
// Finally, add the extension component's descriptor (with projectRealm
|
// Finally, add the extension component's descriptor (with projectRealm
|
||||||
// set as the lookup realm) to the container.
|
// set as the lookup realm) to the container.
|
||||||
|
@ -361,7 +351,7 @@ public class DefaultExtensionManager
|
||||||
}
|
}
|
||||||
catch ( NoSuchRealmException e )
|
catch ( NoSuchRealmException e )
|
||||||
{
|
{
|
||||||
throw new ExtensionManagerException( "Failed to create import for component: " + implementation + " from extension realm: " + extensionRealm.getId() + " to project realm: " + projectRealm.getId(), extensionArtifact, projectId, e );
|
throw new ExtensionManagerException( "Failed to create import for component: " + implementation + " from extension realm: " + extensionRealm.getId() + " to project realm: " + realm.getId(), extensionArtifact, projectId, e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -392,18 +382,9 @@ public class DefaultExtensionManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerWagons( Map projectSessions )
|
public void registerWagons()
|
||||||
{
|
{
|
||||||
for ( Iterator it = projectSessions.values().iterator(); it.hasNext(); )
|
|
||||||
{
|
|
||||||
MavenProjectSession projectSession = (MavenProjectSession) it.next();
|
|
||||||
|
|
||||||
ClassRealm oldRealm = container.setLookupRealm( projectSession.getProjectRealm() );
|
|
||||||
|
|
||||||
wagonManager.findAndRegisterWagons( container );
|
wagonManager.findAndRegisterWagons( container );
|
||||||
|
|
||||||
container.setLookupRealm( oldRealm );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void contextualize( Context context )
|
public void contextualize( Context context )
|
||||||
|
|
|
@ -25,7 +25,6 @@ import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to locate extensions.
|
* Used to locate extensions.
|
||||||
|
@ -35,12 +34,12 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
public interface ExtensionManager
|
public interface ExtensionManager
|
||||||
{
|
{
|
||||||
void addExtension( Extension extension, MavenProject project, ArtifactRepository localRepository, Map projectSessions )
|
void addExtension( Extension extension, MavenProject project, ArtifactRepository localRepository )
|
||||||
throws ExtensionManagerException;
|
throws ExtensionManagerException;
|
||||||
|
|
||||||
void registerWagons( Map projectSessions );
|
void registerWagons();
|
||||||
|
|
||||||
void addExtension( Extension extension, Model originatingModel, List remoteRepositories,
|
void addExtension( Extension extension, Model originatingModel, List remoteRepositories,
|
||||||
ArtifactRepository localRepository, Map projectSessions )
|
ArtifactRepository localRepository )
|
||||||
throws ExtensionManagerException;
|
throws ExtensionManagerException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,8 @@ public class ExtensionManagerException
|
||||||
{
|
{
|
||||||
|
|
||||||
private Artifact extensionArtifact;
|
private Artifact extensionArtifact;
|
||||||
private final String projectId;
|
|
||||||
private ArtifactResolutionResult resolutionResult;
|
private ArtifactResolutionResult resolutionResult;
|
||||||
|
private String projectId;
|
||||||
|
|
||||||
public ExtensionManagerException( String message,
|
public ExtensionManagerException( String message,
|
||||||
Artifact extensionArtifact,
|
Artifact extensionArtifact,
|
||||||
|
|
|
@ -28,7 +28,6 @@ import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||||
import org.apache.maven.context.BuildContextManager;
|
import org.apache.maven.context.BuildContextManager;
|
||||||
import org.apache.maven.execution.MavenProjectSession;
|
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.execution.ReactorManager;
|
import org.apache.maven.execution.ReactorManager;
|
||||||
import org.apache.maven.lifecycle.binding.MojoBindingFactory;
|
import org.apache.maven.lifecycle.binding.MojoBindingFactory;
|
||||||
|
@ -57,7 +56,6 @@ import org.apache.maven.project.MavenProject;
|
||||||
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
||||||
import org.codehaus.plexus.PlexusConstants;
|
import org.codehaus.plexus.PlexusConstants;
|
||||||
import org.codehaus.plexus.PlexusContainer;
|
import org.codehaus.plexus.PlexusContainer;
|
||||||
import org.codehaus.plexus.PlexusContainerException;
|
|
||||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||||
import org.codehaus.plexus.context.Context;
|
import org.codehaus.plexus.context.Context;
|
||||||
|
@ -404,26 +402,29 @@ public class DefaultLifecycleExecutor
|
||||||
MavenProject rootProject )
|
MavenProject rootProject )
|
||||||
throws LifecycleExecutionException
|
throws LifecycleExecutionException
|
||||||
{
|
{
|
||||||
MavenProjectSession projectSession;
|
// MavenProjectSession projectSession;
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
projectSession = session.getProjectSession( rootProject );
|
// projectSession = session.getProjectSession( rootProject );
|
||||||
}
|
// }
|
||||||
catch ( PlexusContainerException e )
|
// catch ( PlexusContainerException e )
|
||||||
{
|
// {
|
||||||
throw new LifecycleExecutionException(
|
// throw new LifecycleExecutionException(
|
||||||
"Failed to create project-specific session for: "
|
// "Failed to create project-specific session for: "
|
||||||
+ rootProject.getId(),
|
// + rootProject.getId(),
|
||||||
rootProject, e );
|
// rootProject, e );
|
||||||
}
|
// }
|
||||||
if ( projectSession != null )
|
// if ( projectSession != null )
|
||||||
{
|
// {
|
||||||
return container.setLookupRealm( projectSession.getProjectRealm() );
|
// return container.setLookupRealm( projectSession.getProjectRealm() );
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
// TODO: Fix this to use project-level realm!
|
||||||
|
return container.getLookupRealm();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.apache.maven.plugin;
|
||||||
|
|
||||||
import org.apache.maven.ArtifactFilterManager;
|
import org.apache.maven.ArtifactFilterManager;
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
|
import org.apache.maven.artifact.ArtifactUtils;
|
||||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||||
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
||||||
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
||||||
|
@ -36,7 +37,6 @@ import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
||||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||||
import org.apache.maven.artifact.versioning.VersionRange;
|
import org.apache.maven.artifact.versioning.VersionRange;
|
||||||
import org.apache.maven.context.BuildContextManager;
|
import org.apache.maven.context.BuildContextManager;
|
||||||
import org.apache.maven.execution.MavenProjectSession;
|
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.execution.RuntimeInformation;
|
import org.apache.maven.execution.RuntimeInformation;
|
||||||
import org.apache.maven.lifecycle.LifecycleExecutionContext;
|
import org.apache.maven.lifecycle.LifecycleExecutionContext;
|
||||||
|
@ -66,7 +66,6 @@ import org.codehaus.plexus.PlexusConstants;
|
||||||
import org.codehaus.plexus.PlexusContainer;
|
import org.codehaus.plexus.PlexusContainer;
|
||||||
import org.codehaus.plexus.PlexusContainerException;
|
import org.codehaus.plexus.PlexusContainerException;
|
||||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||||
import org.codehaus.plexus.classworlds.realm.DuplicateRealmException;
|
|
||||||
import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
|
import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
|
||||||
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
|
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
|
||||||
import org.codehaus.plexus.component.configurator.ComponentConfigurator;
|
import org.codehaus.plexus.component.configurator.ComponentConfigurator;
|
||||||
|
@ -86,7 +85,6 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
|
||||||
import org.codehaus.plexus.util.StringUtils;
|
import org.codehaus.plexus.util.StringUtils;
|
||||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -319,6 +317,11 @@ public class DefaultPluginManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String createPluginRealmId( String groupId, String artifactId )
|
||||||
|
{
|
||||||
|
return "/plugins/" + ArtifactUtils.versionlessKey( groupId, artifactId );
|
||||||
|
}
|
||||||
|
|
||||||
protected void addPlugin( Plugin plugin,
|
protected void addPlugin( Plugin plugin,
|
||||||
Artifact pluginArtifact,
|
Artifact pluginArtifact,
|
||||||
MavenProject project,
|
MavenProject project,
|
||||||
|
@ -347,21 +350,25 @@ public class DefaultPluginManager
|
||||||
|
|
||||||
ClassRealm pluginRealm = null;
|
ClassRealm pluginRealm = null;
|
||||||
|
|
||||||
MavenProjectSession projectSession;
|
// MavenProjectSession projectSession;
|
||||||
|
//
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// projectSession = session.getProjectSession( project );
|
||||||
|
// }
|
||||||
|
// catch ( PlexusContainerException e )
|
||||||
|
// {
|
||||||
|
// throw new PluginManagerException( plugin, "Failed to create project-specific session for project: " + project.getId()
|
||||||
|
// + ".", project, e );
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
|
||||||
|
String pluginRealmId = createPluginRealmId( projectPlugin.getGroupId(), projectPlugin.getArtifactId() );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
projectSession = session.getProjectSession( project );
|
// pluginRealm = projectSession.getPluginRealm( projectPlugin );
|
||||||
}
|
pluginRealm = container.getClassWorld().getRealm( pluginRealmId );
|
||||||
catch ( PlexusContainerException e )
|
|
||||||
{
|
|
||||||
throw new PluginManagerException( plugin, "Failed to create project-specific session for project: " + project.getId()
|
|
||||||
+ ".", project, e );
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pluginRealm = projectSession.getPluginRealm( projectPlugin );
|
|
||||||
}
|
}
|
||||||
catch ( NoSuchRealmException e )
|
catch ( NoSuchRealmException e )
|
||||||
{
|
{
|
||||||
|
@ -386,32 +393,40 @@ public class DefaultPluginManager
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pluginRealm = projectSession.createPluginRealm( projectPlugin );
|
// pluginRealm = projectSession.createPluginRealm( projectPlugin );
|
||||||
|
|
||||||
try
|
List jars = new ArrayList();
|
||||||
{
|
|
||||||
pluginRealm.addURL( pluginArtifact.getFile().toURI().toURL() );
|
jars.add( pluginArtifact.getFile() );
|
||||||
}
|
// try
|
||||||
catch ( MalformedURLException e )
|
// {
|
||||||
{
|
// pluginRealm.addURL( pluginArtifact.getFile().toURI().toURL() );
|
||||||
throw new PluginContainerException( plugin, pluginRealm, "Error rendering plugin artifact: " + pluginArtifact.getId() + " as URL.", e );
|
// }
|
||||||
}
|
// catch ( MalformedURLException e )
|
||||||
|
// {
|
||||||
|
// throw new PluginContainerException( plugin, pluginRealm, "Error rendering plugin artifact: " + pluginArtifact.getId() + " as URL.", e );
|
||||||
|
// }
|
||||||
|
|
||||||
for ( Iterator i = artifacts.iterator(); i.hasNext(); )
|
for ( Iterator i = artifacts.iterator(); i.hasNext(); )
|
||||||
{
|
{
|
||||||
Artifact artifact = (Artifact) i.next();
|
Artifact artifact = (Artifact) i.next();
|
||||||
|
|
||||||
try
|
// getLogger().debug( "Adding: " + artifact.getId() + " to plugin class-realm: " + key + " in project-session: " + project.getId() );
|
||||||
{
|
|
||||||
getLogger().debug( "Adding: " + artifact.getId() + " to plugin class-realm: " + key + " in project-session: " + project.getId() );
|
getLogger().debug( "Adding: " + artifact.getId() + " to plugin class-realm: " + key );
|
||||||
pluginRealm.addURL( artifact.getFile().toURI().toURL() );
|
jars.add( artifact.getFile() );
|
||||||
}
|
// try
|
||||||
catch ( MalformedURLException e )
|
// {
|
||||||
{
|
// pluginRealm.addURL( artifact.getFile().toURI().toURL() );
|
||||||
throw new PluginContainerException( plugin, pluginRealm, "Error rendering plugin artifact: " + artifact.getId() + " as URL.", e );
|
// }
|
||||||
}
|
// catch ( MalformedURLException e )
|
||||||
|
// {
|
||||||
|
// throw new PluginContainerException( plugin, pluginRealm, "Error rendering plugin artifact: " + artifact.getId() + " as URL.", e );
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pluginRealm = container.createComponentRealm( pluginRealmId, jars );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
getLogger().debug( "Discovering components in realm: " + pluginRealm );
|
getLogger().debug( "Discovering components in realm: " + pluginRealm );
|
||||||
|
@ -427,10 +442,16 @@ public class DefaultPluginManager
|
||||||
throw new PluginContainerException( plugin, pluginRealm, "Error re-scanning project realm for components.", e );
|
throw new PluginContainerException( plugin, pluginRealm, "Error re-scanning project realm for components.", e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch ( DuplicateRealmException e )
|
// catch ( DuplicateRealmException e )
|
||||||
|
// {
|
||||||
|
// throw new PluginContainerException( plugin, pluginRealm, "Failed to create project-specific realm for plugin '" + projectPlugin
|
||||||
|
// + " in project: " + project.getId(), e );
|
||||||
|
// }
|
||||||
|
catch ( PlexusContainerException e )
|
||||||
{
|
{
|
||||||
throw new PluginContainerException( plugin, pluginRealm, "Failed to create project-specific realm for plugin '" + projectPlugin
|
throw new PluginContainerException( plugin, pluginRealm,
|
||||||
+ " in project: " + project.getId(), e );
|
"Failed to create realm for plugin '"
|
||||||
|
+ projectPlugin, e );
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -664,26 +685,31 @@ public class DefaultPluginManager
|
||||||
|
|
||||||
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
|
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
|
||||||
|
|
||||||
MavenProjectSession projectSession;
|
// MavenProjectSession projectSession;
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
projectSession = session.getProjectSession( project );
|
// projectSession = session.getProjectSession( project );
|
||||||
}
|
// }
|
||||||
catch ( PlexusContainerException e )
|
// catch ( PlexusContainerException e )
|
||||||
{
|
// {
|
||||||
throw new PluginManagerException( mojoDescriptor, "Failed to create project-specific session for project: " + project.getId()
|
// throw new PluginManagerException( mojoDescriptor, "Failed to create project-specific session for project: " + project.getId()
|
||||||
+ ".", project, e );
|
// + ".", project, e );
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
String pluginRealmId = createPluginRealmId( pluginDescriptor.getGroupId(), pluginDescriptor.getArtifactId() );
|
||||||
ClassRealm pluginRealm;
|
ClassRealm pluginRealm;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pluginRealm = projectSession.getPluginRealm( pluginDescriptor );
|
// pluginRealm = projectSession.getPluginRealm( pluginDescriptor );
|
||||||
|
pluginRealm = container.getClassWorld().getRealm( pluginRealmId );
|
||||||
}
|
}
|
||||||
catch ( NoSuchRealmException e )
|
catch ( NoSuchRealmException e )
|
||||||
{
|
{
|
||||||
getLogger().debug( "Plugin realm: " + pluginDescriptor.getId() + " not found in project session for: " + project.getId() + ". Using project realm instead." );
|
// getLogger().debug( "Plugin realm: " + pluginDescriptor.getId() + " not found in project session for: " + project.getId() + ". Using project realm instead." );
|
||||||
pluginRealm = projectSession.getProjectRealm();
|
// pluginRealm = projectSession.getProjectRealm();
|
||||||
|
|
||||||
|
getLogger().debug( "Plugin realm: " + pluginRealmId + " not found. Using container realm instead." );
|
||||||
|
pluginRealm = container.getContainerRealm();
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassRealm oldRealm = null;
|
ClassRealm oldRealm = null;
|
||||||
|
@ -804,48 +830,60 @@ public class DefaultPluginManager
|
||||||
|
|
||||||
Mojo plugin;
|
Mojo plugin;
|
||||||
|
|
||||||
ClassRealm realm = null;
|
// ClassRealm pluginRealm = null;
|
||||||
|
//
|
||||||
|
// MavenProjectSession projectSession;
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// projectSession = session.getProjectSession( project );
|
||||||
|
// }
|
||||||
|
// catch ( PlexusContainerException e )
|
||||||
|
// {
|
||||||
|
// throw new PluginManagerException( mojoDescriptor, "Failed to create project-specific session for project: " + project.getId()
|
||||||
|
// + ".", project, e );
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// pluginRealm = projectSession.getPluginRealm( pluginDescriptor );
|
||||||
|
// }
|
||||||
|
// catch ( NoSuchRealmException e )
|
||||||
|
// {
|
||||||
|
// getLogger().debug( "Plugin realm: " + pluginDescriptor.getId() + " not found in project session for: " + project.getId() + ". Using project realm instead." );
|
||||||
|
// pluginRealm = projectSession.getProjectRealm();
|
||||||
|
// }
|
||||||
|
|
||||||
MavenProjectSession projectSession;
|
String pluginRealmId = createPluginRealmId( pluginDescriptor.getGroupId(), pluginDescriptor.getArtifactId() );
|
||||||
|
ClassRealm pluginRealm;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
projectSession = session.getProjectSession( project );
|
pluginRealm = container.getClassWorld().getRealm( pluginRealmId );
|
||||||
}
|
|
||||||
catch ( PlexusContainerException e )
|
|
||||||
{
|
|
||||||
throw new PluginManagerException( mojoDescriptor, "Failed to create project-specific session for project: " + project.getId()
|
|
||||||
+ ".", project, e );
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
realm = projectSession.getPluginRealm( pluginDescriptor );
|
|
||||||
}
|
}
|
||||||
catch ( NoSuchRealmException e )
|
catch ( NoSuchRealmException e )
|
||||||
{
|
{
|
||||||
getLogger().debug( "Plugin realm: " + pluginDescriptor.getId() + " not found in project session for: " + project.getId() + ". Using project realm instead." );
|
getLogger().debug( "Plugin realm: " + pluginRealmId + " not found. Using container realm instead." );
|
||||||
realm = projectSession.getProjectRealm();
|
pluginRealm = container.getContainerRealm();
|
||||||
}
|
}
|
||||||
|
|
||||||
// We are forcing the use of the plugin realm for all lookups that might occur during
|
// We are forcing the use of the plugin realm for all lookups that might occur during
|
||||||
// the lifecycle that is part of the lookup. Here we are specifically trying to keep
|
// the lifecycle that is part of the lookup. Here we are specifically trying to keep
|
||||||
// lookups that occur in contextualize calls in line with the right realm.
|
// lookups that occur in contextualize calls in line with the right realm.
|
||||||
|
|
||||||
ClassRealm oldRealm = container.setLookupRealm( realm );
|
ClassRealm oldRealm = container.setLookupRealm( pluginRealm );
|
||||||
pluginDescriptor.setClassRealm( realm );
|
pluginDescriptor.setClassRealm( pluginRealm );
|
||||||
|
|
||||||
getLogger().debug(
|
getLogger().debug(
|
||||||
"Looking up mojo " + mojoDescriptor.getRoleHint() + " in realm "
|
"Looking up mojo " + mojoDescriptor.getRoleHint() + " in realm "
|
||||||
+ realm.getId() + " - descRealmId="
|
+ pluginRealm.getId() + " - descRealmId="
|
||||||
+ mojoDescriptor.getRealmId() );
|
+ mojoDescriptor.getRealmId() );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
plugin = (Mojo) container.lookup( Mojo.ROLE, mojoDescriptor.getRoleHint(), realm );
|
plugin = (Mojo) container.lookup( Mojo.ROLE, mojoDescriptor.getRoleHint(), pluginRealm );
|
||||||
}
|
}
|
||||||
catch ( ComponentLookupException e )
|
catch ( ComponentLookupException e )
|
||||||
{
|
{
|
||||||
throw new PluginContainerException( mojoDescriptor, realm, "Unable to find the mojo '"
|
throw new PluginContainerException( mojoDescriptor, pluginRealm, "Unable to find the mojo '"
|
||||||
+ mojoDescriptor.getRoleHint() + "' in the plugin '"
|
+ mojoDescriptor.getRoleHint() + "' in the plugin '"
|
||||||
+ pluginDescriptor.getPluginLookupKey() + "'", e );
|
+ pluginDescriptor.getPluginLookupKey() + "'", e );
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.apache.maven.plugin;
|
||||||
|
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||||
|
import org.codehaus.plexus.PlexusContainerException;
|
||||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||||
import org.codehaus.plexus.classworlds.realm.DuplicateRealmException;
|
import org.codehaus.plexus.classworlds.realm.DuplicateRealmException;
|
||||||
import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
|
import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
|
||||||
|
@ -87,6 +88,16 @@ public class PluginContainerException
|
||||||
this.pluginRealm = pluginRealm;
|
this.pluginRealm = pluginRealm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PluginContainerException( Plugin plugin,
|
||||||
|
ClassRealm pluginRealm,
|
||||||
|
String message,
|
||||||
|
PlexusContainerException e )
|
||||||
|
{
|
||||||
|
super( plugin, message, e );
|
||||||
|
|
||||||
|
this.pluginRealm = pluginRealm;
|
||||||
|
}
|
||||||
|
|
||||||
public ClassRealm getPluginRealm()
|
public ClassRealm getPluginRealm()
|
||||||
{
|
{
|
||||||
return pluginRealm;
|
return pluginRealm;
|
||||||
|
|
|
@ -172,6 +172,17 @@ public class PluginManagerException
|
||||||
goal = mojoDescriptor.getGoal();
|
goal = mojoDescriptor.getGoal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PluginManagerException( Plugin plugin,
|
||||||
|
String message,
|
||||||
|
PlexusContainerException cause )
|
||||||
|
{
|
||||||
|
super( message, cause );
|
||||||
|
|
||||||
|
pluginGroupId = plugin.getGroupId();
|
||||||
|
pluginArtifactId = plugin.getArtifactId();
|
||||||
|
pluginVersion = plugin.getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
public String getPluginGroupId()
|
public String getPluginGroupId()
|
||||||
{
|
{
|
||||||
return pluginGroupId;
|
return pluginGroupId;
|
||||||
|
|
|
@ -9,14 +9,12 @@ import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
|
||||||
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
|
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
|
||||||
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
|
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
||||||
import org.apache.maven.execution.MavenProjectSession;
|
|
||||||
import org.apache.maven.lifecycle.mapping.LifecycleMapping;
|
import org.apache.maven.lifecycle.mapping.LifecycleMapping;
|
||||||
import org.apache.maven.model.Build;
|
import org.apache.maven.model.Build;
|
||||||
import org.apache.maven.model.Extension;
|
import org.apache.maven.model.Extension;
|
||||||
import org.apache.maven.model.Model;
|
import org.apache.maven.model.Model;
|
||||||
import org.codehaus.plexus.MutablePlexusContainer;
|
import org.codehaus.plexus.MutablePlexusContainer;
|
||||||
import org.codehaus.plexus.PlexusTestCase;
|
import org.codehaus.plexus.PlexusTestCase;
|
||||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
|
||||||
import org.codehaus.plexus.logging.Logger;
|
import org.codehaus.plexus.logging.Logger;
|
||||||
import org.codehaus.plexus.util.FileUtils;
|
import org.codehaus.plexus.util.FileUtils;
|
||||||
|
|
||||||
|
@ -24,11 +22,9 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class DefaultExtensionManagerTest
|
public class DefaultExtensionManagerTest
|
||||||
|
@ -114,25 +110,14 @@ public class DefaultExtensionManagerTest
|
||||||
|
|
||||||
ExtensionManager mgr = newDefaultExtensionManager();
|
ExtensionManager mgr = newDefaultExtensionManager();
|
||||||
|
|
||||||
Map projectSessions = new HashMap();
|
mgr.addExtension( ext, model, remoteRepositories, localRepository );
|
||||||
|
|
||||||
mgr.addExtension( ext, model, remoteRepositories, localRepository, projectSessions );
|
List compList = getContainer().getComponentDescriptorList( ArtifactFactory.ROLE );
|
||||||
|
|
||||||
MavenProjectSession projectSession = (MavenProjectSession) projectSessions.get( MavenProjectSession.createProjectId( model.getGroupId(),
|
|
||||||
model.getArtifactId(),
|
|
||||||
model.getVersion() ) );
|
|
||||||
|
|
||||||
List compList = getContainer().getComponentDescriptorList( ArtifactFactory.ROLE,
|
|
||||||
projectSession.getProjectRealm() );
|
|
||||||
|
|
||||||
System.out.println( "Got: " + compList );
|
System.out.println( "Got: " + compList );
|
||||||
|
|
||||||
ClassRealm oldRealm = getContainer().setLookupRealm( projectSession.getProjectRealm() );
|
|
||||||
|
|
||||||
ArtifactFactory result = (ArtifactFactory) lookup( ArtifactFactory.ROLE, "test" );
|
ArtifactFactory result = (ArtifactFactory) lookup( ArtifactFactory.ROLE, "test" );
|
||||||
assertNotNull( result );
|
assertNotNull( result );
|
||||||
|
|
||||||
getContainer().setLookupRealm( oldRealm );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void test_addExtension_usingModel_ShouldLoadCustomLifecycleMappingAndArtifactHandler()
|
public void test_addExtension_usingModel_ShouldLoadCustomLifecycleMappingAndArtifactHandler()
|
||||||
|
@ -161,33 +146,21 @@ public class DefaultExtensionManagerTest
|
||||||
|
|
||||||
ExtensionManager mgr = newDefaultExtensionManager();
|
ExtensionManager mgr = newDefaultExtensionManager();
|
||||||
|
|
||||||
Map projectSessions = new HashMap();
|
mgr.addExtension( ext, model, remoteRepositories, localRepository );
|
||||||
|
|
||||||
mgr.addExtension( ext, model, remoteRepositories, localRepository, projectSessions );
|
List lcCompList = getContainer().getComponentDescriptorList( LifecycleMapping.ROLE );
|
||||||
|
|
||||||
MavenProjectSession projectSession = (MavenProjectSession) projectSessions.get( MavenProjectSession.createProjectId( model.getGroupId(),
|
|
||||||
model.getArtifactId(),
|
|
||||||
model.getVersion() ) );
|
|
||||||
|
|
||||||
List lcCompList = getContainer().getComponentDescriptorList( LifecycleMapping.ROLE,
|
|
||||||
projectSession.getProjectRealm() );
|
|
||||||
|
|
||||||
System.out.println( "Got lifecyle mappings: " + lcCompList );
|
System.out.println( "Got lifecyle mappings: " + lcCompList );
|
||||||
|
|
||||||
List ahCompList = getContainer().getComponentDescriptorList( ArtifactHandler.ROLE,
|
List ahCompList = getContainer().getComponentDescriptorList( ArtifactHandler.ROLE );
|
||||||
projectSession.getProjectRealm() );
|
|
||||||
|
|
||||||
System.out.println( "Got artifact handlers: " + ahCompList );
|
System.out.println( "Got artifact handlers: " + ahCompList );
|
||||||
|
|
||||||
ClassRealm oldRealm = getContainer().setLookupRealm( projectSession.getProjectRealm() );
|
|
||||||
|
|
||||||
LifecycleMapping lcResult = (LifecycleMapping) lookup( LifecycleMapping.ROLE, "test" );
|
LifecycleMapping lcResult = (LifecycleMapping) lookup( LifecycleMapping.ROLE, "test" );
|
||||||
assertNotNull( lcResult );
|
assertNotNull( lcResult );
|
||||||
|
|
||||||
ArtifactHandler ahResult = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "test" );
|
ArtifactHandler ahResult = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "test" );
|
||||||
assertNotNull( ahResult );
|
assertNotNull( ahResult );
|
||||||
|
|
||||||
getContainer().setLookupRealm( oldRealm );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ExtensionManager newDefaultExtensionManager()
|
private ExtensionManager newDefaultExtensionManager()
|
||||||
|
|
|
@ -229,8 +229,11 @@ public class PluginParameterExpressionEvaluatorTest
|
||||||
.setBaseDirectory( new File( "" ) )
|
.setBaseDirectory( new File( "" ) )
|
||||||
.setLocalRepository( repo );
|
.setLocalRepository( repo );
|
||||||
|
|
||||||
|
// return new MavenSession( container, request, new DefaultEventDispatcher(),
|
||||||
|
// new ReactorManager( Collections.EMPTY_LIST, ReactorManager.FAIL_FAST ), Collections.EMPTY_MAP );
|
||||||
|
|
||||||
return new MavenSession( container, request, new DefaultEventDispatcher(),
|
return new MavenSession( container, request, new DefaultEventDispatcher(),
|
||||||
new ReactorManager( Collections.EMPTY_LIST, ReactorManager.FAIL_FAST ), Collections.EMPTY_MAP );
|
new ReactorManager( Collections.EMPTY_LIST, ReactorManager.FAIL_FAST ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLocalRepositoryExtraction()
|
public void testLocalRepositoryExtraction()
|
||||||
|
|
|
@ -35,7 +35,6 @@ import org.apache.maven.execution.DefaultMavenExecutionRequest;
|
||||||
import org.apache.maven.execution.DefaultMavenExecutionResult;
|
import org.apache.maven.execution.DefaultMavenExecutionResult;
|
||||||
import org.apache.maven.execution.MavenExecutionRequest;
|
import org.apache.maven.execution.MavenExecutionRequest;
|
||||||
import org.apache.maven.execution.MavenExecutionResult;
|
import org.apache.maven.execution.MavenExecutionResult;
|
||||||
import org.apache.maven.execution.MavenProjectSession;
|
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.execution.ReactorManager;
|
import org.apache.maven.execution.ReactorManager;
|
||||||
import org.apache.maven.extension.BuildExtensionScanner;
|
import org.apache.maven.extension.BuildExtensionScanner;
|
||||||
|
@ -320,7 +319,8 @@ public class MavenEmbedder
|
||||||
{
|
{
|
||||||
PluginManager pluginManager = (PluginManager) container.lookup( PluginManager.ROLE );
|
PluginManager pluginManager = (PluginManager) container.lookup( PluginManager.ROLE );
|
||||||
|
|
||||||
MavenSession session = new MavenSession( container, request, null, null, projectSessions );
|
// MavenSession session = new MavenSession( container, request, null, null, projectSessions );
|
||||||
|
MavenSession session = new MavenSession( container, request, null, null );
|
||||||
|
|
||||||
pluginManager.verifyPlugin( plugin, project, session );
|
pluginManager.verifyPlugin( plugin, project, session );
|
||||||
}
|
}
|
||||||
|
@ -434,7 +434,7 @@ public class MavenEmbedder
|
||||||
{
|
{
|
||||||
getLogger().info( "Scanning for extensions: " + mavenProject );
|
getLogger().info( "Scanning for extensions: " + mavenProject );
|
||||||
|
|
||||||
extensionScanner.scanForBuildExtensions( mavenProject, request.getLocalRepository(), request.getProfileManager(), projectSessions );
|
extensionScanner.scanForBuildExtensions( mavenProject, request.getLocalRepository(), request.getProfileManager() );
|
||||||
|
|
||||||
getLogger().info( "Building MavenProject instance: " + mavenProject );
|
getLogger().info( "Building MavenProject instance: " + mavenProject );
|
||||||
|
|
||||||
|
@ -618,22 +618,6 @@ public class MavenEmbedder
|
||||||
|
|
||||||
private MavenExecutionRequest request;
|
private MavenExecutionRequest request;
|
||||||
|
|
||||||
private Map projectSessions;
|
|
||||||
|
|
||||||
public void clearProjectSessions()
|
|
||||||
{
|
|
||||||
if ( ( projectSessions != null ) && !projectSessions.isEmpty() )
|
|
||||||
{
|
|
||||||
for ( Iterator it = projectSessions.values().iterator(); it.hasNext(); )
|
|
||||||
{
|
|
||||||
MavenProjectSession session = (MavenProjectSession) it.next();
|
|
||||||
session.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
projectSessions.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void start( Configuration configuration )
|
private void start( Configuration configuration )
|
||||||
throws MavenEmbedderException
|
throws MavenEmbedderException
|
||||||
{
|
{
|
||||||
|
@ -641,8 +625,6 @@ public class MavenEmbedder
|
||||||
|
|
||||||
logger = configuration.getMavenEmbedderLogger();
|
logger = configuration.getMavenEmbedderLogger();
|
||||||
|
|
||||||
projectSessions = new HashMap();
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Don't override any existing SecurityManager if one has been installed. Our
|
// Don't override any existing SecurityManager if one has been installed. Our
|
||||||
// SecurityManager just checks to make sure
|
// SecurityManager just checks to make sure
|
||||||
|
|
Loading…
Reference in New Issue