diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java index 31738a482c..d16a47f9db 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -65,7 +65,6 @@ import java.util.Collections; import java.util.Date; import java.util.Iterator; import java.util.List; -import java.util.Map; /** * @author jason van zyl @@ -184,8 +183,7 @@ public class DefaultMaven MavenSession session = createSession( request, reactorManager, - dispatcher, - request.getProjectSessions() ); + dispatcher ); for ( Iterator i = request.getGoals().iterator(); i.hasNext(); ) { @@ -281,7 +279,7 @@ public class DefaultMaven // instances just-in-time. try { - buildExtensionScanner.scanForBuildExtensions( files, request.getLocalRepository(), request.getProfileManager(), request.getProjectSessions() ); + buildExtensionScanner.scanForBuildExtensions( files, request.getLocalRepository(), request.getProfileManager() ); } catch ( ExtensionScanningException e ) { @@ -417,15 +415,13 @@ public class DefaultMaven protected MavenSession createSession( MavenExecutionRequest request, ReactorManager reactorManager, - EventDispatcher dispatcher, - Map projectSessions ) + EventDispatcher dispatcher ) { MavenSession session = new MavenSession( container, request, dispatcher, - reactorManager, - projectSessions ); + reactorManager ); SessionContext ctx = new SessionContext( session ); ctx.store( buildContextManager ); diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java index 2f67d9fe4e..6caa25218c 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java @@ -28,9 +28,7 @@ import org.apache.maven.wagon.events.TransferListener; import java.io.File; import java.util.ArrayList; import java.util.Date; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Properties; /** @@ -62,13 +60,6 @@ public class DefaultMavenExecutionRequest 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 // might be running in a mode where its executing many threads with totally @@ -612,20 +603,4 @@ public class DefaultMavenExecutionRequest { return remoteRepositories; } - - public Map getProjectSessions() - { - if ( projectSessions == null ) - { - projectSessions = new HashMap(); - } - - return projectSessions; - } - - public MavenExecutionRequest setProjectSessions( Map projectSessions ) - { - this.projectSessions = projectSessions; - return this; - } } diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java index fbe6625fb5..d22050df06 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java @@ -30,7 +30,6 @@ import org.codehaus.plexus.logging.Logger; import java.io.File; import java.util.Date; import java.util.List; -import java.util.Map; import java.util.Properties; /** @@ -203,7 +202,4 @@ public interface MavenExecutionRequest MavenExecutionRequest addRemoteRepository( ArtifactRepository repository ); List getRemoteRepositories(); - - MavenExecutionRequest setProjectSessions( Map projectSessions ); - Map getProjectSessions(); } diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java b/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java index ac2c52542c..54c6d779f4 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java @@ -25,11 +25,9 @@ import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.MavenProject; import org.apache.maven.settings.Settings; import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.PlexusContainerException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import java.util.Date; -import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -53,13 +51,10 @@ public class MavenSession private Map reports = new LinkedHashMap(); - private final Map projectSessions; - public MavenSession( PlexusContainer container, MavenExecutionRequest request, EventDispatcher eventDispatcher, - ReactorManager reactorManager, - Map projectSessions ) + ReactorManager reactorManager ) { this.container = container; @@ -68,24 +63,6 @@ public class MavenSession this.eventDispatcher = eventDispatcher; 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, diff --git a/maven-core/src/main/java/org/apache/maven/extension/BuildExtensionScanner.java b/maven-core/src/main/java/org/apache/maven/extension/BuildExtensionScanner.java index 21243c9f15..f4012d35c7 100644 --- a/maven-core/src/main/java/org/apache/maven/extension/BuildExtensionScanner.java +++ b/maven-core/src/main/java/org/apache/maven/extension/BuildExtensionScanner.java @@ -24,7 +24,6 @@ import org.apache.maven.profiles.ProfileManager; import java.io.File; import java.util.List; -import java.util.Map; public interface BuildExtensionScanner { @@ -33,14 +32,12 @@ public interface BuildExtensionScanner void scanForBuildExtensions( List files, ArtifactRepository localRepository, - ProfileManager globalProfileManager, - Map projectSessions ) + ProfileManager globalProfileManager ) throws ExtensionScanningException; void scanForBuildExtensions( File pom, ArtifactRepository localRepository, - ProfileManager globalProfileManager, - Map projectSessions ) + ProfileManager globalProfileManager ) throws ExtensionScanningException; } diff --git a/maven-core/src/main/java/org/apache/maven/extension/DefaultBuildExtensionScanner.java b/maven-core/src/main/java/org/apache/maven/extension/DefaultBuildExtensionScanner.java index 0e3272c320..cea87c6ebe 100644 --- a/maven-core/src/main/java/org/apache/maven/extension/DefaultBuildExtensionScanner.java +++ b/maven-core/src/main/java/org/apache/maven/extension/DefaultBuildExtensionScanner.java @@ -71,8 +71,7 @@ public class DefaultBuildExtensionScanner public void scanForBuildExtensions( List files, ArtifactRepository localRepository, - ProfileManager globalProfileManager, - Map projectSessions ) + ProfileManager globalProfileManager ) throws ExtensionScanningException { List visited = new ArrayList(); @@ -81,17 +80,16 @@ public class DefaultBuildExtensionScanner { File pom = (File) it.next(); - scanInternal( pom, localRepository, globalProfileManager, visited, files, projectSessions ); + scanInternal( pom, localRepository, globalProfileManager, visited, files ); } } public void scanForBuildExtensions( File pom, ArtifactRepository localRepository, - ProfileManager globalProfileManager, - Map projectSessions ) + ProfileManager globalProfileManager ) 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, @@ -100,8 +98,7 @@ public class DefaultBuildExtensionScanner ArtifactRepository localRepository, ProfileManager globalProfileManager, List visitedModelIds, - List reactorFiles, - Map projectSessions ) + List reactorFiles ) throws ExtensionScanningException { @@ -158,7 +155,7 @@ public class DefaultBuildExtensionScanner model = modelInterpolator.interpolate( model, inheritedInterpolationValues, false ); - checkModelBuildForExtensions( model, localRepository, inheritedRemoteRepositories, projectSessions ); + checkModelBuildForExtensions( model, localRepository, inheritedRemoteRepositories ); if ( !reactorFiles.contains( modelPom ) ) { @@ -174,8 +171,7 @@ public class DefaultBuildExtensionScanner originalRemoteRepositories, globalProfileManager, visitedModelIds, - reactorFiles, - projectSessions ); + reactorFiles ); } Properties modelProps = model.getProperties(); @@ -187,7 +183,7 @@ public class DefaultBuildExtensionScanner getLogger().debug( "Finished pre-scanning: " + pom + " for build extensions." ); - extensionManager.registerWagons( projectSessions ); + extensionManager.registerWagons(); } catch ( ModelInterpolationException e ) { @@ -222,8 +218,7 @@ public class DefaultBuildExtensionScanner List originalRemoteRepositories, ProfileManager globalProfileManager, List visitedModelIds, - List reactorFiles, - Map projectSessions ) + List reactorFiles ) throws ExtensionScanningException { // FIXME: This gets a little sticky, because modules can be added by profiles that require @@ -289,12 +284,12 @@ public class DefaultBuildExtensionScanner 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 { Build build = model.getBuild(); @@ -318,7 +313,7 @@ public class DefaultBuildExtensionScanner try { - extensionManager.addExtension( extension, model, remoteRepositories, localRepository, projectSessions ); + extensionManager.addExtension( extension, model, remoteRepositories, localRepository ); } catch ( ExtensionManagerException e ) { diff --git a/maven-core/src/main/java/org/apache/maven/extension/DefaultExtensionManager.java b/maven-core/src/main/java/org/apache/maven/extension/DefaultExtensionManager.java index 1f4acfadcb..6f91aa18c5 100644 --- a/maven-core/src/main/java/org/apache/maven/extension/DefaultExtensionManager.java +++ b/maven-core/src/main/java/org/apache/maven/extension/DefaultExtensionManager.java @@ -43,7 +43,6 @@ import org.apache.maven.plugin.DefaultPluginManager; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.MutablePlexusContainer; import org.codehaus.plexus.PlexusConstants; -import org.codehaus.plexus.PlexusContainerException; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.classworlds.realm.DuplicateRealmException; @@ -117,8 +116,7 @@ public class DefaultExtensionManager public void addExtension( Extension extension, Model originatingModel, List remoteRepositories, - ArtifactRepository localRepository, - Map projectSessions ) + ArtifactRepository localRepository ) throws ExtensionManagerException { Artifact extensionArtifact = artifactFactory.createBuildArtifact( extension.getGroupId(), @@ -150,14 +148,12 @@ public class DefaultExtensionManager remoteRepositories, localRepository, null, - projectSessions, MavenProjectSession.createProjectId( groupId, artifactId, version ) ); } public void addExtension( Extension extension, MavenProject project, - ArtifactRepository localRepository, - Map projectSessions ) + ArtifactRepository localRepository ) throws ExtensionManagerException { String extensionId = ArtifactUtils.versionlessKey( extension.getGroupId(), extension.getArtifactId() ); @@ -171,40 +167,24 @@ public class DefaultExtensionManager project.getRemoteArtifactRepositories(), localRepository, new ActiveArtifactResolver( project ), - projectSessions, MavenProjectSession.createProjectId( project.getGroupId(), project.getArtifactId(), project.getVersion() ) ); } + private String createExtensionRealmId( Artifact realmArtifact ) + { + return "/extensions/" + ArtifactUtils.versionlessKey( realmArtifact ); + } + private void addExtension( Artifact extensionArtifact, Artifact projectArtifact, List remoteRepositories, ArtifactRepository localRepository, ActiveArtifactResolver activeArtifactResolver, - Map projectSessions, String projectId ) throws ExtensionManagerException { 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(); // if the extension is null, @@ -213,9 +193,21 @@ public class DefaultExtensionManager // // skip it. if ( ( extensionArtifact != null ) - && !projectSession.containsExtensionRealm( 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 = new ProjectArtifactExceptionFilter( coreFilter, projectArtifact ); @@ -266,7 +258,7 @@ public class DefaultExtensionManager ClassRealm extensionRealm; try { - extensionRealm = projectSession.createExtensionRealm( extensionArtifact ); + extensionRealm = container.getContainerRealm().createChildRealm( realmId ); } catch ( DuplicateRealmException e ) { @@ -294,17 +286,15 @@ public class DefaultExtensionManager } } - importLocalExtensionComponents( extensionRealm, projectSession, extensionArtifact ); + importLocalExtensionComponents( extensionRealm, projectId, extensionArtifact ); } } private void importLocalExtensionComponents( ClassRealm extensionRealm, - MavenProjectSession projectSession, + String projectId, Artifact extensionArtifact ) throws ExtensionManagerException { - String projectId = projectSession.getProjectId(); - ClassWorld discoveryWorld = new ClassWorld(); try { @@ -324,7 +314,7 @@ public class DefaultExtensionManager ComponentDiscoverer discoverer = new DefaultComponentDiscoverer(); discoverer.setManager( new DummyDiscovererManager() ); - ClassRealm projectRealm = projectSession.getProjectRealm(); + ClassRealm realm = container.getContainerRealm(); try { // Find the extension component descriptors that exist ONLY in the immediate extension @@ -342,18 +332,18 @@ public class DefaultExtensionManager 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 // 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 // project-level realm, since we now have a restricted import // that allows most of the extension to stay hidden, and the // specific local extension components are still accessible // from the project-level realm. - comp.setRealmId( projectRealm.getId() ); + comp.setRealmId( realm.getId() ); // Finally, add the extension component's descriptor (with projectRealm // set as the lookup realm) to the container. @@ -361,7 +351,7 @@ public class DefaultExtensionManager } 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 ); - - container.setLookupRealm( oldRealm ); - } + wagonManager.findAndRegisterWagons( container ); } public void contextualize( Context context ) diff --git a/maven-core/src/main/java/org/apache/maven/extension/ExtensionManager.java b/maven-core/src/main/java/org/apache/maven/extension/ExtensionManager.java index 8af81f87e2..04aacd6a6c 100644 --- a/maven-core/src/main/java/org/apache/maven/extension/ExtensionManager.java +++ b/maven-core/src/main/java/org/apache/maven/extension/ExtensionManager.java @@ -25,7 +25,6 @@ import org.apache.maven.model.Model; import org.apache.maven.project.MavenProject; import java.util.List; -import java.util.Map; /** * Used to locate extensions. @@ -35,12 +34,12 @@ import java.util.Map; */ public interface ExtensionManager { - void addExtension( Extension extension, MavenProject project, ArtifactRepository localRepository, Map projectSessions ) + void addExtension( Extension extension, MavenProject project, ArtifactRepository localRepository ) throws ExtensionManagerException; - void registerWagons( Map projectSessions ); + void registerWagons(); void addExtension( Extension extension, Model originatingModel, List remoteRepositories, - ArtifactRepository localRepository, Map projectSessions ) + ArtifactRepository localRepository ) throws ExtensionManagerException; } diff --git a/maven-core/src/main/java/org/apache/maven/extension/ExtensionManagerException.java b/maven-core/src/main/java/org/apache/maven/extension/ExtensionManagerException.java index 2f1d2dae85..92fb07130f 100644 --- a/maven-core/src/main/java/org/apache/maven/extension/ExtensionManagerException.java +++ b/maven-core/src/main/java/org/apache/maven/extension/ExtensionManagerException.java @@ -16,8 +16,8 @@ public class ExtensionManagerException { private Artifact extensionArtifact; - private final String projectId; private ArtifactResolutionResult resolutionResult; + private String projectId; public ExtensionManagerException( String message, Artifact extensionArtifact, diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java index c83ebca2e9..37bc6db821 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java @@ -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.ArtifactResolutionException; import org.apache.maven.context.BuildContextManager; -import org.apache.maven.execution.MavenProjectSession; import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.ReactorManager; 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.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.PlexusContainerException; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.context.Context; @@ -404,26 +402,29 @@ public class DefaultLifecycleExecutor MavenProject rootProject ) throws LifecycleExecutionException { - MavenProjectSession projectSession; - try - { - projectSession = session.getProjectSession( rootProject ); - } - catch ( PlexusContainerException e ) - { - throw new LifecycleExecutionException( - "Failed to create project-specific session for: " - + rootProject.getId(), - rootProject, e ); - } - if ( projectSession != null ) - { - return container.setLookupRealm( projectSession.getProjectRealm() ); - } - else - { - return null; - } +// MavenProjectSession projectSession; +// try +// { +// projectSession = session.getProjectSession( rootProject ); +// } +// catch ( PlexusContainerException e ) +// { +// throw new LifecycleExecutionException( +// "Failed to create project-specific session for: " +// + rootProject.getId(), +// rootProject, e ); +// } +// if ( projectSession != null ) +// { +// return container.setLookupRealm( projectSession.getProjectRealm() ); +// } +// else +// { +// return null; +// } + + // TODO: Fix this to use project-level realm! + return container.getLookupRealm(); } /** diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java index da66839d9b..5e87b7ff82 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java @@ -21,6 +21,7 @@ package org.apache.maven.plugin; import org.apache.maven.ArtifactFilterManager; import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; 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.VersionRange; import org.apache.maven.context.BuildContextManager; -import org.apache.maven.execution.MavenProjectSession; import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.RuntimeInformation; import org.apache.maven.lifecycle.LifecycleExecutionContext; @@ -66,7 +66,6 @@ import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.PlexusContainerException; 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.component.configurator.ComponentConfigurationException; 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.xml.Xpp3Dom; -import java.net.MalformedURLException; import java.util.ArrayList; import java.util.Collection; 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, Artifact pluginArtifact, MavenProject project, @@ -347,21 +350,25 @@ public class DefaultPluginManager 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 { - projectSession = session.getProjectSession( project ); - } - catch ( PlexusContainerException e ) - { - throw new PluginManagerException( plugin, "Failed to create project-specific session for project: " + project.getId() - + ".", project, e ); - } - - try - { - pluginRealm = projectSession.getPluginRealm( projectPlugin ); +// pluginRealm = projectSession.getPluginRealm( projectPlugin ); + pluginRealm = container.getClassWorld().getRealm( pluginRealmId ); } catch ( NoSuchRealmException e ) { @@ -386,32 +393,40 @@ public class DefaultPluginManager try { - pluginRealm = projectSession.createPluginRealm( projectPlugin ); +// pluginRealm = projectSession.createPluginRealm( projectPlugin ); - try - { - pluginRealm.addURL( pluginArtifact.getFile().toURI().toURL() ); - } - catch ( MalformedURLException e ) - { - throw new PluginContainerException( plugin, pluginRealm, "Error rendering plugin artifact: " + pluginArtifact.getId() + " as URL.", e ); - } + List jars = new ArrayList(); + + jars.add( pluginArtifact.getFile() ); +// try +// { +// pluginRealm.addURL( pluginArtifact.getFile().toURI().toURL() ); +// } +// catch ( MalformedURLException e ) +// { +// throw new PluginContainerException( plugin, pluginRealm, "Error rendering plugin artifact: " + pluginArtifact.getId() + " as URL.", e ); +// } for ( Iterator i = artifacts.iterator(); i.hasNext(); ) { Artifact artifact = (Artifact) i.next(); - try - { - getLogger().debug( "Adding: " + artifact.getId() + " to plugin class-realm: " + key + " in project-session: " + project.getId() ); - pluginRealm.addURL( artifact.getFile().toURI().toURL() ); - } - catch ( MalformedURLException e ) - { - throw new PluginContainerException( plugin, pluginRealm, "Error rendering plugin artifact: " + artifact.getId() + " as URL.", e ); - } +// 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 ); + jars.add( artifact.getFile() ); +// try +// { +// pluginRealm.addURL( artifact.getFile().toURI().toURL() ); +// } +// catch ( MalformedURLException e ) +// { +// throw new PluginContainerException( plugin, pluginRealm, "Error rendering plugin artifact: " + artifact.getId() + " as URL.", e ); +// } } + pluginRealm = container.createComponentRealm( pluginRealmId, jars ); + try { 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 ); } } - 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 - + " in project: " + project.getId(), e ); + throw new PluginContainerException( plugin, pluginRealm, + "Failed to create realm for plugin '" + + projectPlugin, e ); } try @@ -664,26 +685,31 @@ public class DefaultPluginManager ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); - 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 ); - } +// 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 ); +// } + String pluginRealmId = createPluginRealmId( pluginDescriptor.getGroupId(), pluginDescriptor.getArtifactId() ); ClassRealm pluginRealm; try { - pluginRealm = projectSession.getPluginRealm( pluginDescriptor ); +// pluginRealm = projectSession.getPluginRealm( pluginDescriptor ); + pluginRealm = container.getClassWorld().getRealm( pluginRealmId ); } catch ( NoSuchRealmException e ) { - getLogger().debug( "Plugin realm: " + pluginDescriptor.getId() + " not found in project session for: " + project.getId() + ". Using project realm instead." ); - pluginRealm = projectSession.getProjectRealm(); +// getLogger().debug( "Plugin realm: " + pluginDescriptor.getId() + " not found in project session for: " + project.getId() + ". Using project realm instead." ); +// pluginRealm = projectSession.getProjectRealm(); + + getLogger().debug( "Plugin realm: " + pluginRealmId + " not found. Using container realm instead." ); + pluginRealm = container.getContainerRealm(); } ClassRealm oldRealm = null; @@ -804,48 +830,60 @@ public class DefaultPluginManager 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 { - projectSession = session.getProjectSession( project ); - } - catch ( PlexusContainerException e ) - { - throw new PluginManagerException( mojoDescriptor, "Failed to create project-specific session for project: " + project.getId() - + ".", project, e ); - } - - try - { - realm = projectSession.getPluginRealm( pluginDescriptor ); + pluginRealm = container.getClassWorld().getRealm( pluginRealmId ); } catch ( NoSuchRealmException e ) { - getLogger().debug( "Plugin realm: " + pluginDescriptor.getId() + " not found in project session for: " + project.getId() + ". Using project realm instead." ); - realm = projectSession.getProjectRealm(); + getLogger().debug( "Plugin realm: " + pluginRealmId + " not found. Using container realm instead." ); + pluginRealm = container.getContainerRealm(); } // 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 // lookups that occur in contextualize calls in line with the right realm. - ClassRealm oldRealm = container.setLookupRealm( realm ); - pluginDescriptor.setClassRealm( realm ); + ClassRealm oldRealm = container.setLookupRealm( pluginRealm ); + pluginDescriptor.setClassRealm( pluginRealm ); getLogger().debug( "Looking up mojo " + mojoDescriptor.getRoleHint() + " in realm " - + realm.getId() + " - descRealmId=" + + pluginRealm.getId() + " - descRealmId=" + mojoDescriptor.getRealmId() ); try { - plugin = (Mojo) container.lookup( Mojo.ROLE, mojoDescriptor.getRoleHint(), realm ); + plugin = (Mojo) container.lookup( Mojo.ROLE, mojoDescriptor.getRoleHint(), pluginRealm ); } 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 '" + pluginDescriptor.getPluginLookupKey() + "'", e ); } diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginContainerException.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginContainerException.java index 3912a1e925..0391edc03a 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/PluginContainerException.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginContainerException.java @@ -2,6 +2,7 @@ package org.apache.maven.plugin; import org.apache.maven.model.Plugin; 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.DuplicateRealmException; import org.codehaus.plexus.classworlds.realm.NoSuchRealmException; @@ -87,6 +88,16 @@ public class PluginContainerException this.pluginRealm = pluginRealm; } + public PluginContainerException( Plugin plugin, + ClassRealm pluginRealm, + String message, + PlexusContainerException e ) + { + super( plugin, message, e ); + + this.pluginRealm = pluginRealm; + } + public ClassRealm getPluginRealm() { return pluginRealm; diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginManagerException.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginManagerException.java index 08f8c25c45..f07298a4c0 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/PluginManagerException.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginManagerException.java @@ -172,6 +172,17 @@ public class PluginManagerException 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() { return pluginGroupId; diff --git a/maven-core/src/test/java/org/apache/maven/extension/DefaultExtensionManagerTest.java b/maven-core/src/test/java/org/apache/maven/extension/DefaultExtensionManagerTest.java index ed3dc12f76..07115426d9 100644 --- a/maven-core/src/test/java/org/apache/maven/extension/DefaultExtensionManagerTest.java +++ b/maven-core/src/test/java/org/apache/maven/extension/DefaultExtensionManagerTest.java @@ -9,14 +9,12 @@ import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.repository.DefaultArtifactRepository; import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.apache.maven.artifact.resolver.ArtifactResolver; -import org.apache.maven.execution.MavenProjectSession; import org.apache.maven.lifecycle.mapping.LifecycleMapping; import org.apache.maven.model.Build; import org.apache.maven.model.Extension; import org.apache.maven.model.Model; import org.codehaus.plexus.MutablePlexusContainer; import org.codehaus.plexus.PlexusTestCase; -import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.FileUtils; @@ -24,11 +22,9 @@ import java.io.File; import java.io.IOException; import java.net.URL; import java.util.ArrayList; -import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; -import java.util.Map; import java.util.Set; public class DefaultExtensionManagerTest @@ -114,25 +110,14 @@ public class DefaultExtensionManagerTest ExtensionManager mgr = newDefaultExtensionManager(); - Map projectSessions = new HashMap(); + mgr.addExtension( ext, model, remoteRepositories, localRepository ); - mgr.addExtension( ext, model, remoteRepositories, localRepository, projectSessions ); - - MavenProjectSession projectSession = (MavenProjectSession) projectSessions.get( MavenProjectSession.createProjectId( model.getGroupId(), - model.getArtifactId(), - model.getVersion() ) ); - - List compList = getContainer().getComponentDescriptorList( ArtifactFactory.ROLE, - projectSession.getProjectRealm() ); + List compList = getContainer().getComponentDescriptorList( ArtifactFactory.ROLE ); System.out.println( "Got: " + compList ); - ClassRealm oldRealm = getContainer().setLookupRealm( projectSession.getProjectRealm() ); - ArtifactFactory result = (ArtifactFactory) lookup( ArtifactFactory.ROLE, "test" ); assertNotNull( result ); - - getContainer().setLookupRealm( oldRealm ); } public void test_addExtension_usingModel_ShouldLoadCustomLifecycleMappingAndArtifactHandler() @@ -161,33 +146,21 @@ public class DefaultExtensionManagerTest ExtensionManager mgr = newDefaultExtensionManager(); - Map projectSessions = new HashMap(); + mgr.addExtension( ext, model, remoteRepositories, localRepository ); - mgr.addExtension( ext, model, remoteRepositories, localRepository, projectSessions ); - - MavenProjectSession projectSession = (MavenProjectSession) projectSessions.get( MavenProjectSession.createProjectId( model.getGroupId(), - model.getArtifactId(), - model.getVersion() ) ); - - List lcCompList = getContainer().getComponentDescriptorList( LifecycleMapping.ROLE, - projectSession.getProjectRealm() ); + List lcCompList = getContainer().getComponentDescriptorList( LifecycleMapping.ROLE ); System.out.println( "Got lifecyle mappings: " + lcCompList ); - List ahCompList = getContainer().getComponentDescriptorList( ArtifactHandler.ROLE, - projectSession.getProjectRealm() ); + List ahCompList = getContainer().getComponentDescriptorList( ArtifactHandler.ROLE ); System.out.println( "Got artifact handlers: " + ahCompList ); - ClassRealm oldRealm = getContainer().setLookupRealm( projectSession.getProjectRealm() ); - LifecycleMapping lcResult = (LifecycleMapping) lookup( LifecycleMapping.ROLE, "test" ); assertNotNull( lcResult ); ArtifactHandler ahResult = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "test" ); assertNotNull( ahResult ); - - getContainer().setLookupRealm( oldRealm ); } private ExtensionManager newDefaultExtensionManager() diff --git a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java index d6c86b6f59..25a34458be 100644 --- a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java +++ b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java @@ -229,8 +229,11 @@ public class PluginParameterExpressionEvaluatorTest .setBaseDirectory( new File( "" ) ) .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(), - new ReactorManager( Collections.EMPTY_LIST, ReactorManager.FAIL_FAST ), Collections.EMPTY_MAP ); + new ReactorManager( Collections.EMPTY_LIST, ReactorManager.FAIL_FAST ) ); } public void testLocalRepositoryExtraction() diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java index 75ef949c5c..97910545c6 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java +++ b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java @@ -35,7 +35,6 @@ import org.apache.maven.execution.DefaultMavenExecutionRequest; import org.apache.maven.execution.DefaultMavenExecutionResult; import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenExecutionResult; -import org.apache.maven.execution.MavenProjectSession; import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.ReactorManager; import org.apache.maven.extension.BuildExtensionScanner; @@ -320,7 +319,8 @@ public class MavenEmbedder { 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 ); } @@ -434,7 +434,7 @@ public class MavenEmbedder { 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 ); @@ -618,22 +618,6 @@ public class MavenEmbedder 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 ) throws MavenEmbedderException { @@ -641,8 +625,6 @@ public class MavenEmbedder logger = configuration.getMavenEmbedderLogger(); - projectSessions = new HashMap(); - // ---------------------------------------------------------------------------- // Don't override any existing SecurityManager if one has been installed. Our // SecurityManager just checks to make sure