Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Fedorenko2011-07-28 09:18:39 -0400
committerIgor Fedorenko2011-07-28 10:14:48 -0400
commit74e41f5cadf4d515ccb47e38a8656a7b111ef457 (patch)
tree209ec55e2a5ce2b2ced7c8b07006918fdaca641a
parent443101083b86f0df1fb95b202bf8e44ba3136328 (diff)
downloadm2e-core-74e41f5cadf4d515ccb47e38a8656a7b111ef457.tar.gz
m2e-core-74e41f5cadf4d515ccb47e38a8656a7b111ef457.tar.xz
m2e-core-74e41f5cadf4d515ccb47e38a8656a7b111ef457.zip
353312 - @requiresDependencyResolution is not honoured
Remember dependency artifacts of all session projects. Invoke MojoExecutor.ensureDependenciesAreResolved to make sure all projects have expected dependency artifacts. Reset artifacts for all projects back to their original values after executing the mojo Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java28
1 files changed, 28 insertions, 0 deletions
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 5d35bdb0..056a9d93 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
@@ -20,12 +20,17 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
+import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -74,7 +79,9 @@ 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.DependencyContext;
import org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator;
+import org.apache.maven.lifecycle.internal.MojoExecutor;
import org.apache.maven.model.ConfigurationContainer;
import org.apache.maven.model.InputLocation;
import org.apache.maven.model.Model;
@@ -286,10 +293,31 @@ public class MavenImpl implements IMaven, IMavenConfigurationChangeListener {
}
public void execute(MavenSession session, MojoExecution execution, IProgressMonitor monitor) {
+ Map<MavenProject, Set<Artifact>> artifacts = new HashMap<MavenProject, Set<Artifact>>();
+ for(MavenProject project : session.getProjects()) {
+ artifacts.put(project, new LinkedHashSet<Artifact>(project.getArtifacts()));
+ }
try {
+ MojoExecutor mojoExecutor = lookup(MojoExecutor.class);
+ DependencyContext dependencyContext = mojoExecutor.newDependencyContext(session,
+ Collections.singletonList(execution));
+
+ // workaround for http://jira.codehaus.org/browse/MNG-5141
+ // use reflection until we can get maven 3.0.4+, which has MNG-5141 fixed
+ Method ensureDependenciesAreResolved = mojoExecutor.getClass().getDeclaredMethod("ensureDependenciesAreResolved",
+ MojoDescriptor.class, MavenSession.class, DependencyContext.class);
+ ensureDependenciesAreResolved.setAccessible(true);
+ ensureDependenciesAreResolved.invoke(mojoExecutor, execution.getMojoDescriptor(), session, dependencyContext);
+
lookup(BuildPluginManager.class).executeMojo(session, execution);
} catch(Exception ex) {
session.getResult().addException(ex);
+ } finally {
+ for(MavenProject project : session.getProjects()) {
+ project.setArtifactFilter(null);
+ project.setResolvedArtifacts(null);
+ project.setArtifacts(artifacts.get(project));
+ }
}
}

Back to the top