From 86d1a481f59280407f333af4b75643695b8f7fce Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Wed, 28 Sep 2005 03:38:00 +0000 Subject: [PATCH] Storing plugin contexts by plugin and project in the release manager, and furnishing access to them via the session. This will restrict shared information scopes to the plugin AND the project, in a reactored situation. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@292105 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/maven/execution/MavenSession.java | 15 ++++++++--- .../maven/execution/ReactorManager.java | 26 ++++++++++++++++++- .../maven/plugin/DefaultPluginManager.java | 16 +----------- .../apache/maven/plugin/ContextEnabled.java | 2 -- 4 files changed, 37 insertions(+), 22 deletions(-) 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 1c230cbcd0..572480c7f7 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 @@ -18,6 +18,8 @@ package org.apache.maven.execution; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.monitor.event.EventDispatcher; +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.component.repository.exception.ComponentLookupException; @@ -42,14 +44,14 @@ public class MavenSession // TODO: make this the central one, get rid of build settings... private final Settings settings; - private ReactorManager rpm; + private ReactorManager reactorManager; private final String executionRootDir; private boolean usingPOMsFromFilesystem; public MavenSession( PlexusContainer container, Settings settings, ArtifactRepository localRepository, - EventDispatcher eventDispatcher, ReactorManager rpm, List goals, String executionRootDir ) + EventDispatcher eventDispatcher, ReactorManager reactorManager, List goals, String executionRootDir ) { this.container = container; @@ -59,12 +61,17 @@ public class MavenSession this.eventDispatcher = eventDispatcher; - this.rpm = rpm; + this.reactorManager = reactorManager; this.goals = goals; this.executionRootDir = executionRootDir; } + + public Map getPluginContext( PluginDescriptor pluginDescriptor, MavenProject project ) + { + return reactorManager.getPluginContext( pluginDescriptor, project ); + } public PlexusContainer getContainer() { @@ -121,7 +128,7 @@ public class MavenSession public List getSortedProjects() { - return rpm.getSortedProjects(); + return reactorManager.getSortedProjects(); } public String getExecutionRootDirectory() diff --git a/maven-core/src/main/java/org/apache/maven/execution/ReactorManager.java b/maven-core/src/main/java/org/apache/maven/execution/ReactorManager.java index df47c8d8a7..238bebab01 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/ReactorManager.java +++ b/maven-core/src/main/java/org/apache/maven/execution/ReactorManager.java @@ -17,6 +17,7 @@ package org.apache.maven.execution; */ import org.apache.maven.artifact.ArtifactUtils; +import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.MavenProject; import org.apache.maven.project.ProjectSorter; import org.codehaus.plexus.util.dag.CycleDetectedException; @@ -39,15 +40,38 @@ public class ReactorManager private Map buildFailuresByProject = new HashMap(); + private Map pluginContextsByProjectAndPluginKey = new HashMap(); + private String failureBehavior = FAIL_FAST; private final ProjectSorter sorter; - + public ReactorManager( List projects ) throws CycleDetectedException { this.sorter = new ProjectSorter( projects ); } + + public Map getPluginContext( PluginDescriptor plugin, MavenProject project ) + { + Map pluginContextsByKey = (Map) pluginContextsByProjectAndPluginKey.get( project.getId() ); + + if ( pluginContextsByKey == null ) + { + pluginContextsByKey = new HashMap(); + pluginContextsByProjectAndPluginKey.put( project.getId(), pluginContextsByKey ); + } + + Map pluginContext = (Map) pluginContextsByKey.get( plugin.getPluginLookupKey() ); + + if ( pluginContext == null ) + { + pluginContext = new HashMap(); + pluginContextsByKey.put( plugin.getPluginLookupKey(), pluginContext ); + } + + return pluginContext; + } public void setFailureBehavior( String failureBehavior ) { 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 f42eb3f9df..a7b51da7cb 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 @@ -518,21 +518,7 @@ public class DefaultPluginManager if ( plugin instanceof ContextEnabled ) { - Map pluginContext; - try - { - pluginContext = (Map) pluginContainer.getContext().get( ContextEnabled.PLUGIN_CONTEXT_SESSION_KEY ); - } - catch ( ContextException e ) - { - // this is thrown the first time for each plugin, since the map hasn't been initialized in the - // new plugin's container context. - getLogger().debug( "Initializing plugin context map for plugin: " + pluginDescriptor.getPluginLookupKey() ); - - pluginContext = new HashMap(); - - pluginContainer.getContext().put( ContextEnabled.PLUGIN_CONTEXT_SESSION_KEY, pluginContext ); - } + Map pluginContext = session.getPluginContext( pluginDescriptor, project ); ( (ContextEnabled) plugin ).setPluginContext( pluginContext ); } diff --git a/maven-plugin-api/src/main/java/org/apache/maven/plugin/ContextEnabled.java b/maven-plugin-api/src/main/java/org/apache/maven/plugin/ContextEnabled.java index 3225f17c1d..ec0f51027b 100644 --- a/maven-plugin-api/src/main/java/org/apache/maven/plugin/ContextEnabled.java +++ b/maven-plugin-api/src/main/java/org/apache/maven/plugin/ContextEnabled.java @@ -5,8 +5,6 @@ import java.util.Map; public interface ContextEnabled { - String PLUGIN_CONTEXT_SESSION_KEY = "mavenPluginContext"; - void setPluginContext( Map pluginContext ); Map getPluginContext();