Skip to content

Commit 5640b34

Browse files
committed
Setup a fresh execution to account for the current context
Fix #1150
1 parent ca08523 commit 5640b34

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenExecutionContext.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import org.apache.maven.execution.MavenExecutionResult;
5555
import org.apache.maven.execution.MavenSession;
5656
import org.apache.maven.lifecycle.internal.DependencyContext;
57+
import org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator;
5758
import org.apache.maven.lifecycle.internal.MojoExecutor;
5859
import org.apache.maven.plugin.BuildPluginManager;
5960
import org.apache.maven.plugin.LegacySupport;
@@ -325,14 +326,18 @@ private static void executeMojo(MavenSession session, MojoExecution execution, I
325326
artifacts.put(project, new LinkedHashSet<>(project.getArtifacts()));
326327
snapshots.put(project, MavenProjectMutableState.takeSnapshot(project));
327328
}
329+
MojoExecution clone = new MojoExecution(execution.getPlugin(), execution.getGoal(), execution.getExecutionId());
328330
try {
331+
MavenProject currentProject = session.getCurrentProject();
332+
LifecycleExecutionPlanCalculator executionPlanCalculator = lookup.lookup(LifecycleExecutionPlanCalculator.class);
333+
executionPlanCalculator.setupMojoExecution(session, currentProject, clone);
329334
MojoExecutor mojoExecutor = lookup.lookup(MojoExecutor.class);
330-
DependencyContext dependencyContext = mojoExecutor.newDependencyContext(session, List.of(execution));
331-
mojoExecutor.ensureDependenciesAreResolved(execution.getMojoDescriptor(), session, dependencyContext);
332-
lookup.lookup(BuildPluginManager.class).executeMojo(session, execution);
335+
DependencyContext dependencyContext = mojoExecutor.newDependencyContext(session, List.of(clone));
336+
mojoExecutor.ensureDependenciesAreResolved(clone.getMojoDescriptor(), session, dependencyContext);
337+
BuildPluginManager buildPluginManager = lookup.lookup(BuildPluginManager.class);
338+
buildPluginManager.executeMojo(session, clone);
333339
} catch(Exception ex) {
334-
session.getResult().addException(ex);
335-
throw new CoreException(Status.error("Failed to execute mojo", ex));
340+
throw new CoreException(Status.error("Failed to execute mojo " + clone, ex));
336341
} finally {
337342
for(MavenProject project : session.getProjects()) {
338343
project.setArtifactFilter(null);

0 commit comments

Comments
 (0)