Skip to content

Commit 187ee27

Browse files
committed
Add IPluginFacade and migrate PDEMavenBundlePluginConfigurator off raw
Plugin/MojoExecution
1 parent d1a053a commit 187ee27

6 files changed

Lines changed: 175 additions & 26 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.eclipse.m2e.core.internal.embedder.MavenImpl;
2222
import org.eclipse.m2e.core.project.IMavenProjectFacade;
2323
import org.eclipse.m2e.core.project.IMojoExecutionFacade;
24+
import org.eclipse.m2e.core.project.IPluginFacade;
2425
import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
2526

2627

@@ -48,6 +49,11 @@ public MojoExecutionKey getKey() {
4849
return key;
4950
}
5051

52+
@Override
53+
public IPluginFacade getPlugin() {
54+
return IPluginFacade.wrap(mojoExecution.getPlugin());
55+
}
56+
5157
@Override
5258
public <T> T getMojoParameterValue(String parameter, Class<T> asType, IProgressMonitor monitor)
5359
throws CoreException {
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 Christoph Läubrich and others
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License 2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*******************************************************************************/
10+
11+
package org.eclipse.m2e.core.internal.project.registry;
12+
13+
import org.apache.maven.model.Plugin;
14+
15+
import org.eclipse.m2e.core.project.IPluginFacade;
16+
17+
18+
/**
19+
* Default {@link IPluginFacade} implementation simply wrapping a Maven-core {@link Plugin}.
20+
*/
21+
public class PluginFacade implements IPluginFacade {
22+
23+
private final Plugin plugin;
24+
25+
public PluginFacade(Plugin plugin) {
26+
this.plugin = plugin;
27+
}
28+
29+
@Override
30+
public String getGroupId() {
31+
return plugin.getGroupId();
32+
}
33+
34+
@Override
35+
public String getArtifactId() {
36+
return plugin.getArtifactId();
37+
}
38+
39+
@Override
40+
public String getVersion() {
41+
return plugin.getVersion();
42+
}
43+
44+
@Override
45+
public String getKey() {
46+
return plugin.getKey();
47+
}
48+
49+
@Override
50+
public String toString() {
51+
return getKey();
52+
}
53+
54+
}

org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/IMojoExecutionFacade.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ public interface IMojoExecutionFacade {
3636
*/
3737
MojoExecutionKey getKey();
3838

39+
/**
40+
* @return a facade for the plugin that provides the wrapped mojo execution
41+
* @since 2.9
42+
*/
43+
IPluginFacade getPlugin();
44+
3945
/**
4046
* Resolves a configuration parameter from the wrapped mojo execution. It coerces from String to the given type and
4147
* considers expressions and default values.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 Christoph Läubrich and others
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License 2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*******************************************************************************/
10+
11+
package org.eclipse.m2e.core.project;
12+
13+
import org.apache.maven.model.Plugin;
14+
15+
import org.eclipse.m2e.core.internal.project.registry.PluginFacade;
16+
17+
18+
/**
19+
* Facade for the (build) plugin backing a {@link IMojoExecutionFacade}. This decouples consumers that just need the
20+
* plugin's coordinates from depending directly on Maven-core API such as {@link Plugin}.
21+
*
22+
* @noimplement This interface is not intended to be implemented by clients.
23+
* @since 2.9
24+
*/
25+
public interface IPluginFacade {
26+
27+
/**
28+
* @return the group id of the plugin
29+
*/
30+
String getGroupId();
31+
32+
/**
33+
* @return the artifact id of the plugin
34+
*/
35+
String getArtifactId();
36+
37+
/**
38+
* @return the version of the plugin
39+
*/
40+
String getVersion();
41+
42+
/**
43+
* @return the {@code groupId:artifactId} key uniquely identifying the plugin (independent of its version)
44+
*/
45+
String getKey();
46+
47+
/**
48+
* Wraps a raw {@link Plugin} into an {@link IPluginFacade}.
49+
* <p>
50+
* This is intended as a transitional helper for client code that still acquires or receives (e.g. through a
51+
* framework callback) a raw {@link Plugin} instance, until such code can be migrated to acquire an
52+
* {@link IPluginFacade} directly from {@link IMojoExecutionFacade#getPlugin()}.
53+
* </p>
54+
*
55+
* @param plugin the raw plugin to wrap
56+
* @return a facade wrapping the given plugin, or {@code null} if {@code plugin} is {@code null}
57+
*/
58+
static IPluginFacade wrap(Plugin plugin) {
59+
if(plugin == null) {
60+
return null;
61+
}
62+
return new PluginFacade(plugin);
63+
}
64+
65+
}

org.eclipse.m2e.pde.connector/src/org/eclipse/m2e/pde/connector/PDEMavenBundlePluginConfigurator.java

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import org.eclipse.m2e.core.project.IMavenProjectFacade;
5454
import org.eclipse.m2e.core.project.IMavenProjectRegistry;
5555
import org.eclipse.m2e.core.project.IMojoExecutionFacade;
56+
import org.eclipse.m2e.core.project.IPluginFacade;
5657
import org.eclipse.m2e.core.project.configurator.AbstractBuildParticipant;
5758
import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator;
5859
import org.eclipse.m2e.core.project.configurator.ILifecycleMappingConfiguration;
@@ -88,15 +89,13 @@ public class PDEMavenBundlePluginConfigurator extends AbstractProjectConfigurato
8889

8990
@Override
9091
public void configure(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException {
91-
List<MojoExecution> executions = getMojoExecutions(request, monitor);
92+
List<IMojoExecutionFacade> executions = getMojoExecutionFacades(request, monitor);
9293
boolean hasManifestExecution = false;
93-
for (MojoExecution execution : executions) {
94-
Plugin plugin = execution.getPlugin();
94+
for (IMojoExecutionFacade execution : executions) {
95+
IPluginFacade plugin = execution.getPlugin();
9596
if (isFelix(plugin)) {
9697
if (isFelixManifestGoal(execution)) {
97-
IMojoExecutionFacade executionFacade = IMojoExecutionFacade.wrap(request.mavenProjectFacade(),
98-
execution);
99-
Boolean supportIncremental = executionFacade.getMojoParameterValue(
98+
Boolean supportIncremental = execution.getMojoParameterValue(
10099
FELIX_PARAM_SUPPORTINCREMENTALBUILD, Boolean.class, monitor);
101100
if (supportIncremental == null || !supportIncremental.booleanValue()) {
102101
createWarningMarker(request, execution, SourceLocationHelper.CONFIGURATION,
@@ -109,7 +108,7 @@ public void configure(ProjectConfigurationRequest request, IProgressMonitor moni
109108
}
110109
}
111110
if (!hasManifestExecution && !executions.isEmpty()) {
112-
MojoExecution execution = executions.get(0);
111+
IMojoExecutionFacade execution = executions.get(0);
113112
createWarningMarker(request, execution, "executions",
114113
"There is currently no execution that generates a manifest, consider adding an execution for one of the following goal: "
115114
+ (isFelix(execution.getPlugin()) ? FELIX_MANIFEST_GOAL : BND_MANIFEST_GOALS) + ".");
@@ -120,33 +119,42 @@ public void configure(ProjectConfigurationRequest request, IProgressMonitor moni
120119
PDEProjectHelper.addPDENature(facade.getProject(), metainfPath, monitor);
121120
}
122121

123-
private void createWarningMarker(ProjectConfigurationRequest request, MojoExecution execution, String attribute,
124-
String message) {
125-
createWarningMarker(projectManager, markerManager, request, execution, attribute, message);
122+
private void createWarningMarker(ProjectConfigurationRequest request, IMojoExecutionFacade execution,
123+
String attribute, String message) {
124+
createWarningMarker(projectManager, markerManager, request, execution.getKey(), attribute, message);
126125
}
127126

128127
static void createWarningMarker(IMavenProjectRegistry projectManager, IMavenMarkerManager markerManager,
129-
ProjectConfigurationRequest request, MojoExecution execution, String attribute, String message) {
130-
SourceLocation location = SourceLocationHelper.findLocation(execution.getPlugin(), attribute);
128+
ProjectConfigurationRequest request, MojoExecutionKey executionKey, String attribute, String message) {
129+
Plugin plugin = request.mavenProject().getPlugin(executionKey.groupId() + ":" + executionKey.artifactId());
130+
SourceLocation location = SourceLocationHelper.findLocation(plugin, attribute);
131131

132132
String[] gav = location.getResourceId().split(":");
133133
IMavenProjectFacade facade = projectManager.getMavenProject(gav[0], gav[1], gav[2]);
134134
if (facade == null) {
135135
// attribute specifying project (probably parent) is not in the workspace.
136136
// The following code returns the location of the project's parent-element.
137-
location = SourceLocationHelper.findLocation(request.mavenProject(), new MojoExecutionKey(execution));
137+
location = SourceLocationHelper.findLocation(request.mavenProject(), executionKey);
138138
facade = request.mavenProjectFacade();
139139
}
140140
MavenProblemInfo problem = new MavenProblemInfo(message, IMarker.SEVERITY_WARNING, location);
141141
markerManager.addErrorMarker(facade.getPom(), IMavenConstants.MARKER_LIFECYCLEMAPPING_ID, problem);
142142
}
143143

144-
private boolean isFelixManifestGoal(MojoExecution execution) {
145-
return FELIX_MANIFEST_GOAL.equals(execution.getGoal());
144+
private boolean isFelixManifestGoal(IMojoExecutionFacade execution) {
145+
return isFelixManifestGoal(execution.getKey().goal());
146146
}
147147

148-
private boolean isBNDBundleGoal(MojoExecution execution) {
149-
return BND_MANIFEST_GOALS.contains(execution.getGoal());
148+
private boolean isFelixManifestGoal(String goal) {
149+
return FELIX_MANIFEST_GOAL.equals(goal);
150+
}
151+
152+
private boolean isBNDBundleGoal(IMojoExecutionFacade execution) {
153+
return isBNDBundleGoal(execution.getKey().goal());
154+
}
155+
156+
private boolean isBNDBundleGoal(String goal) {
157+
return BND_MANIFEST_GOALS.contains(goal);
150158
}
151159

152160
@Override
@@ -159,26 +167,34 @@ public void configureRawClasspath(ProjectConfigurationRequest request, IClasspat
159167
IProgressMonitor monitor) throws CoreException { // nothing to do
160168
}
161169

162-
private IPath getMetainfPath(IMavenProjectFacade facade, List<MojoExecution> executions, IProgressMonitor monitor)
163-
throws CoreException {
170+
private IPath getMetainfPath(IMavenProjectFacade facade, List<IMojoExecutionFacade> executions,
171+
IProgressMonitor monitor) throws CoreException {
164172
// TODO: warn on multiple executions and prefer the one without classifier (i.e.
165173
// the main artifact or the one for the bnd-process/jar goal??
166-
for (MojoExecution execution : executions) {
167-
Plugin plugin = execution.getPlugin();
174+
for (IMojoExecutionFacade execution : executions) {
175+
IPluginFacade plugin = execution.getPlugin();
168176
String manifestParameter = isBND(plugin) ? BND_PARAM_MANIFESTLOCATION : FELIX_PARAM_MANIFESTLOCATION;
169-
IMojoExecutionFacade executionFacade = IMojoExecutionFacade.wrap(facade, execution);
170-
File location = executionFacade.getMojoParameterValue(manifestParameter, File.class, monitor);
177+
File location = execution.getMojoParameterValue(manifestParameter, File.class, monitor);
171178
if (location != null) {
172179
return facade.getProjectRelativePath(location.getAbsolutePath());
173180
}
174181
}
175182
return null;
176183
}
177184

185+
private boolean isBND(IPluginFacade plugin) {
186+
return plugin != null && "bnd-maven-plugin".equals(plugin.getArtifactId());
187+
}
188+
178189
private boolean isBND(Plugin plugin) {
179190
return plugin != null && "bnd-maven-plugin".equals(plugin.getArtifactId());
180191
}
181192

193+
private boolean isFelix(IPluginFacade plugin) {
194+
return plugin != null && "org.apache.felix".equals(plugin.getGroupId())
195+
&& "maven-bundle-plugin".equals(plugin.getArtifactId());
196+
}
197+
182198
private boolean isFelix(Plugin plugin) {
183199
return plugin != null && "org.apache.felix".equals(plugin.getGroupId())
184200
&& "maven-bundle-plugin".equals(plugin.getArtifactId());
@@ -194,7 +210,8 @@ public boolean hasConfigurationChanged(IMavenProjectFacade newFacade,
194210
public AbstractBuildParticipant getBuildParticipant(IMavenProjectFacade projectFacade, MojoExecution execution,
195211
IPluginExecutionMetadata executionMetadata) {
196212
Plugin plugin = execution.getPlugin();
197-
if ((isFelix(plugin) && isFelixManifestGoal(execution)) || (isBND(plugin) && isBNDBundleGoal(execution))) {
213+
if ((isFelix(plugin) && isFelixManifestGoal(execution.getGoal()))
214+
|| (isBND(plugin) && isBNDBundleGoal(execution.getGoal()))) {
198215
// Run .classpath synchronization on each incremental build in order to consider
199216
// potential changes on the Bundle-ClassPath and the resources recognized by the
200217
// '-includeResource' instruction that are caused by previous mojo executions.

org.eclipse.m2e.pde.connector/src/org/eclipse/m2e/pde/connector/TychoDSConfigurator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.eclipse.m2e.core.project.IMavenProjectFacade;
2626
import org.eclipse.m2e.core.project.IMojoExecutionFacade;
2727
import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator;
28+
import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
2829
import org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest;
2930
import org.eclipse.pde.ds.internal.annotations.DSAnnotationVersion;
3031
import org.osgi.framework.Version;
@@ -105,7 +106,7 @@ private List<MojoExecution> getTychoDsPluginMojoExecutions(IMavenProjectFacade p
105106

106107
private void createWarningMarker(ProjectConfigurationRequest request, MojoExecution execution, String attribute,
107108
String message) {
108-
PDEMavenBundlePluginConfigurator.createWarningMarker(projectManager, markerManager, request, execution,
109-
attribute, message);
109+
PDEMavenBundlePluginConfigurator.createWarningMarker(projectManager, markerManager, request,
110+
new MojoExecutionKey(execution), attribute, message);
110111
}
111112
}

0 commit comments

Comments
 (0)