Skip to content

Commit 996c2d7

Browse files
Copilotlaeubi
andcommitted
Add LifecycleExecutionPlanCalculatorFacade and update usages
Co-authored-by: laeubi <[email protected]>
1 parent 8ffc33c commit 996c2d7

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-4
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator;
6161
import org.apache.maven.lifecycle.internal.MojoExecutor;
6262
import org.apache.maven.plugin.BuildPluginManager;
63+
import org.eclipse.m2e.internal.maven.compat.LifecycleExecutionPlanCalculatorFacade;
6364
import org.apache.maven.plugin.LegacySupport;
6465
import org.apache.maven.plugin.MojoExecution;
6566
import org.apache.maven.project.DefaultProjectBuildingRequest;
@@ -395,7 +396,8 @@ private static void executeMojo(MavenSession session, MojoExecution execution, I
395396
MojoExecution clone = cloneMojoExecution(execution);
396397
try {
397398
MavenProject currentProject = session.getCurrentProject();
398-
LifecycleExecutionPlanCalculator executionPlanCalculator = lookup.lookup(LifecycleExecutionPlanCalculator.class);
399+
LifecycleExecutionPlanCalculatorFacade executionPlanCalculator = new LifecycleExecutionPlanCalculatorFacade(
400+
lookup.lookup(LifecycleExecutionPlanCalculator.class));
399401
executionPlanCalculator.setupMojoExecution(session, currentProject, clone);
400402
MojoExecutor mojoExecutor = lookup.lookup(MojoExecutor.class);
401403
DependencyContext dependencyContext = mojoExecutor.newDependencyContext(session, List.of(clone));

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
import org.apache.maven.lifecycle.MavenExecutionPlan;
8686
import org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator;
8787
import org.apache.maven.model.ConfigurationContainer;
88+
import org.eclipse.m2e.internal.maven.compat.LifecycleExecutionPlanCalculatorFacade;
8889
import org.apache.maven.model.Model;
8990
import org.apache.maven.model.Plugin;
9091
import org.apache.maven.model.Profile;
@@ -238,7 +239,8 @@ private MojoExecution setupMojoExecution(MavenSession session, MavenProject proj
238239
clone.setConfiguration(new Xpp3Dom(execution.getConfiguration()));
239240
}
240241
clone.setLifecyclePhase(execution.getLifecyclePhase());
241-
LifecycleExecutionPlanCalculator executionPlanCalculator = lookup(LifecycleExecutionPlanCalculator.class);
242+
LifecycleExecutionPlanCalculatorFacade executionPlanCalculator = new LifecycleExecutionPlanCalculatorFacade(
243+
lookup(LifecycleExecutionPlanCalculator.class));
242244
try {
243245
executionPlanCalculator.setupMojoExecution(session, project, clone);
244246
} catch(Exception ex) {

org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/MavenProjectFacade.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.apache.maven.project.MavenProject;
4848

4949
import org.eclipse.m2e.core.embedder.ArtifactKey;
50+
import org.eclipse.m2e.internal.maven.compat.LifecycleExecutionPlanCalculatorFacade;
5051
import org.eclipse.m2e.core.embedder.ArtifactRef;
5152
import org.eclipse.m2e.core.embedder.ArtifactRepositoryRef;
5253
import org.eclipse.m2e.core.embedder.IComponentLookup;
@@ -541,8 +542,8 @@ private MojoExecution setupMojoExecution(MojoExecution mojoExecution, IProgressM
541542
}
542543
clone.setLifecyclePhase(mojoExecution.getLifecyclePhase());
543544
createExecutionContext().execute(mavenProject, (ctx, mon) -> {
544-
LifecycleExecutionPlanCalculator executionPlanCalculator = ctx.getComponentLookup()
545-
.lookup(LifecycleExecutionPlanCalculator.class);
545+
LifecycleExecutionPlanCalculatorFacade executionPlanCalculator = new LifecycleExecutionPlanCalculatorFacade(
546+
ctx.getComponentLookup().lookup(LifecycleExecutionPlanCalculator.class));
546547
try {
547548
executionPlanCalculator.setupMojoExecution(ctx.getSession(), mavenProject, clone);
548549
} catch(Exception ex) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/********************************************************************************
2+
* Copyright (c) 2025 Christoph Läubrich and others
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Christoph Läubrich - initial API and implementation
12+
********************************************************************************/
13+
14+
package org.eclipse.m2e.internal.maven.compat;
15+
16+
import org.apache.maven.execution.MavenSession;
17+
import org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator;
18+
import org.apache.maven.plugin.MojoExecution;
19+
import org.apache.maven.project.MavenProject;
20+
21+
/**
22+
* Facade for {@link LifecycleExecutionPlanCalculator} to avoid direct usage that might change in Maven 4.
23+
* This facade wraps the calculator and provides delegate methods for the functionality m2e actually uses.
24+
*/
25+
public class LifecycleExecutionPlanCalculatorFacade {
26+
27+
private final LifecycleExecutionPlanCalculator delegate;
28+
29+
public LifecycleExecutionPlanCalculatorFacade(LifecycleExecutionPlanCalculator delegate) {
30+
this.delegate = delegate;
31+
}
32+
33+
/**
34+
* Sets up the MojoExecution with its configuration from the project's POM.
35+
*
36+
* @param session the Maven session
37+
* @param project the Maven project
38+
* @param mojoExecution the mojo execution to setup
39+
* @throws Exception if setup fails
40+
*/
41+
public void setupMojoExecution(MavenSession session, MavenProject project, MojoExecution mojoExecution)
42+
throws Exception {
43+
delegate.setupMojoExecution(session, project, mojoExecution);
44+
}
45+
}

0 commit comments

Comments
 (0)