mirror of https://github.com/apache/maven.git
o branch for my simplification of the lifecycle executor
git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@751454 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c7b8d7ec3b
commit
41df8abcf8
|
@ -26,15 +26,15 @@ package org.apache.maven;
|
|||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public abstract class BuildFailureException
|
||||
public class BuildFailureException
|
||||
extends Exception
|
||||
{
|
||||
protected BuildFailureException( String message )
|
||||
public BuildFailureException( String message )
|
||||
{
|
||||
super( message );
|
||||
}
|
||||
|
||||
protected BuildFailureException( String message, Throwable cause )
|
||||
public BuildFailureException( String message, Throwable cause )
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
||||
|
|
|
@ -19,14 +19,12 @@ package org.apache.maven.execution;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
||||
import org.apache.maven.lifecycle.plan.BuildPlan;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
/** @author Jason van Zyl */
|
||||
public class DefaultMavenExecutionResult
|
||||
|
@ -34,7 +32,7 @@ public class DefaultMavenExecutionResult
|
|||
{
|
||||
private MavenProject project;
|
||||
|
||||
private List topologicallySortedProjects;
|
||||
private List<MavenProject> topologicallySortedProjects;
|
||||
|
||||
private ArtifactResolutionResult artifactResolutionResult;
|
||||
|
||||
|
|
|
@ -19,12 +19,10 @@ package org.apache.maven.execution;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
||||
import org.apache.maven.lifecycle.plan.BuildPlan;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
/**
|
||||
* @author Jason van Zyl
|
||||
|
@ -35,7 +33,7 @@ public interface MavenExecutionResult
|
|||
MavenProject getProject();
|
||||
|
||||
MavenExecutionResult setTopologicallySortedProjects( List projects );
|
||||
List getTopologicallySortedProjects();
|
||||
List<MavenProject> getTopologicallySortedProjects();
|
||||
|
||||
MavenExecutionResult setArtifactResolutionResult( ArtifactResolutionResult result );
|
||||
ArtifactResolutionResult getArtifactResolutionResult();
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,12 +1,6 @@
|
|||
package org.apache.maven.lifecycle;
|
||||
|
||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.plugin.PluginConfigurationException;
|
||||
import org.apache.maven.plugin.PluginLoaderException;
|
||||
import org.apache.maven.plugin.PluginManagerException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
|
@ -28,79 +22,37 @@ import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
|||
*/
|
||||
|
||||
/**
|
||||
* @author Jason van Zyl
|
||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class LifecycleExecutionException
|
||||
extends Exception
|
||||
{
|
||||
private final MavenProject project;
|
||||
private MavenProject project;
|
||||
|
||||
public LifecycleExecutionException( String message )
|
||||
{
|
||||
super( message );
|
||||
}
|
||||
|
||||
public LifecycleExecutionException( Throwable cause )
|
||||
{
|
||||
super( cause );
|
||||
}
|
||||
|
||||
public LifecycleExecutionException( String message, Throwable cause )
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
||||
|
||||
public LifecycleExecutionException( String message, MavenProject project )
|
||||
{
|
||||
super( message );
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
public LifecycleExecutionException( String message, MavenProject project,
|
||||
PluginManagerException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
public LifecycleExecutionException( String message, MavenProject project,
|
||||
ArtifactNotFoundException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
public LifecycleExecutionException( String message, MavenProject project,
|
||||
ArtifactResolutionException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
public LifecycleExecutionException( String message,
|
||||
MavenProject project, PluginLoaderException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
public LifecycleExecutionException( String message,
|
||||
MavenProject project, LifecycleException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
public LifecycleExecutionException( String message, MavenProject project,
|
||||
InvalidDependencyVersionException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
public LifecycleExecutionException( String message, MavenProject project,
|
||||
PluginConfigurationException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
public LifecycleExecutionException( String message,
|
||||
Throwable cause )
|
||||
{
|
||||
super( message, cause );
|
||||
project = null;
|
||||
}
|
||||
|
||||
|
||||
public MavenProject getProject()
|
||||
{
|
||||
return project;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,45 +19,20 @@ package org.apache.maven.lifecycle;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.maven.BuildFailureException;
|
||||
import org.apache.maven.execution.MavenExecutionRequest;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.execution.ReactorManager;
|
||||
import org.apache.maven.monitor.event.EventDispatcher;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
/**
|
||||
* Responsible for orchestrating the process of building the ordered list of
|
||||
* steps required to achieve the specified set of tasks passed into Maven, then
|
||||
* executing these mojos in order. This class also manages the various error messages
|
||||
* that may occur during this process, and directing the behavior of the build
|
||||
* according to what's specified in {@link MavenExecutionRequest#getReactorFailureBehavior()}.
|
||||
*
|
||||
* @author Jason van Zyl
|
||||
* @author jdcasey
|
||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface LifecycleExecutor
|
||||
{
|
||||
/**
|
||||
* Provides a fail-fast way to check that all goals specified in {@link MavenExecutionRequest#getGoals()}
|
||||
* or {@link MavenSession#getGoals()} is valid.
|
||||
*/
|
||||
TaskValidationResult isTaskValid( String task, MavenSession session, MavenProject rootProject );
|
||||
|
||||
/**
|
||||
* Order and execute mojos associated with the current set of projects in the
|
||||
* reactor. Specific lifecycle phases and mojo invocations that determine what
|
||||
* phases and mojos this method will attempt to execute are provided in {@link MavenSession#getGoals()},
|
||||
* which is populated from {@link MavenExecutionRequest#getGoals()}.
|
||||
*/
|
||||
|
||||
void execute( MavenSession session, ReactorManager rm, EventDispatcher dispatcher )
|
||||
throws LifecycleExecutionException, BuildFailureException;
|
||||
|
||||
/**
|
||||
* @since 2.0.10
|
||||
*/
|
||||
List getLifecycles();
|
||||
|
||||
}
|
||||
|
|
|
@ -1,333 +0,0 @@
|
|||
package org.apache.maven.lifecycle.binding;
|
||||
|
||||
import org.apache.maven.lifecycle.model.LifecycleBinding;
|
||||
import org.apache.maven.lifecycle.model.LifecycleBindings;
|
||||
import org.apache.maven.lifecycle.model.MojoBinding;
|
||||
import org.apache.maven.lifecycle.model.Phase;
|
||||
import org.apache.maven.model.Build;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.PluginContainer;
|
||||
import org.apache.maven.model.PluginExecution;
|
||||
import org.apache.maven.model.PluginManagement;
|
||||
import org.apache.maven.model.ReportPlugin;
|
||||
import org.apache.maven.model.ReportSet;
|
||||
import org.apache.maven.model.Reporting;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.ModelUtils;
|
||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Set of utilities used to create and manipulate MojoBindings, both singly and in collections that
|
||||
* constitute LifecycleBindings instances. Some of the methods contained here have fairly generic
|
||||
* names, but have a specialized purpose for this package (such as those that build plugin keys
|
||||
* that lack the version); therefore, this class and all of its methods are package-scoped.
|
||||
*/
|
||||
final class BindingUtils
|
||||
{
|
||||
|
||||
/**
|
||||
* Builds a mapping of groupId:artifactId --> Plugin from the POM. If a plugin is listed
|
||||
* without a groupId, the {@link BindingUtils#createPluginKey(Plugin)} method will fill it in
|
||||
* using org.apache.maven.plugins.
|
||||
*/
|
||||
static Map buildPluginMap( MavenProject project )
|
||||
{
|
||||
Map pluginMap = new HashMap();
|
||||
|
||||
if ( project != null )
|
||||
{
|
||||
Build build = project.getBuild();
|
||||
if ( build != null )
|
||||
{
|
||||
for ( Iterator it = build.getPlugins().iterator(); it.hasNext(); )
|
||||
{
|
||||
Plugin plugin = (Plugin) it.next();
|
||||
|
||||
pluginMap.put( createPluginKey( plugin ), plugin );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pluginMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a mapping of groupId:artifactId --> ReportPlugin from the POM. If a plugin is listed
|
||||
* without a groupId, the {@link BindingUtils#createPluginKey(Plugin)} method will fill it in
|
||||
* using org.apache.maven.plugins.
|
||||
*/
|
||||
static Map buildReportPluginMap( MavenProject project )
|
||||
{
|
||||
Map pluginMap = new HashMap();
|
||||
|
||||
if ( project != null )
|
||||
{
|
||||
Reporting reporting = project.getReporting();
|
||||
if ( reporting != null )
|
||||
{
|
||||
for ( Iterator it = reporting.getPlugins().iterator(); it.hasNext(); )
|
||||
{
|
||||
ReportPlugin plugin = (ReportPlugin) it.next();
|
||||
|
||||
pluginMap.put( createPluginKey( plugin.getGroupId(), plugin.getArtifactId() ), plugin );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pluginMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a mapping of groupId:artifactId --> Plugin from a PluginContainer, such as the build
|
||||
* or pluginManagement section of a POM. If a plugin is listed without a groupId, the
|
||||
* {@link BindingUtils#createPluginKey(Plugin)} method will fill it in using org.apache.maven.plugins.
|
||||
*/
|
||||
static Map buildPluginMap( PluginContainer pluginContainer )
|
||||
{
|
||||
Map pluginMap = new HashMap();
|
||||
|
||||
if ( pluginContainer != null )
|
||||
{
|
||||
for ( Iterator it = pluginContainer.getPlugins().iterator(); it.hasNext(); )
|
||||
{
|
||||
Plugin plugin = (Plugin) it.next();
|
||||
|
||||
pluginMap.put( createPluginKey( plugin ), plugin );
|
||||
}
|
||||
}
|
||||
|
||||
return pluginMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a key for the given Plugin, for use in mappings. The key consists of groupId:artifactId,
|
||||
* where groupId == org.apache.maven.plugins if the Plugin instance has a groupId == null.
|
||||
*/
|
||||
static String createPluginKey( Plugin plugin )
|
||||
{
|
||||
return createPluginKey( plugin.getGroupId(), plugin.getArtifactId() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a key for use in looking up Plugin instances from mappings. The key consists of
|
||||
* groupId:artifactId, where groupId == org.apache.maven.plugins if the supplied groupId
|
||||
* value == null.
|
||||
*/
|
||||
static String createPluginKey( String groupId, String artifactId )
|
||||
{
|
||||
return ( groupId == null ? PluginDescriptor.getDefaultPluginGroupId() : groupId ) + ":" + artifactId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge the ReportPlugin and ReportSet configurations, with the ReportSet configuration taking
|
||||
* precedence.
|
||||
*/
|
||||
static Object mergeConfigurations( ReportPlugin reportPlugin, ReportSet reportSet )
|
||||
{
|
||||
if ( ( reportPlugin == null ) && ( reportSet == null ) )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if ( reportSet == null )
|
||||
{
|
||||
return reportPlugin.getConfiguration();
|
||||
}
|
||||
else if ( reportPlugin == null )
|
||||
{
|
||||
return reportSet.getConfiguration();
|
||||
}
|
||||
else
|
||||
{
|
||||
return mergeRawConfigurations( reportSet.getConfiguration(), reportPlugin.getConfiguration() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge the Plugin and PluginExecution configurations, with the PluginExecution configuration
|
||||
* taking precedence.
|
||||
*/
|
||||
static Object mergeConfigurations( Plugin plugin, PluginExecution execution )
|
||||
{
|
||||
if ( ( plugin == null ) && ( execution == null ) )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if ( execution == null )
|
||||
{
|
||||
return plugin.getConfiguration();
|
||||
}
|
||||
else if ( plugin == null )
|
||||
{
|
||||
return execution.getConfiguration();
|
||||
}
|
||||
else
|
||||
{
|
||||
return mergeRawConfigurations( execution.getConfiguration(), plugin.getConfiguration() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge two configurations, assuming they are Xpp3Dom instances. This method creates a defensive
|
||||
* copy of the dominant configuration before merging, to avoid polluting the original dominant
|
||||
* one.
|
||||
*/
|
||||
static Object mergeRawConfigurations( Object dominant, Object recessive )
|
||||
{
|
||||
Xpp3Dom dominantConfig = (Xpp3Dom) dominant;
|
||||
Xpp3Dom recessiveConfig = (Xpp3Dom) recessive;
|
||||
|
||||
if ( recessiveConfig == null )
|
||||
{
|
||||
return dominantConfig;
|
||||
}
|
||||
else if ( dominantConfig == null )
|
||||
{
|
||||
return recessiveConfig;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Xpp3Dom.mergeXpp3Dom( new Xpp3Dom( dominantConfig ), recessiveConfig );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject any plugin configuration available from the specified POM into the MojoBinding, after
|
||||
* first merging in the applicable configuration from the POM's pluginManagement section.
|
||||
*/
|
||||
static void injectProjectConfiguration( MojoBinding binding, MavenProject project )
|
||||
{
|
||||
Map pluginMap = buildPluginMap( project );
|
||||
|
||||
String key = createPluginKey( binding.getGroupId(), binding.getArtifactId() );
|
||||
Plugin plugin = (Plugin) pluginMap.get( key );
|
||||
|
||||
if ( plugin == null )
|
||||
{
|
||||
plugin = new Plugin();
|
||||
plugin.setGroupId( binding.getGroupId() );
|
||||
plugin.setArtifactId( binding.getArtifactId() );
|
||||
plugin.setVersion( binding.getVersion() );
|
||||
}
|
||||
|
||||
injectPluginManagementInfo( plugin, project );
|
||||
|
||||
PluginExecution exec = (PluginExecution) plugin.getExecutionsAsMap().get( binding.getExecutionId() );
|
||||
|
||||
Object configuration = mergeConfigurations( plugin, exec );
|
||||
|
||||
ReportPlugin reportPlugin = (ReportPlugin) BindingUtils.buildReportPluginMap( project ).get( key );
|
||||
if ( reportPlugin != null )
|
||||
{
|
||||
Map reportSets = reportPlugin.getReportSetsAsMap();
|
||||
|
||||
ReportSet reportSet = null;
|
||||
if ( ( reportSets != null ) && ( exec != null ) )
|
||||
{
|
||||
reportSet = (ReportSet) reportSets.get( exec.getId() );
|
||||
}
|
||||
|
||||
Object reportConfig = BindingUtils.mergeConfigurations( reportPlugin, reportSet );
|
||||
|
||||
// NOTE: This looks weird, but we must retain some consistency with
|
||||
// dominance of plugin configs, regardless of whether they're report
|
||||
// mojos or not.
|
||||
configuration = mergeRawConfigurations( reportConfig, configuration );
|
||||
}
|
||||
|
||||
binding.setVersion( plugin.getVersion() );
|
||||
binding.setConfiguration( configuration );
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject any plugin configuration available from the specified POM into the MojoBindings
|
||||
* present in the given LifecycleBindings instance, after first merging in the configuration
|
||||
* from the POM's pluginManagement section.
|
||||
*/
|
||||
static void injectProjectConfiguration( LifecycleBindings bindings, MavenProject project )
|
||||
{
|
||||
Map pluginsByVersionlessKey = buildPluginMap( project );
|
||||
Map reportPluginsByVersionlessKey = buildReportPluginMap( project );
|
||||
|
||||
for ( Iterator lifecycleIt = bindings.getBindingList().iterator(); lifecycleIt.hasNext(); )
|
||||
{
|
||||
LifecycleBinding binding = (LifecycleBinding) lifecycleIt.next();
|
||||
|
||||
for ( Iterator phaseIt = binding.getPhasesInOrder().iterator(); phaseIt.hasNext(); )
|
||||
{
|
||||
Phase phase = (Phase) phaseIt.next();
|
||||
|
||||
for ( Iterator mojoIt = phase.getBindings().iterator(); mojoIt.hasNext(); )
|
||||
{
|
||||
MojoBinding mojo = (MojoBinding) mojoIt.next();
|
||||
|
||||
String pluginKey = createPluginKey( mojo.getGroupId(), mojo.getArtifactId() );
|
||||
|
||||
Plugin plugin = (Plugin) pluginsByVersionlessKey.get( pluginKey );
|
||||
ReportPlugin reportPlugin = (ReportPlugin) reportPluginsByVersionlessKey.get( pluginKey );
|
||||
|
||||
if ( plugin == null )
|
||||
{
|
||||
plugin = new Plugin();
|
||||
plugin.setGroupId( mojo.getGroupId() );
|
||||
plugin.setArtifactId( mojo.getArtifactId() );
|
||||
|
||||
if ( reportPlugin != null )
|
||||
{
|
||||
plugin.setVersion( reportPlugin.getVersion() );
|
||||
}
|
||||
}
|
||||
|
||||
injectPluginManagementInfo( plugin, project );
|
||||
|
||||
PluginExecution exec = (PluginExecution) plugin.getExecutionsAsMap().get( mojo.getExecutionId() );
|
||||
|
||||
mojo.setConfiguration( mergeConfigurations( plugin, exec ) );
|
||||
|
||||
mojo.setVersion( plugin.getVersion() );
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject any applicable configuration available from the POM's pluginManagement section into the
|
||||
* specified Plugin instance.
|
||||
*/
|
||||
static void injectPluginManagementInfo( Plugin plugin, MavenProject project )
|
||||
{
|
||||
if ( project == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Build build = project.getBuild();
|
||||
if ( build == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PluginManagement plugMgmt = build.getPluginManagement();
|
||||
if ( plugMgmt == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Map plugMgmtMap = buildPluginMap( plugMgmt );
|
||||
|
||||
String key = createPluginKey( plugin );
|
||||
|
||||
Plugin mgmtPlugin = (Plugin) plugMgmtMap.get( key );
|
||||
|
||||
if ( mgmtPlugin != null )
|
||||
{
|
||||
ModelUtils.mergePluginDefinitions( plugin, mgmtPlugin, false );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,651 +0,0 @@
|
|||
package org.apache.maven.lifecycle.binding;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.lifecycle.LifecycleBindingLoader;
|
||||
import org.apache.maven.lifecycle.LifecycleLoaderException;
|
||||
import org.apache.maven.lifecycle.LifecycleSpecificationException;
|
||||
import org.apache.maven.lifecycle.LifecycleUtils;
|
||||
import org.apache.maven.lifecycle.MojoBindingUtils;
|
||||
import org.apache.maven.lifecycle.mapping.LifecycleMapping;
|
||||
import org.apache.maven.lifecycle.model.LifecycleBindings;
|
||||
import org.apache.maven.lifecycle.model.MojoBinding;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.PluginExecution;
|
||||
import org.apache.maven.model.ReportPlugin;
|
||||
import org.apache.maven.model.ReportSet;
|
||||
import org.apache.maven.plugin.PluginLoaderException;
|
||||
import org.apache.maven.plugin.PluginManager;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
import org.apache.maven.plugin.lifecycle.Execution;
|
||||
import org.apache.maven.plugin.lifecycle.Lifecycle;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.reporting.MavenReport;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||
import org.codehaus.plexus.component.annotations.Requirement;
|
||||
import org.codehaus.plexus.logging.LogEnabled;
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* Responsible for the gross construction of LifecycleBindings, or mappings of MojoBinding instances to different parts
|
||||
* of the three lifecycles: clean, build, and site. Also, handles transcribing these LifecycleBindings instances into
|
||||
* lists of MojoBinding's, which can be consumed by the LifecycleExecutor.
|
||||
*
|
||||
* @author jdcasey
|
||||
*
|
||||
*/
|
||||
//@Component(role = LifecycleBindingManager.class)
|
||||
//!! This is configuration that needs to be bound in so we can't generate this quite yet.
|
||||
public class DefaultLifecycleBindingManager
|
||||
implements LifecycleBindingManager, LogEnabled
|
||||
{
|
||||
@Requirement
|
||||
private PluginManager pluginLoader;
|
||||
|
||||
@Requirement
|
||||
private MojoBindingFactory mojoBindingFactory;
|
||||
|
||||
@Requirement
|
||||
private PlexusContainer container;
|
||||
|
||||
@Requirement
|
||||
private LegacyLifecycleMappingParser legacyLifecycleMappingParser;
|
||||
|
||||
private Map bindingsByPackaging;
|
||||
|
||||
private Map legacyMappingsByPackaging;
|
||||
|
||||
private Logger logger;
|
||||
|
||||
// configured. Moved out of DefaultLifecycleExecutor...
|
||||
private List<org.apache.maven.lifecycle.binding.Lifecycle> lifecycles;
|
||||
|
||||
// configured. Moved out of DefaultLifecycleExecutor...
|
||||
private List defaultReports;
|
||||
|
||||
public List getLifecycles()
|
||||
{
|
||||
return lifecycles;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public LifecycleBindings getBindingsForPackaging( final MavenProject project, final MavenSession session )
|
||||
throws LifecycleLoaderException, LifecycleSpecificationException
|
||||
{
|
||||
String packaging = project.getPackaging();
|
||||
|
||||
LifecycleBindings bindings = null;
|
||||
|
||||
ClassRealm projectRealm = session.getRealmManager().getProjectRealm( project.getGroupId(), project.getArtifactId(), project.getVersion() );
|
||||
|
||||
ClassRealm oldRealm = container.setLookupRealm( projectRealm );
|
||||
|
||||
try
|
||||
{
|
||||
LifecycleBindingLoader loader = (LifecycleBindingLoader) bindingsByPackaging.get( packaging );
|
||||
if ( loader != null )
|
||||
{
|
||||
bindings = loader.getBindings();
|
||||
}
|
||||
|
||||
// TODO: Remove this once we no longer have to support legacy-style lifecycle mappings
|
||||
if ( bindings == null )
|
||||
{
|
||||
LifecycleMapping mapping = (LifecycleMapping) legacyMappingsByPackaging.get( packaging );
|
||||
if ( mapping != null )
|
||||
{
|
||||
bindings = legacyLifecycleMappingParser.parseMappings( mapping, packaging );
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
container.setLookupRealm( oldRealm );
|
||||
}
|
||||
|
||||
if ( bindings != null )
|
||||
{
|
||||
BindingUtils.injectProjectConfiguration( bindings, project );
|
||||
}
|
||||
|
||||
if ( bindings == null )
|
||||
{
|
||||
bindings = getDefaultBindings( project );
|
||||
}
|
||||
|
||||
return bindings;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public LifecycleBindings getDefaultBindings( final MavenProject project ) throws LifecycleSpecificationException
|
||||
{
|
||||
LifecycleBindings bindings = legacyLifecycleMappingParser.parseDefaultMappings( lifecycles );
|
||||
|
||||
BindingUtils.injectProjectConfiguration( bindings, project );
|
||||
|
||||
return bindings;
|
||||
}
|
||||
|
||||
public void enableLogging( final Logger logger )
|
||||
{
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public LifecycleBindings getProjectCustomBindings( final MavenProject project, final MavenSession session, Set unbindableMojos )
|
||||
throws LifecycleLoaderException, LifecycleSpecificationException
|
||||
{
|
||||
LifecycleBindings bindings = new LifecycleBindings();
|
||||
bindings.setPackaging( project.getPackaging() );
|
||||
|
||||
List plugins = project.getBuildPlugins();
|
||||
if ( plugins != null )
|
||||
{
|
||||
for ( Iterator it = plugins.iterator(); it.hasNext(); )
|
||||
{
|
||||
Plugin plugin = (Plugin) it.next();
|
||||
BindingUtils.injectPluginManagementInfo( plugin, project );
|
||||
|
||||
PluginDescriptor pluginDescriptor = null;
|
||||
|
||||
List executions = plugin.getExecutions();
|
||||
if ( executions != null )
|
||||
{
|
||||
for ( Iterator execIt = executions.iterator(); execIt.hasNext(); )
|
||||
{
|
||||
PluginExecution execution = (PluginExecution) execIt.next();
|
||||
|
||||
List goals = execution.getGoals();
|
||||
if ( ( goals != null ) && !goals.isEmpty() )
|
||||
{
|
||||
for ( Iterator goalIterator = goals.iterator(); goalIterator.hasNext(); )
|
||||
{
|
||||
String goal = (String) goalIterator.next();
|
||||
|
||||
if ( goal == null )
|
||||
{
|
||||
logger.warn( "Execution: " + execution.getId() + " in plugin: " + plugin.getKey()
|
||||
+ " in the POM has a null goal." );
|
||||
continue;
|
||||
}
|
||||
|
||||
MojoBinding mojoBinding = new MojoBinding();
|
||||
|
||||
mojoBinding.setGroupId( plugin.getGroupId() );
|
||||
mojoBinding.setArtifactId( plugin.getArtifactId() );
|
||||
mojoBinding.setVersion( plugin.getVersion() );
|
||||
mojoBinding.setGoal( goal );
|
||||
mojoBinding.setConfiguration( BindingUtils.mergeConfigurations( plugin, execution ) );
|
||||
mojoBinding.setExecutionId( execution.getId() );
|
||||
mojoBinding.setOrigin( MojoBinding.POM_ORIGIN );
|
||||
|
||||
logger.debug( "Mojo: " + MojoBindingUtils.toString( mojoBinding ) + ": determining binding phase." );
|
||||
|
||||
String phase = execution.getPhase();
|
||||
|
||||
logger.debug( "Phase from <execution/> section (merged with outer <plugin/> section) is: " + phase );
|
||||
|
||||
boolean pluginResolved = false;
|
||||
|
||||
if ( phase == null )
|
||||
{
|
||||
if ( pluginDescriptor == null )
|
||||
{
|
||||
try
|
||||
{
|
||||
pluginDescriptor = pluginLoader.loadPlugin( plugin, project, session );
|
||||
pluginResolved = true;
|
||||
}
|
||||
catch ( PluginLoaderException e )
|
||||
{
|
||||
unbindableMojos.add( mojoBinding );
|
||||
|
||||
String message = "Failed to load plugin descriptor for: "
|
||||
+ plugin
|
||||
+ ". Assigning this plugin to be resolved again just prior to its execution. "
|
||||
+ "NOTE, This may affect assignment of the mojo: "
|
||||
+ mojoBinding.getGoal()
|
||||
+ " if its default phase (given in the plugin descriptor) is used.";
|
||||
|
||||
if ( logger.isDebugEnabled() )
|
||||
{
|
||||
logger.debug( message, e );
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.warn( message + " Check debug output (-X) for more information." );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( pluginDescriptor != null )
|
||||
{
|
||||
if ( pluginDescriptor.getMojos() == null )
|
||||
{
|
||||
logger.error( "Somehow, the PluginDescriptor for plugin: " + plugin.getKey()
|
||||
+ " contains no mojos. This is highly irregular. Ignoring..." );
|
||||
|
||||
unbindableMojos.add( mojoBinding );
|
||||
continue;
|
||||
}
|
||||
|
||||
MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal );
|
||||
if(mojoDescriptor == null)
|
||||
{
|
||||
throw new LifecycleSpecificationException( "Mojo Descriptor for goal is invalid: Plugin = "
|
||||
+ plugin.getKey() + ", Plugin Descriptor = "
|
||||
+ pluginDescriptor.getPluginLookupKey() +", Goal = " + goal);
|
||||
}
|
||||
phase = mojoDescriptor.getPhase();
|
||||
|
||||
logger.debug( "Phase from plugin descriptor: " + mojoDescriptor.getFullGoalName() + " is: " + phase );
|
||||
}
|
||||
|
||||
if ( phase == null )
|
||||
{
|
||||
if ( pluginResolved )
|
||||
{
|
||||
StringBuffer message = new StringBuffer();
|
||||
|
||||
message.append( "\n\nNo lifecycle phase binding can be found for goal: " + goal );
|
||||
message.append( ",\nspecified as a part of the execution: " + execution.getId() );
|
||||
message.append( "in plugin: " );
|
||||
message.append( pluginDescriptor.getPluginLookupKey() );
|
||||
message.append( "\n\nThis plugin was resolved successfully." );
|
||||
message.append( "\nHowever, the mojo metadata it contains does not specify a default lifecycle phase binding." );
|
||||
message.append( "\n\nPlease provide a valid <phase/> specification for execution: " )
|
||||
.append( execution.getId() )
|
||||
.append( "\nin plugin: " )
|
||||
.append( plugin.getKey() );
|
||||
message.append( "\n\n" );
|
||||
|
||||
throw new LifecycleSpecificationException( message.toString() );
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.warn( "\n\nSkipping addition to build-plan for goal: "
|
||||
+ goal
|
||||
+ " in execution: "
|
||||
+ execution.getId()
|
||||
+ " of plugin: "
|
||||
+ plugin.getKey()
|
||||
+ " because no phase information was available (either through the mojo descriptor, which is currently missing, or in the POM itself).\n\n" );
|
||||
|
||||
unbindableMojos.add( mojoBinding );
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LifecycleUtils.addMojoBinding( phase, mojoBinding, bindings );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LifecycleUtils.setOrigin( bindings, "POM" );
|
||||
|
||||
return bindings;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public LifecycleBindings getPluginLifecycleOverlay( final PluginDescriptor pluginDescriptor,
|
||||
final String lifecycleId, final MavenProject project )
|
||||
throws LifecycleLoaderException, LifecycleSpecificationException
|
||||
{
|
||||
Lifecycle lifecycleOverlay = null;
|
||||
|
||||
try
|
||||
{
|
||||
lifecycleOverlay = pluginDescriptor.getLifecycleMapping( lifecycleId );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new LifecycleLoaderException( "Unable to read lifecycle mapping file: " + e.getMessage(), e );
|
||||
}
|
||||
catch ( XmlPullParserException e )
|
||||
{
|
||||
throw new LifecycleLoaderException( "Unable to parse lifecycle mapping file: " + e.getMessage(), e );
|
||||
}
|
||||
|
||||
if ( lifecycleOverlay == null )
|
||||
{
|
||||
throw new LifecycleLoaderException( "Lifecycle '" + lifecycleId + "' not found in plugin" );
|
||||
}
|
||||
|
||||
LifecycleBindings bindings = new LifecycleBindings();
|
||||
|
||||
for ( Iterator i = lifecycleOverlay.getPhases().iterator(); i.hasNext(); )
|
||||
{
|
||||
org.apache.maven.plugin.lifecycle.Phase phase = (org.apache.maven.plugin.lifecycle.Phase) i.next();
|
||||
List phaseBindings = new ArrayList();
|
||||
|
||||
for ( Iterator j = phase.getExecutions().iterator(); j.hasNext(); )
|
||||
{
|
||||
Execution exec = (Execution) j.next();
|
||||
|
||||
for ( Iterator k = exec.getGoals().iterator(); k.hasNext(); )
|
||||
{
|
||||
String goal = (String) k.next();
|
||||
|
||||
// Here we are looking to see if we have a mojo from an external plugin.
|
||||
// If we do then we need to lookup the plugin descriptor for the externally
|
||||
// referenced plugin so that we can overly the execution into the lifecycle.
|
||||
// An example of this is the corbertura plugin that needs to call the surefire
|
||||
// plugin in forking mode.
|
||||
//
|
||||
// <phase>
|
||||
// <id>test</id>
|
||||
// <executions>
|
||||
// <execution>
|
||||
// <goals>
|
||||
// <goal>org.apache.maven.plugins:maven-surefire-plugin:test</goal>
|
||||
// </goals>
|
||||
// <configuration>
|
||||
// <classesDirectory>${project.build.directory}/generated-classes/cobertura</classesDirectory>
|
||||
// <ignoreFailures>true</ignoreFailures>
|
||||
// <forkMode>once</forkMode>
|
||||
// </configuration>
|
||||
// </execution>
|
||||
// </executions>
|
||||
// </phase>
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
MojoBinding binding;
|
||||
if ( goal.indexOf( ":" ) > 0 )
|
||||
{
|
||||
binding = mojoBindingFactory.parseMojoBinding( goal, project );
|
||||
}
|
||||
else
|
||||
{
|
||||
binding = new MojoBinding();
|
||||
binding.setGroupId( pluginDescriptor.getGroupId() );
|
||||
binding.setArtifactId( pluginDescriptor.getArtifactId() );
|
||||
binding.setVersion( pluginDescriptor.getVersion() );
|
||||
binding.setGoal( goal );
|
||||
}
|
||||
|
||||
Xpp3Dom configuration = (Xpp3Dom) exec.getConfiguration();
|
||||
if ( phase.getConfiguration() != null )
|
||||
{
|
||||
configuration =
|
||||
Xpp3Dom.mergeXpp3Dom( new Xpp3Dom( (Xpp3Dom) phase.getConfiguration() ), configuration );
|
||||
}
|
||||
|
||||
binding.setConfiguration( configuration );
|
||||
binding.setOrigin( MojoBinding.LIFECYCLE_MAPPING_ORIGIN );
|
||||
binding.setOriginDescription( "Lifecycle overlay: " + lifecycleId );
|
||||
|
||||
LifecycleUtils.addMojoBinding( phase.getId(), binding, bindings );
|
||||
phaseBindings.add( binding );
|
||||
}
|
||||
}
|
||||
|
||||
if ( phase.getConfiguration() != null )
|
||||
{
|
||||
// Merge in general configuration for a phase.
|
||||
// TODO: this is all kind of backwards from the POMM. Let's align it all under 2.1.
|
||||
// We should create a new lifecycle executor for modelVersion >5.0.0
|
||||
// [jdcasey; 08-March-2007] Not sure what the above to-do references...how _should_
|
||||
// this work??
|
||||
for ( Iterator j = phaseBindings.iterator(); j.hasNext(); )
|
||||
{
|
||||
MojoBinding binding = (MojoBinding) j.next();
|
||||
|
||||
Xpp3Dom configuration =
|
||||
Xpp3Dom.mergeXpp3Dom( new Xpp3Dom( (Xpp3Dom) phase.getConfiguration() ),
|
||||
(Xpp3Dom) binding.getConfiguration() );
|
||||
|
||||
binding.setConfiguration( configuration );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return bindings;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public List getReportBindings( final MavenProject project, final MavenSession session )
|
||||
throws LifecycleLoaderException, LifecycleSpecificationException
|
||||
{
|
||||
if ( project.getModel().getReports() != null )
|
||||
{
|
||||
logger.warn( "Plugin contains a <reports/> section: this is IGNORED - please use <reporting/> instead." );
|
||||
}
|
||||
|
||||
List reportPlugins = getReportPluginsForProject( project );
|
||||
|
||||
List reports = new ArrayList();
|
||||
if ( reportPlugins != null )
|
||||
{
|
||||
for ( Iterator it = reportPlugins.iterator(); it.hasNext(); )
|
||||
{
|
||||
ReportPlugin reportPlugin = (ReportPlugin) it.next();
|
||||
|
||||
List reportSets = reportPlugin.getReportSets();
|
||||
|
||||
if ( ( reportSets == null ) || reportSets.isEmpty() )
|
||||
{
|
||||
reports.addAll( getReportsForPlugin( reportPlugin, null, project, session ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( Iterator j = reportSets.iterator(); j.hasNext(); )
|
||||
{
|
||||
ReportSet reportSet = (ReportSet) j.next();
|
||||
|
||||
reports.addAll( getReportsForPlugin( reportPlugin, reportSet, project, session ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return reports;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the ReportPlugin instances referenced in the specified POM.
|
||||
*/
|
||||
private List getReportPluginsForProject( final MavenProject project )
|
||||
{
|
||||
List reportPlugins = project.getReportPlugins();
|
||||
|
||||
if ( ( project.getReporting() == null ) || !project.getReporting().isExcludeDefaults() )
|
||||
{
|
||||
if ( reportPlugins == null )
|
||||
{
|
||||
reportPlugins = new ArrayList();
|
||||
}
|
||||
else
|
||||
{
|
||||
reportPlugins = new ArrayList( reportPlugins );
|
||||
}
|
||||
|
||||
for ( Iterator i = defaultReports.iterator(); i.hasNext(); )
|
||||
{
|
||||
String report = (String) i.next();
|
||||
|
||||
StringTokenizer tok = new StringTokenizer( report, ":" );
|
||||
int count = tok.countTokens();
|
||||
if ( count != 2 && count != 3 )
|
||||
{
|
||||
logger.warn( "Invalid default report ignored: '" + report + "' (must be groupId:artifactId[:version])" );
|
||||
}
|
||||
else
|
||||
{
|
||||
String groupId = tok.nextToken();
|
||||
String artifactId = tok.nextToken();
|
||||
String version = tok.hasMoreTokens() ? tok.nextToken() : null;
|
||||
|
||||
boolean found = false;
|
||||
for ( Iterator j = reportPlugins.iterator(); j.hasNext() && !found; )
|
||||
{
|
||||
ReportPlugin reportPlugin = (ReportPlugin) j.next();
|
||||
if ( reportPlugin.getGroupId().equals( groupId )
|
||||
&& reportPlugin.getArtifactId().equals( artifactId ) )
|
||||
{
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !found )
|
||||
{
|
||||
ReportPlugin reportPlugin = new ReportPlugin();
|
||||
reportPlugin.setGroupId( groupId );
|
||||
reportPlugin.setArtifactId( artifactId );
|
||||
reportPlugin.setVersion( version );
|
||||
reportPlugins.add( reportPlugin );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return reportPlugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve any reports from the specified ReportPlugin which are referenced in the specified POM.
|
||||
*/
|
||||
private List getReportsForPlugin( final ReportPlugin reportPlugin, final ReportSet reportSet,
|
||||
final MavenProject project, final MavenSession session ) throws LifecycleLoaderException
|
||||
{
|
||||
PluginDescriptor pluginDescriptor;
|
||||
try
|
||||
{
|
||||
pluginDescriptor = pluginLoader.loadReportPlugin( reportPlugin, project, session );
|
||||
}
|
||||
catch ( PluginLoaderException e )
|
||||
{
|
||||
throw new LifecycleLoaderException( "Failed to load report plugin: " + reportPlugin.getKey() + ". Reason: "
|
||||
+ e.getMessage(), e );
|
||||
}
|
||||
|
||||
List reports = new ArrayList();
|
||||
for ( Iterator i = pluginDescriptor.getMojos().iterator(); i.hasNext(); )
|
||||
{
|
||||
MojoDescriptor mojoDescriptor = (MojoDescriptor) i.next();
|
||||
|
||||
|
||||
// FIXME: Can't we be smarter about what is and what is not a report???
|
||||
try
|
||||
{
|
||||
if ( !isReport( mojoDescriptor ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
catch ( ClassNotFoundException e )
|
||||
{
|
||||
throw new LifecycleLoaderException( "Failed while verifying that mojo: " + mojoDescriptor.getId() + " is a report mojo. Reason: " + e.getMessage(), e );
|
||||
}
|
||||
|
||||
// TODO: check ID is correct for reports
|
||||
// if the POM configured no reports, give all from plugin
|
||||
if ( ( reportSet == null ) || reportSet.getReports().contains( mojoDescriptor.getGoal() ) )
|
||||
{
|
||||
String id = null;
|
||||
if ( reportSet != null )
|
||||
{
|
||||
id = reportSet.getId();
|
||||
}
|
||||
|
||||
MojoBinding binding = new MojoBinding();
|
||||
binding.setGroupId( pluginDescriptor.getGroupId() );
|
||||
binding.setArtifactId( pluginDescriptor.getArtifactId() );
|
||||
binding.setVersion( pluginDescriptor.getVersion() );
|
||||
binding.setGoal( mojoDescriptor.getGoal() );
|
||||
binding.setExecutionId( id );
|
||||
binding.setOrigin( MojoBinding.POM_ORIGIN );
|
||||
|
||||
BindingUtils.injectProjectConfiguration( binding, project );
|
||||
|
||||
reports.add( binding );
|
||||
}
|
||||
}
|
||||
return reports;
|
||||
}
|
||||
|
||||
private boolean isReport( MojoDescriptor mojoDescriptor )
|
||||
throws ClassNotFoundException
|
||||
{
|
||||
ClassRealm classRealm = mojoDescriptor.getPluginDescriptor().getClassRealm();
|
||||
String impl = mojoDescriptor.getImplementation();
|
||||
|
||||
Class mojoClass = classRealm.loadClass( impl );
|
||||
Class reportClass = classRealm.loadClass( MavenReport.class.getName() );
|
||||
|
||||
return reportClass.isAssignableFrom( mojoClass );
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void resolveUnbindableMojos( final Set unbindableMojos,
|
||||
final MavenProject project,
|
||||
final MavenSession session,
|
||||
final LifecycleBindings lifecycleBindings )
|
||||
throws LifecycleSpecificationException
|
||||
{
|
||||
for ( Iterator it = unbindableMojos.iterator(); it.hasNext(); )
|
||||
{
|
||||
MojoBinding binding = (MojoBinding) it.next();
|
||||
PluginDescriptor pluginDescriptor;
|
||||
try
|
||||
{
|
||||
pluginDescriptor = pluginLoader.loadPlugin( binding, project, session );
|
||||
}
|
||||
catch ( PluginLoaderException e )
|
||||
{
|
||||
String message = "Failed to load plugin descriptor for: "
|
||||
+ MojoBindingUtils.toString( binding )
|
||||
+ ". Cannot discover it's default phase, specified in its plugin descriptor.";
|
||||
|
||||
throw new LifecycleSpecificationException( message, e );
|
||||
}
|
||||
|
||||
MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( binding.getGoal() );
|
||||
if ( mojoDescriptor == null )
|
||||
{
|
||||
throw new LifecycleSpecificationException( "Cannot find mojo descriptor for goal: " + binding.getGoal() + " in plugin: " + pluginDescriptor.getPluginLookupKey() );
|
||||
}
|
||||
|
||||
String phase = mojoDescriptor.getPhase();
|
||||
if ( phase == null )
|
||||
{
|
||||
throw new LifecycleSpecificationException(
|
||||
"Mojo descriptor: "
|
||||
+ mojoDescriptor.getFullGoalName()
|
||||
+ " doesn't have a default lifecycle phase. Please specify a <phase/> for this goal in your POM." );
|
||||
}
|
||||
|
||||
LifecycleUtils.addMojoBinding( phase, binding, lifecycleBindings );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,158 +0,0 @@
|
|||
package org.apache.maven.lifecycle.binding;
|
||||
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.lifecycle.LifecycleLoaderException;
|
||||
import org.apache.maven.lifecycle.LifecycleSpecificationException;
|
||||
import org.apache.maven.lifecycle.model.MojoBinding;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.plugin.PluginLoaderException;
|
||||
import org.apache.maven.plugin.PluginManager;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.component.annotations.Requirement;
|
||||
|
||||
/**
|
||||
* Responsible for constructing or parsing MojoBinding instances from one of several sources, potentially
|
||||
* using the {@link PluginLoader} to resolve any plugin prefixes first.
|
||||
*
|
||||
* @author jdcasey
|
||||
*
|
||||
*/
|
||||
@Component(role = MojoBindingFactory.class)
|
||||
public class DefaultMojoBindingFactory
|
||||
implements MojoBindingFactory
|
||||
{
|
||||
@Requirement
|
||||
PluginManager pluginPrefixLoader;
|
||||
|
||||
/**
|
||||
* Parse the specified mojo string into a MojoBinding, optionally allowing plugin-prefix references.
|
||||
* If a plugin-prefix is allowed and used, resolve the prefix and use the resulting PluginDescriptor
|
||||
* to set groupId and artifactId on the MojoBinding instance.
|
||||
*/
|
||||
public MojoBinding parseMojoBinding( String bindingSpec, MavenProject project, MavenSession session, boolean allowPrefixReference )
|
||||
throws LifecycleSpecificationException, LifecycleLoaderException
|
||||
{
|
||||
StringTokenizer tok = new StringTokenizer( bindingSpec, ":" );
|
||||
int numTokens = tok.countTokens();
|
||||
|
||||
MojoBinding binding = null;
|
||||
|
||||
if ( numTokens == 2 )
|
||||
{
|
||||
if ( !allowPrefixReference )
|
||||
{
|
||||
String msg = "Mapped-prefix lookup of mojos are only supported from direct invocation. "
|
||||
+ "Please use specification of the form groupId:artifactId[:version]:goal instead.";
|
||||
|
||||
throw new LifecycleSpecificationException( msg );
|
||||
}
|
||||
|
||||
String prefix = tok.nextToken();
|
||||
|
||||
Plugin plugin;
|
||||
try
|
||||
{
|
||||
plugin = pluginPrefixLoader.findPluginForPrefix( prefix, project, session );
|
||||
}
|
||||
catch ( PluginLoaderException e )
|
||||
{
|
||||
throw new LifecycleLoaderException(
|
||||
"Failed to find plugin for prefix: " + prefix + ". Reason: " + e.getMessage(),
|
||||
e );
|
||||
}
|
||||
|
||||
binding = createMojoBinding( plugin.getGroupId(), plugin.getArtifactId(),
|
||||
plugin.getVersion(), tok.nextToken(), project );
|
||||
}
|
||||
else if ( ( numTokens == 3 ) || ( numTokens == 4 ) )
|
||||
{
|
||||
binding = new MojoBinding();
|
||||
|
||||
String groupId = tok.nextToken();
|
||||
String artifactId = tok.nextToken();
|
||||
|
||||
String version = null;
|
||||
if ( numTokens == 4 )
|
||||
{
|
||||
version = tok.nextToken();
|
||||
}
|
||||
|
||||
String goal = tok.nextToken();
|
||||
|
||||
binding = createMojoBinding( groupId, artifactId, version, goal, project );
|
||||
}
|
||||
else
|
||||
{
|
||||
String message = "Invalid task '" + bindingSpec + "': you must specify a valid lifecycle phase, or"
|
||||
+ " a goal in the format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal";
|
||||
|
||||
throw new LifecycleSpecificationException( message );
|
||||
}
|
||||
|
||||
return binding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new MojoBinding instance with the specified information, and inject POM configurations
|
||||
* appropriate to that mojo before returning it.
|
||||
*/
|
||||
public MojoBinding createMojoBinding( String groupId, String artifactId, String version, String goal, MavenProject project )
|
||||
{
|
||||
MojoBinding binding = new MojoBinding();
|
||||
|
||||
binding.setGroupId( groupId );
|
||||
binding.setArtifactId( artifactId );
|
||||
binding.setVersion( version );
|
||||
binding.setGoal( goal );
|
||||
|
||||
BindingUtils.injectProjectConfiguration( binding, project );
|
||||
|
||||
return binding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simplified version of {@link MojoBindingFactory#parseMojoBinding(String, MavenProject, boolean)}
|
||||
* which assumes the project is null and prefixes are not allowed. This method will <b>never</b>
|
||||
* result in the {@link PluginLoader} being used to resolve the PluginDescriptor.
|
||||
*/
|
||||
public MojoBinding parseMojoBinding( String bindingSpec )
|
||||
throws LifecycleSpecificationException
|
||||
{
|
||||
try
|
||||
{
|
||||
return parseMojoBinding( bindingSpec, null, null, false );
|
||||
}
|
||||
catch ( LifecycleLoaderException e )
|
||||
{
|
||||
IllegalStateException error = new IllegalStateException( e.getMessage()
|
||||
+ "\n\nTHIS SHOULD BE IMPOSSIBLE DUE TO THE USAGE OF THE PLUGIN-LOADER." );
|
||||
|
||||
error.initCause( e );
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
public MojoBinding parseMojoBinding( String bindingSpec,
|
||||
MavenProject project )
|
||||
throws LifecycleSpecificationException
|
||||
{
|
||||
try
|
||||
{
|
||||
return parseMojoBinding( bindingSpec, project, null, false );
|
||||
}
|
||||
catch ( LifecycleLoaderException e )
|
||||
{
|
||||
IllegalStateException error = new IllegalStateException( e.getMessage()
|
||||
+ "\n\nTHIS SHOULD BE IMPOSSIBLE DUE TO THE USAGE OF THE PLUGIN-LOADER." );
|
||||
|
||||
error.initCause( e );
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,221 +0,0 @@
|
|||
package org.apache.maven.lifecycle.binding;
|
||||
|
||||
import org.apache.maven.lifecycle.LifecycleSpecificationException;
|
||||
import org.apache.maven.lifecycle.LifecycleUtils;
|
||||
import org.apache.maven.lifecycle.mapping.LifecycleMapping;
|
||||
import org.apache.maven.lifecycle.model.BuildBinding;
|
||||
import org.apache.maven.lifecycle.model.CleanBinding;
|
||||
import org.apache.maven.lifecycle.model.LifecycleBindings;
|
||||
import org.apache.maven.lifecycle.model.MojoBinding;
|
||||
import org.apache.maven.lifecycle.model.Phase;
|
||||
import org.apache.maven.lifecycle.model.SiteBinding;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.component.annotations.Requirement;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
* Responsible for parsing the Maven-2.0.x lifecycle-definition syntaxes. This class is partitioned from the others,
|
||||
* because this syntax should be deprecated and removed from support, eventually.
|
||||
*
|
||||
* @author jdcasey
|
||||
*/
|
||||
@Component(role = LegacyLifecycleMappingParser.class)
|
||||
public class LegacyLifecycleMappingParser
|
||||
{
|
||||
public static final String ROLE = LegacyLifecycleMappingParser.class.getName();
|
||||
|
||||
@Requirement
|
||||
private MojoBindingFactory mojoBindingFactory;
|
||||
|
||||
public LifecycleBindings parseDefaultMappings( final List lifecycles )
|
||||
throws LifecycleSpecificationException
|
||||
{
|
||||
if( lifecycles == null )
|
||||
{
|
||||
throw new IllegalArgumentException("lifecycles: null");
|
||||
}
|
||||
|
||||
LifecycleBindings bindings = new LifecycleBindings();
|
||||
|
||||
bindings.setPackaging( "unmatched" );
|
||||
|
||||
for ( Iterator it = lifecycles.iterator(); it.hasNext(); )
|
||||
{
|
||||
Lifecycle lifecycle = (Lifecycle) it.next();
|
||||
|
||||
if ( "clean".equals( lifecycle.getId() ) )
|
||||
{
|
||||
bindings.setCleanBinding( parseCleanBindings( lifecycle.getDefaultPhases(), Collections.EMPTY_LIST ) );
|
||||
}
|
||||
else if ( "site".equals( lifecycle.getId() ) )
|
||||
{
|
||||
bindings.setSiteBinding( parseSiteBindings( lifecycle.getDefaultPhases(), Collections.EMPTY_LIST ) );
|
||||
}
|
||||
else if ( "default".equals( lifecycle.getId() ) )
|
||||
{
|
||||
bindings.setBuildBinding( parseBuildBindings( lifecycle.getDefaultPhases(), Collections.EMPTY_LIST ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new LifecycleSpecificationException( "Unrecognized lifecycle: " + lifecycle.getId() );
|
||||
}
|
||||
}
|
||||
|
||||
LifecycleUtils.setOrigin( bindings, "default lifecycle" );
|
||||
|
||||
return bindings;
|
||||
}
|
||||
|
||||
public LifecycleBindings parseMappings( final LifecycleMapping mapping, final String packaging )
|
||||
throws LifecycleSpecificationException
|
||||
{
|
||||
LifecycleBindings bindings = new LifecycleBindings();
|
||||
bindings.setPackaging( packaging );
|
||||
|
||||
bindings.setCleanBinding( parseCleanBindings( mapping.getPhases( "clean" ), mapping.getOptionalMojos( "clean" ) ) );
|
||||
|
||||
bindings.setBuildBinding( parseBuildBindings( mapping.getPhases( "default" ),
|
||||
mapping.getOptionalMojos( "default" ) ) );
|
||||
|
||||
bindings.setSiteBinding( parseSiteBindings( mapping.getPhases( "site" ), mapping.getOptionalMojos( "site" ) ) );
|
||||
|
||||
LifecycleUtils.setOrigin( bindings, "packaging: " + packaging );
|
||||
|
||||
return bindings;
|
||||
}
|
||||
|
||||
private BuildBinding parseBuildBindings( final Map phases, final List optionalKeys )
|
||||
throws LifecycleSpecificationException
|
||||
{
|
||||
BuildBinding binding = new BuildBinding();
|
||||
|
||||
if ( phases != null )
|
||||
{
|
||||
binding.setValidate( parsePhaseBindings( (String) phases.get( "validate" ), optionalKeys ) );
|
||||
|
||||
binding.setInitialize( parsePhaseBindings( (String) phases.get( "initialize" ), optionalKeys ) );
|
||||
|
||||
binding.setGenerateSources( parsePhaseBindings( (String) phases.get( "generate-sources" ), optionalKeys ) );
|
||||
|
||||
binding.setProcessSources( parsePhaseBindings( (String) phases.get( "process-sources" ), optionalKeys ) );
|
||||
|
||||
binding.setGenerateResources( parsePhaseBindings( (String) phases.get( "generate-resources" ), optionalKeys ) );
|
||||
|
||||
binding.setProcessResources( parsePhaseBindings( (String) phases.get( "process-resources" ), optionalKeys ) );
|
||||
|
||||
binding.setCompile( parsePhaseBindings( (String) phases.get( "compile" ), optionalKeys ) );
|
||||
|
||||
binding.setProcessClasses( parsePhaseBindings( (String) phases.get( "process-classes" ), optionalKeys ) );
|
||||
|
||||
binding.setGenerateTestSources( parsePhaseBindings( (String) phases.get( "generate-test-sources" ),
|
||||
optionalKeys ) );
|
||||
|
||||
binding.setProcessTestSources( parsePhaseBindings( (String) phases.get( "process-test-sources" ),
|
||||
optionalKeys ) );
|
||||
|
||||
binding.setGenerateTestResources( parsePhaseBindings( (String) phases.get( "generate-test-resources" ),
|
||||
optionalKeys ) );
|
||||
|
||||
binding.setProcessTestResources( parsePhaseBindings( (String) phases.get( "process-test-resources" ),
|
||||
optionalKeys ) );
|
||||
|
||||
binding.setTestCompile( parsePhaseBindings( (String) phases.get( "test-compile" ), optionalKeys ) );
|
||||
|
||||
binding.setProcessTestClasses( parsePhaseBindings( (String) phases.get( "process-test-classes" ),
|
||||
optionalKeys ) );
|
||||
|
||||
binding.setTest( parsePhaseBindings( (String) phases.get( "test" ), optionalKeys ) );
|
||||
|
||||
binding.setPreparePackage( parsePhaseBindings( (String) phases.get( "prepare-package" ), optionalKeys ) );
|
||||
|
||||
binding.setCreatePackage( parsePhaseBindings( (String) phases.get( "package" ), optionalKeys ) );
|
||||
|
||||
binding.setPreIntegrationTest( parsePhaseBindings( (String) phases.get( "pre-integration-test" ),
|
||||
optionalKeys ) );
|
||||
|
||||
binding.setIntegrationTest( parsePhaseBindings( (String) phases.get( "integration-test" ), optionalKeys ) );
|
||||
|
||||
binding.setPostIntegrationTest( parsePhaseBindings( (String) phases.get( "post-integration-test" ),
|
||||
optionalKeys ) );
|
||||
|
||||
binding.setVerify( parsePhaseBindings( (String) phases.get( "verify" ), optionalKeys ) );
|
||||
|
||||
binding.setInstall( parsePhaseBindings( (String) phases.get( "install" ), optionalKeys ) );
|
||||
|
||||
binding.setDeploy( parsePhaseBindings( (String) phases.get( "deploy" ), optionalKeys ) );
|
||||
}
|
||||
|
||||
return binding;
|
||||
}
|
||||
|
||||
private CleanBinding parseCleanBindings( final Map phaseMappings, final List optionalKeys )
|
||||
throws LifecycleSpecificationException
|
||||
{
|
||||
CleanBinding binding = new CleanBinding();
|
||||
|
||||
if ( phaseMappings != null )
|
||||
{
|
||||
binding.setPreClean( parsePhaseBindings( (String) phaseMappings.get( "pre-clean" ), optionalKeys ) );
|
||||
|
||||
binding.setClean( parsePhaseBindings( (String) phaseMappings.get( "clean" ), optionalKeys ) );
|
||||
|
||||
binding.setPostClean( parsePhaseBindings( (String) phaseMappings.get( "post-clean" ), optionalKeys ) );
|
||||
}
|
||||
|
||||
return binding;
|
||||
}
|
||||
|
||||
private Phase parsePhaseBindings( final String bindingList, final List optionalKeys )
|
||||
throws LifecycleSpecificationException
|
||||
{
|
||||
Phase phase = new Phase();
|
||||
|
||||
if ( bindingList != null )
|
||||
{
|
||||
for ( StringTokenizer tok = new StringTokenizer( bindingList, "," ); tok.hasMoreTokens(); )
|
||||
{
|
||||
String rawBinding = tok.nextToken().trim();
|
||||
|
||||
MojoBinding binding = mojoBindingFactory.parseMojoBinding( rawBinding );
|
||||
if ( ( optionalKeys != null ) && optionalKeys.contains( rawBinding ) )
|
||||
{
|
||||
binding.setOptional( true );
|
||||
}
|
||||
|
||||
if ( binding == null )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
phase.addBinding( binding );
|
||||
}
|
||||
}
|
||||
|
||||
return phase;
|
||||
}
|
||||
|
||||
private SiteBinding parseSiteBindings( final Map phases, final List optionalKeys )
|
||||
throws LifecycleSpecificationException
|
||||
{
|
||||
SiteBinding binding = new SiteBinding();
|
||||
|
||||
if ( phases != null )
|
||||
{
|
||||
binding.setPreSite( parsePhaseBindings( (String) phases.get( "pre-site" ), optionalKeys ) );
|
||||
|
||||
binding.setSite( parsePhaseBindings( (String) phases.get( "site" ), optionalKeys ) );
|
||||
|
||||
binding.setPostSite( parsePhaseBindings( (String) phases.get( "post-site" ), optionalKeys ) );
|
||||
|
||||
binding.setSiteDeploy( parsePhaseBindings( (String) phases.get( "site-deploy" ), optionalKeys ) );
|
||||
}
|
||||
|
||||
return binding;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,101 +0,0 @@
|
|||
package org.apache.maven.lifecycle.binding;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Class Lifecycle.
|
||||
*/
|
||||
public class Lifecycle
|
||||
{
|
||||
/**
|
||||
* Field id
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* Field phases
|
||||
*/
|
||||
private List phases;
|
||||
|
||||
/**
|
||||
* default phases.
|
||||
*/
|
||||
private Map defaultPhases;
|
||||
|
||||
/**
|
||||
* Method addPhase
|
||||
*
|
||||
* @param phase
|
||||
*/
|
||||
public void addPhase( String phase )
|
||||
{
|
||||
getPhases().add( phase );
|
||||
} //-- void addPhase(Phase)
|
||||
|
||||
/**
|
||||
* Method getId
|
||||
*/
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
} //-- String getId()
|
||||
|
||||
/**
|
||||
* Method getPhases
|
||||
*/
|
||||
public List getPhases()
|
||||
{
|
||||
if ( phases == null )
|
||||
{
|
||||
phases = new ArrayList();
|
||||
}
|
||||
|
||||
return phases;
|
||||
} //-- java.util.List getPhases()
|
||||
|
||||
/**
|
||||
* Method setId
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
public void setId( String id )
|
||||
{
|
||||
this.id = id;
|
||||
} //-- void setId(String)
|
||||
|
||||
/**
|
||||
* Method setPhases
|
||||
*
|
||||
* @param phases
|
||||
*/
|
||||
public void setPhases( List phases )
|
||||
{
|
||||
this.phases = phases;
|
||||
} //-- void setPhases(java.util.List)
|
||||
|
||||
public Map getDefaultPhases()
|
||||
{
|
||||
return defaultPhases;
|
||||
}
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
package org.apache.maven.lifecycle.binding;
|
||||
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.lifecycle.LifecycleLoaderException;
|
||||
import org.apache.maven.lifecycle.LifecycleSpecificationException;
|
||||
import org.apache.maven.lifecycle.model.LifecycleBindings;
|
||||
import org.apache.maven.lifecycle.model.MojoBinding;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Responsible for the gross construction of LifecycleBindings, or mappings of MojoBinding instances to different parts
|
||||
* of the three lifecycles: clean, build, and site. Also, handles transcribing these LifecycleBindings instances into
|
||||
* lists of MojoBinding's, which can be consumed by the LifecycleExecutor.
|
||||
*
|
||||
* @author jdcasey
|
||||
*
|
||||
*/
|
||||
public interface LifecycleBindingManager
|
||||
{
|
||||
|
||||
String ROLE = LifecycleBindingManager.class.getName();
|
||||
|
||||
/**
|
||||
* Construct the LifecycleBindings for the default lifecycle mappings, including injection of configuration from the
|
||||
* project into each MojoBinding, where appropriate.
|
||||
*/
|
||||
LifecycleBindings getDefaultBindings( MavenProject project ) throws LifecycleSpecificationException;
|
||||
|
||||
/**
|
||||
* Retrieve the LifecycleBindings given by the lifecycle mapping component/file for the project's packaging. Any
|
||||
* applicable mojo configuration will be injected into the LifecycleBindings from the POM.
|
||||
* @param session
|
||||
*/
|
||||
LifecycleBindings getBindingsForPackaging( MavenProject project, MavenSession session )
|
||||
throws LifecycleLoaderException, LifecycleSpecificationException;
|
||||
|
||||
/**
|
||||
* Construct the LifecycleBindings that constitute the extra mojos bound to the lifecycle within the POM itself.
|
||||
*/
|
||||
LifecycleBindings getProjectCustomBindings( MavenProject project, MavenSession session, Set unresolvableBindings )
|
||||
throws LifecycleLoaderException, LifecycleSpecificationException;
|
||||
|
||||
/**
|
||||
* Construct the LifecycleBindings that constitute the mojos mapped to the lifecycles by an overlay specified in a
|
||||
* plugin. Inject mojo configuration from the POM into all appropriate MojoBinding instances.
|
||||
*/
|
||||
LifecycleBindings getPluginLifecycleOverlay( PluginDescriptor pluginDescriptor, String lifecycleId,
|
||||
MavenProject project )
|
||||
throws LifecycleLoaderException, LifecycleSpecificationException;
|
||||
|
||||
/**
|
||||
* Retrieve the list of MojoBinding instances that correspond to the reports configured for the specified project.
|
||||
* Inject all appropriate configuration from the POM for each MojoBinding, using the following precedence rules:
|
||||
* <br/>
|
||||
* <ol>
|
||||
* <li>report-set-level configuration</li>
|
||||
* <li>reporting-level configuration</li>
|
||||
* <li>execution-level configuration</li>
|
||||
* <li>plugin-level configuration</li>
|
||||
* </ol>
|
||||
*/
|
||||
List getReportBindings( MavenProject project, MavenSession session ) throws LifecycleLoaderException, LifecycleSpecificationException;
|
||||
|
||||
/**
|
||||
* Go through the set of unbindable mojos provided (these are {@link MojoBinding} instancess coming
|
||||
* from the project as custom bindings for which we failed to determine a phase
|
||||
* to bind them during {@link LifecycleBindingManager#getProjectCustomBindings(MavenProject, MavenSession, Set)}).
|
||||
* For each {@link MojoBinding}, attempt to resolve it again, and if successful,
|
||||
* extract the default phase name from the {@link MojoDescriptor}.
|
||||
*
|
||||
* @throws LifecycleSpecificationException In case the plugin cannot be resolved, the plugin doesn't contain the specified mojo,
|
||||
* or the mojo doesn't have a default phase.
|
||||
*/
|
||||
void resolveUnbindableMojos( final Set unbindableMojos,
|
||||
final MavenProject project,
|
||||
final MavenSession session,
|
||||
final LifecycleBindings lifecycleBindings )
|
||||
throws LifecycleSpecificationException;
|
||||
|
||||
List<org.apache.maven.lifecycle.binding.Lifecycle> getLifecycles();
|
||||
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
package org.apache.maven.lifecycle.binding;
|
||||
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.lifecycle.LifecycleLoaderException;
|
||||
import org.apache.maven.lifecycle.LifecycleSpecificationException;
|
||||
import org.apache.maven.lifecycle.model.MojoBinding;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
/**
|
||||
* Responsible for constructing or parsing MojoBinding instances from one of several sources, potentially
|
||||
* using the {@link PluginLoader} to resolve any plugin prefixes first.
|
||||
*
|
||||
* @author jdcasey
|
||||
*
|
||||
*/
|
||||
public interface MojoBindingFactory
|
||||
{
|
||||
|
||||
String ROLE = MojoBindingFactory.class.getName();
|
||||
|
||||
/**
|
||||
* Parse the specified mojo string into a MojoBinding, optionally allowing plugin-prefix references.
|
||||
* If a plugin-prefix is allowed and used, resolve the prefix and use the resulting PluginDescriptor
|
||||
* to set groupId and artifactId on the MojoBinding instance.
|
||||
*/
|
||||
MojoBinding parseMojoBinding( String bindingSpec,
|
||||
MavenProject project,
|
||||
MavenSession session,
|
||||
boolean allowPrefixReference )
|
||||
throws LifecycleSpecificationException, LifecycleLoaderException;
|
||||
|
||||
/**
|
||||
* Create a new MojoBinding instance with the specified information, and inject POM configurations
|
||||
* appropriate to that mojo before returning it.
|
||||
*/
|
||||
MojoBinding createMojoBinding( String groupId,
|
||||
String artifactId,
|
||||
String version,
|
||||
String goal,
|
||||
MavenProject project );
|
||||
|
||||
/**
|
||||
* Simplified version of {@link MojoBindingFactory#parseMojoBinding(String, MavenProject, MavenSession, boolean)}
|
||||
* which assumes the project is null and prefixes are not allowed. This method will <b>never</b>
|
||||
* result in the {@link PluginLoader} being used to resolve the PluginDescriptor.
|
||||
*/
|
||||
MojoBinding parseMojoBinding( String bindingSpec )
|
||||
throws LifecycleSpecificationException;
|
||||
|
||||
/**
|
||||
* Simplified version of {@link MojoBindingFactory#parseMojoBinding(String, MavenProject, MavenSession, boolean)}
|
||||
* which assumes that prefixes are not allowed. This method will <b>never</b>
|
||||
* result in the {@link PluginLoader} being used to resolve the PluginDescriptor.
|
||||
* @throws LifecycleSpecificationException
|
||||
*/
|
||||
MojoBinding parseMojoBinding( String bindingSpec,
|
||||
MavenProject project )
|
||||
throws LifecycleSpecificationException;
|
||||
|
||||
}
|
|
@ -24,15 +24,12 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
|
||||
/**
|
||||
* Lifecycle mapping for a POM.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
@Component(role = LifecycleMapping.class)
|
||||
public class DefaultLifecycleMapping
|
||||
implements LifecycleMapping
|
||||
{
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.Map;
|
|||
|
||||
/**
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface LifecycleMapping
|
||||
{
|
||||
|
|
|
@ -1,342 +0,0 @@
|
|||
package org.apache.maven.lifecycle.plan;
|
||||
|
||||
import org.apache.maven.lifecycle.LifecycleLoaderException;
|
||||
import org.apache.maven.lifecycle.LifecycleSpecificationException;
|
||||
import org.apache.maven.lifecycle.LifecycleUtils;
|
||||
import org.apache.maven.lifecycle.MojoBindingUtils;
|
||||
import org.apache.maven.lifecycle.NoSuchPhaseException;
|
||||
import org.apache.maven.lifecycle.model.LifecycleBinding;
|
||||
import org.apache.maven.lifecycle.model.LifecycleBindings;
|
||||
import org.apache.maven.lifecycle.model.MojoBinding;
|
||||
import org.apache.maven.lifecycle.statemgmt.StateManagementUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
|
||||
public class BuildPlan
|
||||
{
|
||||
private LifecycleBindings bindings;
|
||||
|
||||
private final List tasks;
|
||||
|
||||
private final Map forkedDirectInvocations;
|
||||
|
||||
private final Map forkedPhases;
|
||||
|
||||
private List renderedLifecycleMojos = new ArrayList();
|
||||
|
||||
private final Map directInvocationBindings;
|
||||
|
||||
private Set fullyResolvedBindings = new HashSet();
|
||||
|
||||
private boolean includingReports = false;
|
||||
|
||||
private Set unbindableMojos;
|
||||
|
||||
public BuildPlan( final LifecycleBindings packaging, final LifecycleBindings projectBindings,
|
||||
final LifecycleBindings defaults, final Set unbindableMojos, final List tasks )
|
||||
throws LifecycleSpecificationException, LifecycleLoaderException
|
||||
{
|
||||
this( LifecycleUtils.mergeBindings( packaging, projectBindings, defaults, true, false ), unbindableMojos, tasks );
|
||||
}
|
||||
|
||||
public BuildPlan( final LifecycleBindings bindings, final Set unbindableMojos, final List tasks )
|
||||
throws LifecycleSpecificationException, LifecycleLoaderException
|
||||
{
|
||||
this.bindings = bindings;
|
||||
this.unbindableMojos = unbindableMojos == null ? null : new HashSet( unbindableMojos );
|
||||
this.tasks = tasks;
|
||||
forkedDirectInvocations = new HashMap();
|
||||
forkedPhases = new HashMap();
|
||||
directInvocationBindings = new HashMap();
|
||||
}
|
||||
|
||||
private BuildPlan( final LifecycleBindings bindings, final Map forkedDirectInvocations, final Map forkedPhases,
|
||||
final Map directInvocationBindings, final Set fullyResolvedMojoBindings, final Set unbindableMojos,
|
||||
final List tasks, boolean includingReports )
|
||||
{
|
||||
this.unbindableMojos = unbindableMojos == null ? null : new HashSet( unbindableMojos );
|
||||
this.bindings = LifecycleUtils.cloneBindings( bindings );
|
||||
this.forkedDirectInvocations = new HashMap( forkedDirectInvocations );
|
||||
this.forkedPhases = new HashMap( forkedPhases );
|
||||
fullyResolvedBindings = new HashSet( fullyResolvedMojoBindings );
|
||||
this.tasks = tasks;
|
||||
this.includingReports = includingReports;
|
||||
this.directInvocationBindings = new HashMap( directInvocationBindings );
|
||||
}
|
||||
|
||||
public void markAsIncludingReports()
|
||||
{
|
||||
includingReports = true;
|
||||
}
|
||||
|
||||
public boolean isIncludingReports()
|
||||
{
|
||||
return includingReports;
|
||||
}
|
||||
|
||||
public boolean hasUnbindableMojos()
|
||||
{
|
||||
return unbindableMojos != null && !unbindableMojos.isEmpty();
|
||||
}
|
||||
|
||||
public Set getUnbindableMojos()
|
||||
{
|
||||
return unbindableMojos;
|
||||
}
|
||||
|
||||
public void clearUnbindableMojos()
|
||||
{
|
||||
unbindableMojos = null;
|
||||
}
|
||||
|
||||
public void addUnbindableMojo( MojoBinding binding )
|
||||
{
|
||||
unbindableMojos.add( binding );
|
||||
}
|
||||
|
||||
public boolean isFullyResolved( final MojoBinding mojoBinding )
|
||||
{
|
||||
String key = MojoBindingUtils.createMojoBindingKey( mojoBinding, false );
|
||||
|
||||
return fullyResolvedBindings.contains( key );
|
||||
}
|
||||
|
||||
public void markFullyResolved()
|
||||
throws NoSuchPhaseException
|
||||
{
|
||||
List bindings = renderExecutionPlan( new Stack() );
|
||||
|
||||
for ( Iterator it = bindings.iterator(); it.hasNext(); )
|
||||
{
|
||||
MojoBinding mojoBinding = (MojoBinding) it.next();
|
||||
|
||||
String key = MojoBindingUtils.createMojoBindingKey( mojoBinding, false );
|
||||
|
||||
fullyResolvedBindings.add( key );
|
||||
}
|
||||
}
|
||||
|
||||
public void addLifecycleOverlay( final LifecycleBindings overlay )
|
||||
{
|
||||
bindings = LifecycleUtils.mergeBindings( overlay, bindings, null, true, true );
|
||||
}
|
||||
|
||||
public void addTask( final String task, final MojoBinding binding )
|
||||
throws LifecycleSpecificationException, LifecycleLoaderException
|
||||
{
|
||||
tasks.add( task );
|
||||
|
||||
if ( !LifecycleUtils.isValidPhaseName( task ) )
|
||||
{
|
||||
addDirectInvocationBinding( task, binding );
|
||||
}
|
||||
}
|
||||
|
||||
public LifecycleBindings getLifecycleBindings()
|
||||
{
|
||||
return bindings;
|
||||
}
|
||||
|
||||
public List getTasks()
|
||||
{
|
||||
return tasks;
|
||||
}
|
||||
|
||||
public void addDirectInvocationBinding( final String key, final MojoBinding binding )
|
||||
{
|
||||
directInvocationBindings.put( MojoBindingUtils.createMojoBindingKey( binding, false ), binding );
|
||||
directInvocationBindings.put( key, binding );
|
||||
}
|
||||
|
||||
public Map getDirectInvocationBindings()
|
||||
{
|
||||
return directInvocationBindings;
|
||||
}
|
||||
|
||||
public Map getForkedDirectInvocations()
|
||||
{
|
||||
return forkedDirectInvocations;
|
||||
}
|
||||
|
||||
public Map getForkedPhases()
|
||||
{
|
||||
return forkedPhases;
|
||||
}
|
||||
|
||||
public void addForkedExecution( final MojoBinding mojoBinding, final BuildPlan plan )
|
||||
{
|
||||
String key = MojoBindingUtils.createMojoBindingKey( mojoBinding, false );
|
||||
|
||||
forkedPhases.put( key, plan );
|
||||
}
|
||||
|
||||
public void addForkedExecution( final MojoBinding mojoBinding, final List forkedInvocations )
|
||||
{
|
||||
String key = MojoBindingUtils.createMojoBindingKey( mojoBinding, false );
|
||||
|
||||
List invoke = (List) forkedDirectInvocations.get( key );
|
||||
|
||||
if ( invoke == null )
|
||||
{
|
||||
invoke = new ArrayList();
|
||||
forkedDirectInvocations.put( key, invoke );
|
||||
}
|
||||
|
||||
invoke.addAll( forkedInvocations );
|
||||
}
|
||||
|
||||
public BuildPlan copy( String task )
|
||||
{
|
||||
return copy( Collections.singletonList( task ) );
|
||||
}
|
||||
|
||||
public BuildPlan copy( final List newTasks )
|
||||
{
|
||||
return new BuildPlan( bindings, forkedDirectInvocations, forkedPhases, directInvocationBindings, fullyResolvedBindings, unbindableMojos, newTasks, includingReports );
|
||||
}
|
||||
|
||||
public void resetExecutionProgress()
|
||||
{
|
||||
renderedLifecycleMojos = new ArrayList();
|
||||
for ( Iterator it = forkedPhases.values().iterator(); it.hasNext(); )
|
||||
{
|
||||
BuildPlan plan = (BuildPlan) it.next();
|
||||
plan.resetExecutionProgress();
|
||||
}
|
||||
}
|
||||
|
||||
public List renderExecutionPlan( final Stack executionStack )
|
||||
throws NoSuchPhaseException
|
||||
{
|
||||
LifecycleUtils.setupTrackingInfo( bindings );
|
||||
|
||||
List plan = new ArrayList();
|
||||
|
||||
for ( Iterator it = tasks.iterator(); it.hasNext(); )
|
||||
{
|
||||
String task = (String) it.next();
|
||||
|
||||
if ( LifecycleUtils.isValidPhaseName( task ) )
|
||||
{
|
||||
// find the lifecyle that this task belongs in...
|
||||
LifecycleBinding binding = LifecycleUtils.findLifecycleBindingForPhase( task, bindings );
|
||||
|
||||
// get the list of mojo bindings before or at the specified phase in the lifecycle
|
||||
List bindingsToAdd = LifecycleUtils.getMojoBindingListForLifecycle( task, binding );
|
||||
|
||||
// backup copy for rendered tracking...
|
||||
List newRendered = new ArrayList( bindingsToAdd );
|
||||
|
||||
// if we've already executed part of the lifecycle, just continue with the new bindings.
|
||||
if ( ( renderedLifecycleMojos != null ) && ( renderedLifecycleMojos.size() < bindingsToAdd.size() )
|
||||
&& bindingsToAdd.containsAll( renderedLifecycleMojos ) )
|
||||
{
|
||||
bindingsToAdd = bindingsToAdd.subList( renderedLifecycleMojos.size(), bindingsToAdd.size() );
|
||||
}
|
||||
|
||||
// save the current binding list for tracking progress through the lifecycle.
|
||||
renderedLifecycleMojos = newRendered;
|
||||
|
||||
for ( Iterator itMojos = bindingsToAdd.iterator(); itMojos.hasNext(); )
|
||||
{
|
||||
MojoBinding mojoBinding = (MojoBinding) itMojos.next();
|
||||
String key = MojoBindingUtils.createMojoBindingKey( mojoBinding, false );
|
||||
if ( !executionStack.contains( key ) )
|
||||
{
|
||||
plan.addAll( findForkedBindings( mojoBinding, executionStack ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MojoBinding mojoBinding = (MojoBinding) directInvocationBindings.get( task );
|
||||
String key = MojoBindingUtils.createMojoBindingKey( mojoBinding, false );
|
||||
if ( !executionStack.contains( key ) )
|
||||
{
|
||||
plan.addAll( findForkedBindings( mojoBinding, executionStack ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return plan;
|
||||
}
|
||||
|
||||
private List findForkedBindings( final MojoBinding mojoBinding, final Stack executionStack )
|
||||
throws NoSuchPhaseException
|
||||
{
|
||||
List bindings = new ArrayList();
|
||||
|
||||
String key = MojoBindingUtils.createMojoBindingKey( mojoBinding, false );
|
||||
|
||||
executionStack.push( key );
|
||||
try
|
||||
{
|
||||
List forkedBindings = new ArrayList();
|
||||
|
||||
BuildPlan forkedPlan = (BuildPlan) forkedPhases.get( key );
|
||||
|
||||
// if we have a forked build plan, recurse into it and retrieve the execution plan.
|
||||
if ( forkedPlan != null )
|
||||
{
|
||||
forkedBindings = forkedPlan.renderExecutionPlan( executionStack );
|
||||
}
|
||||
|
||||
List directInvocations = (List) forkedDirectInvocations.get( key );
|
||||
|
||||
// leave room for new kinds of forks, and do some extra validation...
|
||||
// if this is a list, it's a list of direct mojo invocations...we have to see if they have their own
|
||||
// forks.
|
||||
if ( directInvocations != null )
|
||||
{
|
||||
for ( Iterator it = directInvocations.iterator(); it.hasNext(); )
|
||||
{
|
||||
MojoBinding invocation = (MojoBinding) it.next();
|
||||
|
||||
String invocationKey = MojoBindingUtils.createMojoBindingKey( invocation, false );
|
||||
|
||||
if ( executionStack.contains( invocationKey ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
forkedBindings.addAll( findForkedBindings( invocation, executionStack ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( !forkedBindings.isEmpty() )
|
||||
{
|
||||
bindings.add( StateManagementUtils.createStartForkedExecutionMojoBinding() );
|
||||
bindings.addAll( forkedBindings );
|
||||
bindings.add( StateManagementUtils.createEndForkedExecutionMojoBinding() );
|
||||
}
|
||||
|
||||
bindings.add( mojoBinding );
|
||||
|
||||
if ( !forkedBindings.isEmpty() )
|
||||
{
|
||||
bindings.add( StateManagementUtils.createClearForkedExecutionMojoBinding() );
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
executionStack.pop();
|
||||
}
|
||||
|
||||
return bindings;
|
||||
}
|
||||
|
||||
public void removeAll( List mojoBindings )
|
||||
throws NoSuchPhaseException
|
||||
{
|
||||
LifecycleUtils.removeMojoBindings( mojoBindings, bindings, false );
|
||||
}
|
||||
|
||||
}
|
|
@ -1,157 +0,0 @@
|
|||
package org.apache.maven.lifecycle.plan;
|
||||
|
||||
import org.apache.maven.lifecycle.LifecycleSpecificationException;
|
||||
import org.apache.maven.lifecycle.MojoBindingUtils;
|
||||
import org.apache.maven.lifecycle.model.MojoBinding;
|
||||
import org.apache.maven.lifecycle.statemgmt.StateManagementUtils;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* Collection of static utility methods used to work with LifecycleBindings and other collections of MojoBinding
|
||||
* instances that make up a build plan.
|
||||
*/
|
||||
public final class BuildPlanUtils
|
||||
{
|
||||
|
||||
private BuildPlanUtils()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an entire build plan to a String. If extendedInfo == true, include each MojoBinding's configuration in the
|
||||
* output.
|
||||
*/
|
||||
public static String listBuildPlan( final BuildPlan plan, final boolean extendedInfo )
|
||||
throws LifecycleSpecificationException, LifecyclePlannerException
|
||||
{
|
||||
List mojos = plan.renderExecutionPlan( new Stack() );
|
||||
plan.resetExecutionProgress();
|
||||
|
||||
return listBuildPlan( mojos, extendedInfo );
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a list containing the MojoBinding instances for an entire build plan to a String. If extendedInfo == true,
|
||||
* include each MojoBinding's configuration in the output.
|
||||
*/
|
||||
public static String listBuildPlan( final List mojoBindings, final boolean extendedInfo )
|
||||
throws LifecycleSpecificationException, LifecyclePlannerException
|
||||
{
|
||||
StringBuffer listing = new StringBuffer();
|
||||
int indentLevel = 0;
|
||||
|
||||
int counter = 1;
|
||||
for ( Iterator it = mojoBindings.iterator(); it.hasNext(); )
|
||||
{
|
||||
MojoBinding binding = (MojoBinding) it.next();
|
||||
|
||||
if ( StateManagementUtils.isForkedExecutionStartMarker( binding ) )
|
||||
{
|
||||
newListingLine( listing, indentLevel, counter );
|
||||
listing.append( "[fork start]" );
|
||||
|
||||
if ( extendedInfo )
|
||||
{
|
||||
listing.append( ' ' ).append( formatMojoListing( binding, indentLevel, extendedInfo ) );
|
||||
}
|
||||
|
||||
indentLevel++;
|
||||
}
|
||||
else if ( StateManagementUtils.isForkedExecutionClearMarker( binding ) )
|
||||
{
|
||||
indentLevel--;
|
||||
|
||||
newListingLine( listing, indentLevel, counter );
|
||||
listing.append( "[fork cleanup]" );
|
||||
|
||||
if ( extendedInfo )
|
||||
{
|
||||
listing.append( ' ' ).append( formatMojoListing( binding, indentLevel, extendedInfo ) );
|
||||
}
|
||||
}
|
||||
else if ( StateManagementUtils.isForkedExecutionEndMarker( binding ) )
|
||||
{
|
||||
indentLevel--;
|
||||
|
||||
newListingLine( listing, indentLevel, counter );
|
||||
listing.append( "[fork end]" );
|
||||
|
||||
if ( extendedInfo )
|
||||
{
|
||||
listing.append( ' ' ).append( formatMojoListing( binding, indentLevel, extendedInfo ) );
|
||||
}
|
||||
|
||||
indentLevel++;
|
||||
}
|
||||
else
|
||||
{
|
||||
newListingLine( listing, indentLevel, counter );
|
||||
listing.append( formatMojoListing( binding, indentLevel, extendedInfo ) );
|
||||
}
|
||||
|
||||
counter++;
|
||||
}
|
||||
|
||||
return listing.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Append a newline character, add the next line's number, and indent the new line to the appropriate level (which
|
||||
* tracks separate forked executions).
|
||||
*/
|
||||
private static void newListingLine( final StringBuffer listing, final int indentLevel, final int counter )
|
||||
{
|
||||
listing.append( '\n' );
|
||||
|
||||
listing.append( counter ).append( "." );
|
||||
|
||||
for ( int i = 0; i < indentLevel; i++ )
|
||||
{
|
||||
listing.append( " " );
|
||||
}
|
||||
|
||||
// adding a minimal offset from the counter (line-number) of the listing.
|
||||
listing.append( ' ' );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a single MojoBinding for inclusion in a build plan listing. If extendedInfo == true, include the
|
||||
* MojoBinding's configuration in the output.
|
||||
*/
|
||||
public static String formatMojoListing( final MojoBinding binding, final int indentLevel, final boolean extendedInfo )
|
||||
{
|
||||
StringBuffer listing = new StringBuffer();
|
||||
|
||||
listing.append( MojoBindingUtils.toString( binding ) );
|
||||
listing.append( " [executionId: " ).append( binding.getExecutionId() ).append( ", phase: " );
|
||||
|
||||
if ( ( binding.getPhase() != null ) && ( binding.getPhase().getName() != null ) )
|
||||
{
|
||||
listing.append( binding.getPhase().getName() );
|
||||
}
|
||||
else
|
||||
{
|
||||
listing.append( "None specified" );
|
||||
}
|
||||
|
||||
listing.append( "]" );
|
||||
|
||||
if ( extendedInfo )
|
||||
{
|
||||
listing.append( "\nOrigin: " ).append( binding.getOrigin() );
|
||||
listing.append( "\nOrigin Description: " ).append( binding.getOriginDescription() );
|
||||
listing.append( "\nConfiguration:\n\t" ).append(
|
||||
String.valueOf( binding.getConfiguration() ).replaceAll(
|
||||
"\\n",
|
||||
"\n\t" ) ).append(
|
||||
'\n' );
|
||||
}
|
||||
|
||||
return listing.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package org.apache.maven.lifecycle.plan;
|
||||
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.lifecycle.LifecycleLoaderException;
|
||||
import org.apache.maven.lifecycle.LifecycleSpecificationException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Responsible for creating a plan of execution for a given project and list of tasks. This build plan consists of
|
||||
* MojoBinding instances that carry all the information necessary to execute a mojo, including configuration from the
|
||||
* POM and other sources. NOTE: the build plan may be constructed of a main lifecycle binding-set, plus any number of
|
||||
* lifecycle modifiers and direct-invocation modifiers, to handle cases of forked execution.
|
||||
*
|
||||
* @author jdcasey
|
||||
*
|
||||
*/
|
||||
public interface BuildPlanner
|
||||
{
|
||||
|
||||
/**
|
||||
* Orchestrates construction of the build plan which will be used by the user of LifecycleExecutor.
|
||||
*/
|
||||
BuildPlan constructBuildPlan( List tasks, MavenProject project, MavenSession session, boolean allowUnbindableMojos )
|
||||
throws LifecycleLoaderException, LifecycleSpecificationException, LifecyclePlannerException;
|
||||
}
|
|
@ -1,422 +0,0 @@
|
|||
package org.apache.maven.lifecycle.plan;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.lifecycle.LifecycleLoaderException;
|
||||
import org.apache.maven.lifecycle.LifecycleSpecificationException;
|
||||
import org.apache.maven.lifecycle.LifecycleUtils;
|
||||
import org.apache.maven.lifecycle.MojoBindingUtils;
|
||||
import org.apache.maven.lifecycle.binding.LifecycleBindingManager;
|
||||
import org.apache.maven.lifecycle.binding.MojoBindingFactory;
|
||||
import org.apache.maven.lifecycle.model.LifecycleBindings;
|
||||
import org.apache.maven.lifecycle.model.MojoBinding;
|
||||
import org.apache.maven.plugin.PluginLoaderException;
|
||||
import org.apache.maven.plugin.PluginManager;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.component.annotations.Requirement;
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
|
||||
/**
|
||||
* Responsible for creating a plan of execution for a given project and list of tasks. This build
|
||||
* plan consists of MojoBinding instances that carry all the information necessary to execute a
|
||||
* mojo, including configuration from the POM and other sources. NOTE: the build plan may be
|
||||
* constructed of a main lifecycle binding-set, plus any number of lifecycle modifiers and
|
||||
* direct-invocation modifiers, to handle cases of forked execution.
|
||||
*
|
||||
* @author jdcasey
|
||||
*
|
||||
*/
|
||||
@Component(role = BuildPlanner.class)
|
||||
public class DefaultBuildPlanner
|
||||
implements BuildPlanner
|
||||
{
|
||||
@Requirement
|
||||
private PluginManager pluginLoader;
|
||||
|
||||
@Requirement
|
||||
private LifecycleBindingManager lifecycleBindingManager;
|
||||
|
||||
@Requirement
|
||||
private MojoBindingFactory mojoBindingFactory;
|
||||
|
||||
@Requirement
|
||||
private Logger logger;
|
||||
|
||||
public void constructInitialProjectBuildPlans( MavenSession session )
|
||||
throws LifecycleLoaderException, LifecycleSpecificationException, LifecyclePlannerException
|
||||
{
|
||||
for ( Iterator it = session.getSortedProjects().iterator(); it.hasNext(); )
|
||||
{
|
||||
MavenProject project = (MavenProject) it.next();
|
||||
|
||||
constructInitialProjectBuildPlan( project, session );
|
||||
}
|
||||
}
|
||||
|
||||
public BuildPlan constructInitialProjectBuildPlan( MavenProject project, MavenSession session )
|
||||
throws LifecycleLoaderException, LifecycleSpecificationException, LifecyclePlannerException
|
||||
{
|
||||
BuildPlan plan = constructBuildPlan( Collections.EMPTY_LIST, project, session, true );
|
||||
|
||||
return plan;
|
||||
}
|
||||
|
||||
/**
|
||||
* Orchestrates construction of the build plan which will be used by the user of
|
||||
* LifecycleExecutor.
|
||||
*/
|
||||
public BuildPlan constructBuildPlan( List tasks, MavenProject project, MavenSession session, boolean allowUnbindableMojos )
|
||||
throws LifecycleLoaderException, LifecycleSpecificationException, LifecyclePlannerException
|
||||
{
|
||||
boolean pluginResolutionAttempted = false;
|
||||
|
||||
LifecycleBindings defaultBindings = lifecycleBindingManager.getDefaultBindings( project );
|
||||
|
||||
LifecycleBindings packagingBindings = lifecycleBindingManager.getBindingsForPackaging( project, session );
|
||||
|
||||
Set unbindableMojos = new HashSet();
|
||||
LifecycleBindings projectBindings = lifecycleBindingManager.getProjectCustomBindings( project, session, unbindableMojos );
|
||||
|
||||
BuildPlan plan = new BuildPlan( packagingBindings, projectBindings, defaultBindings, unbindableMojos, tasks );
|
||||
|
||||
pluginResolutionAttempted = true;
|
||||
|
||||
if ( ( !pluginResolutionAttempted || !allowUnbindableMojos ) && plan.hasUnbindableMojos() )
|
||||
{
|
||||
lifecycleBindingManager.resolveUnbindableMojos( plan.getUnbindableMojos(), project, session, plan.getLifecycleBindings() );
|
||||
plan.clearUnbindableMojos();
|
||||
}
|
||||
|
||||
// initialize/resolve any direct-invocation tasks, if possible.
|
||||
initializeDirectInvocations( plan, project, session );
|
||||
|
||||
// Inject forked lifecycles as plan modifiers for each mojo that has @execute in it.
|
||||
addForkedLifecycleModifiers( plan, project, session, new LinkedList(), allowUnbindableMojos );
|
||||
addReportingLifecycleModifiers( plan, project, session, new LinkedList(), allowUnbindableMojos );
|
||||
|
||||
plan.markFullyResolved();
|
||||
|
||||
// TODO: Inject relative-ordered project/plugin executions as plan modifiers.
|
||||
|
||||
return plan;
|
||||
}
|
||||
|
||||
private void initializeDirectInvocations( final BuildPlan plan, final MavenProject project, final MavenSession session )
|
||||
throws LifecycleSpecificationException, LifecycleLoaderException
|
||||
{
|
||||
|
||||
List tasks = plan.getTasks();
|
||||
|
||||
for ( Iterator it = tasks.iterator(); it.hasNext(); )
|
||||
{
|
||||
String task = (String) it.next();
|
||||
|
||||
if ( !LifecycleUtils.isValidPhaseName( task ) )
|
||||
{
|
||||
MojoBinding binding = mojoBindingFactory.parseMojoBinding( task, project, session, true );
|
||||
|
||||
binding.setOrigin( MojoBinding.DIRECT_INVOCATION_ORIGIN );
|
||||
binding.setOriginDescription( "Original reference from user: " + task );
|
||||
|
||||
plan.addDirectInvocationBinding( task, binding );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Traverses all MojoBinding instances discovered from the POM and its packaging-mappings, and
|
||||
* orchestrates the process of injecting any modifiers that are necessary to accommodate forked
|
||||
* execution.
|
||||
*
|
||||
* @param callStack
|
||||
*/
|
||||
private void addForkedLifecycleModifiers( final BuildPlan plan, final MavenProject project, final MavenSession session, LinkedList callStack, final boolean allowUnbindableMojos )
|
||||
throws LifecyclePlannerException, LifecycleSpecificationException, LifecycleLoaderException
|
||||
{
|
||||
List planBindings = plan.renderExecutionPlan( new Stack() );
|
||||
plan.resetExecutionProgress();
|
||||
|
||||
for ( Iterator it = planBindings.iterator(); it.hasNext(); )
|
||||
{
|
||||
MojoBinding mojoBinding = (MojoBinding) it.next();
|
||||
|
||||
if ( !plan.isFullyResolved( mojoBinding ) )
|
||||
{
|
||||
findForkModifiers( mojoBinding, plan, project, session, callStack, allowUnbindableMojos );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void findForkModifiers( final MojoBinding mojoBinding, final BuildPlan plan, final MavenProject project, MavenSession session, LinkedList callStack, final boolean allowUnbindableMojos )
|
||||
throws LifecyclePlannerException, LifecycleSpecificationException, LifecycleLoaderException
|
||||
{
|
||||
PluginDescriptor pluginDescriptor = loadPluginDescriptor( mojoBinding, plan, project, session, allowUnbindableMojos );
|
||||
|
||||
if ( pluginDescriptor == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( mojoBinding.getGoal() );
|
||||
if ( mojoDescriptor == null )
|
||||
{
|
||||
throw new LifecyclePlannerException( "Mojo: " + mojoBinding.getGoal() + " does not exist in plugin: " + pluginDescriptor.getId() + "." );
|
||||
}
|
||||
|
||||
findForkModifiers( mojoBinding, pluginDescriptor, plan, project, session, callStack, false, allowUnbindableMojos );
|
||||
}
|
||||
|
||||
/**
|
||||
* Traverses all MojoBinding instances discovered from the POM and its packaging-mappings, and
|
||||
* orchestrates the process of injecting any modifiers that are necessary to accommodate mojos
|
||||
* that require access to the project's configured reports.
|
||||
*/
|
||||
private void addReportingLifecycleModifiers( final BuildPlan plan, final MavenProject project, final MavenSession session, LinkedList callStack, final boolean allowUnbindableMojos )
|
||||
throws LifecyclePlannerException, LifecycleSpecificationException, LifecycleLoaderException
|
||||
{
|
||||
if ( plan.isIncludingReports() )
|
||||
{
|
||||
logger.debug( "Report modifiers are already present in the build plan." );
|
||||
return;
|
||||
}
|
||||
|
||||
List planBindings = plan.renderExecutionPlan( new Stack() );
|
||||
plan.resetExecutionProgress();
|
||||
|
||||
for ( Iterator it = planBindings.iterator(); it.hasNext(); )
|
||||
{
|
||||
MojoBinding mojoBinding = (MojoBinding) it.next();
|
||||
|
||||
if ( plan.isFullyResolved( mojoBinding ) )
|
||||
{
|
||||
logger.debug( "Skipping report-discovery for mojo: " + MojoBindingUtils.toString( mojoBinding ) + "; it is already fully resolved in the build plan." );
|
||||
continue;
|
||||
}
|
||||
|
||||
PluginDescriptor pluginDescriptor = loadPluginDescriptor( mojoBinding, plan, project, session, allowUnbindableMojos );
|
||||
|
||||
if ( pluginDescriptor == null )
|
||||
{
|
||||
logger.debug( "Plugin descriptor not found for mojo: " + MojoBindingUtils.toString( mojoBinding ) + "; skipping for report-discovery." );
|
||||
continue;
|
||||
}
|
||||
|
||||
MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( mojoBinding.getGoal() );
|
||||
if ( mojoDescriptor == null )
|
||||
{
|
||||
throw new LifecyclePlannerException( "Mojo: " + mojoBinding.getGoal() + " does not exist in plugin: " + pluginDescriptor.getId() + "." );
|
||||
}
|
||||
|
||||
if ( mojoDescriptor.isRequiresReports() )
|
||||
{
|
||||
logger.debug( "Mojo: " + MojoBindingUtils.toString( mojoBinding ) + " requires reports; running report-discovery." );
|
||||
List reportBindings = lifecycleBindingManager.getReportBindings( project, session );
|
||||
|
||||
if ( reportBindings != null )
|
||||
{
|
||||
plan.addForkedExecution( mojoBinding, reportBindings );
|
||||
|
||||
for ( Iterator reportBindingIt = reportBindings.iterator(); reportBindingIt.hasNext(); )
|
||||
{
|
||||
MojoBinding reportBinding = (MojoBinding) reportBindingIt.next();
|
||||
|
||||
if ( plan.isFullyResolved( reportBinding ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
PluginDescriptor pd = loadPluginDescriptor( reportBinding, plan, project, session, allowUnbindableMojos );
|
||||
|
||||
if ( pd != null )
|
||||
{
|
||||
findForkModifiers( reportBinding, pd, plan, project, session, callStack, true, allowUnbindableMojos );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
plan.markAsIncludingReports();
|
||||
|
||||
// NOTE: the first sighting of a mojo requiring reports should satisfy this condition.
|
||||
// therefore, we can break out as soon as we find one.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PluginDescriptor loadPluginDescriptor( final MojoBinding mojoBinding, final BuildPlan plan, final MavenProject project, final MavenSession session, final boolean allowUnbindableMojos )
|
||||
throws LifecyclePlannerException
|
||||
{
|
||||
PluginDescriptor pluginDescriptor = null;
|
||||
|
||||
try
|
||||
{
|
||||
pluginDescriptor = pluginLoader.loadPlugin( mojoBinding, project, session );
|
||||
}
|
||||
catch ( PluginLoaderException e )
|
||||
{
|
||||
if ( allowUnbindableMojos )
|
||||
{
|
||||
String message = "Failed to load plugin: " + MojoBindingUtils.createPluginKey( mojoBinding ) + ". Adding to late-bound plugins list.\nReason: " + e.getMessage();
|
||||
|
||||
if ( logger.isDebugEnabled() )
|
||||
{
|
||||
logger.debug( message, e );
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.warn( message );
|
||||
}
|
||||
|
||||
plan.addUnbindableMojo( mojoBinding );
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new LifecyclePlannerException( "Failed to resolve plugin for mojo binding: " + MojoBindingUtils.toString( mojoBinding ), e );
|
||||
}
|
||||
}
|
||||
|
||||
return pluginDescriptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Explores a single MojoBinding, and injects any necessary plan modifiers to accommodate any of
|
||||
* the three types of forked execution, along with any new mojos/lifecycles that entails.
|
||||
*
|
||||
* @param callStack
|
||||
*/
|
||||
private void findForkModifiers( final MojoBinding mojoBinding, final PluginDescriptor pluginDescriptor, final BuildPlan plan, final MavenProject project, final MavenSession session,
|
||||
LinkedList callStack, final boolean includeReportConfig, final boolean allowUnbindableMojos )
|
||||
throws LifecyclePlannerException, LifecycleSpecificationException, LifecycleLoaderException
|
||||
{
|
||||
String referencingGoal = mojoBinding.getGoal();
|
||||
|
||||
MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( referencingGoal );
|
||||
|
||||
if ( mojoDescriptor == null )
|
||||
{
|
||||
throw new LifecyclePlannerException( "Cannot find mojo descriptor for: " + referencingGoal + " in plugin: " + pluginDescriptor.getId() );
|
||||
}
|
||||
|
||||
if ( mojoDescriptor.getExecuteGoal() != null )
|
||||
{
|
||||
recurseSingleMojoFork( mojoBinding, pluginDescriptor, plan, project, includeReportConfig );
|
||||
}
|
||||
else if ( mojoDescriptor.getExecutePhase() != null )
|
||||
{
|
||||
recursePhaseMojoFork( mojoBinding, pluginDescriptor, plan, project, session, callStack, includeReportConfig, allowUnbindableMojos );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the lifecycle bindings used to execute a particular fork, given the forking mojo
|
||||
* binding. If the mojo binding specifies a lifecycle overlay, this method will add that into
|
||||
* the forked lifecycle, and calculate the bindings to inject based on the phase in that new
|
||||
* lifecycle which should be executed.
|
||||
*
|
||||
* Hands off to the
|
||||
* {@link DefaultBuildPlanner#modifyBuildPlanForForkedLifecycle(MojoBinding, PluginDescriptor, ModifiablePlanElement, LifecycleBindings, MavenProject, LinkedList, List)}
|
||||
* method to handle the actual plan modification.
|
||||
*
|
||||
* @param session
|
||||
*/
|
||||
private void recursePhaseMojoFork( final MojoBinding mojoBinding, final PluginDescriptor pluginDescriptor, final BuildPlan plan, final MavenProject project, final MavenSession session,
|
||||
LinkedList callStack, final boolean includeReportConfig, final boolean allowUnbindableMojos )
|
||||
throws LifecyclePlannerException, LifecycleSpecificationException, LifecycleLoaderException
|
||||
{
|
||||
callStack.addFirst( mojoBinding );
|
||||
|
||||
try
|
||||
{
|
||||
String referencingGoal = mojoBinding.getGoal();
|
||||
|
||||
MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( referencingGoal );
|
||||
|
||||
String phase = mojoDescriptor.getExecutePhase();
|
||||
|
||||
if ( phase == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !LifecycleUtils.isValidPhaseName( phase ) )
|
||||
{
|
||||
throw new LifecyclePlannerException( "Cannot find lifecycle for phase: " + phase );
|
||||
}
|
||||
|
||||
BuildPlan clonedPlan = plan.copy( phase );
|
||||
clonedPlan.removeAll( callStack );
|
||||
|
||||
String executeLifecycle = mojoDescriptor.getExecuteLifecycle();
|
||||
if ( executeLifecycle != null )
|
||||
{
|
||||
LifecycleBindings overlayBindings;
|
||||
try
|
||||
{
|
||||
overlayBindings = lifecycleBindingManager.getPluginLifecycleOverlay( pluginDescriptor, executeLifecycle, project );
|
||||
}
|
||||
catch ( LifecycleLoaderException e )
|
||||
{
|
||||
throw new LifecyclePlannerException( "Failed to load overlay lifecycle: " + executeLifecycle + ". Reason: " + e.getMessage(), e );
|
||||
}
|
||||
|
||||
clonedPlan.addLifecycleOverlay( overlayBindings );
|
||||
}
|
||||
|
||||
plan.addForkedExecution( mojoBinding, clonedPlan );
|
||||
|
||||
addForkedLifecycleModifiers( clonedPlan, project, session, callStack, allowUnbindableMojos );
|
||||
}
|
||||
finally
|
||||
{
|
||||
callStack.removeFirst();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the information necessary to create a new MojoBinding for a single-mojo forked
|
||||
* execution, then hands off to the
|
||||
* {@link DefaultBuildPlanner#modifyBuildPlanForForkedDirectInvocation(MojoBinding, MojoBinding, PluginDescriptor, ModifiablePlanElement, LifecycleBindings, MavenProject, LinkedList, List)}
|
||||
* method to actually inject the modification.
|
||||
*
|
||||
* @param callStack
|
||||
*/
|
||||
private void recurseSingleMojoFork( final MojoBinding mojoBinding, final PluginDescriptor pluginDescriptor, final BuildPlan plan, final MavenProject project, final boolean includeReportConfig )
|
||||
throws LifecyclePlannerException, LifecycleSpecificationException, LifecycleLoaderException
|
||||
{
|
||||
String referencingGoal = mojoBinding.getGoal();
|
||||
|
||||
MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( referencingGoal );
|
||||
|
||||
String executeGoal = mojoDescriptor.getExecuteGoal();
|
||||
|
||||
if ( executeGoal == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MojoDescriptor otherDescriptor = pluginDescriptor.getMojo( executeGoal );
|
||||
if ( otherDescriptor == null )
|
||||
{
|
||||
throw new LifecyclePlannerException( "Mojo: " + executeGoal + " (referenced by: " + referencingGoal + ") does not exist in plugin: " + pluginDescriptor.getId() + "." );
|
||||
}
|
||||
|
||||
MojoBinding binding = mojoBindingFactory.createMojoBinding( pluginDescriptor.getGroupId(), pluginDescriptor.getArtifactId(), pluginDescriptor.getVersion(), executeGoal, project );
|
||||
|
||||
binding.setOrigin( MojoBinding.FORKED_DIRECT_REFERENCE_ORIGIN );
|
||||
binding.setOriginDescription( "Forked from: " + MojoBindingUtils.toString( mojoBinding ) );
|
||||
|
||||
plan.addForkedExecution( mojoBinding, Collections.singletonList( binding ) );
|
||||
}
|
||||
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
package org.apache.maven.lifecycle.plan;
|
||||
|
||||
import org.apache.maven.lifecycle.LifecycleException;
|
||||
|
||||
/**
|
||||
* Signals an error during build-plan construction.
|
||||
*
|
||||
* @author jdcasey
|
||||
*
|
||||
*/
|
||||
public class LifecyclePlannerException
|
||||
extends LifecycleException
|
||||
{
|
||||
|
||||
public LifecyclePlannerException( String message, Throwable cause )
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
||||
|
||||
public LifecyclePlannerException( String message )
|
||||
{
|
||||
super( message );
|
||||
}
|
||||
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
package org.apache.maven.lifecycle.statemgmt;
|
||||
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
/**
|
||||
* Remove the execution-project used during the fork, now that the forking mojo is finished executing.
|
||||
*
|
||||
* @author jdcasey
|
||||
*
|
||||
*/
|
||||
public class ClearForkedContextMojo
|
||||
extends AbstractMojo
|
||||
{
|
||||
|
||||
private MavenProject project;
|
||||
|
||||
private int forkId = -1;
|
||||
|
||||
public void execute()
|
||||
throws MojoExecutionException, MojoFailureException
|
||||
{
|
||||
getLog().info( "Cleaning up forked execution context [fork id: " + forkId + "]" );
|
||||
|
||||
if ( project != null )
|
||||
{
|
||||
project.clearExecutionProject();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package org.apache.maven.lifecycle.statemgmt;
|
||||
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
/**
|
||||
* Restore the lifecycle execution context's current-project, and set the project instance from the
|
||||
* forked execution to project.getExecutionProject() for the forking mojo to use.
|
||||
*
|
||||
* @author jdcasey
|
||||
*
|
||||
*/
|
||||
public class EndForkedExecutionMojo
|
||||
extends AbstractMojo
|
||||
{
|
||||
|
||||
private int forkId = -1;
|
||||
|
||||
private MavenSession session;
|
||||
|
||||
public void execute()
|
||||
throws MojoExecutionException, MojoFailureException
|
||||
{
|
||||
getLog().info( "Ending forked execution [fork id: " + forkId + "]" );
|
||||
|
||||
MavenProject executionProject = session.removeForkedProject();
|
||||
|
||||
MavenProject project = session.getCurrentProject();
|
||||
if ( ( project != null ) && ( executionProject != null ) )
|
||||
{
|
||||
project.setExecutionProject( executionProject );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
package org.apache.maven.lifecycle.statemgmt;
|
||||
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.lifecycle.MojoBindingUtils;
|
||||
import org.apache.maven.lifecycle.binding.MojoBindingFactory;
|
||||
import org.apache.maven.lifecycle.model.MojoBinding;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugin.PluginLoaderException;
|
||||
import org.apache.maven.plugin.PluginManager;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
public class ResolveLateBoundPluginMojo extends AbstractMojo
|
||||
{
|
||||
|
||||
/**
|
||||
* @component
|
||||
*/
|
||||
private PluginManager pluginLoader;
|
||||
|
||||
private String groupId;
|
||||
|
||||
private String artifactId;
|
||||
|
||||
private String version;
|
||||
|
||||
private String goal;
|
||||
|
||||
private MavenProject project;
|
||||
|
||||
private MavenSession session;
|
||||
|
||||
private MojoBindingFactory bindingFactory;
|
||||
|
||||
public void execute() throws MojoExecutionException, MojoFailureException
|
||||
{
|
||||
MojoBinding binding = bindingFactory.createMojoBinding( groupId, artifactId, version, artifactId, project );
|
||||
try
|
||||
{
|
||||
PluginDescriptor descriptor = pluginLoader.loadPlugin( binding, project, session );
|
||||
|
||||
MojoDescriptor mojoDescriptor = descriptor.getMojo( goal );
|
||||
|
||||
if ( mojoDescriptor == null )
|
||||
{
|
||||
throw new MojoExecutionException( "Resolved plugin: " + descriptor.getId()
|
||||
+ " does not contain a mojo called \'" + goal + "\'." );
|
||||
}
|
||||
}
|
||||
catch ( PluginLoaderException e )
|
||||
{
|
||||
throw new MojoExecutionException( "Failed to load late-bound plugin: "
|
||||
+ MojoBindingUtils.createPluginKey( binding ), e );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
package org.apache.maven.lifecycle.statemgmt;
|
||||
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
/**
|
||||
* Setup a new project instance for the forked executions to use.
|
||||
*
|
||||
* @author jdcasey
|
||||
*
|
||||
*/
|
||||
public class StartForkedExecutionMojo
|
||||
extends AbstractMojo
|
||||
{
|
||||
|
||||
private MavenProject project;
|
||||
|
||||
private MavenSession session;
|
||||
|
||||
private int forkId = -1;
|
||||
|
||||
public void execute()
|
||||
throws MojoExecutionException, MojoFailureException
|
||||
{
|
||||
getLog().info( "Starting forked execution [fork id: " + forkId + "]" );
|
||||
|
||||
if ( project != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
session.addForkedProject( (MavenProject) project.clone() );
|
||||
}
|
||||
catch ( CloneNotSupportedException e )
|
||||
{
|
||||
throw new IllegalStateException( "MavenProject instance of class " + project.getClass().getName() +
|
||||
" does not support clone " );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,199 +0,0 @@
|
|||
package org.apache.maven.lifecycle.statemgmt;
|
||||
|
||||
import org.apache.maven.lifecycle.model.MojoBinding;
|
||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||
|
||||
/**
|
||||
* Constructs and matches MojoBinding instances that refer to the forked-execution context manager mojos.
|
||||
*
|
||||
* @author jdcasey
|
||||
*
|
||||
*/
|
||||
public final class StateManagementUtils
|
||||
{
|
||||
|
||||
public static final String GROUP_ID = "org.apache.maven.plugins.internal";
|
||||
|
||||
public static final String ARTIFACT_ID = "maven-state-management";
|
||||
|
||||
public static final String END_FORKED_EXECUTION_GOAL = "end-fork";
|
||||
|
||||
public static final String START_FORKED_EXECUTION_GOAL = "start-fork";
|
||||
|
||||
public static final String VERSION = "2.1";
|
||||
|
||||
public static final String CLEAR_FORKED_EXECUTION_GOAL = "clear-fork-context";
|
||||
|
||||
public static final String RESOLVE_LATE_BOUND_PLUGIN_GOAL = "resolve-late-bound-plugin";
|
||||
|
||||
private static int CURRENT_FORK_ID = 0;
|
||||
|
||||
private StateManagementUtils()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new MojoBinding instance that refers to the internal mojo used to setup a new forked-execution context.
|
||||
* Also, set the configuration to contain the forkId for this new context.
|
||||
*/
|
||||
public static MojoBinding createStartForkedExecutionMojoBinding()
|
||||
{
|
||||
MojoBinding binding = new MojoBinding();
|
||||
|
||||
binding.setGroupId( GROUP_ID );
|
||||
binding.setArtifactId( ARTIFACT_ID );
|
||||
binding.setVersion( VERSION );
|
||||
binding.setGoal( START_FORKED_EXECUTION_GOAL );
|
||||
binding.setOrigin( MojoBinding.INTERNAL_ORIGIN );
|
||||
|
||||
CURRENT_FORK_ID = (int) System.currentTimeMillis();
|
||||
|
||||
Xpp3Dom config = new Xpp3Dom( "configuration" );
|
||||
Xpp3Dom forkId = new Xpp3Dom( "forkId" );
|
||||
forkId.setValue( "" + CURRENT_FORK_ID );
|
||||
|
||||
config.addChild( forkId );
|
||||
|
||||
binding.setConfiguration( config );
|
||||
|
||||
return binding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new MojoBinding instance that refers to the internal mojo used to end a forked-execution context. Also,
|
||||
* set the configuration to contain the forkId for this new context.
|
||||
*/
|
||||
public static MojoBinding createEndForkedExecutionMojoBinding()
|
||||
{
|
||||
MojoBinding binding = new MojoBinding();
|
||||
|
||||
binding.setGroupId( GROUP_ID );
|
||||
binding.setArtifactId( ARTIFACT_ID );
|
||||
binding.setVersion( VERSION );
|
||||
binding.setGoal( END_FORKED_EXECUTION_GOAL );
|
||||
binding.setOrigin( MojoBinding.INTERNAL_ORIGIN );
|
||||
|
||||
Xpp3Dom config = new Xpp3Dom( "configuration" );
|
||||
Xpp3Dom forkId = new Xpp3Dom( "forkId" );
|
||||
forkId.setValue( "" + CURRENT_FORK_ID );
|
||||
|
||||
config.addChild( forkId );
|
||||
|
||||
binding.setConfiguration( config );
|
||||
|
||||
return binding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new MojoBinding instance that refers to the internal mojo used to cleanup a completed forked-execution
|
||||
* context. Also, set the configuration to contain the forkId for this new context.
|
||||
*/
|
||||
public static MojoBinding createClearForkedExecutionMojoBinding()
|
||||
{
|
||||
MojoBinding binding = new MojoBinding();
|
||||
|
||||
binding.setGroupId( GROUP_ID );
|
||||
binding.setArtifactId( ARTIFACT_ID );
|
||||
binding.setVersion( VERSION );
|
||||
binding.setGoal( CLEAR_FORKED_EXECUTION_GOAL );
|
||||
binding.setOrigin( MojoBinding.INTERNAL_ORIGIN );
|
||||
|
||||
Xpp3Dom config = new Xpp3Dom( "configuration" );
|
||||
Xpp3Dom forkId = new Xpp3Dom( "forkId" );
|
||||
forkId.setValue( "" + CURRENT_FORK_ID );
|
||||
|
||||
config.addChild( forkId );
|
||||
|
||||
binding.setConfiguration( config );
|
||||
|
||||
return binding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the specified MojoBinding refers to the internal mojo used to setup a new forked-execution
|
||||
* context. This is useful for formatting when listing the build plan, when expression of these actual mojo names
|
||||
* isn't necessarily useful, and can be confusing.
|
||||
*/
|
||||
public static boolean isForkedExecutionStartMarker( final MojoBinding binding )
|
||||
{
|
||||
return GROUP_ID.equals( binding.getGroupId() ) && ARTIFACT_ID.equals( binding.getArtifactId() )
|
||||
&& START_FORKED_EXECUTION_GOAL.equals( binding.getGoal() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the specified MojoBinding refers to the internal mojo used to end a forked-execution context. This
|
||||
* is useful for formatting when listing the build plan, when expression of these actual mojo names isn't
|
||||
* necessarily useful, and can be confusing.
|
||||
*/
|
||||
public static boolean isForkedExecutionEndMarker( final MojoBinding binding )
|
||||
{
|
||||
return GROUP_ID.equals( binding.getGroupId() ) && ARTIFACT_ID.equals( binding.getArtifactId() )
|
||||
&& END_FORKED_EXECUTION_GOAL.equals( binding.getGoal() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the specified MojoBinding refers to the internal mojo used to clean up a completed
|
||||
* forked-execution context. This is useful for formatting when listing the build plan, when expression of these
|
||||
* actual mojo names isn't necessarily useful, and can be confusing.
|
||||
*/
|
||||
public static boolean isForkedExecutionClearMarker( final MojoBinding binding )
|
||||
{
|
||||
return GROUP_ID.equals( binding.getGroupId() ) && ARTIFACT_ID.equals( binding.getArtifactId() )
|
||||
&& CLEAR_FORKED_EXECUTION_GOAL.equals( binding.getGoal() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new MojoBinding instance that refers to the internal mojo used to resolve a late-bound plugin just
|
||||
* before it is to be used. Also, set the configuration to contain the parameters necessary for this resolution.
|
||||
*/
|
||||
public static MojoBinding createResolveLateBoundMojoBinding( final MojoBinding lateBound )
|
||||
{
|
||||
MojoBinding binding = new MojoBinding();
|
||||
|
||||
binding.setGroupId( GROUP_ID );
|
||||
binding.setArtifactId( ARTIFACT_ID );
|
||||
binding.setVersion( VERSION );
|
||||
binding.setGoal( RESOLVE_LATE_BOUND_PLUGIN_GOAL );
|
||||
binding.setOrigin( MojoBinding.INTERNAL_ORIGIN );
|
||||
|
||||
Xpp3Dom config = new Xpp3Dom( "configuration" );
|
||||
Xpp3Dom param = new Xpp3Dom( "groupId" );
|
||||
param.setValue( lateBound.getGroupId() );
|
||||
|
||||
config.addChild( param );
|
||||
|
||||
param = new Xpp3Dom( "artifactId" );
|
||||
param.setValue( lateBound.getArtifactId() );
|
||||
|
||||
config.addChild( param );
|
||||
|
||||
if ( lateBound.getVersion() != null )
|
||||
{
|
||||
param = new Xpp3Dom( "version" );
|
||||
param.setValue( lateBound.getVersion() );
|
||||
|
||||
config.addChild( param );
|
||||
}
|
||||
|
||||
param = new Xpp3Dom( "goal" );
|
||||
param.setValue( lateBound.getGoal() );
|
||||
|
||||
config.addChild( param );
|
||||
|
||||
binding.setConfiguration( config );
|
||||
|
||||
return binding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the specified MojoBinding refers to the internal mojo used to resolve a late-bound mojo. This is
|
||||
* useful for formatting when listing the build plan, when expression of these actual mojo names isn't necessarily
|
||||
* useful, and can be confusing.
|
||||
*/
|
||||
public static boolean isResolveLateBoundMojoBinding( final MojoBinding binding )
|
||||
{
|
||||
return GROUP_ID.equals( binding.getGroupId() ) && ARTIFACT_ID.equals( binding.getArtifactId() )
|
||||
&& RESOLVE_LATE_BOUND_PLUGIN_GOAL.equals( binding.getGoal() );
|
||||
}
|
||||
|
||||
}
|
|
@ -53,8 +53,6 @@ import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException
|
|||
import org.apache.maven.artifact.versioning.VersionRange;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.execution.RuntimeInformation;
|
||||
import org.apache.maven.lifecycle.model.MojoBinding;
|
||||
import org.apache.maven.lifecycle.statemgmt.StateManagementUtils;
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Plugin;
|
||||
|
@ -110,17 +108,6 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
|||
public class DefaultPluginManager
|
||||
implements PluginManager
|
||||
{
|
||||
private static final List RESERVED_GROUP_IDS;
|
||||
|
||||
static
|
||||
{
|
||||
List rgids = new ArrayList();
|
||||
|
||||
rgids.add( StateManagementUtils.GROUP_ID );
|
||||
|
||||
RESERVED_GROUP_IDS = rgids;
|
||||
}
|
||||
|
||||
@Requirement
|
||||
private Logger logger;
|
||||
|
||||
|
@ -205,17 +192,9 @@ public class DefaultPluginManager
|
|||
// the 'Can't find plexus container for plugin: xxx' error.
|
||||
try
|
||||
{
|
||||
// if the groupId is internal, don't try to resolve it...
|
||||
if ( !RESERVED_GROUP_IDS.contains( plugin.getGroupId() ) )
|
||||
{
|
||||
Artifact pluginArtifact = resolvePluginArtifact( plugin, project, session );
|
||||
Artifact pluginArtifact = resolvePluginArtifact( plugin, project, session );
|
||||
|
||||
addPlugin( plugin, pluginArtifact, project, session );
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.debug( "Skipping resolution for Maven built-in plugin: " + plugin.getKey() );
|
||||
}
|
||||
addPlugin( plugin, pluginArtifact, project, session );
|
||||
|
||||
project.addPlugin( plugin );
|
||||
}
|
||||
|
@ -2053,9 +2032,11 @@ public class DefaultPluginManager
|
|||
RepositoryMetadata metadata = new GroupRepositoryMetadata( groupId );
|
||||
|
||||
logger.debug( "Checking repositories:\n" + pluginRepositories + "\n\nfor plugin prefix metadata: " + groupId );
|
||||
|
||||
repositoryMetadataManager.resolve( metadata, pluginRepositories, localRepository );
|
||||
|
||||
Metadata repoMetadata = metadata.getMetadata();
|
||||
|
||||
if ( repoMetadata != null )
|
||||
{
|
||||
for ( Iterator pluginIterator = repoMetadata.getPlugins().iterator(); pluginIterator.hasNext(); )
|
||||
|
@ -2086,34 +2067,6 @@ public class DefaultPluginManager
|
|||
|
||||
// Plugin Loader
|
||||
|
||||
/**
|
||||
* Load the {@link PluginDescriptor} instance for the plugin implied by the specified MojoBinding,
|
||||
* using the project for {@link ArtifactRepository} and other supplemental plugin information as
|
||||
* necessary.
|
||||
*/
|
||||
public PluginDescriptor loadPlugin( MojoBinding mojoBinding, MavenProject project, MavenSession session )
|
||||
throws PluginLoaderException
|
||||
{
|
||||
PluginDescriptor pluginDescriptor = null;
|
||||
|
||||
Plugin plugin = new Plugin();
|
||||
plugin.setGroupId( mojoBinding.getGroupId() );
|
||||
plugin.setArtifactId( mojoBinding.getArtifactId() );
|
||||
plugin.setVersion( mojoBinding.getVersion() );
|
||||
|
||||
pluginDescriptor = loadPlugin( plugin, project, session );
|
||||
|
||||
// fill in any blanks once we know more about this plugin.
|
||||
if ( pluginDescriptor != null )
|
||||
{
|
||||
mojoBinding.setGroupId( pluginDescriptor.getGroupId() );
|
||||
mojoBinding.setArtifactId( pluginDescriptor.getArtifactId() );
|
||||
mojoBinding.setVersion( pluginDescriptor.getVersion() );
|
||||
}
|
||||
|
||||
return pluginDescriptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the {@link PluginDescriptor} instance for the specified plugin, using the project for
|
||||
* the {@link ArtifactRepository} and other supplemental plugin information as necessary.
|
||||
|
@ -2166,31 +2119,6 @@ public class DefaultPluginManager
|
|||
}
|
||||
}
|
||||
|
||||
public void enableLogging( Logger logger )
|
||||
{
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the {@link PluginDescriptor} instance for the report plugin implied by the specified MojoBinding,
|
||||
* using the project for {@link ArtifactRepository} and other supplemental report/plugin information as
|
||||
* necessary.
|
||||
*/
|
||||
public PluginDescriptor loadReportPlugin( MojoBinding mojoBinding, MavenProject project, MavenSession session )
|
||||
throws PluginLoaderException
|
||||
{
|
||||
ReportPlugin plugin = new ReportPlugin();
|
||||
plugin.setGroupId( mojoBinding.getGroupId() );
|
||||
plugin.setArtifactId( mojoBinding.getArtifactId() );
|
||||
plugin.setVersion( mojoBinding.getVersion() );
|
||||
|
||||
PluginDescriptor pluginDescriptor = loadReportPlugin( plugin, project, session );
|
||||
|
||||
mojoBinding.setVersion( pluginDescriptor.getVersion() );
|
||||
|
||||
return pluginDescriptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the {@link PluginDescriptor} instance for the specified report plugin, using the project for
|
||||
* the {@link ArtifactRepository} and other supplemental report/plugin information as necessary.
|
||||
|
|
|
@ -29,6 +29,7 @@ import java.util.List;
|
|||
* Describes a single mojo invocation.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class MojoExecution
|
||||
{
|
||||
|
@ -38,6 +39,10 @@ public class MojoExecution
|
|||
|
||||
private Xpp3Dom configuration;
|
||||
|
||||
private List forkedExecutions = new ArrayList();
|
||||
|
||||
private List reports;
|
||||
|
||||
public MojoExecution( MojoDescriptor mojoDescriptor )
|
||||
{
|
||||
this.mojoDescriptor = mojoDescriptor;
|
||||
|
@ -74,8 +79,38 @@ public class MojoExecution
|
|||
return configuration;
|
||||
}
|
||||
|
||||
public void addMojoExecution( MojoExecution execution )
|
||||
{
|
||||
forkedExecutions.add( execution );
|
||||
}
|
||||
|
||||
public void setReports( List reports )
|
||||
{
|
||||
this.reports = reports;
|
||||
}
|
||||
|
||||
public List getReports()
|
||||
{
|
||||
return reports;
|
||||
}
|
||||
|
||||
public List getForkedExecutions()
|
||||
{
|
||||
return forkedExecutions;
|
||||
}
|
||||
|
||||
public void setConfiguration( Xpp3Dom configuration )
|
||||
{
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
public String identify()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
sb.append( executionId );
|
||||
sb.append( configuration.toString() );
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import java.util.Collection;
|
|||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.lifecycle.model.MojoBinding;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.ReportPlugin;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
|
@ -42,14 +41,6 @@ public interface PluginManager
|
|||
|
||||
Plugin getPluginDefinitionForPrefix( String prefix, MavenSession session, MavenProject project );
|
||||
|
||||
PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, MavenSession session )
|
||||
throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException, InvalidPluginException, PluginManagerException, PluginNotFoundException,
|
||||
PluginVersionNotFoundException;
|
||||
|
||||
PluginDescriptor verifyReportPlugin( ReportPlugin reportPlugin, MavenProject project, MavenSession session )
|
||||
throws PluginVersionResolutionException, ArtifactResolutionException, ArtifactNotFoundException, InvalidPluginException, PluginManagerException, PluginNotFoundException,
|
||||
PluginVersionNotFoundException;
|
||||
|
||||
Plugin findPluginForPrefix( String prefix, MavenProject project, MavenSession session )
|
||||
throws PluginLoaderException;
|
||||
|
||||
|
@ -61,37 +52,10 @@ public interface PluginManager
|
|||
|
||||
void executeMojo( MojoExecution mojoExecution, MavenSession session )
|
||||
throws Exception;
|
||||
|
||||
// Plugin Loader
|
||||
|
||||
/**
|
||||
* Load the {@link PluginDescriptor} instance for the specified plugin, using the project for
|
||||
* the {@link ArtifactRepository} and other supplemental plugin information as necessary.
|
||||
*/
|
||||
|
||||
PluginDescriptor loadPlugin( Plugin plugin, MavenProject project, MavenSession session )
|
||||
throws PluginLoaderException;
|
||||
|
||||
/**
|
||||
* Load the {@link PluginDescriptor} instance for the plugin implied by the specified MojoBinding,
|
||||
* using the project for {@link ArtifactRepository} and other supplemental plugin information as
|
||||
* necessary.
|
||||
*/
|
||||
PluginDescriptor loadPlugin( MojoBinding mojoBinding, MavenProject project, MavenSession session )
|
||||
throws PluginLoaderException;
|
||||
|
||||
/**
|
||||
* Load the {@link PluginDescriptor} instance for the specified report plugin, using the project for
|
||||
* the {@link ArtifactRepository} and other supplemental report/plugin information as necessary.
|
||||
*/
|
||||
PluginDescriptor loadReportPlugin( ReportPlugin reportPlugin, MavenProject project, MavenSession session )
|
||||
throws PluginLoaderException;
|
||||
|
||||
/**
|
||||
* Load the {@link PluginDescriptor} instance for the report plugin implied by the specified MojoBinding,
|
||||
* using the project for {@link ArtifactRepository} and other supplemental report/plugin information as
|
||||
* necessary.
|
||||
*/
|
||||
PluginDescriptor loadReportPlugin( MojoBinding mojoBinding, MavenProject project, MavenSession session )
|
||||
throws PluginLoaderException;
|
||||
|
||||
throws PluginLoaderException;
|
||||
}
|
|
@ -27,32 +27,12 @@ use a configuration source to pull in the lifecycle information.
|
|||
<component-set>
|
||||
<components>
|
||||
<component>
|
||||
<role>org.apache.maven.lifecycle.binding.LifecycleBindingManager</role>
|
||||
<role-hint>default</role-hint>
|
||||
<implementation>org.apache.maven.lifecycle.binding.DefaultLifecycleBindingManager</implementation>
|
||||
<role>org.apache.maven.lifecycle.LifecycleExecutor</role>
|
||||
<implementation>org.apache.maven.lifecycle.DefaultLifecycleExecutor</implementation>
|
||||
<requirements>
|
||||
<requirement>
|
||||
<role>org.apache.maven.plugin.PluginManager</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.lifecycle.LifecycleBindingLoader</role>
|
||||
<field-name>bindingsByPackaging</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
|
||||
<field-name>legacyMappingsByPackaging</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.lifecycle.binding.MojoBindingFactory</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.lifecycle.binding.LegacyLifecycleMappingParser</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.codehaus.plexus.PlexusContainer</role>
|
||||
<role-hint>default</role-hint>
|
||||
<field-name>container</field-name>
|
||||
</requirement>
|
||||
</requirements>
|
||||
<configuration>
|
||||
<lifecycles>
|
||||
|
@ -75,7 +55,6 @@ use a configuration source to pull in the lifecycle information.
|
|||
<phase>test-compile</phase>
|
||||
<phase>process-test-classes</phase>
|
||||
<phase>test</phase>
|
||||
<phase>prepare-package</phase>
|
||||
<phase>package</phase>
|
||||
<phase>pre-integration-test</phase>
|
||||
<phase>integration-test</phase>
|
||||
|
@ -113,20 +92,11 @@ use a configuration source to pull in the lifecycle information.
|
|||
</lifecycles>
|
||||
<!-- START SNIPPET: default-reports -->
|
||||
<defaultReports>
|
||||
<report>org.apache.maven.plugins:maven-project-info-reports-plugin:2.0.1</report>
|
||||
<!-- TODO: currently in mojo - should they be defaults any more?
|
||||
<report>org.apache.maven.plugins:maven-checkstyle-plugin</report>
|
||||
<report>org.apache.maven.plugins:maven-javadoc-plugin</report>
|
||||
<report>org.apache.maven.plugins:maven-changelog-plugin</report>
|
||||
<report>org.apache.maven.plugins:maven-surefire-report-plugin</report>
|
||||
<report>org.apache.maven.plugins:maven-jdepend-plugin</report>
|
||||
<report>org.apache.maven.plugins:maven-jxr-plugin</report>
|
||||
<report>org.apache.maven.plugins:maven-taglist-plugin</report>
|
||||
-->
|
||||
<report>org.apache.maven.plugins:maven-project-info-reports-plugin:2.1</report>
|
||||
</defaultReports>
|
||||
<!-- END SNIPPET: default-reports -->
|
||||
</configuration>
|
||||
</component>
|
||||
</component>
|
||||
|
||||
<component>
|
||||
<role>org.sonatype.plexus.components.sec.dispatcher.SecDispatcher</role>
|
||||
|
|
|
@ -1,153 +0,0 @@
|
|||
package org.apache.maven.lifecycle;
|
||||
|
||||
import org.apache.maven.lifecycle.binding.LegacyLifecycleMappingParser;
|
||||
import org.apache.maven.lifecycle.binding.LegacyLifecycleParsingTestComponent;
|
||||
import org.apache.maven.lifecycle.mapping.LifecycleMapping;
|
||||
import org.apache.maven.lifecycle.model.BuildBinding;
|
||||
import org.apache.maven.lifecycle.model.LifecycleBindings;
|
||||
import org.apache.maven.lifecycle.model.MojoBinding;
|
||||
import org.codehaus.plexus.PlexusTestCase;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LegacyLifecycleMappingParserTest
|
||||
extends PlexusTestCase
|
||||
{
|
||||
|
||||
private LegacyLifecycleParsingTestComponent testComponent;
|
||||
|
||||
private LifecycleMapping testMapping;
|
||||
|
||||
private LifecycleMapping testMapping2;
|
||||
|
||||
private LegacyLifecycleMappingParser parser;
|
||||
|
||||
public void setUp()
|
||||
throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
parser = lookup( LegacyLifecycleMappingParser.class, "default" );
|
||||
|
||||
testComponent = lookup( LegacyLifecycleParsingTestComponent.class, "default" );
|
||||
testMapping = lookup( LifecycleMapping.class, "test-mapping" );
|
||||
testMapping2 = lookup( LifecycleMapping.class, "test-mapping2" );
|
||||
}
|
||||
|
||||
public void tearDown()
|
||||
throws Exception
|
||||
{
|
||||
release( testComponent );
|
||||
release( testMapping );
|
||||
release( testMapping2 );
|
||||
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testParseDefaultMappings_UsingExistingDefaultMappings()
|
||||
throws LifecycleSpecificationException
|
||||
{
|
||||
List lifecycles = testComponent.getLifecycles();
|
||||
LifecycleBindings bindings = parser.parseDefaultMappings( lifecycles );
|
||||
|
||||
// <clean>org.apache.maven.plugins:maven-clean-plugin:clean</clean>
|
||||
List cleanPhase = bindings.getCleanBinding().getClean().getBindings();
|
||||
assertEquals( 1, cleanPhase.size() );
|
||||
|
||||
MojoBinding binding = (MojoBinding) cleanPhase.get( 0 );
|
||||
assertMojo( "org.apache.maven.plugins", "maven-clean-plugin", "clean", binding );
|
||||
|
||||
// <site>org.apache.maven.plugins:maven-site-plugin:site</site>
|
||||
List sitePhase = bindings.getSiteBinding().getSite().getBindings();
|
||||
assertEquals( 1, sitePhase.size() );
|
||||
|
||||
binding = (MojoBinding) sitePhase.get( 0 );
|
||||
assertMojo( "org.apache.maven.plugins", "maven-site-plugin", "site", binding );
|
||||
|
||||
// <site-deploy>org.apache.maven.plugins:maven-site-plugin:deploy</site-deploy>
|
||||
List siteDeployPhase = bindings.getSiteBinding().getSiteDeploy().getBindings();
|
||||
assertEquals( 1, siteDeployPhase.size() );
|
||||
|
||||
binding = (MojoBinding) siteDeployPhase.get( 0 );
|
||||
assertMojo( "org.apache.maven.plugins", "maven-site-plugin", "deploy", binding );
|
||||
}
|
||||
|
||||
private void assertMojo( String groupId, String artifactId, String goal, MojoBinding binding )
|
||||
{
|
||||
assertEquals( groupId, binding.getGroupId() );
|
||||
assertEquals( artifactId, binding.getArtifactId() );
|
||||
assertEquals( goal, binding.getGoal() );
|
||||
}
|
||||
|
||||
public void testParseMappings_SparselyPopulatedMappings()
|
||||
throws LifecycleSpecificationException
|
||||
{
|
||||
LifecycleBindings bindings = parser.parseMappings( testMapping, "test-mapping" );
|
||||
|
||||
BuildBinding bb = bindings.getBuildBinding();
|
||||
assertNotNull( bb );
|
||||
|
||||
// <phases>
|
||||
// <package>org.apache.maven.plugins:maven-site-plugin:attach-descriptor</package>
|
||||
// <install>org.apache.maven.plugins:maven-install-plugin:install</install>
|
||||
// <deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
|
||||
// </phases>
|
||||
// <optional-mojos>
|
||||
// <optional-mojo>org.apache.maven.plugins:maven-site-plugin:attach-descriptor</optional-mojo>
|
||||
// </optional-mojos>
|
||||
List mojos = bb.getCreatePackage().getBindings();
|
||||
|
||||
assertEquals( 1, mojos.size() );
|
||||
assertMojo( "org.apache.maven.plugins", "maven-site-plugin", "attach-descriptor", (MojoBinding) mojos.get( 0 ) );
|
||||
assertTrue( ( (MojoBinding) mojos.get( 0 ) ).isOptional() );
|
||||
|
||||
mojos = bb.getInstall().getBindings();
|
||||
|
||||
assertEquals( 1, mojos.size() );
|
||||
assertMojo( "org.apache.maven.plugins", "maven-install-plugin", "install", (MojoBinding) mojos.get( 0 ) );
|
||||
assertFalse( ( (MojoBinding) mojos.get( 0 ) ).isOptional() );
|
||||
|
||||
mojos = bb.getDeploy().getBindings();
|
||||
|
||||
assertEquals( 1, mojos.size() );
|
||||
assertMojo( "org.apache.maven.plugins", "maven-deploy-plugin", "deploy", (MojoBinding) mojos.get( 0 ) );
|
||||
assertFalse( ( (MojoBinding) mojos.get( 0 ) ).isOptional() );
|
||||
}
|
||||
|
||||
public void testParseMappings_MappingsWithTwoBindingsInOnePhase()
|
||||
throws LifecycleSpecificationException
|
||||
{
|
||||
LifecycleBindings bindings = parser.parseMappings( testMapping2, "test-mapping2" );
|
||||
|
||||
BuildBinding bb = bindings.getBuildBinding();
|
||||
assertNotNull( bb );
|
||||
|
||||
// <phases>
|
||||
// <package>org.apache.maven.plugins:maven-site-plugin:attach-descriptor</package>
|
||||
// <install>org.apache.maven.plugins:maven-install-plugin:install</install>
|
||||
// <deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
|
||||
// </phases>
|
||||
// <optional-mojos>
|
||||
// <optional-mojo>org.apache.maven.plugins:maven-site-plugin:attach-descriptor</optional-mojo>
|
||||
// </optional-mojos>
|
||||
List mojos = bb.getCreatePackage().getBindings();
|
||||
|
||||
assertEquals( 2, mojos.size() );
|
||||
assertMojo( "org.apache.maven.plugins", "maven-site-plugin", "attach-descriptor", (MojoBinding) mojos.get( 0 ) );
|
||||
assertTrue( ( (MojoBinding) mojos.get( 0 ) ).isOptional() );
|
||||
assertMojo( "org.apache.maven.plugins", "maven-clean-plugin", "clean", (MojoBinding) mojos.get( 1 ) );
|
||||
|
||||
mojos = bb.getInstall().getBindings();
|
||||
|
||||
assertEquals( 1, mojos.size() );
|
||||
assertMojo( "org.apache.maven.plugins", "maven-install-plugin", "install", (MojoBinding) mojos.get( 0 ) );
|
||||
assertFalse( ( (MojoBinding) mojos.get( 0 ) ).isOptional() );
|
||||
|
||||
mojos = bb.getDeploy().getBindings();
|
||||
|
||||
assertEquals( 1, mojos.size() );
|
||||
assertMojo( "org.apache.maven.plugins", "maven-deploy-plugin", "deploy", (MojoBinding) mojos.get( 0 ) );
|
||||
assertFalse( ( (MojoBinding) mojos.get( 0 ) ).isOptional() );
|
||||
}
|
||||
|
||||
}
|
|
@ -1,145 +0,0 @@
|
|||
package org.apache.maven.lifecycle.binding;
|
||||
|
||||
import org.apache.maven.lifecycle.model.BuildBinding;
|
||||
import org.apache.maven.lifecycle.model.LifecycleBindings;
|
||||
import org.apache.maven.lifecycle.model.MojoBinding;
|
||||
import org.apache.maven.lifecycle.model.Phase;
|
||||
import org.apache.maven.model.Build;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.ReportPlugin;
|
||||
import org.apache.maven.model.Reporting;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class BindingUtilsTest
|
||||
extends TestCase
|
||||
{
|
||||
|
||||
public void testInjectProjectConfiguration_CheckReportPluginsForVersionInformation()
|
||||
{
|
||||
Model model = new Model();
|
||||
Build build = new Build();
|
||||
|
||||
String gid = "group";
|
||||
String aid = "artifact";
|
||||
String version = "1";
|
||||
|
||||
model.setGroupId( gid );
|
||||
model.setArtifactId( aid );
|
||||
model.setVersion( version );
|
||||
|
||||
model.setBuild( build );
|
||||
|
||||
String pGid = "group.plugins";
|
||||
String pAid = "maven-test-plugin";
|
||||
String pVersion = "2";
|
||||
|
||||
Plugin plugin = new Plugin();
|
||||
plugin.setGroupId( pGid );
|
||||
plugin.setArtifactId( pAid );
|
||||
plugin.setVersion( pVersion );
|
||||
|
||||
build.addPlugin( plugin );
|
||||
|
||||
Reporting reporting = new Reporting();
|
||||
|
||||
model.setReporting( reporting );
|
||||
|
||||
String rGid = "group.reports";
|
||||
String rAid = "maven-report-plugin";
|
||||
String rVersion = "3";
|
||||
|
||||
ReportPlugin rPlugin = new ReportPlugin();
|
||||
rPlugin.setGroupId( rGid );
|
||||
rPlugin.setArtifactId( rAid );
|
||||
rPlugin.setVersion( rVersion );
|
||||
|
||||
reporting.addPlugin( rPlugin );
|
||||
|
||||
MavenProject project = new MavenProject( model );
|
||||
|
||||
LifecycleBindings bindings = new LifecycleBindings();
|
||||
|
||||
BuildBinding buildBinding = new BuildBinding();
|
||||
bindings.setBuildBinding( buildBinding );
|
||||
|
||||
MojoBinding mb = new MojoBinding();
|
||||
mb.setGroupId( rGid );
|
||||
mb.setArtifactId( rAid );
|
||||
mb.setExecutionId( "test" );
|
||||
mb.setGoal( "goal" );
|
||||
|
||||
Phase compile = new Phase();
|
||||
compile.addBinding( mb );
|
||||
|
||||
buildBinding.setCompile( compile );
|
||||
|
||||
BindingUtils.injectProjectConfiguration( bindings, project );
|
||||
|
||||
assertEquals( rVersion, mb.getVersion() );
|
||||
}
|
||||
|
||||
public void testInjectProjectConfiguration_NormalPluginInformationOverridesReportPluginsInformation()
|
||||
{
|
||||
Model model = new Model();
|
||||
Build build = new Build();
|
||||
|
||||
String gid = "group";
|
||||
String aid = "artifact";
|
||||
String version = "1";
|
||||
|
||||
model.setGroupId( gid );
|
||||
model.setArtifactId( aid );
|
||||
model.setVersion( version );
|
||||
|
||||
model.setBuild( build );
|
||||
|
||||
String pAid = "maven-test-plugin";
|
||||
String pVersion = "2";
|
||||
|
||||
Plugin plugin = new Plugin();
|
||||
plugin.setGroupId( gid );
|
||||
plugin.setArtifactId( pAid );
|
||||
plugin.setVersion( pVersion );
|
||||
|
||||
build.addPlugin( plugin );
|
||||
|
||||
Reporting reporting = new Reporting();
|
||||
|
||||
model.setReporting( reporting );
|
||||
|
||||
String rVersion = "3";
|
||||
|
||||
ReportPlugin rPlugin = new ReportPlugin();
|
||||
rPlugin.setGroupId( gid );
|
||||
rPlugin.setArtifactId( pAid );
|
||||
rPlugin.setVersion( rVersion );
|
||||
|
||||
reporting.addPlugin( rPlugin );
|
||||
|
||||
MavenProject project = new MavenProject( model );
|
||||
|
||||
LifecycleBindings bindings = new LifecycleBindings();
|
||||
|
||||
BuildBinding buildBinding = new BuildBinding();
|
||||
bindings.setBuildBinding( buildBinding );
|
||||
|
||||
MojoBinding mb = new MojoBinding();
|
||||
mb.setGroupId( gid );
|
||||
mb.setArtifactId( pAid );
|
||||
mb.setExecutionId( "test" );
|
||||
mb.setGoal( "goal" );
|
||||
|
||||
Phase compile = new Phase();
|
||||
compile.addBinding( mb );
|
||||
|
||||
buildBinding.setCompile( compile );
|
||||
|
||||
BindingUtils.injectProjectConfiguration( bindings, project );
|
||||
|
||||
assertEquals( pVersion, mb.getVersion() );
|
||||
}
|
||||
|
||||
}
|
|
@ -1,319 +0,0 @@
|
|||
package org.apache.maven.lifecycle.binding;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.execution.DefaultMavenExecutionRequest;
|
||||
import org.apache.maven.execution.MavenExecutionRequest;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.lifecycle.LifecycleLoaderException;
|
||||
import org.apache.maven.lifecycle.LifecycleSpecificationException;
|
||||
import org.apache.maven.lifecycle.model.BuildBinding;
|
||||
import org.apache.maven.lifecycle.model.LifecycleBindings;
|
||||
import org.apache.maven.lifecycle.model.MojoBinding;
|
||||
import org.apache.maven.lifecycle.model.Phase;
|
||||
import org.apache.maven.model.Build;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.PluginExecution;
|
||||
import org.apache.maven.model.PluginManagement;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.realm.DefaultMavenRealmManager;
|
||||
import org.apache.maven.realm.MavenRealmManager;
|
||||
import org.apache.maven.shared.tools.easymock.MockManager;
|
||||
import org.codehaus.plexus.PlexusTestCase;
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
import org.codehaus.plexus.logging.console.ConsoleLogger;
|
||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||
import org.easymock.MockControl;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
public class DefaultLifecycleBindingManagerTest
|
||||
extends PlexusTestCase
|
||||
{
|
||||
|
||||
private LifecycleBindingManager mgr;
|
||||
|
||||
public void setUp()
|
||||
throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
mgr = lookup( LifecycleBindingManager.class, "default" );
|
||||
}
|
||||
|
||||
public void testLookup()
|
||||
{
|
||||
assertNotNull( mgr );
|
||||
}
|
||||
|
||||
public void testGetBindingsForPackaging_TestMergePluginConfigToBinding()
|
||||
throws Exception
|
||||
{
|
||||
Model model = new Model();
|
||||
model.setGroupId( "group" );
|
||||
model.setArtifactId( "artifact" );
|
||||
model.setVersion( "1" );
|
||||
|
||||
Build build = new Build();
|
||||
model.setBuild( build );
|
||||
|
||||
Plugin plugin = new Plugin();
|
||||
build.addPlugin( plugin );
|
||||
|
||||
plugin.setGroupId( "org.apache.maven.plugins" );
|
||||
plugin.setArtifactId( "maven-compiler-plugin" );
|
||||
|
||||
Properties pluginConfig = new Properties();
|
||||
|
||||
pluginConfig.setProperty( "test", "value" );
|
||||
pluginConfig.setProperty( "test2", "other-value" );
|
||||
|
||||
plugin.setConfiguration( createConfiguration( pluginConfig ) );
|
||||
|
||||
MavenProject project = new MavenProject( model );
|
||||
|
||||
MavenRealmManager realmManager = new DefaultMavenRealmManager(
|
||||
getContainer(),
|
||||
new ConsoleLogger(
|
||||
Logger.LEVEL_DEBUG,
|
||||
"test" ) );
|
||||
MavenExecutionRequest request = new DefaultMavenExecutionRequest().setRealmManager( realmManager );
|
||||
|
||||
LifecycleBindings lifecycleBindings = mgr.getBindingsForPackaging( project,
|
||||
new MavenSession(
|
||||
getContainer(),
|
||||
request,
|
||||
null,
|
||||
null ) );
|
||||
|
||||
List bindings = lifecycleBindings.getBuildBinding().getCompile().getBindings();
|
||||
|
||||
assertNotNull( bindings );
|
||||
assertEquals( 1, bindings.size() );
|
||||
|
||||
MojoBinding binding = (MojoBinding) bindings.get( 0 );
|
||||
|
||||
Xpp3Dom config = (Xpp3Dom) binding.getConfiguration();
|
||||
|
||||
assertNotNull( config );
|
||||
|
||||
assertEquals( "value", config.getChild( "test" ).getValue() );
|
||||
assertEquals( "other-value", config.getChild( "test2" ).getValue() );
|
||||
}
|
||||
|
||||
public void testGetBindingsForPackaging_TestMergePluginManagementConfigToBinding()
|
||||
throws Exception
|
||||
{
|
||||
Model model = new Model();
|
||||
model.setGroupId( "group" );
|
||||
model.setArtifactId( "artifact" );
|
||||
model.setVersion( "1" );
|
||||
|
||||
Build build = new Build();
|
||||
model.setBuild( build );
|
||||
|
||||
PluginManagement plugMgmt = new PluginManagement();
|
||||
build.setPluginManagement( plugMgmt );
|
||||
|
||||
Plugin plugin = new Plugin();
|
||||
plugMgmt.addPlugin( plugin );
|
||||
|
||||
plugin.setGroupId( "org.apache.maven.plugins" );
|
||||
plugin.setArtifactId( "maven-compiler-plugin" );
|
||||
|
||||
Properties pluginConfig = new Properties();
|
||||
|
||||
pluginConfig.setProperty( "test", "value" );
|
||||
pluginConfig.setProperty( "test2", "other-value" );
|
||||
|
||||
plugin.setConfiguration( createConfiguration( pluginConfig ) );
|
||||
|
||||
MavenProject project = new MavenProject( model );
|
||||
|
||||
MavenRealmManager realmManager = new DefaultMavenRealmManager(
|
||||
getContainer(),
|
||||
new ConsoleLogger(
|
||||
Logger.LEVEL_DEBUG,
|
||||
"test" ) );
|
||||
MavenExecutionRequest request = new DefaultMavenExecutionRequest().setRealmManager( realmManager );
|
||||
|
||||
LifecycleBindings lifecycleBindings = mgr.getBindingsForPackaging( project,
|
||||
new MavenSession(
|
||||
getContainer(),
|
||||
request,
|
||||
null,
|
||||
null ) );
|
||||
|
||||
List bindings = lifecycleBindings.getBuildBinding().getCompile().getBindings();
|
||||
|
||||
assertNotNull( bindings );
|
||||
assertEquals( 1, bindings.size() );
|
||||
|
||||
MojoBinding binding = (MojoBinding) bindings.get( 0 );
|
||||
|
||||
Xpp3Dom config = (Xpp3Dom) binding.getConfiguration();
|
||||
|
||||
assertNotNull( config );
|
||||
|
||||
assertEquals( "value", config.getChild( "test" ).getValue() );
|
||||
assertEquals( "other-value", config.getChild( "test2" ).getValue() );
|
||||
}
|
||||
|
||||
public void testGetProjectCustomBindings_ExecutionConfigShouldOverridePluginConfig()
|
||||
throws LifecycleLoaderException, LifecycleSpecificationException
|
||||
{
|
||||
Model model = new Model();
|
||||
model.setGroupId( "group" );
|
||||
model.setArtifactId( "artifact" );
|
||||
model.setVersion( "1" );
|
||||
|
||||
Build build = new Build();
|
||||
model.setBuild( build );
|
||||
|
||||
Plugin plugin = new Plugin();
|
||||
build.addPlugin( plugin );
|
||||
|
||||
plugin.setGroupId( "plugin.group" );
|
||||
plugin.setArtifactId( "plugin-artifact" );
|
||||
plugin.setVersion( "1" );
|
||||
|
||||
Properties pluginConfig = new Properties();
|
||||
|
||||
pluginConfig.setProperty( "test", "value" );
|
||||
pluginConfig.setProperty( "test2", "other-value" );
|
||||
|
||||
plugin.setConfiguration( createConfiguration( pluginConfig ) );
|
||||
|
||||
PluginExecution exec = new PluginExecution();
|
||||
plugin.addExecution( exec );
|
||||
|
||||
exec.setId( "test-execution" );
|
||||
exec.setPhase( "validate" );
|
||||
exec.setGoals( Collections.singletonList( "goal" ) );
|
||||
|
||||
Properties execConfig = new Properties();
|
||||
execConfig.setProperty( "test", "value2" );
|
||||
|
||||
exec.setConfiguration( createConfiguration( execConfig ) );
|
||||
|
||||
MavenProject project = new MavenProject( model );
|
||||
|
||||
LifecycleBindings lifecycleBindings = mgr.getProjectCustomBindings( project, null, new HashSet() );
|
||||
|
||||
List bindings = lifecycleBindings.getBuildBinding().getValidate().getBindings();
|
||||
|
||||
assertNotNull( bindings );
|
||||
assertEquals( 1, bindings.size() );
|
||||
|
||||
MojoBinding binding = (MojoBinding) bindings.get( 0 );
|
||||
|
||||
Xpp3Dom config = (Xpp3Dom) binding.getConfiguration();
|
||||
|
||||
assertEquals( "value2", config.getChild( "test" ).getValue() );
|
||||
assertEquals( "other-value", config.getChild( "test2" ).getValue() );
|
||||
}
|
||||
|
||||
public void test_GetBindingsForPackaging_CustomLifecycleIsUsedFromRealmManager()
|
||||
throws Exception
|
||||
{
|
||||
Model model = new Model();
|
||||
|
||||
model.setPackaging( "test" );
|
||||
|
||||
MavenProject project = new MavenProject( model );
|
||||
|
||||
MavenRealmManager realmManager = new DefaultMavenRealmManager(
|
||||
getContainer(),
|
||||
new ConsoleLogger(
|
||||
Logger.LEVEL_DEBUG,
|
||||
"test" ) );
|
||||
|
||||
MockManager mockManager = new MockManager();
|
||||
|
||||
MockControl extArtifactCtl = MockControl.createControl( Artifact.class );
|
||||
mockManager.add( extArtifactCtl );
|
||||
|
||||
Artifact extensionArtifact = (Artifact) extArtifactCtl.getMock();
|
||||
|
||||
extensionArtifact.getGroupId();
|
||||
extArtifactCtl.setReturnValue( "group", MockControl.ZERO_OR_MORE );
|
||||
|
||||
extensionArtifact.getArtifactId();
|
||||
extArtifactCtl.setReturnValue( "artifact", MockControl.ZERO_OR_MORE );
|
||||
|
||||
extensionArtifact.getVersion();
|
||||
extArtifactCtl.setReturnValue( "1", MockControl.ZERO_OR_MORE );
|
||||
|
||||
extensionArtifact.getFile();
|
||||
extArtifactCtl.setReturnValue( getResourceFile( "org/apache/maven/lifecycle/plan/test-custom-lifecycle-buildPlan-1.jar" ),
|
||||
MockControl.ZERO_OR_MORE );
|
||||
|
||||
mockManager.replayAll();
|
||||
|
||||
realmManager.createExtensionRealm( extensionArtifact, Collections.EMPTY_LIST );
|
||||
realmManager.importExtensionsIntoProjectRealm( "group", "project", "1", extensionArtifact );
|
||||
|
||||
MavenExecutionRequest request = new DefaultMavenExecutionRequest().setRealmManager( realmManager );
|
||||
|
||||
MavenSession session = new MavenSession( getContainer(), request, null, null );
|
||||
|
||||
LifecycleBindings lifecycleBindings = mgr.getBindingsForPackaging( project, session );
|
||||
|
||||
BuildBinding buildBinding = lifecycleBindings.getBuildBinding();
|
||||
assertNotNull( buildBinding );
|
||||
|
||||
Phase installPhase = buildBinding.getInstall();
|
||||
Phase deployPhase = buildBinding.getDeploy();
|
||||
Phase packagePhase = buildBinding.getCreatePackage();
|
||||
|
||||
assertTrue( ( packagePhase.getBindings() == null ) || packagePhase.getBindings().isEmpty() );
|
||||
assertNotNull( installPhase.getBindings() );
|
||||
assertEquals( 1, installPhase.getBindings().size() );
|
||||
assertEquals( "maven-deploy-plugin",
|
||||
( (MojoBinding) installPhase.getBindings().get( 0 ) ).getArtifactId() );
|
||||
|
||||
assertNotNull( deployPhase.getBindings() );
|
||||
assertEquals( 1, deployPhase.getBindings().size() );
|
||||
assertEquals( "maven-install-plugin",
|
||||
( (MojoBinding) deployPhase.getBindings().get( 0 ) ).getArtifactId() );
|
||||
|
||||
mockManager.verifyAll();
|
||||
}
|
||||
|
||||
private File getResourceFile( String path )
|
||||
{
|
||||
ClassLoader cloader = Thread.currentThread().getContextClassLoader();
|
||||
URL resource = cloader.getResource( path );
|
||||
|
||||
if ( resource == null )
|
||||
{
|
||||
fail( "Cannot find test resource: " + path );
|
||||
}
|
||||
|
||||
return new File( resource.getPath() );
|
||||
}
|
||||
|
||||
private Object createConfiguration( final Properties configProperties )
|
||||
{
|
||||
Xpp3Dom config = new Xpp3Dom( "configuration" );
|
||||
for ( Iterator it = configProperties.keySet().iterator(); it.hasNext(); )
|
||||
{
|
||||
String key = (String) it.next();
|
||||
String value = configProperties.getProperty( key );
|
||||
|
||||
Xpp3Dom child = new Xpp3Dom( key );
|
||||
child.setValue( value );
|
||||
|
||||
config.addChild( child );
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
package org.apache.maven.lifecycle.binding;
|
||||
|
||||
import org.apache.maven.lifecycle.LifecycleLoaderException;
|
||||
import org.apache.maven.lifecycle.LifecycleSpecificationException;
|
||||
import org.apache.maven.lifecycle.model.MojoBinding;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.PlexusTestCase;
|
||||
|
||||
public class DefaultMojoBindingFactoryTest
|
||||
extends PlexusTestCase
|
||||
{
|
||||
|
||||
private MojoBindingFactory factory;
|
||||
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
factory = lookup( MojoBindingFactory.class, "default" );
|
||||
}
|
||||
|
||||
public void testPrefixGoalSpec_PrefixReferenceNotAllowed()
|
||||
throws LifecycleLoaderException
|
||||
{
|
||||
String spec = "prefix:goal";
|
||||
|
||||
try
|
||||
{
|
||||
factory.parseMojoBinding( spec, new MavenProject( new Model() ), null, false );
|
||||
|
||||
fail( "Should fail when prefix references are not allowed." );
|
||||
}
|
||||
catch ( LifecycleSpecificationException e )
|
||||
{
|
||||
// expected.
|
||||
}
|
||||
}
|
||||
|
||||
public void testGroupIdArtifactIdGoalSpec_ShouldParseCorrectly()
|
||||
throws LifecycleSpecificationException, LifecycleLoaderException
|
||||
{
|
||||
String spec = "group:artifact:goal";
|
||||
|
||||
MojoBinding binding = factory.parseMojoBinding( spec, new MavenProject( new Model() ), null, false );
|
||||
|
||||
assertEquals( "group", binding.getGroupId() );
|
||||
assertEquals( "artifact", binding.getArtifactId() );
|
||||
assertNull( binding.getVersion() );
|
||||
assertEquals( "goal", binding.getGoal() );
|
||||
}
|
||||
|
||||
public void testGroupIdArtifactIdVersionGoalSpec_ShouldParseCorrectly()
|
||||
throws LifecycleSpecificationException, LifecycleLoaderException
|
||||
{
|
||||
String spec = "group:artifact:version:goal";
|
||||
|
||||
MojoBinding binding = factory.parseMojoBinding( spec, new MavenProject( new Model() ), null, false );
|
||||
|
||||
assertEquals( "group", binding.getGroupId() );
|
||||
assertEquals( "artifact", binding.getArtifactId() );
|
||||
assertEquals( "version", binding.getVersion() );
|
||||
assertEquals( "goal", binding.getGoal() );
|
||||
}
|
||||
|
||||
public void testSpecWithTooManyParts_ShouldFail()
|
||||
throws LifecycleLoaderException
|
||||
{
|
||||
String spec = "group:artifact:version:type:goal";
|
||||
|
||||
try
|
||||
{
|
||||
factory.parseMojoBinding( spec, new MavenProject( new Model() ), null, false );
|
||||
|
||||
fail( "Should fail because spec has too many parts (type part is not allowed)." );
|
||||
}
|
||||
catch ( LifecycleSpecificationException e )
|
||||
{
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package org.apache.maven.lifecycle.binding;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LegacyLifecycleParsingTestComponent
|
||||
{
|
||||
|
||||
public static final String ROLE = LegacyLifecycleParsingTestComponent.class.getName();
|
||||
private List lifecycles;
|
||||
|
||||
public List getLifecycles()
|
||||
{
|
||||
return lifecycles;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,153 +0,0 @@
|
|||
package org.apache.maven.lifecycle.plan;
|
||||
|
||||
import org.apache.maven.lifecycle.LifecycleLoaderException;
|
||||
import org.apache.maven.lifecycle.LifecycleSpecificationException;
|
||||
import org.apache.maven.lifecycle.MojoBindingUtils;
|
||||
import org.apache.maven.lifecycle.model.BuildBinding;
|
||||
import org.apache.maven.lifecycle.model.LifecycleBindings;
|
||||
import org.apache.maven.lifecycle.model.MojoBinding;
|
||||
import org.apache.maven.lifecycle.statemgmt.StateManagementUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class BuildPlanTest
|
||||
extends TestCase
|
||||
{
|
||||
|
||||
public void testRender_OneDirectInvocationWithForkedPhase_NoLifecycleOverlay()
|
||||
throws LifecycleSpecificationException, LifecycleLoaderException
|
||||
{
|
||||
List check = new ArrayList();
|
||||
|
||||
check.add( StateManagementUtils.createStartForkedExecutionMojoBinding() );
|
||||
|
||||
MojoBinding mb = new MojoBinding();
|
||||
mb.setGroupId( "test" );
|
||||
mb.setArtifactId( "test-plugin" );
|
||||
mb.setVersion( "1" );
|
||||
mb.setGoal( "validate" );
|
||||
|
||||
check.add( mb );
|
||||
|
||||
BuildBinding binding = new BuildBinding();
|
||||
binding.getValidate().addBinding( mb );
|
||||
|
||||
mb = new MojoBinding();
|
||||
mb.setGroupId( "test" );
|
||||
mb.setArtifactId( "test-plugin" );
|
||||
mb.setVersion( "1" );
|
||||
mb.setGoal( "generate-sources" );
|
||||
|
||||
check.add( mb );
|
||||
|
||||
check.add( StateManagementUtils.createEndForkedExecutionMojoBinding() );
|
||||
|
||||
binding.getGenerateSources().addBinding( mb );
|
||||
|
||||
LifecycleBindings bindings = new LifecycleBindings();
|
||||
bindings.setBuildBinding( binding );
|
||||
|
||||
List tasks = Collections.singletonList( "eclipse:eclipse" );
|
||||
|
||||
MojoBinding eclipseBinding = new MojoBinding();
|
||||
eclipseBinding.setGroupId( "org.apache.maven.plugins" );
|
||||
eclipseBinding.setArtifactId( "maven-eclipse-plugin" );
|
||||
eclipseBinding.setVersion( "2.3" );
|
||||
eclipseBinding.setGoal( "eclipse" );
|
||||
|
||||
check.add( eclipseBinding );
|
||||
|
||||
check.add( StateManagementUtils.createClearForkedExecutionMojoBinding() );
|
||||
|
||||
BuildPlan plan = new BuildPlan( new LifecycleBindings(), new HashSet(), tasks );
|
||||
|
||||
plan.addDirectInvocationBinding( "eclipse:eclipse", eclipseBinding );
|
||||
|
||||
plan.addForkedExecution( eclipseBinding, new BuildPlan( bindings,
|
||||
new HashSet(),
|
||||
Collections.singletonList( "generate-sources" ) ) );
|
||||
|
||||
List executionPlan = plan.renderExecutionPlan( new Stack() );
|
||||
|
||||
assertBindings( check, executionPlan );
|
||||
}
|
||||
|
||||
public void testRender_MojoBoundToPackagePhaseAndForkingPackagePhaseGetsFilteredOut()
|
||||
throws LifecycleSpecificationException, LifecycleLoaderException
|
||||
{
|
||||
MojoBinding mb = new MojoBinding();
|
||||
mb.setGroupId( "test" );
|
||||
mb.setArtifactId( "test-plugin" );
|
||||
mb.setVersion( "1" );
|
||||
mb.setGoal( "validate" );
|
||||
|
||||
BuildBinding binding = new BuildBinding();
|
||||
binding.getValidate().addBinding( mb );
|
||||
|
||||
MojoBinding mb2 = new MojoBinding();
|
||||
mb2.setGroupId( "test" );
|
||||
mb2.setArtifactId( "test-plugin" );
|
||||
mb2.setVersion( "1" );
|
||||
mb2.setGoal( "generate-sources" );
|
||||
|
||||
binding.getGenerateSources().addBinding( mb2 );
|
||||
|
||||
MojoBinding assemblyBinding = new MojoBinding();
|
||||
assemblyBinding.setGroupId( "org.apache.maven.plugins" );
|
||||
assemblyBinding.setArtifactId( "maven-assembly-plugin" );
|
||||
assemblyBinding.setVersion( "2.1" );
|
||||
assemblyBinding.setGoal( "assembly" );
|
||||
|
||||
binding.getCreatePackage().addBinding( assemblyBinding );
|
||||
|
||||
List check = new ArrayList();
|
||||
|
||||
check.add( mb );
|
||||
check.add( mb2 );
|
||||
check.add( StateManagementUtils.createStartForkedExecutionMojoBinding() );
|
||||
check.add( mb );
|
||||
check.add( mb2 );
|
||||
check.add( StateManagementUtils.createEndForkedExecutionMojoBinding() );
|
||||
check.add( assemblyBinding );
|
||||
check.add( StateManagementUtils.createClearForkedExecutionMojoBinding() );
|
||||
|
||||
LifecycleBindings bindings = new LifecycleBindings();
|
||||
bindings.setBuildBinding( binding );
|
||||
|
||||
List tasks = Collections.singletonList( "package" );
|
||||
|
||||
BuildPlan plan = new BuildPlan( bindings, new HashSet(), tasks );
|
||||
|
||||
plan.addForkedExecution( assemblyBinding, plan.copy( "package" ) );
|
||||
|
||||
List executionPlan = plan.renderExecutionPlan( new Stack() );
|
||||
|
||||
assertBindings( check, executionPlan );
|
||||
}
|
||||
|
||||
private void assertBindings( final List check, final List executionPlan )
|
||||
{
|
||||
assertNotNull( executionPlan );
|
||||
|
||||
System.out.println( "\n\nExpected execution plan:\n" + String.valueOf( check ).replace( ',', '\n' ) );
|
||||
System.out.println( "\nActual execution plan:\n" + String.valueOf( executionPlan ).replace( ',', '\n' ) );
|
||||
|
||||
assertEquals( "Execution plan does not contain the expected number of mojo bindings.", check.size(),
|
||||
executionPlan.size() );
|
||||
for ( int i = 0; i < check.size(); i++ )
|
||||
{
|
||||
MojoBinding checkBinding = (MojoBinding) check.get( i );
|
||||
MojoBinding realBinding = (MojoBinding) executionPlan.get( i );
|
||||
|
||||
assertEquals( "Expected mojo binding does not match execution plan.",
|
||||
MojoBindingUtils.createMojoBindingKey( checkBinding, true ),
|
||||
MojoBindingUtils.createMojoBindingKey( realBinding, true ) );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -272,6 +272,7 @@ public final class CLIReportingUtils
|
|||
handleGenericException( e, showStackTraces, writer );
|
||||
|
||||
MavenProject project = e.getProject();
|
||||
|
||||
if(project != null)
|
||||
{
|
||||
writer.write( NEWLINE );
|
||||
|
|
|
@ -53,6 +53,7 @@ import org.apache.maven.plugin.InvalidPluginException;
|
|||
import org.apache.maven.plugin.MavenPluginCollector;
|
||||
import org.apache.maven.plugin.MavenPluginDiscoverer;
|
||||
import org.apache.maven.plugin.MojoExecution;
|
||||
import org.apache.maven.plugin.PluginLoaderException;
|
||||
import org.apache.maven.plugin.PluginManager;
|
||||
import org.apache.maven.plugin.PluginManagerException;
|
||||
import org.apache.maven.plugin.PluginNotFoundException;
|
||||
|
@ -315,15 +316,13 @@ public class MavenEmbedder
|
|||
/**
|
||||
* mkleint: protected so that IDE integrations can selectively allow downloading artifacts
|
||||
* from remote repositories (if they prohibit by default on project loading)
|
||||
* @throws PluginLoaderException
|
||||
*/
|
||||
protected void verifyPlugin( Plugin plugin, MavenProject project )
|
||||
throws ComponentLookupException, ArtifactResolutionException, PluginVersionResolutionException,
|
||||
ArtifactNotFoundException, InvalidPluginException, PluginManagerException,
|
||||
PluginNotFoundException, PluginVersionNotFoundException
|
||||
throws ComponentLookupException, PluginLoaderException
|
||||
{
|
||||
PluginManager pluginManager = container.lookup( PluginManager.class );
|
||||
MavenSession session = new MavenSession( container, request, null, null );
|
||||
pluginManager.verifyPlugin( plugin, project, session );
|
||||
pluginManager.loadPlugin( plugin, project, session );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -237,7 +237,6 @@ under the License.
|
|||
<modules>
|
||||
<module>maven-core</module>
|
||||
<module>apache-maven</module>
|
||||
<module>maven-lifecycle</module>
|
||||
<module>maven-model</module>
|
||||
<module>maven-plugin-api</module>
|
||||
<module>maven-project</module>
|
||||
|
@ -248,6 +247,7 @@ under the License.
|
|||
<module>maven-toolchain</module>
|
||||
<module>maven-compat</module>
|
||||
<module>maven-repository</module>
|
||||
<module>maven-repository-mercury</module>
|
||||
</modules>
|
||||
<!-- FIXME: Remove once model-builder is released -->
|
||||
<repositories>
|
||||
|
|
Loading…
Reference in New Issue