Skip to content

Commit 26b24d9

Browse files
fbriconlaeubi
authored andcommitted
Properly clone mojoExecution
Change-Id: I95b533aeba275ad2f1b317358191c99c0d15f9cb Signed-off-by: Fred Bricon <[email protected]>
1 parent d5c25f9 commit 26b24d9

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ private static void executeMojo(MavenSession session, MojoExecution execution, I
326326
artifacts.put(project, new LinkedHashSet<>(project.getArtifacts()));
327327
snapshots.put(project, MavenProjectMutableState.takeSnapshot(project));
328328
}
329-
MojoExecution clone = new MojoExecution(execution.getPlugin(), execution.getGoal(), execution.getExecutionId());
329+
MojoExecution clone = cloneMojoExecution(execution);
330330
try {
331331
MavenProject currentProject = session.getCurrentProject();
332332
LifecycleExecutionPlanCalculator executionPlanCalculator = lookup.lookup(LifecycleExecutionPlanCalculator.class);
@@ -351,6 +351,26 @@ private static void executeMojo(MavenSession session, MojoExecution execution, I
351351
}
352352
}
353353

354+
private static MojoExecution cloneMojoExecution(MojoExecution execution) {
355+
MojoExecution clone = new MojoExecution(execution.getPlugin(), execution.getGoal(), execution.getExecutionId());
356+
//FIXME something's wrong with this "cloning" approach, as we lose the original mojoDescriptor.
357+
// Intuitively, something like the following looks more "right", as it would clone the mojoDescriptor,
358+
// in order to avoid any caching shenanigans as mentioned in https://github.com/eclipse-m2e/m2e-core/issues/1304#issuecomment-1457955512.
359+
// but even cloning the descriptor leads to an occurrence of https://github.com/eclipse-m2e/m2e-core/issues/1150 on project import
360+
// var descriptor = execution.getMojoDescriptor();
361+
// if(descriptor != null) {
362+
// clone = new MojoExecution(execution.getPlugin(), execution.getGoal(), execution.getExecutionId());
363+
// } else {
364+
// clone = new MojoExecution(descriptor.clone(), execution.getExecutionId(), execution.getSource());
365+
// }
366+
clone.setConfiguration(execution.getConfiguration());
367+
clone.setLifecyclePhase(execution.getLifecyclePhase());
368+
execution.getForkedExecutions().forEach((k, v) -> {
369+
clone.setForkedExecutions(k, v);
370+
});
371+
return clone;
372+
}
373+
354374
private <V> V executeBare(MavenProject project, ICallable<V> callable, IProgressMonitor monitor)
355375
throws CoreException {
356376
final MavenSession mavenSession = getSession();

0 commit comments

Comments
 (0)