You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jd...@apache.org on 2007/03/13 22:02:52 UTC
svn commit: r517868 [1/4] - in
/maven/components/branches/2.1-lifecycle-refactor: ./
maven-core/src/main/java/org/apache/maven/execution/
maven-core/src/main/java/org/apache/maven/lifecycle/
maven-core/src/main/java/org/apache/maven/lifecycle/binding/ ...
Author: jdcasey
Date: Tue Mar 13 14:02:48 2007
New Revision: 517868
URL: http://svn.apache.org/viewvc?view=rev&rev=517868
Log:
Works, ready for merging HEAD to this branch, then integration testing...
Added:
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/binding/LegacyLifecycle.java (with props)
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/plan/BuildPlan.java
- copied, changed from r516585, maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/plan/LifecyclePlan.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/plan/BuildPlanModifier.java
- copied, changed from r516585, maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/plan/LifecyclePlanModifier.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/plan/BuildPlanUtils.java (with props)
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/plan/BuildPlanner.java
- copied, changed from r516180, maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/plan/LifecyclePlanner.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/plan/DefaultBuildPlanner.java
- copied, changed from r516623, maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/plan/DefaultLifecyclePlanner.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/plan/DirectInvocationPlan.java (with props)
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/plan/ForkPlanModifier.java
- copied, changed from r516585, maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/plan/DefaultLifecyclePlanModifier.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/plan/ForkedLifecycleBuildPlan.java (with props)
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/plan/LifecycleBuildPlan.java
- copied, changed from r516585, maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/plan/DefaultLifecyclePlan.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/plan/ReportingPlanModifier.java (with props)
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/statemgmt/
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/statemgmt/EndForkedExecutionMojo.java (with props)
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/statemgmt/StartForkedExecutionMojo.java (with props)
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/statemgmt/StateManagementUtils.java (with props)
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/resources/META-INF/maven/plugin.xml (with props)
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/test/java/org/apache/maven/lifecycle/binding/
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/test/java/org/apache/maven/lifecycle/binding/DefaultLifecycleBindingManagerTest.java (with props)
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/test/java/org/apache/maven/lifecycle/binding/LegacyLifecycleParsingTestComponent.java
- copied, changed from r516585, maven/components/branches/2.1-lifecycle-refactor/maven-core/src/test/java/org/apache/maven/lifecycle/LegacyLifecycleParsingTestComponent.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/test/java/org/apache/maven/lifecycle/plan/BuildPlanUtilsTest.java (with props)
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/test/java/org/apache/maven/lifecycle/plan/ForkPlanModifierTest.java
- copied, changed from r516625, maven/components/branches/2.1-lifecycle-refactor/maven-core/src/test/java/org/apache/maven/lifecycle/plan/DefaultLifecyclePlanModifierTest.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/test/java/org/apache/maven/lifecycle/plan/ReportingPlanModifierTest.java (with props)
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/test/resources/META-INF/maven/
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/test/resources/META-INF/maven/org.apache.maven/
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/test/resources/META-INF/maven/org.apache.maven/maven-core/
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/test/resources/META-INF/maven/org.apache.maven/maven-core/pom.properties (with props)
maven/components/branches/2.1-lifecycle-refactor/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/MojoBindingUtils.java
- copied, changed from r516585, maven/components/branches/2.1-lifecycle-refactor/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/MojoBindingParser.java
maven/components/branches/2.1-lifecycle-refactor/maven-lifecycle/src/test/java/org/apache/maven/lifecycle/MojoBindingUtilsTest.java
- copied, changed from r516585, maven/components/branches/2.1-lifecycle-refactor/maven-lifecycle/src/test/java/org/apache/maven/lifecycle/MojoBindingParserTest.java
Removed:
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/Lifecycle.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/plan/DefaultLifecyclePlan.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/plan/DefaultLifecyclePlanModifier.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/plan/DefaultLifecyclePlanner.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/plan/LifecycleOverlayPlanModifier.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/plan/LifecyclePlan.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/plan/LifecyclePlanModifier.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/plan/LifecyclePlanner.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/test/java/org/apache/maven/lifecycle/LegacyLifecycleParsingTestComponent.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/test/java/org/apache/maven/lifecycle/plan/DefaultLifecyclePlanModifierTest.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/test/java/org/apache/maven/lifecycle/plan/LifecycleOverlayPlanModifierTest.java
maven/components/branches/2.1-lifecycle-refactor/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/MojoBindingParser.java
maven/components/branches/2.1-lifecycle-refactor/maven-lifecycle/src/test/java/org/apache/maven/lifecycle/MojoBindingParserTest.java
Modified:
maven/components/branches/2.1-lifecycle-refactor/build.properties
maven/components/branches/2.1-lifecycle-refactor/build.xml
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/LegacyLifecycleMappingParser.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/binding/DefaultLifecycleBindingManager.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/binding/LifecycleBindingManager.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/DefaultLifecycleMapping.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/Lifecycle.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/plan/ModifiablePlanElement.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/plugin/loader/DefaultPluginLoader.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/plugin/loader/PluginLoader.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/plugin/loader/PluginLoaderException.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/resources/META-INF/plexus/components.xml
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/test/java/org/apache/maven/lifecycle/LegacyLifecycleMappingParserTest.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/test/java/org/apache/maven/lifecycle/plan/DefaultLifecyclePlanTest.java
maven/components/branches/2.1-lifecycle-refactor/maven-core/src/test/resources/META-INF/plexus/components.xml
maven/components/branches/2.1-lifecycle-refactor/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java
maven/components/branches/2.1-lifecycle-refactor/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestDefaultsPopulator.java
maven/components/branches/2.1-lifecycle-refactor/maven-embedder/src/test/java/org/apache/maven/embedder/AbstractEmbedderExecutionTestCase.java
maven/components/branches/2.1-lifecycle-refactor/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java
maven/components/branches/2.1-lifecycle-refactor/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/LifecycleUtils.java
maven/components/branches/2.1-lifecycle-refactor/maven-lifecycle/src/main/mdo/maven-lifecycle.mdo
maven/components/branches/2.1-lifecycle-refactor/maven-lifecycle/src/test/java/org/apache/maven/lifecycle/LifecycleUtilsTest.java
maven/components/branches/2.1-lifecycle-refactor/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
maven/components/branches/2.1-lifecycle-refactor/pom.xml
Modified: maven/components/branches/2.1-lifecycle-refactor/build.properties
URL: http://svn.apache.org/viewvc/maven/components/branches/2.1-lifecycle-refactor/build.properties?view=diff&rev=517868&r1=517867&r2=517868
==============================================================================
--- maven/components/branches/2.1-lifecycle-refactor/build.properties (original)
+++ maven/components/branches/2.1-lifecycle-refactor/build.properties Tue Mar 13 14:02:48 2007
@@ -16,7 +16,8 @@
# under the License.
classworlds.version=1.2-alpha-7
-plexus.version=1.0-alpha-19-SNAPSHOT
+plexus-active-collections.version=1.0-SNAPSHOT
+plexus.version=1.0-alpha-18
plexus-archiver.version=1.0-alpha-8
plexus-utils.version=1.4
plexus-interactivity-api.version=1.0-alpha-6-SNAPSHOT
Modified: maven/components/branches/2.1-lifecycle-refactor/build.xml
URL: http://svn.apache.org/viewvc/maven/components/branches/2.1-lifecycle-refactor/build.xml?view=diff&rev=517868&r1=517867&r2=517868
==============================================================================
--- maven/components/branches/2.1-lifecycle-refactor/build.xml (original)
+++ maven/components/branches/2.1-lifecycle-refactor/build.xml Tue Mar 13 14:02:48 2007
@@ -116,6 +116,7 @@
</sequential>
</macrodef>
<pull orgpath="commons-cli/commons-cli" version="${commons-cli.version}" name="commons-cli"/>
+ <pull orgpath="org/codehaus/plexus/plexus-active-collections" version="${plexus-active-collections.version}" name="plexus-active-collections" repository="codehaus"/>
<pull orgpath="org/codehaus/plexus/plexus-utils" version="${plexus-utils.version}" name="plexus-utils" repository="codehaus"/>
<pull orgpath="org/codehaus/plexus/plexus-container-default" version="${plexus.version}" name="plexus-container-default" repository="codehaus"/>
<pull orgpath="org/codehaus/plexus/plexus-component-api" version="${plexus.version}" name="plexus-component-api" repository="codehaus"/>
@@ -154,6 +155,7 @@
<path id="pre.classpath">
<pathelement location="${maven.repo.local}/commons-cli/commons-cli/${commons-cli.version}/commons-cli-${commons-cli.version}.jar"/>
<pathelement location="${maven.repo.local}/commons-lang/commons-lang/${commons-lang.version}/commons-lang-${commons-lang.version}.jar"/>
+ <pathelement location="${maven.repo.local}/org/codehaus/plexus/plexus-active-collections/${plexus-active-collections.version}/plexus-active-collections-${plexus-active-collections.version}.jar"/>
<pathelement location="${maven.repo.local}/org/codehaus/plexus/plexus-utils/${plexus-utils.version}/plexus-utils-${plexus-utils.version}.jar"/>
<pathelement location="${maven.repo.local}/org/codehaus/plexus/plexus-container-default/${plexus.version}/plexus-container-default-${plexus.version}.jar"/>
<pathelement location="${maven.repo.local}/org/codehaus/plexus/plexus-component-api/${plexus.version}/plexus-component-api-${plexus.version}.jar"/>
@@ -227,6 +229,7 @@
<modello file="maven-model/src/main/mdo/maven.mdo" version="4.0.0"/>
<!-- DGF TODO turn this into a big <apply> task? write a custom task? -->
+ <modello file="maven-lifecycle/src/main/mdo/maven-lifecycle.mdo"/>
<modello file="maven-plugin-descriptor/src/main/mdo/lifecycle.mdo"/>
<modello file="maven-plugin-parameter-documenter/src/main/mdo/paramdoc.mdo"/>
<modello file="maven-plugin-registry/plugin-registry.mdo"/>
Modified: maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java
URL: http://svn.apache.org/viewvc/maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java?view=diff&rev=517868&r1=517867&r2=517868
==============================================================================
--- maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java (original)
+++ maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java Tue Mar 13 14:02:48 2007
@@ -21,13 +21,17 @@
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.monitor.event.EventDispatcher;
+import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
+import org.apache.maven.reporting.MavenReport;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+import java.util.ArrayList;
import java.util.Date;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -48,6 +52,8 @@
private MavenExecutionRequest request;
+ private Map reports = new LinkedHashMap();
+
public MavenSession( PlexusContainer container,
MavenExecutionRequest request,
EventDispatcher eventDispatcher,
@@ -155,5 +161,22 @@
public MavenExecutionRequest getRequest()
{
return request;
+ }
+
+ // this is a hack to try to untangle Maven's reporting system from the lifecycle executor,
+ // so we can plan the lifecycle steps ahead of any actual execution.
+ public List getReports()
+ {
+ return new ArrayList( reports.values() );
+ }
+
+ public void clearReports()
+ {
+ reports.clear();
+ }
+
+ public void addReport( MojoDescriptor mojoDescriptor, MavenReport report )
+ {
+ reports.put( mojoDescriptor.getId(), report );
}
}
Modified: maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
URL: http://svn.apache.org/viewvc/maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java?view=diff&rev=517868&r1=517867&r2=517868
==============================================================================
--- maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java (original)
+++ maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java Tue Mar 13 14:02:48 2007
@@ -27,11 +27,11 @@
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.ReactorManager;
-import org.apache.maven.lifecycle.mapping.LifecycleMapping;
+import org.apache.maven.lifecycle.model.MojoBinding;
+import org.apache.maven.lifecycle.plan.BuildPlan;
+import org.apache.maven.lifecycle.plan.BuildPlanUtils;
+import org.apache.maven.lifecycle.plan.BuildPlanner;
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.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.MavenEvents;
import org.apache.maven.plugin.InvalidPluginException;
@@ -44,29 +44,22 @@
import org.apache.maven.plugin.PluginNotFoundException;
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.Phase;
+import org.apache.maven.plugin.loader.PluginLoader;
+import org.apache.maven.plugin.loader.PluginLoaderException;
import org.apache.maven.plugin.version.PluginVersionNotFoundException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
-import org.apache.maven.reporting.MavenReport;
-import org.apache.maven.settings.Settings;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
-import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Stack;
-import java.util.StringTokenizer;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@@ -84,15 +77,13 @@
// ----------------------------------------------------------------------
private PluginManager pluginManager;
-
- private List lifecycles;
+
+ private PluginLoader pluginLoader;
+
+ private BuildPlanner lifecyclePlanner;
private ArtifactHandlerManager artifactHandlerManager;
- private List defaultReports;
-
- private Map phaseToLifecycleMap;
-
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
@@ -165,23 +156,27 @@
getLogger().info( " " + segment );
line();
+
+ String target = rootProject.getId() + " ( " + segment + " )";
+ getLogger().debug( "Constructing build plan for " + target );
+
// !! This is ripe for refactoring to an aspect.
// Event monitoring.
String event = MavenEvents.PROJECT_EXECUTION;
long buildStartTime = System.currentTimeMillis();
- String target = rootProject.getId() + " ( " + segment + " )";
-
dispatcher.dispatchStart( event, target );
+ List mojoBindings = getLifecycleBindings( segment.getTasks(), rootProject, target );
+
// only call once, with the top-level project (assumed to be provided as a parameter)...
- for ( Iterator goalIterator = segment.getTasks().iterator(); goalIterator.hasNext(); )
+ for ( Iterator mojoIterator = mojoBindings.iterator(); mojoIterator.hasNext(); )
{
- String task = (String) goalIterator.next();
+ MojoBinding binding = (MojoBinding) mojoIterator.next();
- executeGoalAndHandleFailures( task, session, rootProject, dispatcher, event, rm, buildStartTime,
+ executeGoalAndHandleFailures( binding, session, rootProject, dispatcher, event, rm, buildStartTime,
target );
}
@@ -222,20 +217,23 @@
line();
+ String target = currentProject.getId() + " ( " + segment + " )";
+
// !! This is ripe for refactoring to an aspect.
// Event monitoring.
String event = MavenEvents.PROJECT_EXECUTION;
long buildStartTime = System.currentTimeMillis();
- String target = currentProject.getId() + " ( " + segment + " )";
dispatcher.dispatchStart( event, target );
- for ( Iterator goalIterator = segment.getTasks().iterator(); goalIterator.hasNext(); )
+ List mojoBindings = getLifecycleBindings( segment.getTasks(), currentProject, target );
+
+ for ( Iterator mojoIterator = mojoBindings.iterator(); mojoIterator.hasNext(); )
{
- String task = (String) goalIterator.next();
+ MojoBinding mojoBinding = (MojoBinding) mojoIterator.next();
- executeGoalAndHandleFailures( task, session, currentProject, dispatcher, event, rm,
+ executeGoalAndHandleFailures( mojoBinding, session, currentProject, dispatcher, event, rm,
buildStartTime, target );
}
@@ -261,20 +259,102 @@
}
}
- private void executeGoalAndHandleFailures( String task, MavenSession session, MavenProject project,
+ private List getLifecycleBindings( List tasks, MavenProject project, String targetDescription )
+ throws LifecycleExecutionException
+ {
+ List mojoBindings;
+ try
+ {
+ BuildPlan plan = lifecyclePlanner.constructLifecyclePlan( tasks, project );
+
+ if ( getLogger().isDebugEnabled() )
+ {
+ getLogger().debug( "\n\nOur build plan is:\n" + BuildPlanUtils.listBuildPlan( plan ) + "\n\n" );
+ }
+
+ mojoBindings = plan.getPlanMojoBindings();
+ }
+ catch ( LifecycleException e )
+ {
+ throw new LifecycleExecutionException( "Failed to construct build plan for: " + targetDescription + ". Reason: "
+ + e.getMessage(), e );
+ }
+
+ return mojoBindings;
+ }
+
+ private void executeGoalAndHandleFailures( MojoBinding mojoBinding, MavenSession session, MavenProject project,
EventDispatcher dispatcher, String event, ReactorManager rm,
long buildStartTime, String target )
throws BuildFailureException, LifecycleExecutionException
{
try
{
- executeGoal( task, session, project );
+ PluginDescriptor pluginDescriptor = null;
+ try
+ {
+ pluginDescriptor = pluginLoader.loadPlugin( mojoBinding, project );
+ }
+ catch ( PluginLoaderException e )
+ {
+ if ( mojoBinding.isOptional() )
+ {
+ getLogger().debug( "Skipping optional mojo execution: " + MojoBindingUtils.toString( mojoBinding ) );
+ }
+ else
+ {
+ throw new LifecycleExecutionException( "Failed to load plugin for: " + MojoBindingUtils.toString( mojoBinding )
+ + ". Reason: " + e.getMessage(), e );
+ }
+ }
+
+ if ( pluginDescriptor != null )
+ {
+ MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( mojoBinding.getGoal() );
+ MojoExecution mojoExecution = new MojoExecution( mojoDescriptor );
+
+ mojoExecution.setConfiguration( (Xpp3Dom) mojoBinding.getConfiguration() );
+
+ try
+ {
+ pluginManager.executeMojo( project, mojoExecution, session );
+ }
+ catch ( PluginManagerException e )
+ {
+ throw new LifecycleExecutionException( "Internal error in the plugin manager executing goal '" +
+ mojoDescriptor.getId() + "': " + e.getMessage(), e );
+ }
+ catch ( ArtifactNotFoundException e )
+ {
+ throw new LifecycleExecutionException( e.getMessage(), e );
+ }
+ catch ( InvalidDependencyVersionException e )
+ {
+ throw new LifecycleExecutionException( e.getMessage(), e );
+ }
+ catch ( ArtifactResolutionException e )
+ {
+ throw new LifecycleExecutionException( e.getMessage(), e );
+ }
+ catch ( MojoFailureException e )
+ {
+ throw new BuildFailureException( e.getMessage(), e );
+ }
+ catch ( MojoExecutionException e )
+ {
+ throw new LifecycleExecutionException( e.getMessage(), e );
+ }
+ catch ( PluginConfigurationException e )
+ {
+ throw new LifecycleExecutionException( e.getMessage(), e );
+ }
+ }
}
catch ( LifecycleExecutionException e )
{
dispatcher.dispatchError( event, target, e );
- if ( handleExecutionFailure( rm, project, e, task, buildStartTime ) )
+ if ( handleExecutionFailure( rm, project, e, mojoBinding, buildStartTime ) )
{
throw e;
}
@@ -283,17 +363,17 @@
{
dispatcher.dispatchError( event, target, e );
- if ( handleExecutionFailure( rm, project, e, task, buildStartTime ) )
+ if ( handleExecutionFailure( rm, project, e, mojoBinding, buildStartTime ) )
{
throw e;
}
}
}
- private boolean handleExecutionFailure( ReactorManager rm, MavenProject project, Exception e, String task,
+ private boolean handleExecutionFailure( ReactorManager rm, MavenProject project, Exception e, MojoBinding mojoBinding,
long buildStartTime )
{
- rm.registerBuildFailure( project, e, task, System.currentTimeMillis() - buildStartTime );
+ rm.registerBuildFailure( project, e, MojoBindingUtils.toString( mojoBinding ), System.currentTimeMillis() - buildStartTime );
if ( ReactorManager.FAIL_FAST.equals( rm.getFailureBehavior() ) )
{
@@ -307,12 +387,12 @@
return false;
}
- private List segmentTaskListByAggregationNeeds( List tasks, MavenSession session, MavenProject project )
+ private List segmentTaskListByAggregationNeeds( List tasks, MavenSession session, MavenProject rootProject )
throws LifecycleExecutionException, BuildFailureException
{
List segments = new ArrayList();
- if ( project != null )
+ if ( rootProject != null )
{
TaskSegment currentSegment = null;
@@ -322,7 +402,7 @@
// if it's a phase, then we don't need to check whether it's an aggregator.
// simply add it to the current task partition.
- if ( getPhaseToLifecycleMap().containsKey( task ) )
+ if ( LifecycleUtils.isValidPhaseName( task ) )
{
if ( currentSegment != null && currentSegment.aggregate() )
{
@@ -340,18 +420,27 @@
else
{
MojoDescriptor mojo = null;
+ // definitely a CLI goal, can use prefix
try
{
- // definitely a CLI goal, can use prefix
- mojo = getMojoDescriptor( task, session, project, task, true, false );
+ mojo = getMojoDescriptorForDirectInvocation( task, session, rootProject );
}
- catch ( PluginNotFoundException e )
+ catch ( PluginLoaderException e )
{
- // TODO: shouldn't hit this, investigate using the same resolution logic as otheres for plugins in the reactor
+ // TODO: shouldn't hit this, investigate using the same resolution logic as
+ // others for plugins in the reactor
getLogger().info(
"Cannot find mojo descriptor for: \'" + task + "\' - Treating as non-aggregator." );
+
getLogger().debug( "", e );
}
+ catch ( LifecycleSpecificationException e )
+ {
+ String message = "Invalid task '" + task + "': you must specify a valid lifecycle phase, or"
+ + " a goal in the format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal";
+
+ throw new BuildFailureException( message, e );
+ }
// if the mojo descriptor was found, determine aggregator status according to:
// 1. whether the mojo declares itself an aggregator
@@ -404,832 +493,79 @@
return segments;
}
- private void executeGoal( String task, MavenSession session, MavenProject project )
- throws LifecycleExecutionException, BuildFailureException
- {
- try
- {
- Stack forkEntryPoints = new Stack();
- if ( getPhaseToLifecycleMap().containsKey( task ) )
- {
- Lifecycle lifecycle = getLifecycleForPhase( task );
-
- // we have a lifecycle phase, so lets bind all the necessary goals
- Map lifecycleMappings = constructLifecycleMappings( session, task, project, lifecycle );
- executeGoalWithLifecycle( task, forkEntryPoints, session, lifecycleMappings, project, lifecycle );
- }
- else
- {
- executeStandaloneGoal( task, forkEntryPoints, session, project );
- }
- }
- catch ( PluginNotFoundException e )
- {
- throw new BuildFailureException( "A required plugin was not found: " + e.getMessage(), e );
- }
- }
-
- private void executeGoalWithLifecycle( String task, Stack forkEntryPoints, MavenSession session,
- Map lifecycleMappings, MavenProject project, Lifecycle lifecycle )
- throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException
- {
- List goals = processGoalChain( task, lifecycleMappings, lifecycle );
-
- if ( !goals.isEmpty() )
- {
- executeGoals( goals, forkEntryPoints, session, project );
- }
- else
- {
- getLogger().info( "No goals needed for project - skipping" );
- }
- }
-
- private void executeStandaloneGoal( String task, Stack forkEntryPoints, MavenSession session, MavenProject project )
- throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException
- {
- // guaranteed to come from the CLI and not be part of a phase
- MojoDescriptor mojoDescriptor = getMojoDescriptor( task, session, project, task, true, false );
- executeGoals( Collections.singletonList( new MojoExecution( mojoDescriptor ) ), forkEntryPoints, session,
- project );
- }
-
- private void executeGoals( List goals, Stack forkEntryPoints, MavenSession session, MavenProject project )
- throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException
+ /**
+ * @todo Not particularly happy about this. Would like WagonManager and ArtifactTypeHandlerManager to be able to
+ * lookup directly, or have them passed in
+ *
+ * @todo Move this sort of thing to the tail end of the project-building process
+ */
+ private Map findArtifactTypeHandlers( MavenSession session )
+ throws LifecycleExecutionException, PluginNotFoundException
{
- for ( Iterator i = goals.iterator(); i.hasNext(); )
+ Map map = new HashMap();
+ for ( Iterator projectIterator = session.getSortedProjects().iterator(); projectIterator.hasNext(); )
{
- MojoExecution mojoExecution = (MojoExecution) i.next();
-
- MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
-
- if ( mojoDescriptor.getExecutePhase() != null || mojoDescriptor.getExecuteGoal() != null )
- {
- forkEntryPoints.push( mojoDescriptor );
-
- forkLifecycle( mojoDescriptor, forkEntryPoints, session, project );
-
- forkEntryPoints.pop();
- }
-
- if ( mojoDescriptor.isRequiresReports() )
+ MavenProject project = (MavenProject) projectIterator.next();
+
+ for ( Iterator i = project.getBuildPlugins().iterator(); i.hasNext(); )
{
- List reports = getReports( project, mojoExecution, session );
-
- mojoExecution.setReports( reports );
+ Plugin plugin = (Plugin) i.next();
- for ( Iterator j = mojoExecution.getForkedExecutions().iterator(); j.hasNext(); )
+ if ( plugin.isExtensions() )
{
- MojoExecution forkedExecution = (MojoExecution) j.next();
- MojoDescriptor descriptor = forkedExecution.getMojoDescriptor();
+ verifyPlugin( plugin, project, session );
- if ( descriptor.getExecutePhase() != null )
+ // TODO: if moved to the plugin manager we already have the descriptor from above and so do can lookup the container directly
+ try
{
- forkEntryPoints.push( descriptor );
-
- forkLifecycle( descriptor, forkEntryPoints, session, project );
-
- forkEntryPoints.pop();
+ Map components = pluginManager.getPluginComponents( plugin, ArtifactHandler.ROLE );
+ map.putAll( components );
}
- }
- }
-
- try
- {
- pluginManager.executeMojo( project, mojoExecution, session );
- }
- catch ( PluginManagerException e )
- {
- throw new LifecycleExecutionException( "Internal error in the plugin manager executing goal '" +
- mojoDescriptor.getId() + "': " + e.getMessage(), e );
- }
- catch ( ArtifactNotFoundException e )
- {
- throw new LifecycleExecutionException( e.getMessage(), e );
- }
- catch ( InvalidDependencyVersionException e )
- {
- throw new LifecycleExecutionException( e.getMessage(), e );
- }
- catch ( ArtifactResolutionException e )
- {
- throw new LifecycleExecutionException( e.getMessage(), e );
- }
- catch ( MojoFailureException e )
- {
- throw new BuildFailureException( e.getMessage(), e );
- }
- catch ( MojoExecutionException e )
- {
- throw new LifecycleExecutionException( e.getMessage(), e );
- }
- catch ( PluginConfigurationException e )
- {
- throw new LifecycleExecutionException( e.getMessage(), e );
- }
- }
- }
-
- private List getReports( MavenProject project, MojoExecution mojoExecution, MavenSession session )
- throws LifecycleExecutionException, PluginNotFoundException
- {
- List reportPlugins = project.getReportPlugins();
-
- if ( project.getModel().getReports() != null )
- {
- getLogger().error(
- "Plugin contains a <reports/> section: this is IGNORED - please use <reporting/> instead." );
- }
-
- 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, ":" );
- if ( tok.countTokens() != 2 )
- {
- getLogger().warn( "Invalid default report ignored: '" + report + "' (must be groupId:artifactId)" );
- }
- else
- {
- String groupId = tok.nextToken();
- String artifactId = tok.nextToken();
-
- boolean found = false;
- for ( Iterator j = reportPlugins.iterator(); j.hasNext() && !found; )
+ catch ( ComponentLookupException e )
{
- ReportPlugin reportPlugin = (ReportPlugin) j.next();
- if ( reportPlugin.getGroupId().equals( groupId ) &&
- reportPlugin.getArtifactId().equals( artifactId ) )
- {
- found = true;
- }
+ getLogger().debug( "Unable to find the lifecycle component in the extension", e );
}
-
- if ( !found )
+ catch ( PluginManagerException e )
{
- ReportPlugin reportPlugin = new ReportPlugin();
- reportPlugin.setGroupId( groupId );
- reportPlugin.setArtifactId( artifactId );
- reportPlugins.add( reportPlugin );
+ throw new LifecycleExecutionException( "Error looking up available components from plugin '" +
+ plugin.getKey() + "': " + e.getMessage(), e );
}
- }
- }
- }
- 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( getReports( reportPlugin, null, project, session, mojoExecution ) );
- }
- else
- {
- for ( Iterator j = reportSets.iterator(); j.hasNext(); )
+ // shudder...
+ for ( Iterator j = map.values().iterator(); j.hasNext(); )
{
- ReportSet reportSet = (ReportSet) j.next();
-
- reports.addAll( getReports( reportPlugin, reportSet, project, session, mojoExecution ) );
+ ArtifactHandler handler = (ArtifactHandler) j.next();
+ if ( project.getPackaging().equals( handler.getPackaging() ) )
+ {
+ project.getArtifact().setArtifactHandler( handler );
+ }
}
}
}
}
- return reports;
+ return map;
}
- private List getReports( ReportPlugin reportPlugin, ReportSet reportSet, MavenProject project, MavenSession session,
- MojoExecution mojoExecution )
+ private PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, MavenSession session )
throws LifecycleExecutionException, PluginNotFoundException
{
- PluginDescriptor pluginDescriptor = verifyReportPlugin( reportPlugin, project, session );
-
- List reports = new ArrayList();
- for ( Iterator i = pluginDescriptor.getMojos().iterator(); i.hasNext(); )
+ getLogger().debug( "Verifying plugin: " + plugin.getKey() );
+
+ PluginDescriptor pluginDescriptor;
+ try
{
- MojoDescriptor mojoDescriptor = (MojoDescriptor) i.next();
-
- // 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();
- }
-
- MojoExecution reportExecution = new MojoExecution( mojoDescriptor, id );
-
- try
- {
- MavenReport reportMojo = pluginManager.getReport( project, reportExecution, session );
-
- // Comes back null if it was a plugin, not a report - these are mojos in the reporting plugins that are not reports
- if ( reportMojo != null )
- {
- reports.add( reportMojo );
- mojoExecution.addMojoExecution( reportExecution );
- }
- }
- catch ( PluginManagerException e )
- {
- throw new LifecycleExecutionException(
- "Error getting reports from the plugin '" + reportPlugin.getKey() + "': " + e.getMessage(), e );
- }
- catch ( PluginConfigurationException e )
- {
- throw new LifecycleExecutionException(
- "Error getting reports from the plugin '" + reportPlugin.getKey() + "'", e );
- }
- catch ( ArtifactNotFoundException e )
- {
- throw new LifecycleExecutionException( e.getMessage(), e );
- }
- catch ( ArtifactResolutionException e )
- {
- throw new LifecycleExecutionException( e.getMessage(), e );
- }
- }
+ pluginDescriptor = pluginManager.verifyPlugin( plugin, project, session );
}
- return reports;
- }
-
- private void forkLifecycle( MojoDescriptor mojoDescriptor, Stack ancestorLifecycleForkers, MavenSession session,
- MavenProject project )
- throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException
- {
- PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
- getLogger().info( "Preparing " + pluginDescriptor.getGoalPrefix() + ":" + mojoDescriptor.getGoal() );
-
- if ( mojoDescriptor.isAggregator() )
+ catch ( PluginManagerException e )
{
- for ( Iterator i = session.getSortedProjects().iterator(); i.hasNext(); )
- {
- MavenProject reactorProject = (MavenProject) i.next();
-
- line();
-
- getLogger().info( "Building " + reactorProject.getName() );
-
- line();
-
- forkProjectLifecycle( mojoDescriptor, ancestorLifecycleForkers, session, reactorProject );
- }
+ throw new LifecycleExecutionException(
+ "Internal error in the plugin manager getting plugin '" + plugin.getKey() + "': " + e.getMessage(), e );
}
- else
+ catch ( PluginVersionResolutionException e )
{
- forkProjectLifecycle( mojoDescriptor, ancestorLifecycleForkers, session, project );
+ throw new LifecycleExecutionException( e.getMessage(), e );
}
- }
-
- private void forkProjectLifecycle( MojoDescriptor mojoDescriptor, Stack forkEntryPoints, MavenSession session,
- MavenProject project )
- throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException
- {
- forkEntryPoints.push( mojoDescriptor );
-
- PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
-
- String targetPhase = mojoDescriptor.getExecutePhase();
-
- Map lifecycleMappings = null;
- if ( targetPhase != null )
- {
- Lifecycle lifecycle = getLifecycleForPhase( targetPhase );
-
- // Create new lifecycle
- lifecycleMappings = constructLifecycleMappings( session, targetPhase, project, lifecycle );
-
- String executeLifecycle = mojoDescriptor.getExecuteLifecycle();
- if ( executeLifecycle != null )
- {
- org.apache.maven.plugin.lifecycle.Lifecycle lifecycleOverlay;
- try
- {
- lifecycleOverlay = pluginDescriptor.getLifecycleMapping( executeLifecycle );
- }
- catch ( IOException e )
- {
- throw new LifecycleExecutionException( "Unable to read lifecycle mapping file: " + e.getMessage(),
- e );
- }
- catch ( XmlPullParserException e )
- {
- throw new LifecycleExecutionException( "Unable to parse lifecycle mapping file: " + e.getMessage(),
- e );
- }
-
- if ( lifecycleOverlay == null )
- {
- throw new LifecycleExecutionException( "Lifecycle '" + executeLifecycle + "' not found in plugin" );
- }
-
- for ( Iterator i = lifecycleOverlay.getPhases().iterator(); i.hasNext(); )
- {
- Phase phase = (Phase) i.next();
- 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();
-
- PluginDescriptor lifecyclePluginDescriptor;
- String lifecycleGoal;
-
- // 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>
-
- // ----------------------------------------------------------------------
- //
- // ----------------------------------------------------------------------
-
- if ( goal.indexOf( ":" ) > 0 )
- {
- String[] s = StringUtils.split( goal, ":" );
-
- String groupId = s[0];
- String artifactId = s[1];
- lifecycleGoal = s[2];
-
- Plugin plugin = new Plugin();
- plugin.setGroupId( groupId );
- plugin.setArtifactId( artifactId );
- lifecyclePluginDescriptor = verifyPlugin( plugin, project, session );
- if ( lifecyclePluginDescriptor == null )
- {
- throw new LifecycleExecutionException(
- "Unable to find plugin " + groupId + ":" + artifactId );
- }
- }
- else
- {
- lifecyclePluginDescriptor = pluginDescriptor;
- lifecycleGoal = goal;
- }
-
- Xpp3Dom configuration = (Xpp3Dom) exec.getConfiguration();
- if ( phase.getConfiguration() != null )
- {
- configuration = Xpp3Dom.mergeXpp3Dom( new Xpp3Dom( (Xpp3Dom) phase.getConfiguration() ),
- configuration );
- }
-
- MojoDescriptor desc = getMojoDescriptor( lifecyclePluginDescriptor, lifecycleGoal );
- MojoExecution mojoExecution = new MojoExecution( desc, configuration );
- addToLifecycleMappings( lifecycleMappings, phase.getId(), mojoExecution,
- session.getSettings() );
- }
- }
-
- 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
- for ( Iterator j = lifecycleMappings.values().iterator(); j.hasNext(); )
- {
- List tasks = (List) j.next();
-
- for ( Iterator k = tasks.iterator(); k.hasNext(); )
- {
- MojoExecution exec = (MojoExecution) k.next();
-
- Xpp3Dom configuration = Xpp3Dom.mergeXpp3Dom(
- new Xpp3Dom( (Xpp3Dom) phase.getConfiguration() ), exec.getConfiguration() );
-
- exec.setConfiguration( configuration );
- }
- }
- }
-
- }
- }
-
- removeFromLifecycle( forkEntryPoints, lifecycleMappings );
- }
-
- MavenProject executionProject = new MavenProject( project );
- if ( targetPhase != null )
- {
- Lifecycle lifecycle = getLifecycleForPhase( targetPhase );
-
- executeGoalWithLifecycle( targetPhase, forkEntryPoints, session, lifecycleMappings, executionProject,
- lifecycle );
- }
- else
- {
- String goal = mojoDescriptor.getExecuteGoal();
- MojoDescriptor desc = getMojoDescriptor( pluginDescriptor, goal );
- executeGoals( Collections.singletonList( new MojoExecution( desc ) ), forkEntryPoints, session,
- executionProject );
- }
- project.setExecutionProject( executionProject );
- }
-
- private Lifecycle getLifecycleForPhase( String phase )
- throws BuildFailureException, LifecycleExecutionException
- {
- Lifecycle lifecycle = (Lifecycle) getPhaseToLifecycleMap().get( phase );
-
- if ( lifecycle == null )
- {
- throw new BuildFailureException( "Unable to find lifecycle for phase '" + phase + "'" );
- }
- return lifecycle;
- }
-
- private MojoDescriptor getMojoDescriptor( PluginDescriptor pluginDescriptor, String goal )
- throws LifecycleExecutionException
- {
- MojoDescriptor desc = pluginDescriptor.getMojo( goal );
-
- if ( desc == null )
- {
- String message =
- "Required goal '" + goal + "' not found in plugin '" + pluginDescriptor.getGoalPrefix() + "'";
- int index = goal.indexOf( ':' );
- if ( index >= 0 )
- {
- String prefix = goal.substring( index + 1 );
- if ( prefix.equals( pluginDescriptor.getGoalPrefix() ) )
- {
- message = message + " (goals should not be prefixed - try '" + prefix + "')";
- }
- }
- throw new LifecycleExecutionException( message );
- }
- return desc;
- }
-
- private void removeFromLifecycle( Stack lifecycleForkers, Map lifecycleMappings )
- {
- for ( Iterator it = lifecycleForkers.iterator(); it.hasNext(); )
- {
- MojoDescriptor mojoDescriptor = (MojoDescriptor) it.next();
-
- for ( Iterator lifecycleIterator = lifecycleMappings.values().iterator(); lifecycleIterator.hasNext(); )
- {
- List tasks = (List) lifecycleIterator.next();
-
- boolean removed = false;
- for ( Iterator taskIterator = tasks.iterator(); taskIterator.hasNext(); )
- {
- MojoExecution execution = (MojoExecution) taskIterator.next();
-
- if ( mojoDescriptor.equals( execution.getMojoDescriptor() ) )
- {
- taskIterator.remove();
- removed = true;
- }
- }
-
- if ( removed )
- {
- getLogger().warn( "Removing: " + mojoDescriptor.getGoal() +
- " from forked lifecycle, to prevent recursive invocation." );
- }
- }
- }
- }
-
- private Map constructLifecycleMappings( MavenSession session, String selectedPhase, MavenProject project,
- Lifecycle lifecycle )
- throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException
- {
- // first, bind those associated with the packaging
- Map lifecycleMappings = bindLifecycleForPackaging( session, selectedPhase, project, lifecycle );
-
- // next, loop over plugins and for any that have a phase, bind it
- for ( Iterator i = project.getBuildPlugins().iterator(); i.hasNext(); )
- {
- Plugin plugin = (Plugin) i.next();
-
- bindPluginToLifecycle( plugin, session, lifecycleMappings, project );
- }
-
- return lifecycleMappings;
- }
-
- private Map bindLifecycleForPackaging( MavenSession session, String selectedPhase, MavenProject project,
- Lifecycle lifecycle )
- throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException
- {
- Map mappings = findMappingsForLifecycle( session, project, lifecycle );
-
- List optionalMojos = findOptionalMojosForLifecycle( session, project, lifecycle );
-
- Map lifecycleMappings = new HashMap();
-
- for ( Iterator i = lifecycle.getPhases().iterator(); i.hasNext(); )
- {
- String phase = (String) i.next();
-
- String phaseTasks = (String) mappings.get( phase );
-
- if ( phaseTasks != null )
- {
- for ( StringTokenizer tok = new StringTokenizer( phaseTasks, "," ); tok.hasMoreTokens(); )
- {
- String goal = tok.nextToken().trim();
-
- // Not from the CLI, don't use prefix
- MojoDescriptor mojoDescriptor = getMojoDescriptor( goal, session, project, selectedPhase, false,
- optionalMojos.contains( goal ) );
-
- if ( mojoDescriptor == null )
- {
- continue;
- }
-
- if ( mojoDescriptor.isDirectInvocationOnly() )
- {
- throw new LifecycleExecutionException( "Mojo: \'" + goal +
- "\' requires direct invocation. It cannot be used as part of lifecycle: \'" +
- project.getPackaging() + "\'." );
- }
-
- addToLifecycleMappings( lifecycleMappings, phase, new MojoExecution( mojoDescriptor ),
- session.getSettings() );
- }
- }
-
- if ( phase.equals( selectedPhase ) )
- {
- break;
- }
- }
-
- return lifecycleMappings;
- }
-
- private Map findMappingsForLifecycle( MavenSession session, MavenProject project, Lifecycle lifecycle )
- throws LifecycleExecutionException, PluginNotFoundException
- {
- String packaging = project.getPackaging();
- Map mappings = null;
-
- LifecycleMapping m = (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging, session );
- if ( m != null )
- {
- mappings = m.getPhases( lifecycle.getId() );
- }
-
- Map defaultMappings = lifecycle.getDefaultPhases();
-
- if ( mappings == null )
- {
- try
- {
- m = (LifecycleMapping) session.lookup( LifecycleMapping.ROLE, packaging );
- mappings = m.getPhases( lifecycle.getId() );
- }
- catch ( ComponentLookupException e )
- {
- if ( defaultMappings == null )
- {
- throw new LifecycleExecutionException(
- "Cannot find lifecycle mapping for packaging: \'" + packaging + "\'.", e );
- }
- }
- }
-
- if ( mappings == null )
- {
- if ( defaultMappings == null )
- {
- throw new LifecycleExecutionException(
- "Cannot find lifecycle mapping for packaging: \'" + packaging + "\', and there is no default" );
- }
- else
- {
- mappings = defaultMappings;
- }
- }
-
- return mappings;
- }
-
- private List findOptionalMojosForLifecycle( MavenSession session, MavenProject project, Lifecycle lifecycle )
- throws LifecycleExecutionException, PluginNotFoundException
- {
- String packaging = project.getPackaging();
- List optionalMojos = null;
-
- LifecycleMapping m = (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging, session );
-
- if ( m != null )
- {
- optionalMojos = m.getOptionalMojos( lifecycle.getId() );
- }
-
- if ( optionalMojos == null )
- {
- try
- {
- m = (LifecycleMapping) session.lookup( LifecycleMapping.ROLE, packaging );
- optionalMojos = m.getOptionalMojos( lifecycle.getId() );
- }
- catch ( ComponentLookupException e )
- {
- getLogger().debug( "Error looking up lifecycle mapping to retrieve optional mojos. Lifecycle ID: " +
- lifecycle.getId() + ". Error: " + e.getMessage(), e );
- }
- }
-
- if ( optionalMojos == null )
- {
- optionalMojos = Collections.EMPTY_LIST;
- }
-
- return optionalMojos;
- }
-
- private Object findExtension( MavenProject project, String role, String roleHint, MavenSession session )
- throws LifecycleExecutionException, PluginNotFoundException
- {
- Object pluginComponent = null;
-
- for ( Iterator i = project.getBuildPlugins().iterator(); i.hasNext() && pluginComponent == null; )
- {
- Plugin plugin = (Plugin) i.next();
-
- if ( plugin.isExtensions() )
- {
- verifyPlugin( plugin, project, session );
-
- // TODO: if moved to the plugin manager we already have the descriptor from above and so do can lookup the container directly
- try
- {
- pluginComponent = pluginManager.getPluginComponent( plugin, role, roleHint );
- }
- catch ( ComponentLookupException e )
- {
- getLogger().debug( "Unable to find the lifecycle component in the extension", e );
- }
- catch ( PluginManagerException e )
- {
- throw new LifecycleExecutionException(
- "Error getting extensions from the plugin '" + plugin.getKey() + "': " + e.getMessage(), e );
- }
- }
- }
- return pluginComponent;
- }
-
- /**
- * @todo Not particularly happy about this. Would like WagonManager and ArtifactTypeHandlerManager to be able to
- * lookup directly, or have them passed in
- *
- * @todo Move this sort of thing to the tail end of the project-building process
- */
- private Map findArtifactTypeHandlers( MavenSession session )
- throws LifecycleExecutionException, PluginNotFoundException
- {
- Map map = new HashMap();
- for ( Iterator projectIterator = session.getSortedProjects().iterator(); projectIterator.hasNext(); )
- {
- MavenProject project = (MavenProject) projectIterator.next();
-
- for ( Iterator i = project.getBuildPlugins().iterator(); i.hasNext(); )
- {
- Plugin plugin = (Plugin) i.next();
-
- if ( plugin.isExtensions() )
- {
- verifyPlugin( plugin, project, session );
-
- // TODO: if moved to the plugin manager we already have the descriptor from above and so do can lookup the container directly
- try
- {
- Map components = pluginManager.getPluginComponents( plugin, ArtifactHandler.ROLE );
- map.putAll( components );
- }
- catch ( ComponentLookupException e )
- {
- getLogger().debug( "Unable to find the lifecycle component in the extension", e );
- }
- catch ( PluginManagerException e )
- {
- throw new LifecycleExecutionException( "Error looking up available components from plugin '" +
- plugin.getKey() + "': " + e.getMessage(), e );
- }
-
- // shudder...
- for ( Iterator j = map.values().iterator(); j.hasNext(); )
- {
- ArtifactHandler handler = (ArtifactHandler) j.next();
- if ( project.getPackaging().equals( handler.getPackaging() ) )
- {
- project.getArtifact().setArtifactHandler( handler );
- }
- }
- }
- }
- }
- return map;
- }
-
- /**
- * Take each mojo contained with a plugin, look to see whether it contributes to a
- * phase in the lifecycle and if it does place it at the end of the list of goals
- * to execute for that given phase.
- *
- * @param project
- * @param session
- */
- private void bindPluginToLifecycle( Plugin plugin, MavenSession session, Map phaseMap, MavenProject project )
- throws LifecycleExecutionException, PluginNotFoundException
- {
- Settings settings = session.getSettings();
-
- PluginDescriptor pluginDescriptor =
- verifyPlugin( plugin, project, session );
-
- if ( pluginDescriptor.getMojos() != null && !pluginDescriptor.getMojos().isEmpty() )
- {
- // use the plugin if inherit was true in a base class, or it is in the current POM, otherwise use the default inheritence setting
- if ( plugin.isInheritanceApplied() || pluginDescriptor.isInheritedByDefault() )
- {
- if ( plugin.getGoals() != null )
- {
- getLogger().error(
- "Plugin contains a <goals/> section: this is IGNORED - please use <executions/> instead." );
- }
-
- List executions = plugin.getExecutions();
-
- if ( executions != null )
- {
- for ( Iterator it = executions.iterator(); it.hasNext(); )
- {
- PluginExecution execution = (PluginExecution) it.next();
-
- bindExecutionToLifecycle( pluginDescriptor, phaseMap, execution, settings );
- }
- }
- }
- }
- }
-
- private PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, MavenSession session )
- throws LifecycleExecutionException, PluginNotFoundException
- {
- getLogger().debug( "Verifying plugin: " + plugin.getKey() );
-
- PluginDescriptor pluginDescriptor;
- try
- {
- pluginDescriptor = pluginManager.verifyPlugin( plugin, project, session );
- }
- catch ( PluginManagerException e )
- {
- throw new LifecycleExecutionException(
- "Internal error in the plugin manager getting plugin '" + plugin.getKey() + "': " + e.getMessage(), e );
- }
- catch ( PluginVersionResolutionException e )
- {
- throw new LifecycleExecutionException( e.getMessage(), e );
- }
- catch ( InvalidVersionSpecificationException e )
+ catch ( InvalidVersionSpecificationException e )
{
throw new LifecycleExecutionException( e.getMessage(), e );
}
@@ -1252,310 +588,20 @@
return pluginDescriptor;
}
- private PluginDescriptor verifyReportPlugin( ReportPlugin plugin, MavenProject project, MavenSession session )
- throws LifecycleExecutionException, PluginNotFoundException
+ private MojoDescriptor getMojoDescriptorForDirectInvocation( String task, MavenSession session, MavenProject project )
+ throws LifecycleSpecificationException, PluginLoaderException
{
- PluginDescriptor pluginDescriptor;
- try
- {
- pluginDescriptor = pluginManager.verifyReportPlugin( plugin, project, session );
- }
- catch ( PluginManagerException e )
- {
- throw new LifecycleExecutionException(
- "Internal error in the plugin manager getting report '" + plugin.getKey() + "': " + e.getMessage(), e );
- }
- catch ( PluginVersionResolutionException e )
- {
- throw new LifecycleExecutionException( e.getMessage(), e );
- }
- catch ( InvalidVersionSpecificationException e )
- {
- throw new LifecycleExecutionException( e.getMessage(), e );
- }
- catch ( InvalidPluginException e )
- {
- throw new LifecycleExecutionException( e.getMessage(), e );
- }
- catch ( ArtifactNotFoundException e )
- {
- throw new LifecycleExecutionException( e.getMessage(), e );
- }
- catch ( ArtifactResolutionException e )
- {
- throw new LifecycleExecutionException( e.getMessage(), e );
- }
- catch ( PluginVersionNotFoundException e )
- {
- throw new LifecycleExecutionException( e.getMessage(), e );
- }
- return pluginDescriptor;
- }
-
- private void bindExecutionToLifecycle( PluginDescriptor pluginDescriptor, Map phaseMap, PluginExecution execution,
- Settings settings )
- throws LifecycleExecutionException
- {
- for ( Iterator i = execution.getGoals().iterator(); i.hasNext(); )
- {
- String goal = (String) i.next();
-
- MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal );
- if ( mojoDescriptor == null )
- {
- throw new LifecycleExecutionException(
- "Goal '" + goal + "' was specified in an execution, but not found in plugin " + pluginDescriptor.getId() );
- }
-
- // We have to check to see that the inheritance rules have been applied before binding this mojo.
- if ( execution.isInheritanceApplied() || mojoDescriptor.isInheritedByDefault() )
- {
- MojoExecution mojoExecution = new MojoExecution( mojoDescriptor, execution.getId() );
-
- String phase = execution.getPhase();
-
- if ( phase == null )
- {
- // if the phase was not in the configuration, use the phase in the descriptor
- phase = mojoDescriptor.getPhase();
- }
-
- if ( phase != null )
- {
- if ( mojoDescriptor.isDirectInvocationOnly() )
- {
- throw new LifecycleExecutionException( "Mojo: \'" + goal +
- "\' requires direct invocation. It cannot be used as part of the lifecycle (it was included via the POM)." );
- }
-
- addToLifecycleMappings( phaseMap, phase, mojoExecution, settings );
- }
- }
- }
- }
-
- private void addToLifecycleMappings( Map lifecycleMappings, String phase, MojoExecution mojoExecution,
- Settings settings )
- {
- List goals = (List) lifecycleMappings.get( phase );
-
- if ( goals == null )
- {
- goals = new ArrayList();
- lifecycleMappings.put( phase, goals );
- }
-
- MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
- if ( settings.isOffline() && mojoDescriptor.isOnlineRequired() )
- {
- String goal = mojoDescriptor.getGoal();
- getLogger().warn( goal + " requires online mode, but maven is currently offline. Disabling " + goal + "." );
- }
- else
- {
- goals.add( mojoExecution );
- }
- }
-
- private List processGoalChain( String task, Map phaseMap, Lifecycle lifecycle )
- {
- List goals = new ArrayList();
-
- // only execute up to the given phase
- int index = lifecycle.getPhases().indexOf( task );
-
- for ( int i = 0; i <= index; i++ )
- {
- String p = (String) lifecycle.getPhases().get( i );
-
- List phaseGoals = (List) phaseMap.get( p );
-
- if ( phaseGoals != null )
- {
- goals.addAll( phaseGoals );
- }
- }
- return goals;
- }
-
- private MojoDescriptor getMojoDescriptor( String task, MavenSession session, MavenProject project,
- String invokedVia, boolean canUsePrefix, boolean isOptionalMojo )
- throws BuildFailureException, LifecycleExecutionException, PluginNotFoundException
- {
- String goal;
- Plugin plugin;
-
- PluginDescriptor pluginDescriptor = null;
-
- try
- {
- StringTokenizer tok = new StringTokenizer( task, ":" );
- int numTokens = tok.countTokens();
-
- if ( numTokens == 2 )
- {
- if ( !canUsePrefix )
- {
- String msg = "Mapped-prefix lookup of mojos are only supported from direct invocation. " +
- "Please use specification of the form groupId:artifactId[:version]:goal instead. " +
- "(Offending mojo: \'" + task + "\', invoked via: \'" + invokedVia + "\')";
- throw new LifecycleExecutionException( msg );
- }
-
- String prefix = tok.nextToken();
- goal = tok.nextToken();
-
- // Steps for retrieving the plugin model instance:
- // 1. request directly from the plugin collector by prefix
- pluginDescriptor = pluginManager.getPluginDescriptorForPrefix( prefix );
-
- // 2. look in the repository via search groups
- if ( pluginDescriptor == null )
- {
- plugin = pluginManager.getPluginDefinitionForPrefix( prefix, session, project );
- }
- else
- {
- plugin = new Plugin();
-
- plugin.setGroupId( pluginDescriptor.getGroupId() );
- plugin.setArtifactId( pluginDescriptor.getArtifactId() );
- plugin.setVersion( pluginDescriptor.getVersion() );
- }
-
- // 3. search plugins in the current POM
- if ( plugin == null )
- {
- for ( Iterator i = project.getBuildPlugins().iterator(); i.hasNext(); )
- {
- Plugin buildPlugin = (Plugin) i.next();
-
- PluginDescriptor desc = verifyPlugin( buildPlugin, project, session );
-
- if ( prefix.equals( desc.getGoalPrefix() ) )
- {
- plugin = buildPlugin;
- }
- }
- }
-
- // 4. default to o.a.m.plugins and maven-<prefix>-plugin
- if ( plugin == null )
- {
- plugin = new Plugin();
- plugin.setGroupId( PluginDescriptor.getDefaultPluginGroupId() );
- plugin.setArtifactId( PluginDescriptor.getDefaultPluginArtifactId( prefix ) );
- }
-
- for ( Iterator i = project.getBuildPlugins().iterator(); i.hasNext(); )
- {
- Plugin buildPlugin = (Plugin) i.next();
-
- if ( buildPlugin.getKey().equals( plugin.getKey() ) )
- {
- plugin = buildPlugin;
- break;
- }
- }
- }
- else if ( numTokens == 3 || numTokens == 4 )
- {
- plugin = new Plugin();
-
- plugin.setGroupId( tok.nextToken() );
- plugin.setArtifactId( tok.nextToken() );
-
- if ( numTokens == 4 )
- {
- plugin.setVersion( tok.nextToken() );
- }
-
- goal = tok.nextToken();
- }
- else
- {
- String message = "Invalid task '" + task + "': you must specify a valid lifecycle phase, or" +
- " a goal in the format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal";
- throw new BuildFailureException( message );
- }
-
- project.injectPluginManagementInfo( plugin );
-
- if ( pluginDescriptor == null )
- {
- pluginDescriptor = verifyPlugin( plugin, project, session );
- }
-
- // this has been simplified from the old code that injected the plugin management stuff, since
- // pluginManagement injection is now handled by the project method.
- project.addPlugin( plugin );
-
- MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal );
- if ( mojoDescriptor == null )
- {
- if ( isOptionalMojo )
- {
- getLogger().info( "Skipping missing optional mojo: " + task );
- }
- else
- {
- throw new BuildFailureException( "Required goal not found: " + task );
- }
- }
-
- return mojoDescriptor;
- }
- catch ( PluginNotFoundException e )
- {
- if ( isOptionalMojo )
- {
- getLogger().info( "Skipping missing optional mojo: " + task );
- getLogger().debug( "Mojo: " + task + " could not be found. Reason: " + e.getMessage(), e );
- }
- else
- {
- throw e;
- }
- }
-
- return null;
+ MojoBinding binding = MojoBindingUtils.parseMojoBinding( task, true );
+
+ PluginDescriptor descriptor = pluginLoader.loadPlugin( binding, project );
+ MojoDescriptor mojoDescriptor = descriptor.getMojo( binding.getGoal() );
+
+ return mojoDescriptor;
}
protected void line()
{
getLogger().info( "----------------------------------------------------------------------------" );
- }
-
- public Map getPhaseToLifecycleMap()
- throws LifecycleExecutionException
- {
- if ( phaseToLifecycleMap == null )
- {
- phaseToLifecycleMap = new HashMap();
-
- for ( Iterator i = lifecycles.iterator(); i.hasNext(); )
- {
- Lifecycle lifecycle = (Lifecycle) i.next();
-
- for ( Iterator p = lifecycle.getPhases().iterator(); p.hasNext(); )
- {
- String phase = (String) p.next();
-
- if ( phaseToLifecycleMap.containsKey( phase ) )
- {
- Lifecycle prevLifecycle = (Lifecycle) phaseToLifecycleMap.get( phase );
- throw new LifecycleExecutionException( "Phase '" + phase +
- "' is defined in more than one lifecycle: '" + lifecycle.getId() + "' and '" +
- prevLifecycle.getId() + "'" );
- }
- else
- {
- phaseToLifecycleMap.put( phase, lifecycle );
- }
- }
- }
- }
- return phaseToLifecycleMap;
}
private static class TaskSegment
Modified: maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/LegacyLifecycleMappingParser.java
URL: http://svn.apache.org/viewvc/maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/LegacyLifecycleMappingParser.java?view=diff&rev=517868&r1=517867&r2=517868
==============================================================================
--- maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/LegacyLifecycleMappingParser.java (original)
+++ maven/components/branches/2.1-lifecycle-refactor/maven-core/src/main/java/org/apache/maven/lifecycle/LegacyLifecycleMappingParser.java Tue Mar 13 14:02:48 2007
@@ -1,5 +1,6 @@
package org.apache.maven.lifecycle;
+import org.apache.maven.lifecycle.binding.LegacyLifecycle;
import org.apache.maven.lifecycle.mapping.LifecycleMapping;
import org.apache.maven.lifecycle.model.BuildBinding;
import org.apache.maven.lifecycle.model.CleanBinding;
@@ -26,7 +27,7 @@
for ( Iterator it = lifecycles.iterator(); it.hasNext(); )
{
- Lifecycle lifecycle = (Lifecycle) it.next();
+ LegacyLifecycle lifecycle = (LegacyLifecycle) it.next();
if ( "clean".equals( lifecycle.getId() ) )
{
@@ -46,7 +47,7 @@
}
}
- LifecycleUtils.setOrigin( bindings, "Maven core" );
+ LifecycleUtils.setOrigin( bindings, "Maven default lifecycle" );
return bindings;
}
@@ -61,7 +62,7 @@
bindings.setBuildBinding( parseBuildBindings( mapping.getPhases( "default" ), mapping.getOptionalMojos( "default" ) ) );
bindings.setSiteBinding( parseSiteBindings( mapping.getPhases( "site" ), mapping.getOptionalMojos( "site" ) ) );
- LifecycleUtils.setOrigin( bindings, "Maven core" );
+ LifecycleUtils.setOrigin( bindings, "Maven " + packaging + " lifecycle" );
return bindings;
}
@@ -127,7 +128,7 @@
{
String rawBinding = tok.nextToken().trim();
- MojoBinding binding = MojoBindingParser.parseMojoBinding( rawBinding, false );
+ MojoBinding binding = MojoBindingUtils.parseMojoBinding( rawBinding, false );
if ( optionalKeys.contains( rawBinding ) )
{
binding.setOptional( true );