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
This commit is contained in:
John Dennis Casey 2005-09-28 03:38:00 +00:00
parent 2bc0f749a1
commit 86d1a481f5
4 changed files with 37 additions and 22 deletions

View File

@ -18,6 +18,8 @@
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,13 +61,18 @@ public MavenSession( PlexusContainer container, Settings settings, ArtifactRepos
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()
{
return container;
@ -121,7 +128,7 @@ public Settings getSettings()
public List getSortedProjects()
{
return rpm.getSortedProjects();
return reactorManager.getSortedProjects();
}
public String getExecutionRootDirectory()

View File

@ -17,6 +17,7 @@
*/
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,6 +40,8 @@ public class ReactorManager
private Map buildFailuresByProject = new HashMap();
private Map pluginContextsByProjectAndPluginKey = new HashMap();
private String failureBehavior = FAIL_FAST;
private final ProjectSorter sorter;
@ -49,6 +52,27 @@ public ReactorManager( List projects )
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 )
{
if ( FAIL_FAST.equals( failureBehavior ) || FAIL_AT_END.equals( failureBehavior ) ||

View File

@ -518,21 +518,7 @@ private Mojo getConfiguredMojo( MavenSession session, Xpp3Dom dom, MavenProject
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 );
}

View File

@ -5,8 +5,6 @@
public interface ContextEnabled
{
String PLUGIN_CONTEXT_SESSION_KEY = "mavenPluginContext";
void setPluginContext( Map pluginContext );
Map getPluginContext();