Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Fedorenko2011-01-21 00:59:03 +0000
committerIgor Fedorenko2011-01-21 01:12:23 +0000
commit97d76db1dc790d33920b0092e4844653a8905027 (patch)
tree72d215d6f9d662aafaffb6bb0f53097e7d24e36f
parent67626923fd78267af9b3457de128fd37022462ac (diff)
downloadm2e-core-97d76db1dc790d33920b0092e4844653a8905027.tar.gz
m2e-core-97d76db1dc790d33920b0092e4844653a8905027.tar.xz
m2e-core-97d76db1dc790d33920b0092e4844653a8905027.zip
MNGECLIPSE-2724 do not resolve configuration on not interesting mojo executios
Includes patched versions of several maven core classes Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMaven.java6
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java26
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecycle/InvalidLifecycleMapping.java7
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecycle/LifecycleMappingFactory.java66
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ProjectConfigurationManager.java6
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/MavenProjectFacade.java9
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java11
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/IMavenProjectFacade.java5
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/AbstractCustomizableLifecycleMapping.java109
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/AbstractLifecycleMapping.java7
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/ILifecycleMapping.java4
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/MojoExecutionKey.java86
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/NoopLifecycleMapping.java4
-rw-r--r--org.eclipse.m2e.maven.runtime/.classpath1
-rw-r--r--org.eclipse.m2e.maven.runtime/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.m2e.maven.runtime/build.properties7
-rw-r--r--org.eclipse.m2e.maven.runtime/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java178
-rw-r--r--org.eclipse.m2e.maven.runtime/src/main/java/org/apache/maven/lifecycle/DefaultSchedules.java99
-rw-r--r--org.eclipse.m2e.maven.runtime/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java94
-rw-r--r--org.eclipse.m2e.maven.runtime/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java695
-rw-r--r--org.eclipse.m2e.maven.runtime/src/main/java/org/apache/maven/lifecycle/internal/LifecycleExecutionPlanCalculator.java67
-rw-r--r--org.eclipse.m2e.maven.runtime/src/main/java/org/apache/maven/lifecycle/internal/LifecycleTaskSegmentCalculator.java61
22 files changed, 1393 insertions, 158 deletions
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMaven.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMaven.java
index 885e7268..090b6783 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMaven.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMaven.java
@@ -114,8 +114,10 @@ public interface IMaven {
public void execute(MavenSession session, MojoExecution execution, IProgressMonitor monitor);
- public MavenExecutionPlan calculateExecutionPlan(MavenExecutionRequest request, MavenProject project,
- IProgressMonitor monitor) throws CoreException;
+ public MavenExecutionPlan calculateExecutionPlan(MavenSession session, MavenProject project, List<String> goals,
+ boolean setup, IProgressMonitor monitor) throws CoreException;
+
+ public MojoExecution setupMojoExecution(MavenSession session, MavenProject project, MojoExecution execution) throws CoreException;
public <T> T getMojoParameterValue(MavenSession session, MojoExecution mojoExecution, String parameter,
Class<T> asType) throws CoreException;
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java
index 012b2d84..7be82405 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java
@@ -72,6 +72,7 @@ import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.LifecycleExecutor;
import org.apache.maven.lifecycle.MavenExecutionPlan;
+import org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator;
import org.apache.maven.model.ConfigurationContainer;
import org.apache.maven.model.InputLocation;
import org.apache.maven.model.Model;
@@ -300,18 +301,33 @@ public class MavenImpl implements IMaven, IMavenConfigurationChangeListener {
lookup(MavenPluginManager.class).releaseMojo(mojo, mojoExecution);
}
- public MavenExecutionPlan calculateExecutionPlan(MavenExecutionRequest request, MavenProject project,
- IProgressMonitor monitor) throws CoreException {
- MavenSession session = createSession(request, project);
+ public MavenExecutionPlan calculateExecutionPlan(MavenSession session, MavenProject project, List<String> goals,
+ boolean setup, IProgressMonitor monitor) throws CoreException {
try {
- List<String> goals = request.getGoals();
- return lookup(LifecycleExecutor.class).calculateExecutionPlan(session, goals.toArray(new String[goals.size()]));
+ return lookup(LifecycleExecutor.class).calculateExecutionPlan(session, setup, goals.toArray(new String[goals.size()]));
} catch(Exception ex) {
throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1, NLS.bind(
Messages.MavenImpl_error_calc_build_plan, ex.getMessage()), ex));
}
}
+ public MojoExecution setupMojoExecution(MavenSession session, MavenProject project, MojoExecution execution) throws CoreException {
+ MojoExecution clone = new MojoExecution(execution.getPlugin(), execution.getGoal(), execution.getExecutionId());
+ clone.setMojoDescriptor(execution.getMojoDescriptor());
+ if(execution.getConfiguration() != null) {
+ clone.setConfiguration(new Xpp3Dom(execution.getConfiguration()));
+ }
+ clone.setLifecyclePhase(execution.getLifecyclePhase());
+ LifecycleExecutionPlanCalculator executionPlanCalculator = lookup(LifecycleExecutionPlanCalculator.class);
+ try {
+ executionPlanCalculator.setupMojoExecution(session, project, clone);
+ } catch(Exception ex) {
+ throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1, NLS.bind(
+ Messages.MavenImpl_error_calc_build_plan, ex.getMessage()), ex));
+ }
+ return clone;
+ }
+
public ArtifactRepository getLocalRepository() throws CoreException {
try {
String localRepositoryPath = getLocalRepositoryPath();
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecycle/InvalidLifecycleMapping.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecycle/InvalidLifecycleMapping.java
index 12bd0880..f6da2b84 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecycle/InvalidLifecycleMapping.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecycle/InvalidLifecycleMapping.java
@@ -19,6 +19,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.apache.maven.plugin.MojoExecution;
+import org.eclipse.m2e.core.internal.lifecycle.model.PluginExecutionMetadata;
import org.eclipse.m2e.core.project.configurator.AbstractBuildParticipant;
import org.eclipse.m2e.core.project.configurator.AbstractLifecycleMapping;
import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator;
@@ -77,7 +78,7 @@ public class InvalidLifecycleMapping extends AbstractLifecycleMapping {
return Collections.emptyList();
}
- public List<MojoExecution> getNotCoveredMojoExecutions(IProgressMonitor monitor) {
+ public List<MojoExecutionKey> getNotCoveredMojoExecutions(IProgressMonitor monitor) {
return Collections.emptyList();
}
@@ -89,8 +90,8 @@ public class InvalidLifecycleMapping extends AbstractLifecycleMapping {
return Collections.emptyMap();
}
- public void initializeMapping(List<MojoExecution> executionPlan, MappingMetadataSource originalMapping,
- List<MappingMetadataSource> inheritedMapping) {
+ public void initializeMapping(List<MojoExecution> mojoExecutions,
+ Map<MojoExecutionKey, List<PluginExecutionMetadata>> executionMapping) {
}
public void addMissingLifecyclePackaging(int line, String message, String packaging) {
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecycle/LifecycleMappingFactory.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecycle/LifecycleMappingFactory.java
index 2ed14bea..e7181ecd 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecycle/LifecycleMappingFactory.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecycle/LifecycleMappingFactory.java
@@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@@ -50,6 +51,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.versioning.ComparableVersion;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest;
+import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.MavenExecutionPlan;
import org.apache.maven.model.Build;
import org.apache.maven.model.BuildBase;
@@ -77,6 +79,7 @@ import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator;
import org.eclipse.m2e.core.project.configurator.ILifecycleMapping;
import org.eclipse.m2e.core.project.configurator.LifecycleMappingConfigurationException;
import org.eclipse.m2e.core.project.configurator.MojoExecutionBuildParticipant;
+import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
import org.eclipse.m2e.core.project.configurator.NoopLifecycleMapping;
@@ -231,14 +234,67 @@ public class LifecycleMappingFactory {
// PHASE 2. Bind project configurators to mojo executions.
//
- // XXX the plan is to avoid resolving execution plan and use MavenProject directly for performance and reliability reason
IMaven maven = MavenPlugin.getDefault().getMaven();
- MavenExecutionRequest request = DefaultMavenExecutionRequest.copy(templateRequest); // TODO ain't pretty
- request.setGoals(Arrays.asList("deploy"));
- MavenExecutionPlan executionPlan = maven.calculateExecutionPlan(request, mavenProject, monitor);
+ MavenSession session = maven.createSession(DefaultMavenExecutionRequest.copy(templateRequest), mavenProject);
+ List<String> goals = Arrays.asList("deploy"); //$NON-NLS-1$
+ MavenExecutionPlan executionPlan = maven.calculateExecutionPlan(session, mavenProject, goals, false, monitor);
+
+ Map<MojoExecutionKey, List<PluginExecutionMetadata>> executionMapping = new LinkedHashMap<MojoExecutionKey, List<PluginExecutionMetadata>>();
+ List<MojoExecution> mojoExecutions = new ArrayList<MojoExecution>();
+
+ for(MojoExecution execution : executionPlan.getMojoExecutions()) {
+ MojoExecutionKey executionKey = new MojoExecutionKey(execution);
+
+ PluginExecutionMetadata primaryMetadata = null;
+
+ // find primary mapping first
+ try {
+ for(MappingMetadataSource source : metadataSources) {
+ for(PluginExecutionMetadata executionMetadata : source.getPluginExecutionMetadata(execution)) {
+ if(LifecycleMappingFactory.isPrimaryMapping(executionMetadata)) {
+ if(primaryMetadata != null) {
+ primaryMetadata = null;
+ throw new DuplicateMappingException();
+ }
+ primaryMetadata = executionMetadata;
+ }
+ }
+ if(primaryMetadata != null) {
+ break;
+ }
+ }
+ } catch(DuplicateMappingException e) {
+ lifecycleMapping.addProblem(1, NLS.bind(Messages.PluginExecutionMappingDuplicate, executionKey.toString()));
+ }
+
+ List<PluginExecutionMetadata> executionMetadatas = new ArrayList<PluginExecutionMetadata>();
+ if(primaryMetadata != null) {
+ executionMetadatas.add(primaryMetadata);
+
+ // attach any secondary mapping
+ for(MappingMetadataSource source : metadataSources) {
+ List<PluginExecutionMetadata> metadatas = source.getPluginExecutionMetadata(execution);
+ if(metadatas != null) {
+ for(PluginExecutionMetadata metadata : metadatas) {
+ if(LifecycleMappingFactory.isSecondaryMapping(metadata, primaryMetadata)) {
+ executionMetadatas.add(metadata);
+ }
+ }
+ }
+ }
+
+ executionMapping.put(executionKey, executionMetadatas);
+ }
+ if(!executionMetadatas.isEmpty() && executionMetadatas.get(0).getAction() != PluginExecutionAction.ignore) {
+ mojoExecutions.add(maven.setupMojoExecution(session, mavenProject, execution));
+ } else {
+ // do not setup non-interesting/ignore mojo executions
+ mojoExecutions.add(execution);
+ }
+ }
lifecycleMapping.setMavenProjectFacade(projectFacade);
- lifecycleMapping.initializeMapping(executionPlan.getMojoExecutions(), originalMetadataSource, metadataSources);
+ lifecycleMapping.initializeMapping(mojoExecutions, executionMapping);
return lifecycleMapping;
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ProjectConfigurationManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ProjectConfigurationManager.java
index 59a2fa67..5c4c115d 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ProjectConfigurationManager.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ProjectConfigurationManager.java
@@ -60,7 +60,6 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Model;
-import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.project.MavenProject;
import org.eclipse.m2e.core.MavenPlugin;
@@ -90,6 +89,7 @@ import org.eclipse.m2e.core.project.ResolverConfiguration;
import org.eclipse.m2e.core.project.configurator.AbstractLifecycleMapping;
import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator;
import org.eclipse.m2e.core.project.configurator.ILifecycleMapping;
+import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
import org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest;
import org.eclipse.m2e.core.util.Util;
@@ -360,9 +360,9 @@ public class ProjectConfigurationManager implements IProjectConfigurationManager
return false;
}
- List<MojoExecution> notCoveredMojoExecutions = lifecycleMapping.getNotCoveredMojoExecutions(monitor);
+ List<MojoExecutionKey> notCoveredMojoExecutions = lifecycleMapping.getNotCoveredMojoExecutions(monitor);
if(notCoveredMojoExecutions != null && notCoveredMojoExecutions.size() != 0) {
- for(MojoExecution mojoExecution : notCoveredMojoExecutions) {
+ for(MojoExecutionKey mojoExecution : notCoveredMojoExecutions) {
IMarker marker = mavenMarkerManager.addMarker(
mavenProjectFacade.getPom(),
IMavenConstants.MARKER_CONFIGURATION_ID,
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/MavenProjectFacade.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/MavenProjectFacade.java
index 19b9fbab..69f1ac36 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/MavenProjectFacade.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/MavenProjectFacade.java
@@ -31,7 +31,6 @@ import org.eclipse.core.runtime.Status;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenExecutionResult;
-import org.apache.maven.lifecycle.MavenExecutionPlan;
import org.apache.maven.project.MavenProject;
import org.eclipse.m2e.core.MavenPlugin;
@@ -59,7 +58,6 @@ public class MavenProjectFacade implements IMavenProjectFacade, Serializable {
private final File pomFile;
private transient MavenProject mavenProject;
- private transient MavenExecutionPlan executionPlan;
private transient Map<String, Object> sessionProperties;
@@ -206,13 +204,6 @@ public class MavenProjectFacade implements IMavenProjectFacade, Serializable {
return mavenProject;
}
- public synchronized MavenExecutionPlan getExecutionPlan(IProgressMonitor monitor) throws CoreException {
- if (executionPlan == null) {
- executionPlan = manager.calculateExecutionPlan(this, monitor);
- }
- return executionPlan;
- }
-
public String getPackaging() {
return packaging;
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java
index ef9fe68e..c5da8d6c 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java
@@ -51,7 +51,6 @@ import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.DefaultMavenExecutionResult;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
-import org.apache.maven.lifecycle.MavenExecutionPlan;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.project.MavenProject;
@@ -581,16 +580,6 @@ public class ProjectRegistryManager {
return lifecycleMapping;
}
- MavenExecutionPlan calculateExecutionPlan(MavenProjectFacade facade, IProgressMonitor monitor) throws CoreException {
- return calculateExecutionPlan(projectRegistry, facade, monitor);
- }
-
- private MavenExecutionPlan calculateExecutionPlan(IProjectRegistry state, MavenProjectFacade facade, IProgressMonitor monitor) throws CoreException {
- MavenExecutionRequest request = createExecutionRequest(state, facade.getPom(), facade.getResolverConfiguration(), monitor);
- request.setGoals(Arrays.asList("deploy")); //$NON-NLS-1$
- return getMaven().calculateExecutionPlan(request, facade.getMavenProject(monitor), monitor);
- }
-
public IFile getModulePom(IFile pom, String moduleName) {
return pom.getParent().getFile(new Path(moduleName).append(IMavenConstants.POM_FILE_NAME));
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/IMavenProjectFacade.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/IMavenProjectFacade.java
index 944e9243..67468c7a 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/IMavenProjectFacade.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/IMavenProjectFacade.java
@@ -86,11 +86,6 @@ public interface IMavenProjectFacade {
*/
MavenProject getMavenProject();
- /**
- * Lazy load and cache build execution plan
- */
- MavenExecutionPlan getExecutionPlan(IProgressMonitor monitor) throws CoreException;
-
String getPackaging();
IProject getProject();
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/AbstractCustomizableLifecycleMapping.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/AbstractCustomizableLifecycleMapping.java
index 5397084e..ad9ac268 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/AbstractCustomizableLifecycleMapping.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/AbstractCustomizableLifecycleMapping.java
@@ -16,17 +16,13 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.osgi.util.NLS;
-import org.apache.maven.lifecycle.MavenExecutionPlan;
import org.apache.maven.plugin.MojoExecution;
import org.eclipse.m2e.core.internal.Messages;
-import org.eclipse.m2e.core.internal.lifecycle.DuplicateMappingException;
import org.eclipse.m2e.core.internal.lifecycle.LifecycleMappingFactory;
-import org.eclipse.m2e.core.internal.lifecycle.MappingMetadataSource;
import org.eclipse.m2e.core.internal.lifecycle.model.PluginExecutionAction;
import org.eclipse.m2e.core.internal.lifecycle.model.PluginExecutionMetadata;
@@ -42,12 +38,19 @@ public abstract class AbstractCustomizableLifecycleMapping extends AbstractLifec
private Map<String, AbstractProjectConfigurator> configurators;
+ private List<MojoExecution> executionPlan;
+
+ private List<MojoExecutionKey> notCoveredExecutions;
+
@Override
- public void initializeMapping(List<MojoExecution> executionPlan, MappingMetadataSource originalMapping,
- List<MappingMetadataSource> inheritedMapping) {
+ public void initializeMapping(List<MojoExecution> mojoExecutions,
+ Map<MojoExecutionKey, List<PluginExecutionMetadata>> executionMapping) {
+
+ this.effectiveMapping = executionMapping;
- this.effectiveMapping = getEffectiveMapping(executionPlan, originalMapping, inheritedMapping);
+ this.executionPlan = mojoExecutions;
+ // instantiate configurator
this.configurators = new LinkedHashMap<String, AbstractProjectConfigurator>();
for(List<PluginExecutionMetadata> executionMetadatas : effectiveMapping.values()) {
for(PluginExecutionMetadata executionMetadata : executionMetadatas) {
@@ -63,64 +66,37 @@ public abstract class AbstractCustomizableLifecycleMapping extends AbstractLifec
}
}
}
- }
- protected Map<MojoExecutionKey, List<PluginExecutionMetadata>> getEffectiveMapping(List<MojoExecution> executionPlan,
- MappingMetadataSource originalMapping, List<MappingMetadataSource> inheritedMapping) {
- Map<MojoExecutionKey, List<PluginExecutionMetadata>> executionMapping = new LinkedHashMap<MojoExecutionKey, List<PluginExecutionMetadata>>();
-
- for(MojoExecution execution : executionPlan) {
- PluginExecutionMetadata primaryMetadata = null;
-
- // find primary mapping first
- try {
- for(MappingMetadataSource source : inheritedMapping) {
- for(PluginExecutionMetadata executionMetadata : source.getPluginExecutionMetadata(execution)) {
- if(LifecycleMappingFactory.isPrimaryMapping(executionMetadata)) {
- if(primaryMetadata != null) {
- primaryMetadata = null;
- throw new DuplicateMappingException();
- }
- primaryMetadata = executionMetadata;
- }
- }
- if(primaryMetadata != null) {
- break;
- }
- }
- } catch(DuplicateMappingException e) {
- addProblem(1, NLS.bind(Messages.PluginExecutionMappingDuplicate, execution.toString()));
+ // find and cache not-covered mojo execution keys
+ notCoveredExecutions = new ArrayList<MojoExecutionKey>();
+ all_mojo_executions: for(MojoExecution mojoExecution : executionPlan) {
+ if(!isInterestingPhase(mojoExecution.getLifecyclePhase())) {
+ continue;
}
-
- if(primaryMetadata != null) {
- List<PluginExecutionMetadata> executionMetadatas = new ArrayList<PluginExecutionMetadata>();
- executionMetadatas.add(primaryMetadata);
-
- // attach any secondary mapping
- for(MappingMetadataSource source : inheritedMapping) {
- List<PluginExecutionMetadata> metadatas = source.getPluginExecutionMetadata(execution);
- if(metadatas != null) {
- for(PluginExecutionMetadata metadata : metadatas) {
- if(LifecycleMappingFactory.isSecondaryMapping(metadata, primaryMetadata)) {
- executionMetadatas.add(metadata);
+ MojoExecutionKey executionKey = new MojoExecutionKey(mojoExecution);
+ List<PluginExecutionMetadata> executionMetadatas = effectiveMapping.get(executionKey);
+ if(executionMetadatas != null) {
+ for(PluginExecutionMetadata executionMetadata : executionMetadatas) {
+ switch(executionMetadata.getAction()) {
+ case ignore:
+ case execute:
+ continue all_mojo_executions;
+ case configurator:
+ if(configurators.containsKey(LifecycleMappingFactory.getProjectConfiguratorId(executionMetadata))) {
+ continue all_mojo_executions;
}
- }
}
}
-
- executionMapping.put(new MojoExecutionKey(execution), executionMetadatas);
}
+ notCoveredExecutions.add(executionKey);
}
- return executionMapping;
}
- public Map<MojoExecutionKey, List<AbstractBuildParticipant>> getBuildParticipants(IProgressMonitor monitor)
- throws CoreException {
+ public Map<MojoExecutionKey, List<AbstractBuildParticipant>> getBuildParticipants(IProgressMonitor monitor) {
Map<MojoExecutionKey, List<AbstractBuildParticipant>> result = new LinkedHashMap<MojoExecutionKey, List<AbstractBuildParticipant>>();
- MavenExecutionPlan executionPlan = getMavenProjectFacade().getExecutionPlan(monitor);
- for(MojoExecution mojoExecution : executionPlan.getMojoExecutions()) {
+ for(MojoExecution mojoExecution : executionPlan) {
MojoExecutionKey executionKey = new MojoExecutionKey(mojoExecution);
List<AbstractBuildParticipant> executionMappings = new ArrayList<AbstractBuildParticipant>();
List<PluginExecutionMetadata> executionMetadatas = effectiveMapping.get(executionKey);
@@ -155,30 +131,7 @@ public abstract class AbstractCustomizableLifecycleMapping extends AbstractLifec
return new ArrayList<AbstractProjectConfigurator>(configurators.values());
}
- public List<MojoExecution> getNotCoveredMojoExecutions(IProgressMonitor monitor) throws CoreException {
- List<MojoExecution> result = new ArrayList<MojoExecution>();
-
- MavenExecutionPlan executionPlan = getMavenProjectFacade().getExecutionPlan(monitor);
- all_mojo_executions: for(MojoExecution mojoExecution : executionPlan.getMojoExecutions()) {
- if(!isInterestingPhase(mojoExecution.getLifecyclePhase())) {
- continue;
- }
- List<PluginExecutionMetadata> executionMetadatas = effectiveMapping.get(new MojoExecutionKey(mojoExecution));
- if(executionMetadatas != null) {
- for(PluginExecutionMetadata executionMetadata : executionMetadatas) {
- switch(executionMetadata.getAction()) {
- case ignore:
- case execute:
- continue all_mojo_executions;
- case configurator:
- if(configurators.containsKey(LifecycleMappingFactory.getProjectConfiguratorId(executionMetadata))) {
- continue all_mojo_executions;
- }
- }
- }
- }
- result.add(mojoExecution);
- }
- return result;
+ public List<MojoExecutionKey> getNotCoveredMojoExecutions(IProgressMonitor monitor) {
+ return notCoveredExecutions;
}
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/AbstractLifecycleMapping.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/AbstractLifecycleMapping.java
index 5a40f7fc..fb721d99 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/AbstractLifecycleMapping.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/AbstractLifecycleMapping.java
@@ -13,6 +13,7 @@ package org.eclipse.m2e.core.project.configurator;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IProject;
@@ -24,7 +25,7 @@ import org.eclipse.core.runtime.OperationCanceledException;
import org.apache.maven.plugin.MojoExecution;
import org.eclipse.m2e.core.core.IMavenConstants;
-import org.eclipse.m2e.core.internal.lifecycle.MappingMetadataSource;
+import org.eclipse.m2e.core.internal.lifecycle.model.PluginExecutionMetadata;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
@@ -219,7 +220,7 @@ public abstract class AbstractLifecycleMapping implements ILifecycleMapping {
this.mavenProjectFacade = projectFacade;
}
- public abstract void initializeMapping(List<MojoExecution> executionPlan, MappingMetadataSource originalMapping,
- List<MappingMetadataSource> inheritedMapping);
+ public abstract void initializeMapping(List<MojoExecution> mojoExecutions,
+ Map<MojoExecutionKey, List<PluginExecutionMetadata>> executionMapping);
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/ILifecycleMapping.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/ILifecycleMapping.java
index c4f2f91e..b3404e19 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/ILifecycleMapping.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/ILifecycleMapping.java
@@ -17,8 +17,6 @@ import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.apache.maven.plugin.MojoExecution;
-
/**
* LifecycleMapping
*
@@ -50,7 +48,7 @@ public interface ILifecycleMapping {
//TODO Return Set instead of List
List<AbstractProjectConfigurator> getProjectConfigurators(IProgressMonitor monitor) throws CoreException;
- List<MojoExecution> getNotCoveredMojoExecutions(IProgressMonitor monitor)
+ List<MojoExecutionKey> getNotCoveredMojoExecutions(IProgressMonitor monitor)
throws CoreException;
boolean isInterestingPhase(String phase);
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/MojoExecutionKey.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/MojoExecutionKey.java
index 2be4d631..b89f42da 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/MojoExecutionKey.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/MojoExecutionKey.java
@@ -8,30 +8,42 @@
* Contributors:
* Sonatype, Inc. - initial API and implementation
*******************************************************************************/
+
package org.eclipse.m2e.core.project.configurator;
import org.apache.maven.plugin.MojoExecution;
public class MojoExecutionKey {
- private final MojoExecution mojoExecution;
- public MojoExecutionKey(MojoExecution mojoExecution) {
- this.mojoExecution = mojoExecution;
- }
+ private final String groupId;
+
+ private final String artifactId;
+
+ private final String version;
+
+ private final String goal;
+
+ private final String executionId;
- public MojoExecution getMojoExecution() {
- return mojoExecution;
+ private final String lifecyclePhase;
+
+ public MojoExecutionKey(MojoExecution mojoExecution) {
+ this.groupId = mojoExecution.getGroupId();
+ this.artifactId = mojoExecution.getArtifactId();
+ this.version = mojoExecution.getVersion();
+ this.goal = mojoExecution.getGoal();
+ this.executionId = mojoExecution.getExecutionId();
+ this.lifecyclePhase = mojoExecution.getLifecyclePhase();
}
public int hashCode() {
- int hash = mojoExecution.getGroupId().hashCode();
- hash = 17 * hash + mojoExecution.getArtifactId().hashCode();
- hash = 17 * hash + mojoExecution.getVersion().hashCode();
- hash = 17 * mojoExecution.getGoal().hashCode();
- if(mojoExecution.getExecutionId() != null) {
- hash = 17 * mojoExecution.getExecutionId().hashCode();
- }
+ int hash = groupId.hashCode();
+ hash = 17 * hash + artifactId.hashCode();
+ hash = 17 * hash + version.hashCode();
+ hash = 17 * goal.hashCode();
+ hash = 17 * executionId.hashCode();
+ hash = 17 * lifecyclePhase.hashCode();
return hash;
}
@@ -45,22 +57,44 @@ public class MojoExecutionKey {
MojoExecutionKey other = (MojoExecutionKey) obj;
- boolean equals = mojoExecution.getGroupId().equals(other.mojoExecution.getGroupId())
- && mojoExecution.getArtifactId().equals(other.mojoExecution.getArtifactId())
- && mojoExecution.getVersion().equals(other.mojoExecution.getVersion())
- && mojoExecution.getGoal().equals(other.mojoExecution.getGoal());
- if(!equals) {
- return false;
- }
+ return groupId.equals(other.groupId) && artifactId.equals(other.artifactId) && version.equals(other.version)
+ && goal.equals(other.goal) && executionId.equals(other.executionId)
+ && lifecyclePhase.equals(other.lifecyclePhase);
+ }
- if(mojoExecution.getExecutionId() == null) {
- return other.mojoExecution.getExecutionId() == null;
- }
- return mojoExecution.getExecutionId().equals(other.mojoExecution.getExecutionId());
+ public String getGroupId() {
+ return this.groupId;
+ }
+
+ public String getArtifactId() {
+ return this.artifactId;
+ }
+
+ public String getVersion() {
+ return this.version;
+ }
+
+ public String getGoal() {
+ return this.goal;
+ }
+
+ public String getExecutionId() {
+ return this.executionId;
+ }
+
+ public String getLifecyclePhase() {
+ return lifecyclePhase;
}
public String getKeyString() {
- return mojoExecution.getGroupId() + ":" + mojoExecution.getArtifactId() + ":" + mojoExecution.getVersion() + ":"
- + mojoExecution.getGoal() + ":" + mojoExecution.getExecutionId();
+ return groupId + ":" + artifactId + ":" + version + ":" + goal + ":" + executionId + ":" + lifecyclePhase;
+ }
+
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(groupId).append(":").append(artifactId).append(":").append(version);
+ sb.append(":").append(goal);
+ sb.append(" {execution: ").append(executionId).append("}");
+ return sb.toString();
}
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/NoopLifecycleMapping.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/NoopLifecycleMapping.java
index fd696f9e..d87e059a 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/NoopLifecycleMapping.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/NoopLifecycleMapping.java
@@ -17,8 +17,6 @@ import java.util.Map;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.apache.maven.plugin.MojoExecution;
-
/**
* NoopLifecycleMapping
@@ -45,7 +43,7 @@ public class NoopLifecycleMapping implements ILifecycleMapping {
return Collections.emptyList();
}
- public List<MojoExecution> getNotCoveredMojoExecutions(IProgressMonitor monitor) {
+ public List<MojoExecutionKey> getNotCoveredMojoExecutions(IProgressMonitor monitor) {
return Collections.emptyList();
}
diff --git a/org.eclipse.m2e.maven.runtime/.classpath b/org.eclipse.m2e.maven.runtime/.classpath
index 55d9e06a..38d6319a 100644
--- a/org.eclipse.m2e.maven.runtime/.classpath
+++ b/org.eclipse.m2e.maven.runtime/.classpath
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
+ <classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry exported="true" kind="lib" path="jars/maven-embedder-3.0.jar"/>
diff --git a/org.eclipse.m2e.maven.runtime/META-INF/MANIFEST.MF b/org.eclipse.m2e.maven.runtime/META-INF/MANIFEST.MF
index 7dd3c089..f37b4938 100644
--- a/org.eclipse.m2e.maven.runtime/META-INF/MANIFEST.MF
+++ b/org.eclipse.m2e.maven.runtime/META-INF/MANIFEST.MF
@@ -185,7 +185,8 @@ Export-Package: META-INF.plexus,
org.sonatype.plexus.components.sec.dispatcher.model,
org.sonatype.plexus.components.sec.dispatcher.model.io.xpp3
Bundle-Vendor: Sonatype
-Bundle-ClassPath: jars/maven-embedder-3.0.jar,
+Bundle-ClassPath: local-patches.jar,
+ jars/maven-embedder-3.0.jar,
jars/maven-settings-3.0.jar,
jars/maven-plugin-api-3.0.jar,
jars/maven-model-builder-3.0.jar,
diff --git a/org.eclipse.m2e.maven.runtime/build.properties b/org.eclipse.m2e.maven.runtime/build.properties
index c41c5b4e..f10d8cb0 100644
--- a/org.eclipse.m2e.maven.runtime/build.properties
+++ b/org.eclipse.m2e.maven.runtime/build.properties
@@ -10,4 +10,9 @@
#
bin.includes = META-INF/,\
- jars/
+ jars/,\
+ local-patches.jar
+jars.compile.order = local-patches.jar
+source.local-patches.jar = src/main/java/
+output.local-patches.jar = target/classes
+source.local-patches.jar = src/main/java/
diff --git a/org.eclipse.m2e.maven.runtime/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java b/org.eclipse.m2e.maven.runtime/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
new file mode 100644
index 00000000..a719a0c7
--- /dev/null
+++ b/org.eclipse.m2e.maven.runtime/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
@@ -0,0 +1,178 @@
+package org.apache.maven.lifecycle;
+
+/*
+ * 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 org.apache.maven.execution.MavenSession;
+import org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator;
+import org.apache.maven.lifecycle.internal.LifecycleStarter;
+import org.apache.maven.lifecycle.internal.LifecycleTaskSegmentCalculator;
+import org.apache.maven.lifecycle.internal.MojoDescriptorCreator;
+import org.apache.maven.lifecycle.internal.MojoExecutor;
+import org.apache.maven.lifecycle.internal.ProjectIndex;
+import org.apache.maven.lifecycle.internal.TaskSegment;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.plugin.InvalidPluginDescriptorException;
+import org.apache.maven.plugin.MojoExecution;
+import org.apache.maven.plugin.MojoNotFoundException;
+import org.apache.maven.plugin.PluginDescriptorParsingException;
+import org.apache.maven.plugin.PluginManagerException;
+import org.apache.maven.plugin.PluginNotFoundException;
+import org.apache.maven.plugin.PluginResolutionException;
+import org.apache.maven.plugin.descriptor.MojoDescriptor;
+import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
+import org.apache.maven.plugin.version.PluginVersionResolutionException;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Requirement;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A facade that provides lifecycle services to components outside maven core.
+ *
+ * Note that this component is not normally used from within core itself.
+ *
+ * @author Jason van Zyl
+ * @author Benjamin Bentmann
+ * @author Kristian Rosenvold
+ */
+@Component( role = LifecycleExecutor.class )
+public class DefaultLifecycleExecutor
+ implements LifecycleExecutor
+{
+
+ @Requirement
+ private LifeCyclePluginAnalyzer lifeCyclePluginAnalyzer;
+
+ @Requirement
+ private DefaultLifecycles defaultLifeCycles;
+
+ @Requirement
+ private LifecycleTaskSegmentCalculator lifecycleTaskSegmentCalculator;
+
+ @Requirement
+ private LifecycleExecutionPlanCalculator lifecycleExecutionPlanCalculator;
+
+ @Requirement
+ private MojoExecutor mojoExecutor;
+
+ @Requirement
+ private LifecycleStarter lifecycleStarter;
+
+
+ public void execute( MavenSession session )
+ {
+ lifecycleStarter.execute( session );
+ }
+
+ @Requirement
+ private MojoDescriptorCreator mojoDescriptorCreator;
+
+ // These methods deal with construction intact Plugin object that look like they come from a standard
+ // <plugin/> block in a Maven POM. We have to do some wiggling to pull the sources of information
+ // together and this really shows the problem of constructing a sensible default configuration but
+ // it's all encapsulated here so it appears normalized to the POM builder.
+
+ // We are going to take the project packaging and find all plugin in the default lifecycle and create
+ // fully populated Plugin objects, including executions with goals and default configuration taken
+ // from the plugin.xml inside a plugin.
+ //
+ // TODO: This whole method could probably removed by injecting lifeCyclePluginAnalyzer straight into client site.
+ // TODO: But for some reason the whole plexus appcontext refuses to start when I try this.
+
+ public Set<Plugin> getPluginsBoundByDefaultToAllLifecycles( String packaging )
+ {
+ return lifeCyclePluginAnalyzer.getPluginsBoundByDefaultToAllLifecycles( packaging );
+ }
+
+ // USED BY MAVEN HELP PLUGIN
+
+ @SuppressWarnings( { "UnusedDeclaration" } )
+ @Deprecated
+ public Map<String, Lifecycle> getPhaseToLifecycleMap()
+ {
+ return defaultLifeCycles.getPhaseToLifecycleMap();
+ }
+
+ // NOTE: Backward-compat with maven-help-plugin:2.1
+
+ @SuppressWarnings( { "UnusedDeclaration" } )
+ MojoDescriptor getMojoDescriptor( String task, MavenSession session, MavenProject project, String invokedVia,
+ boolean canUsePrefix, boolean isOptionalMojo )
+ throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
+ MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
+ PluginVersionResolutionException
+ {
+ return mojoDescriptorCreator.getMojoDescriptor( task, session, project );
+ }
+
+ // Used by m2eclipse
+
+ @SuppressWarnings( { "UnusedDeclaration" } )
+ public MavenExecutionPlan calculateExecutionPlan( MavenSession session, boolean setup, String... tasks )
+ throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
+ MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
+ PluginManagerException, LifecyclePhaseNotFoundException, LifecycleNotFoundException,
+ PluginVersionResolutionException
+ {
+ List<TaskSegment> taskSegments =
+ lifecycleTaskSegmentCalculator.calculateTaskSegments( session, Arrays.asList( tasks ) );
+
+ TaskSegment mergedSegment = new TaskSegment( false );
+
+ for ( TaskSegment taskSegment : taskSegments )
+ {
+ mergedSegment.getTasks().addAll( taskSegment.getTasks() );
+ }
+
+ return lifecycleExecutionPlanCalculator.calculateExecutionPlan( session, session.getCurrentProject(),
+ mergedSegment.getTasks(), setup );
+ }
+
+ public MavenExecutionPlan calculateExecutionPlan( MavenSession session, String... tasks )
+ throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
+ MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
+ PluginManagerException, LifecyclePhaseNotFoundException, LifecycleNotFoundException,
+ PluginVersionResolutionException
+ {
+ return calculateExecutionPlan( session, true, tasks );
+ }
+
+ // Site 3.x
+ public void calculateForkedExecutions( MojoExecution mojoExecution, MavenSession session )
+ throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
+ PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
+ LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
+ {
+ lifecycleExecutionPlanCalculator.calculateForkedExecutions( mojoExecution, session );
+ }
+
+
+ // Site 3.x
+ public List<MavenProject> executeForkedExecutions( MojoExecution mojoExecution, MavenSession session )
+ throws LifecycleExecutionException
+ {
+ return mojoExecutor.executeForkedExecutions( mojoExecution, session, new ProjectIndex( session.getProjects() ) );
+ }
+
+}
diff --git a/org.eclipse.m2e.maven.runtime/src/main/java/org/apache/maven/lifecycle/DefaultSchedules.java b/org.eclipse.m2e.maven.runtime/src/main/java/org/apache/maven/lifecycle/DefaultSchedules.java
new file mode 100644
index 00000000..4c1fe571
--- /dev/null
+++ b/org.eclipse.m2e.maven.runtime/src/main/java/org/apache/maven/lifecycle/DefaultSchedules.java
@@ -0,0 +1,99 @@
+package org.apache.maven.lifecycle;
+
+/*
+ * 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 org.apache.maven.lifecycle.internal.BuilderCommon;
+import org.apache.maven.lifecycle.internal.ExecutionPlanItem;
+import org.apache.maven.plugin.MojoExecution;
+import org.apache.maven.project.MavenProject;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Defines scheduling information needed by weave mode.
+ *
+ * @since 3.0
+ * @author Kristian Rosenvold
+ */
+public class DefaultSchedules
+{
+ List<Scheduling> schedules;
+
+ @SuppressWarnings( { "UnusedDeclaration" } )
+ public DefaultSchedules()
+ {
+ }
+
+ public DefaultSchedules( List<Scheduling> schedules )
+ {
+ this.schedules = schedules;
+ }
+
+ public List<ExecutionPlanItem> createExecutionPlanItem( MavenProject mavenProject, List<MojoExecution> executions )
+ {
+ BuilderCommon.attachToThread( mavenProject );
+
+ List<ExecutionPlanItem> result = new ArrayList<ExecutionPlanItem>();
+ for ( MojoExecution mojoExecution : executions )
+ {
+ String lifeCyclePhase = mojoExecution.getLifecyclePhase();
+ final Scheduling scheduling = getScheduling( "default" );
+ Schedule schedule = null;
+ if ( scheduling != null )
+ {
+ schedule = scheduling.getSchedule( mojoExecution );
+ if ( schedule == null )
+ {
+ schedule = scheduling.getSchedule( lifeCyclePhase );
+ }
+ }
+ result.add( new ExecutionPlanItem( mojoExecution, schedule ) );
+
+ }
+ return result;
+ }
+
+ /**
+ * Gets scheduling associated with a given phase.
+ * <p/>
+ * This is part of the experimental weave mode and therefore not part of the public api.
+ *
+ * @param lifecyclePhaseName The name of the lifecycle phase
+ * @return Schecduling information related to phase
+ */
+
+ Scheduling getScheduling( String lifecyclePhaseName )
+ {
+ for ( Scheduling schedule : schedules )
+ {
+ if ( lifecyclePhaseName.equals( schedule.getLifecycle() ) )
+ {
+ return schedule;
+ }
+ }
+ return null;
+ }
+
+ public List<Scheduling> getSchedules()
+ {
+ return schedules;
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.m2e.maven.runtime/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java b/org.eclipse.m2e.maven.runtime/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java
new file mode 100644
index 00000000..37b6e499
--- /dev/null
+++ b/org.eclipse.m2e.maven.runtime/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java
@@ -0,0 +1,94 @@
+package org.apache.maven.lifecycle;
+
+/*
+ * 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 org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.plugin.InvalidPluginDescriptorException;
+import org.apache.maven.plugin.MojoExecution;
+import org.apache.maven.plugin.MojoNotFoundException;
+import org.apache.maven.plugin.PluginDescriptorParsingException;
+import org.apache.maven.plugin.PluginManagerException;
+import org.apache.maven.plugin.PluginNotFoundException;
+import org.apache.maven.plugin.PluginResolutionException;
+import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
+import org.apache.maven.plugin.version.PluginVersionResolutionException;
+import org.apache.maven.project.MavenProject;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * A facade that provides lifecycle services to components outside maven core.
+ *
+ *
+ * @author Jason van Zyl
+ */
+@SuppressWarnings( { "UnusedDeclaration" } )
+public interface LifecycleExecutor
+{
+
+ // USED BY MAVEN HELP PLUGIN
+ @Deprecated
+ String ROLE = LifecycleExecutor.class.getName();
+
+ // For a given project packaging find all the plugins that are bound to any registered
+ // lifecycles. The project builder needs to now what default plugin information needs to be
+ // merged into POM being built. Once the POM builder has this plugin information, versions can be assigned
+ // by the POM builder because they will have to be defined in plugin management. Once this is setComplete then it
+ // can be passed back so that the default configuraiton information can be populated.
+ //
+ // We need to know the specific version so that we can lookup the right version of the plugin descriptor
+ // which tells us what the default configuration is.
+ //
+
+ /**
+ * @return The plugins bound to the lifecycles of the specified packaging or {@code null} if the packaging is
+ * unknown.
+ */
+ Set<Plugin> getPluginsBoundByDefaultToAllLifecycles( String packaging );
+
+ MavenExecutionPlan calculateExecutionPlan( MavenSession session, String... tasks )
+ throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
+ MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
+ PluginManagerException, LifecyclePhaseNotFoundException, LifecycleNotFoundException,
+ PluginVersionResolutionException;
+
+ MavenExecutionPlan calculateExecutionPlan( MavenSession session, boolean setup, String... tasks )
+ throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
+ MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
+ PluginManagerException, LifecyclePhaseNotFoundException, LifecycleNotFoundException,
+ PluginVersionResolutionException;
+
+ void execute( MavenSession session );
+
+ // used by the site plugin 3.x
+ void calculateForkedExecutions( MojoExecution mojoExecution, MavenSession session )
+ throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
+ PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
+ LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException;
+
+
+ // used by the site plugin 3.x
+ List<MavenProject> executeForkedExecutions( MojoExecution mojoExecution, MavenSession session )
+ throws LifecycleExecutionException;
+
+
+}
diff --git a/org.eclipse.m2e.maven.runtime/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java b/org.eclipse.m2e.maven.runtime/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java
new file mode 100644
index 00000000..b28e6c01
--- /dev/null
+++ b/org.eclipse.m2e.maven.runtime/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java
@@ -0,0 +1,695 @@
+/*
+ * 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.
+ */
+package org.apache.maven.lifecycle.internal;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.lifecycle.DefaultLifecycles;
+import org.apache.maven.lifecycle.DefaultSchedules;
+import org.apache.maven.lifecycle.Lifecycle;
+import org.apache.maven.lifecycle.LifecycleNotFoundException;
+import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException;
+import org.apache.maven.lifecycle.MavenExecutionPlan;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.model.PluginExecution;
+import org.apache.maven.plugin.BuildPluginManager;
+import org.apache.maven.plugin.InvalidPluginDescriptorException;
+import org.apache.maven.plugin.MojoExecution;
+import org.apache.maven.plugin.MojoNotFoundException;
+import org.apache.maven.plugin.PluginDescriptorParsingException;
+import org.apache.maven.plugin.PluginNotFoundException;
+import org.apache.maven.plugin.PluginResolutionException;
+import org.apache.maven.plugin.descriptor.MojoDescriptor;
+import org.apache.maven.plugin.descriptor.Parameter;
+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.prefix.NoPluginFoundForPrefixException;
+import org.apache.maven.plugin.version.PluginVersionResolutionException;
+import org.apache.maven.plugin.version.PluginVersionResolver;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Requirement;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+/**
+ * @since 3.0
+ * @author Benjamin Bentmann
+ * @author Kristian Rosenvold (Extract class)
+ * <p/>
+ * NOTE: This class is not part of any public api and can be changed or deleted without prior notice.
+ */
+@Component( role = LifecycleExecutionPlanCalculator.class )
+public class DefaultLifecycleExecutionPlanCalculator
+ implements LifecycleExecutionPlanCalculator
+{
+ @Requirement
+ private PluginVersionResolver pluginVersionResolver;
+
+ @Requirement
+ private BuildPluginManager pluginManager;
+
+ @Requirement
+ private DefaultLifecycles defaultLifeCycles;
+
+ @Requirement
+ private DefaultSchedules defaultSchedules;
+
+ @Requirement
+ private MojoDescriptorCreator mojoDescriptorCreator;
+
+ @Requirement
+ private LifecyclePluginResolver lifecyclePluginResolver;
+
+ @SuppressWarnings( { "UnusedDeclaration" } )
+ public DefaultLifecycleExecutionPlanCalculator()
+ {
+ }
+
+ public DefaultLifecycleExecutionPlanCalculator( BuildPluginManager pluginManager,
+ DefaultLifecycles defaultLifeCycles,
+ MojoDescriptorCreator mojoDescriptorCreator,
+ LifecyclePluginResolver lifecyclePluginResolver,
+ DefaultSchedules defaultSchedules )
+ {
+ this.pluginManager = pluginManager;
+ this.defaultLifeCycles = defaultLifeCycles;
+ this.mojoDescriptorCreator = mojoDescriptorCreator;
+ this.lifecyclePluginResolver = lifecyclePluginResolver;
+ this.defaultSchedules = defaultSchedules;
+ }
+
+ public MavenExecutionPlan calculateExecutionPlan( MavenSession session, MavenProject project, List<Object> tasks, boolean setup )
+ throws PluginNotFoundException, PluginResolutionException, LifecyclePhaseNotFoundException,
+ PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException,
+ NoPluginFoundForPrefixException, LifecycleNotFoundException, PluginVersionResolutionException
+ {
+ lifecyclePluginResolver.resolveMissingPluginVersions( project, session );
+
+ final List<MojoExecution> executions = calculateMojoExecutions( session, project, tasks );
+
+ if ( setup )
+ {
+ setupMojoExecutions( session, project, executions );
+ }
+
+ final List<ExecutionPlanItem> planItem = defaultSchedules.createExecutionPlanItem( project, executions );
+
+ return new MavenExecutionPlan( planItem, defaultLifeCycles );
+ }
+
+ public MavenExecutionPlan calculateExecutionPlan( MavenSession session, MavenProject project, List<Object> tasks )
+ throws PluginNotFoundException, PluginResolutionException, LifecyclePhaseNotFoundException,
+ PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException,
+ NoPluginFoundForPrefixException, LifecycleNotFoundException, PluginVersionResolutionException
+ {
+ return calculateExecutionPlan( session, project, tasks, true );
+ }
+
+ private void setupMojoExecutions( MavenSession session, MavenProject project, List<MojoExecution> mojoExecutions )
+ throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
+ MojoNotFoundException, InvalidPluginDescriptorException, NoPluginFoundForPrefixException,
+ LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
+ {
+ for ( MojoExecution mojoExecution : mojoExecutions )
+ {
+ setupMojoExecution( session, project, mojoExecution );
+ }
+ }
+
+ public void setupMojoExecution( MavenSession session, MavenProject project, MojoExecution mojoExecution )
+ throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
+ MojoNotFoundException, InvalidPluginDescriptorException, NoPluginFoundForPrefixException,
+ LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
+ {
+ MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
+
+ if ( mojoDescriptor == null )
+ {
+ mojoDescriptor =
+ pluginManager.getMojoDescriptor( mojoExecution.getPlugin(), mojoExecution.getGoal(),
+ project.getRemotePluginRepositories(),
+ session.getRepositorySession() );
+
+ mojoExecution.setMojoDescriptor( mojoDescriptor );
+ }
+
+ populateMojoExecutionConfiguration( project, mojoExecution,
+ MojoExecution.Source.CLI.equals( mojoExecution.getSource() ) );
+
+ finalizeMojoConfiguration( mojoExecution );
+
+ calculateForkedExecutions( mojoExecution, session, project, new HashSet<MojoDescriptor>() );
+ }
+
+ public List<MojoExecution> calculateMojoExecutions( MavenSession session, MavenProject project,
+ List<Object> tasks )
+ throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
+ MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
+ PluginVersionResolutionException, LifecyclePhaseNotFoundException
+ {
+ final List<MojoExecution> mojoExecutions = new ArrayList<MojoExecution>();
+
+ for ( Object task : tasks )
+ {
+ if ( task instanceof GoalTask )
+ {
+ String pluginGoal = ( (GoalTask) task ).pluginGoal;
+
+ MojoDescriptor mojoDescriptor = mojoDescriptorCreator.getMojoDescriptor( pluginGoal, session, project );
+
+ MojoExecution mojoExecution =
+ new MojoExecution( mojoDescriptor, "default-cli", MojoExecution.Source.CLI );
+
+ mojoExecutions.add( mojoExecution );
+ }
+ else if ( task instanceof LifecycleTask )
+ {
+ String lifecyclePhase = ( (LifecycleTask) task ).getLifecyclePhase();
+
+ Map<String, List<MojoExecution>> phaseToMojoMapping =
+ calculateLifecycleMappings( session, project, lifecyclePhase );
+
+ for ( List<MojoExecution> mojoExecutionsFromLifecycle : phaseToMojoMapping.values() )
+ {
+ mojoExecutions.addAll( mojoExecutionsFromLifecycle );
+ }
+ }
+ else
+ {
+ throw new IllegalStateException( "unexpected task " + task );
+ }
+ }
+ return mojoExecutions;
+ }
+
+ private Map<String, List<MojoExecution>> calculateLifecycleMappings( MavenSession session, MavenProject project,
+ String lifecyclePhase )
+ throws LifecyclePhaseNotFoundException, PluginNotFoundException, PluginResolutionException,
+ PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException
+ {
+ /*
+ * Determine the lifecycle that corresponds to the given phase.
+ */
+
+ Lifecycle lifecycle = defaultLifeCycles.get( lifecyclePhase );
+
+ if ( lifecycle == null )
+ {
+ throw new LifecyclePhaseNotFoundException(
+ "Unknown lifecycle phase \"" + lifecyclePhase + "\". You must specify a valid lifecycle phase" +
+ " or a goal in the format <plugin-prefix>:<goal> or" +
+ " <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: " +
+ defaultLifeCycles.getLifecyclePhaseList() + ".", lifecyclePhase );
+ }
+
+ /*
+ * Initialize mapping from lifecycle phase to bound mojos. The key set of this map denotes the phases the caller
+ * is interested in, i.e. all phases up to and including the specified phase.
+ */
+
+ Map<String, Map<Integer, List<MojoExecution>>> mappings =
+ new LinkedHashMap<String, Map<Integer, List<MojoExecution>>>();
+
+ for ( String phase : lifecycle.getPhases() )
+ {
+ Map<Integer, List<MojoExecution>> phaseBindings = new TreeMap<Integer, List<MojoExecution>>();
+
+ mappings.put( phase, phaseBindings );
+
+ if ( phase.equals( lifecyclePhase ) )
+ {
+ break;
+ }
+ }
+
+ /*
+ * Grab plugin executions that are bound to the selected lifecycle phases from project. The effective model of
+ * the project already contains the plugin executions induced by the project's packaging type. Remember, all
+ * phases of interest and only those are in the lifecyle mapping, if a phase has no value in the map, we are not
+ * interested in any of the executions bound to it.
+ */
+
+ for ( Plugin plugin : project.getBuild().getPlugins() )
+ {
+ for ( PluginExecution execution : plugin.getExecutions() )
+ {
+ // if the phase is specified then I don't have to go fetch the plugin yet and pull it down
+ // to examine the phase it is associated to.
+ if ( execution.getPhase() != null )
+ {
+ Map<Integer, List<MojoExecution>> phaseBindings = mappings.get( execution.getPhase() );
+ if ( phaseBindings != null )
+ {
+ for ( String goal : execution.getGoals() )
+ {
+ MojoExecution mojoExecution = new MojoExecution( plugin, goal, execution.getId() );
+ mojoExecution.setLifecyclePhase( execution.getPhase() );
+ addMojoExecution( phaseBindings, mojoExecution, execution.getPriority() );
+ }
+ }
+ }
+ // if not then i need to grab the mojo descriptor and look at the phase that is specified
+ else
+ {
+ for ( String goal : execution.getGoals() )
+ {
+ MojoDescriptor mojoDescriptor =
+ pluginManager.getMojoDescriptor( plugin, goal, project.getRemotePluginRepositories(),
+ session.getRepositorySession() );
+
+ Map<Integer, List<MojoExecution>> phaseBindings = mappings.get( mojoDescriptor.getPhase() );
+ if ( phaseBindings != null )
+ {
+ MojoExecution mojoExecution = new MojoExecution( mojoDescriptor, execution.getId() );
+ mojoExecution.setLifecyclePhase( mojoDescriptor.getPhase() );
+ addMojoExecution( phaseBindings, mojoExecution, execution.getPriority() );
+ }
+ }
+ }
+ }
+ }
+
+ Map<String, List<MojoExecution>> lifecycleMappings = new LinkedHashMap<String, List<MojoExecution>>();
+
+ for ( Map.Entry<String, Map<Integer, List<MojoExecution>>> entry : mappings.entrySet() )
+ {
+ List<MojoExecution> mojoExecutions = new ArrayList<MojoExecution>();
+
+ for ( List<MojoExecution> executions : entry.getValue().values() )
+ {
+ mojoExecutions.addAll( executions );
+ }
+
+ lifecycleMappings.put( entry.getKey(), mojoExecutions );
+ }
+
+ return lifecycleMappings;
+ }
+
+ private void addMojoExecution( Map<Integer, List<MojoExecution>> phaseBindings, MojoExecution mojoExecution,
+ int priority )
+ {
+ List<MojoExecution> mojoExecutions = phaseBindings.get( priority );
+
+ if ( mojoExecutions == null )
+ {
+ mojoExecutions = new ArrayList<MojoExecution>();
+ phaseBindings.put( priority, mojoExecutions );
+ }
+
+ mojoExecutions.add( mojoExecution );
+ }
+
+ private void populateMojoExecutionConfiguration( MavenProject project, MojoExecution mojoExecution,
+ boolean allowPluginLevelConfig )
+ {
+ String g = mojoExecution.getGroupId();
+
+ String a = mojoExecution.getArtifactId();
+
+ Plugin plugin = findPlugin( g, a, project.getBuildPlugins() );
+
+ if ( plugin == null && project.getPluginManagement() != null )
+ {
+ plugin = findPlugin( g, a, project.getPluginManagement().getPlugins() );
+ }
+
+ if ( plugin != null )
+ {
+ PluginExecution pluginExecution =
+ findPluginExecution( mojoExecution.getExecutionId(), plugin.getExecutions() );
+
+ Xpp3Dom pomConfiguration = null;
+
+ if ( pluginExecution != null )
+ {
+ pomConfiguration = (Xpp3Dom) pluginExecution.getConfiguration();
+ }
+ else if ( allowPluginLevelConfig )
+ {
+ pomConfiguration = (Xpp3Dom) plugin.getConfiguration();
+ }
+
+ Xpp3Dom mojoConfiguration = ( pomConfiguration != null ) ? new Xpp3Dom( pomConfiguration ) : null;
+
+ mojoConfiguration = Xpp3Dom.mergeXpp3Dom( mojoExecution.getConfiguration(), mojoConfiguration );
+
+ mojoExecution.setConfiguration( mojoConfiguration );
+ }
+ }
+
+ private Plugin findPlugin( String groupId, String artifactId, Collection<Plugin> plugins )
+ {
+ for ( Plugin plugin : plugins )
+ {
+ if ( artifactId.equals( plugin.getArtifactId() ) && groupId.equals( plugin.getGroupId() ) )
+ {
+ return plugin;
+ }
+ }
+
+ return null;
+ }
+
+ private PluginExecution findPluginExecution( String executionId, Collection<PluginExecution> executions )
+ {
+ if ( StringUtils.isNotEmpty( executionId ) )
+ {
+ for ( PluginExecution execution : executions )
+ {
+ if ( executionId.equals( execution.getId() ) )
+ {
+ return execution;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Post-processes the effective configuration for the specified mojo execution. This step discards all parameters
+ * from the configuration that are not applicable to the mojo and injects the default values for any missing
+ * parameters.
+ *
+ * @param mojoExecution The mojo execution whose configuration should be finalized, must not be {@code null}.
+ */
+ private void finalizeMojoConfiguration( MojoExecution mojoExecution )
+ {
+ MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
+
+ Xpp3Dom executionConfiguration = mojoExecution.getConfiguration();
+ if ( executionConfiguration == null )
+ {
+ executionConfiguration = new Xpp3Dom( "configuration" );
+ }
+
+ Xpp3Dom defaultConfiguration = getMojoConfiguration( mojoDescriptor );
+
+ Xpp3Dom finalConfiguration = new Xpp3Dom( "configuration" );
+
+ if ( mojoDescriptor.getParameters() != null )
+ {
+ for ( Parameter parameter : mojoDescriptor.getParameters() )
+ {
+ Xpp3Dom parameterConfiguration = executionConfiguration.getChild( parameter.getName() );
+
+ if ( parameterConfiguration == null )
+ {
+ parameterConfiguration = executionConfiguration.getChild( parameter.getAlias() );
+ }
+
+ Xpp3Dom parameterDefaults = defaultConfiguration.getChild( parameter.getName() );
+
+ parameterConfiguration =
+ Xpp3Dom.mergeXpp3Dom( parameterConfiguration, parameterDefaults, Boolean.TRUE );
+
+ if ( parameterConfiguration != null )
+ {
+ parameterConfiguration = new Xpp3Dom( parameterConfiguration, parameter.getName() );
+
+ if ( StringUtils.isEmpty( parameterConfiguration.getAttribute( "implementation" ) ) &&
+ StringUtils.isNotEmpty( parameter.getImplementation() ) )
+ {
+ parameterConfiguration.setAttribute( "implementation", parameter.getImplementation() );
+ }
+
+ finalConfiguration.addChild( parameterConfiguration );
+ }
+ }
+ }
+
+ mojoExecution.setConfiguration( finalConfiguration );
+ }
+
+ private Xpp3Dom getMojoConfiguration( MojoDescriptor mojoDescriptor )
+ {
+ return MojoDescriptorCreator.convert( mojoDescriptor );
+ }
+
+ public void calculateForkedExecutions( MojoExecution mojoExecution, MavenSession session )
+ throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
+ PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
+ LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
+ {
+ calculateForkedExecutions( mojoExecution, session, session.getCurrentProject(), new HashSet<MojoDescriptor>() );
+ }
+
+ private void calculateForkedExecutions( MojoExecution mojoExecution, MavenSession session, MavenProject project,
+ Collection<MojoDescriptor> alreadyForkedExecutions )
+ throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
+ PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
+ LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
+ {
+ MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
+
+ if ( !mojoDescriptor.isForking() )
+ {
+ return;
+ }
+
+ if ( !alreadyForkedExecutions.add( mojoDescriptor ) )
+ {
+ return;
+ }
+
+ List<MavenProject> forkedProjects =
+ LifecycleDependencyResolver.getProjects( project, session, mojoDescriptor.isAggregator() );
+
+ for ( MavenProject forkedProject : forkedProjects )
+ {
+ if ( forkedProject != project )
+ {
+ lifecyclePluginResolver.resolveMissingPluginVersions( forkedProject, session );
+ }
+
+ List<MojoExecution> forkedExecutions;
+
+ if ( StringUtils.isNotEmpty( mojoDescriptor.getExecutePhase() ) )
+ {
+ forkedExecutions =
+ calculateForkedLifecycle( mojoExecution, session, forkedProject, alreadyForkedExecutions );
+ }
+ else
+ {
+ forkedExecutions =
+ calculateForkedGoal( mojoExecution, session, forkedProject, alreadyForkedExecutions );
+ }
+
+ mojoExecution.setForkedExecutions( BuilderCommon.getKey( forkedProject ), forkedExecutions );
+ }
+
+ alreadyForkedExecutions.remove( mojoDescriptor );
+ }
+
+ private List<MojoExecution> calculateForkedLifecycle( MojoExecution mojoExecution, MavenSession session,
+ MavenProject project,
+ Collection<MojoDescriptor> alreadyForkedExecutions )
+ throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
+ PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
+ LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
+ {
+ MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
+
+ String forkedPhase = mojoDescriptor.getExecutePhase();
+
+ Map<String, List<MojoExecution>> lifecycleMappings =
+ calculateLifecycleMappings( session, project, forkedPhase );
+
+ for ( List<MojoExecution> forkedExecutions : lifecycleMappings.values() )
+ {
+ for ( MojoExecution forkedExecution : forkedExecutions )
+ {
+ if ( forkedExecution.getMojoDescriptor() == null )
+ {
+ MojoDescriptor forkedMojoDescriptor =
+ pluginManager.getMojoDescriptor( forkedExecution.getPlugin(), forkedExecution.getGoal(),
+ project.getRemotePluginRepositories(),
+ session.getRepositorySession() );
+
+ forkedExecution.setMojoDescriptor( forkedMojoDescriptor );
+ }
+
+ populateMojoExecutionConfiguration( project, forkedExecution, false );
+ }
+ }
+
+ injectLifecycleOverlay( lifecycleMappings, mojoExecution, session, project );
+
+ List<MojoExecution> mojoExecutions = new ArrayList<MojoExecution>();
+
+ for ( List<MojoExecution> forkedExecutions : lifecycleMappings.values() )
+ {
+ for ( MojoExecution forkedExecution : forkedExecutions )
+ {
+ if ( !alreadyForkedExecutions.contains( forkedExecution.getMojoDescriptor() ) )
+ {
+ finalizeMojoConfiguration( forkedExecution );
+
+ calculateForkedExecutions( forkedExecution, session, project, alreadyForkedExecutions );
+
+ mojoExecutions.add( forkedExecution );
+ }
+ }
+ }
+
+ return mojoExecutions;
+ }
+
+ private void injectLifecycleOverlay( Map<String, List<MojoExecution>> lifecycleMappings,
+ MojoExecution mojoExecution, MavenSession session, MavenProject project )
+ throws PluginDescriptorParsingException, LifecycleNotFoundException, MojoNotFoundException,
+ PluginNotFoundException, PluginResolutionException, NoPluginFoundForPrefixException,
+ InvalidPluginDescriptorException, PluginVersionResolutionException
+ {
+ MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
+
+ PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
+
+ String forkedLifecycle = mojoDescriptor.getExecuteLifecycle();
+
+ if ( StringUtils.isEmpty( forkedLifecycle ) )
+ {
+ return;
+ }
+
+ org.apache.maven.plugin.lifecycle.Lifecycle lifecycleOverlay;
+
+ try
+ {
+ lifecycleOverlay = pluginDescriptor.getLifecycleMapping( forkedLifecycle );
+ }
+ catch ( IOException e )
+ {
+ throw new PluginDescriptorParsingException( pluginDescriptor.getPlugin(), pluginDescriptor.getSource(), e );
+ }
+ catch ( XmlPullParserException e )
+ {
+ throw new PluginDescriptorParsingException( pluginDescriptor.getPlugin(), pluginDescriptor.getSource(), e );
+ }
+
+ if ( lifecycleOverlay == null )
+ {
+ throw new LifecycleNotFoundException( forkedLifecycle );
+ }
+
+ for ( Phase phase : lifecycleOverlay.getPhases() )
+ {
+ List<MojoExecution> forkedExecutions = lifecycleMappings.get( phase.getId() );
+
+ if ( forkedExecutions != null )
+ {
+ for ( Execution execution : phase.getExecutions() )
+ {
+ for ( String goal : execution.getGoals() )
+ {
+ MojoDescriptor forkedMojoDescriptor;
+
+ if ( goal.indexOf( ':' ) < 0 )
+ {
+ forkedMojoDescriptor = pluginDescriptor.getMojo( goal );
+ if ( forkedMojoDescriptor == null )
+ {
+ throw new MojoNotFoundException( goal, pluginDescriptor );
+ }
+ }
+ else
+ {
+ forkedMojoDescriptor = mojoDescriptorCreator.getMojoDescriptor( goal, session, project );
+ }
+
+ MojoExecution forkedExecution =
+ new MojoExecution( forkedMojoDescriptor, mojoExecution.getExecutionId() );
+
+ Xpp3Dom forkedConfiguration = (Xpp3Dom) execution.getConfiguration();
+
+ forkedExecution.setConfiguration( forkedConfiguration );
+
+ populateMojoExecutionConfiguration( project, forkedExecution, true );
+
+ forkedExecutions.add( forkedExecution );
+ }
+ }
+
+ Xpp3Dom phaseConfiguration = (Xpp3Dom) phase.getConfiguration();
+
+ if ( phaseConfiguration != null )
+ {
+ for ( MojoExecution forkedExecution : forkedExecutions )
+ {
+ Xpp3Dom forkedConfiguration = forkedExecution.getConfiguration();
+
+ forkedConfiguration = Xpp3Dom.mergeXpp3Dom( phaseConfiguration, forkedConfiguration );
+
+ forkedExecution.setConfiguration( forkedConfiguration );
+ }
+ }
+ }
+ }
+ }
+ // org.apache.maven.plugins:maven-remote-resources-plugin:1.0:process
+ //TODO: take repo mans into account as one may be aggregating prefixes of many
+ //TODO: collect at the root of the repository, read the one at the root, and fetch remote if something is missing
+ // or the user forces the issue
+
+ private List<MojoExecution> calculateForkedGoal( MojoExecution mojoExecution, MavenSession session,
+ MavenProject project,
+ Collection<MojoDescriptor> alreadyForkedExecutions )
+ throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
+ PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
+ LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
+ {
+ MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
+
+ PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
+
+ String forkedGoal = mojoDescriptor.getExecuteGoal();
+
+ MojoDescriptor forkedMojoDescriptor = pluginDescriptor.getMojo( forkedGoal );
+ if ( forkedMojoDescriptor == null )
+ {
+ throw new MojoNotFoundException( forkedGoal, pluginDescriptor );
+ }
+
+ if ( alreadyForkedExecutions.contains( forkedMojoDescriptor ) )
+ {
+ return Collections.emptyList();
+ }
+
+ MojoExecution forkedExecution = new MojoExecution( forkedMojoDescriptor, forkedGoal );
+
+ populateMojoExecutionConfiguration( project, forkedExecution, true );
+
+ finalizeMojoConfiguration( forkedExecution );
+
+ calculateForkedExecutions( forkedExecution, session, project, alreadyForkedExecutions );
+
+ return Collections.singletonList( forkedExecution );
+ }
+
+
+}
diff --git a/org.eclipse.m2e.maven.runtime/src/main/java/org/apache/maven/lifecycle/internal/LifecycleExecutionPlanCalculator.java b/org.eclipse.m2e.maven.runtime/src/main/java/org/apache/maven/lifecycle/internal/LifecycleExecutionPlanCalculator.java
new file mode 100644
index 00000000..7d35b102
--- /dev/null
+++ b/org.eclipse.m2e.maven.runtime/src/main/java/org/apache/maven/lifecycle/internal/LifecycleExecutionPlanCalculator.java
@@ -0,0 +1,67 @@
+package org.apache.maven.lifecycle.internal;
+
+/*
+ * 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 org.apache.maven.execution.MavenSession;
+import org.apache.maven.lifecycle.LifecycleNotFoundException;
+import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException;
+import org.apache.maven.lifecycle.MavenExecutionPlan;
+import org.apache.maven.plugin.InvalidPluginDescriptorException;
+import org.apache.maven.plugin.MojoExecution;
+import org.apache.maven.plugin.MojoNotFoundException;
+import org.apache.maven.plugin.PluginDescriptorParsingException;
+import org.apache.maven.plugin.PluginNotFoundException;
+import org.apache.maven.plugin.PluginResolutionException;
+import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
+import org.apache.maven.plugin.version.PluginVersionResolutionException;
+import org.apache.maven.project.MavenProject;
+
+import java.util.List;
+
+/**
+ * @since 3.0
+ * @author Benjamin Bentmann
+ * @author Kristian Rosenvold (extract interface only)
+ * <p/>
+ */
+public interface LifecycleExecutionPlanCalculator
+{
+ MavenExecutionPlan calculateExecutionPlan( MavenSession session, MavenProject project, List<Object> tasks )
+ throws PluginNotFoundException, PluginResolutionException, LifecyclePhaseNotFoundException,
+ PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException,
+ NoPluginFoundForPrefixException, LifecycleNotFoundException, PluginVersionResolutionException;
+
+ MavenExecutionPlan calculateExecutionPlan( MavenSession session, MavenProject project, List<Object> tasks,
+ boolean setup )
+ throws PluginNotFoundException, PluginResolutionException, LifecyclePhaseNotFoundException,
+ PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException,
+ NoPluginFoundForPrefixException, LifecycleNotFoundException, PluginVersionResolutionException;
+
+ void calculateForkedExecutions( MojoExecution mojoExecution, MavenSession session )
+ throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
+ PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
+ LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException;
+
+ void setupMojoExecution( MavenSession session, MavenProject project, MojoExecution mojoExecution )
+ throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
+ MojoNotFoundException, InvalidPluginDescriptorException, NoPluginFoundForPrefixException,
+ LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException;
+
+}
diff --git a/org.eclipse.m2e.maven.runtime/src/main/java/org/apache/maven/lifecycle/internal/LifecycleTaskSegmentCalculator.java b/org.eclipse.m2e.maven.runtime/src/main/java/org/apache/maven/lifecycle/internal/LifecycleTaskSegmentCalculator.java
new file mode 100644
index 00000000..113a5ab3
--- /dev/null
+++ b/org.eclipse.m2e.maven.runtime/src/main/java/org/apache/maven/lifecycle/internal/LifecycleTaskSegmentCalculator.java
@@ -0,0 +1,61 @@
+package org.apache.maven.lifecycle.internal;
+
+/*
+ * 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 org.apache.maven.execution.MavenSession;
+import org.apache.maven.lifecycle.LifecycleNotFoundException;
+import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException;
+import org.apache.maven.plugin.InvalidPluginDescriptorException;
+import org.apache.maven.plugin.MojoNotFoundException;
+import org.apache.maven.plugin.PluginDescriptorParsingException;
+import org.apache.maven.plugin.PluginNotFoundException;
+import org.apache.maven.plugin.PluginResolutionException;
+import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
+import org.apache.maven.plugin.version.PluginVersionResolutionException;
+
+import java.util.List;
+
+/**
+ * Calculates the task segments in the build
+ *
+ * @since 3.0
+ * @author Benjamin Bentmann
+ * @author Jason van Zyl
+ * @author jdcasey
+ * @author Kristian Rosenvold (extracted interface)
+ * <p/>
+ * NOTE: This interface is not part of any public api and can be changed or deleted without prior notice.
+ */
+
+public interface LifecycleTaskSegmentCalculator
+{
+ List<TaskSegment> calculateTaskSegments( MavenSession session )
+ throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
+ MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
+ PluginVersionResolutionException, LifecyclePhaseNotFoundException, LifecycleNotFoundException;
+
+ public List<TaskSegment> calculateTaskSegments( MavenSession session, List<String> tasks )
+ throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
+ MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
+ PluginVersionResolutionException;
+
+ boolean requiresProject( MavenSession session );
+
+}

Back to the top