mirror of https://github.com/apache/maven.git
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:
parent
2bc0f749a1
commit
86d1a481f5
|
@ -18,6 +18,8 @@ package org.apache.maven.execution;
|
||||||
|
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.monitor.event.EventDispatcher;
|
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.apache.maven.settings.Settings;
|
||||||
import org.codehaus.plexus.PlexusContainer;
|
import org.codehaus.plexus.PlexusContainer;
|
||||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
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...
|
// TODO: make this the central one, get rid of build settings...
|
||||||
private final Settings settings;
|
private final Settings settings;
|
||||||
|
|
||||||
private ReactorManager rpm;
|
private ReactorManager reactorManager;
|
||||||
|
|
||||||
private final String executionRootDir;
|
private final String executionRootDir;
|
||||||
|
|
||||||
private boolean usingPOMsFromFilesystem;
|
private boolean usingPOMsFromFilesystem;
|
||||||
|
|
||||||
public MavenSession( PlexusContainer container, Settings settings, ArtifactRepository localRepository,
|
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;
|
this.container = container;
|
||||||
|
|
||||||
|
@ -59,12 +61,17 @@ public class MavenSession
|
||||||
|
|
||||||
this.eventDispatcher = eventDispatcher;
|
this.eventDispatcher = eventDispatcher;
|
||||||
|
|
||||||
this.rpm = rpm;
|
this.reactorManager = reactorManager;
|
||||||
|
|
||||||
this.goals = goals;
|
this.goals = goals;
|
||||||
|
|
||||||
this.executionRootDir = executionRootDir;
|
this.executionRootDir = executionRootDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map getPluginContext( PluginDescriptor pluginDescriptor, MavenProject project )
|
||||||
|
{
|
||||||
|
return reactorManager.getPluginContext( pluginDescriptor, project );
|
||||||
|
}
|
||||||
|
|
||||||
public PlexusContainer getContainer()
|
public PlexusContainer getContainer()
|
||||||
{
|
{
|
||||||
|
@ -121,7 +128,7 @@ public class MavenSession
|
||||||
|
|
||||||
public List getSortedProjects()
|
public List getSortedProjects()
|
||||||
{
|
{
|
||||||
return rpm.getSortedProjects();
|
return reactorManager.getSortedProjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getExecutionRootDirectory()
|
public String getExecutionRootDirectory()
|
||||||
|
|
|
@ -17,6 +17,7 @@ package org.apache.maven.execution;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.maven.artifact.ArtifactUtils;
|
import org.apache.maven.artifact.ArtifactUtils;
|
||||||
|
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
import org.apache.maven.project.ProjectSorter;
|
import org.apache.maven.project.ProjectSorter;
|
||||||
import org.codehaus.plexus.util.dag.CycleDetectedException;
|
import org.codehaus.plexus.util.dag.CycleDetectedException;
|
||||||
|
@ -39,15 +40,38 @@ public class ReactorManager
|
||||||
|
|
||||||
private Map buildFailuresByProject = new HashMap();
|
private Map buildFailuresByProject = new HashMap();
|
||||||
|
|
||||||
|
private Map pluginContextsByProjectAndPluginKey = new HashMap();
|
||||||
|
|
||||||
private String failureBehavior = FAIL_FAST;
|
private String failureBehavior = FAIL_FAST;
|
||||||
|
|
||||||
private final ProjectSorter sorter;
|
private final ProjectSorter sorter;
|
||||||
|
|
||||||
public ReactorManager( List projects )
|
public ReactorManager( List projects )
|
||||||
throws CycleDetectedException
|
throws CycleDetectedException
|
||||||
{
|
{
|
||||||
this.sorter = new ProjectSorter( 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 )
|
public void setFailureBehavior( String failureBehavior )
|
||||||
{
|
{
|
||||||
|
|
|
@ -518,21 +518,7 @@ public class DefaultPluginManager
|
||||||
|
|
||||||
if ( plugin instanceof ContextEnabled )
|
if ( plugin instanceof ContextEnabled )
|
||||||
{
|
{
|
||||||
Map pluginContext;
|
Map pluginContext = session.getPluginContext( pluginDescriptor, project );
|
||||||
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 );
|
|
||||||
}
|
|
||||||
|
|
||||||
( (ContextEnabled) plugin ).setPluginContext( pluginContext );
|
( (ContextEnabled) plugin ).setPluginContext( pluginContext );
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,6 @@ import java.util.Map;
|
||||||
public interface ContextEnabled
|
public interface ContextEnabled
|
||||||
{
|
{
|
||||||
|
|
||||||
String PLUGIN_CONTEXT_SESSION_KEY = "mavenPluginContext";
|
|
||||||
|
|
||||||
void setPluginContext( Map pluginContext );
|
void setPluginContext( Map pluginContext );
|
||||||
|
|
||||||
Map getPluginContext();
|
Map getPluginContext();
|
||||||
|
|
Loading…
Reference in New Issue