Skip to content

Commit

Permalink
Properly clone mojoExecution
Browse files Browse the repository at this point in the history
Change-Id: I95b533aeba275ad2f1b317358191c99c0d15f9cb
Signed-off-by: Fred Bricon <[email protected]>
  • Loading branch information
fbricon authored and laeubi committed Mar 7, 2023
1 parent d5c25f9 commit 26b24d9
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ private static void executeMojo(MavenSession session, MojoExecution execution, I
artifacts.put(project, new LinkedHashSet<>(project.getArtifacts()));
snapshots.put(project, MavenProjectMutableState.takeSnapshot(project));
}
MojoExecution clone = new MojoExecution(execution.getPlugin(), execution.getGoal(), execution.getExecutionId());
MojoExecution clone = cloneMojoExecution(execution);
try {
MavenProject currentProject = session.getCurrentProject();
LifecycleExecutionPlanCalculator executionPlanCalculator = lookup.lookup(LifecycleExecutionPlanCalculator.class);
Expand All @@ -351,6 +351,26 @@ private static void executeMojo(MavenSession session, MojoExecution execution, I
}
}

private static MojoExecution cloneMojoExecution(MojoExecution execution) {
MojoExecution clone = new MojoExecution(execution.getPlugin(), execution.getGoal(), execution.getExecutionId());
//FIXME something's wrong with this "cloning" approach, as we lose the original mojoDescriptor.
// Intuitively, something like the following looks more "right", as it would clone the mojoDescriptor,
// in order to avoid any caching shenanigans as mentioned in https://github.com/eclipse-m2e/m2e-core/issues/1304#issuecomment-1457955512.
// but even cloning the descriptor leads to an occurrence of https://github.com/eclipse-m2e/m2e-core/issues/1150 on project import
// var descriptor = execution.getMojoDescriptor();
// if(descriptor != null) {
// clone = new MojoExecution(execution.getPlugin(), execution.getGoal(), execution.getExecutionId());
// } else {
// clone = new MojoExecution(descriptor.clone(), execution.getExecutionId(), execution.getSource());
// }
clone.setConfiguration(execution.getConfiguration());
clone.setLifecyclePhase(execution.getLifecyclePhase());
execution.getForkedExecutions().forEach((k, v) -> {
clone.setForkedExecutions(k, v);
});
return clone;
}

private <V> V executeBare(MavenProject project, ICallable<V> callable, IProgressMonitor monitor)
throws CoreException {
final MavenSession mavenSession = getSession();
Expand Down

0 comments on commit 26b24d9

Please sign in to comment.