Skip to content

Commit 61ff447

Browse files
committed
Add IMavenProjectFacade#getMojoParameterValue
Currently we require consumers to go through IMaven for getting Mojo parameters with a maven project. This is both cumbersome and binds us to the MavenProject API from maven-core what complicates Maven 4 migration. This removes the roundtrip by adding the methods for getting a mojo parameter directly to the facade what later will allow us to exchange the backing implementation much easier.
1 parent 3741914 commit 61ff447

20 files changed

Lines changed: 175 additions & 130 deletions

File tree

org.eclipse.m2e.apt.core/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %Bundle-Name
44
Bundle-SymbolicName: org.eclipse.m2e.apt.core;singleton:=true
5-
Bundle-Version: 2.3.100.qualifier
5+
Bundle-Version: 2.3.200.qualifier
66
Bundle-Localization: plugin
77
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.27.0,4.0.0)",
88
org.eclipse.core.resources,

org.eclipse.m2e.apt.core/src/org/eclipse/m2e/apt/internal/AbstractAptConfiguratorDelegate.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import org.apache.maven.project.MavenProject;
5353

5454
import org.eclipse.m2e.apt.internal.utils.ProjectUtils;
55-
import org.eclipse.m2e.core.MavenPlugin;
5655
import org.eclipse.m2e.core.project.IMavenProjectFacade;
5756
import org.eclipse.m2e.core.project.configurator.AbstractBuildParticipant;
5857
import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator;
@@ -351,12 +350,8 @@ protected <T> T getParameterValue(String parameter, Class<T> asType, MojoExecuti
351350
throws CoreException {
352351
PluginExecution execution = new PluginExecution();
353352
execution.setConfiguration(mojoExecution.getConfiguration());
354-
MavenProject mavenProject = mavenFacade.getMavenProject();
355-
return mavenFacade.createExecutionContext().execute(mavenProject, (context, monitor) -> {
356-
//TODO provide as part of the execution context? We then probably won't need the project parameter at all?
357-
return MavenPlugin.getMaven().getMojoParameterValue(mavenProject, parameter, asType, mojoExecution.getPlugin(),
358-
execution, mojoExecution.getGoal(), null);
359-
}, null);
353+
return mavenFacade.getMojoParameterValue(parameter, asType, mojoExecution.getPlugin(), execution,
354+
mojoExecution.getGoal(), null);
360355
}
361356

362357
}

org.eclipse.m2e.apt.core/src/org/eclipse/m2e/apt/internal/compiler/MavenCompilerBuildParticipant.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,9 @@
2929
import org.codehaus.plexus.util.xml.Xpp3Dom;
3030

3131
import org.apache.maven.plugin.MojoExecution;
32-
import org.apache.maven.project.MavenProject;
3332

3433
import org.sonatype.plexus.build.incremental.BuildContext;
3534

36-
import org.eclipse.m2e.core.MavenPlugin;
37-
import org.eclipse.m2e.core.embedder.IMaven;
3835
import org.eclipse.m2e.core.project.IMavenProjectFacade;
3936
import org.eclipse.m2e.core.project.configurator.MojoExecutionBuildParticipant;
4037

@@ -54,7 +51,6 @@ public MavenCompilerBuildParticipant(MojoExecution execution) {
5451

5552
@Override
5653
public Set<IProject> build(int kind, IProgressMonitor monitor) throws Exception {
57-
IMaven maven = MavenPlugin.getMaven();
5854
BuildContext buildContext = getBuildContext();
5955

6056
MojoExecution mojoExecution = getMojoExecution();
@@ -63,12 +59,11 @@ public Set<IProject> build(int kind, IProgressMonitor monitor) throws Exception
6359

6460
//TODO check delta / scan source for *.java
6561
IMavenProjectFacade mavenProjectFacade = getMavenProjectFacade();
66-
MavenProject project = mavenProjectFacade.getMavenProject();
67-
String compilerArgument = maven.getMojoParameterValue(project, mojoExecution, "compilerArgument", String.class,
68-
null);
62+
String compilerArgument = mavenProjectFacade.getMojoParameterValue(mojoExecution, "compilerArgument",
63+
String.class, null);
6964
boolean isAnnotationProcessingEnabled = (compilerArgument == null) || !compilerArgument.contains("-proc:none");
7065
if(isAnnotationProcessingEnabled) {
71-
String proc = maven.getMojoParameterValue(project, mojoExecution, PROC, String.class, null);
66+
String proc = mavenProjectFacade.getMojoParameterValue(mojoExecution, PROC, String.class, null);
7267
isAnnotationProcessingEnabled = !"none".equals(proc);
7368
}
7469
if(!isAnnotationProcessingEnabled) {
@@ -112,7 +107,7 @@ public Set<IProject> build(int kind, IProgressMonitor monitor) throws Exception
112107
}
113108

114109
// tell m2e builder to refresh generated files
115-
File generated = maven.getMojoParameterValue(project, getMojoExecution(),
110+
File generated = mavenProjectFacade.getMojoParameterValue(getMojoExecution(),
116111
MavenCompilerJdtAptDelegate.OUTPUT_DIRECTORY_PARAMETER, File.class, null);
117112
if(generated != null) {
118113
buildContext.refresh(generated);

org.eclipse.m2e.apt.core/src/org/eclipse/m2e/apt/internal/compiler/MavenCompilerJdtAptDelegate.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import org.apache.maven.model.Dependency;
3636
import org.apache.maven.model.Plugin;
3737
import org.apache.maven.plugin.MojoExecution;
38-
import org.apache.maven.project.MavenProject;
3938

4039
import org.eclipse.m2e.apt.internal.AbstractAptConfiguratorDelegate;
4140
import org.eclipse.m2e.apt.internal.AnnotationProcessorConfiguration;
@@ -45,8 +44,6 @@
4544
import org.eclipse.m2e.apt.internal.processor.MavenProcessorJdtAptDelegate;
4645
import org.eclipse.m2e.apt.internal.utils.PluginDependencyResolver;
4746
import org.eclipse.m2e.apt.internal.utils.ProjectUtils;
48-
import org.eclipse.m2e.core.MavenPlugin;
49-
import org.eclipse.m2e.core.embedder.IMaven;
5047
import org.eclipse.m2e.core.internal.markers.IMavenMarkerManager;
5148
import org.eclipse.m2e.core.internal.markers.MavenProblemInfo;
5249
import org.eclipse.m2e.core.internal.markers.SourceLocation;
@@ -118,46 +115,44 @@ public boolean isIgnored(IProgressMonitor monitor) {
118115
@Override
119116
protected AnnotationProcessorConfiguration getAnnotationProcessorConfiguration(IProgressMonitor monitor)
120117
throws CoreException {
121-
IMaven maven = MavenPlugin.getMaven();
122118
markerManager.deleteMarkers(mavenFacade.getProject(), true, IMavenAptConstants.INVALID_ARGUMENT_MARKER_ID);
123-
MavenProject mavenProject = mavenFacade.getMavenProject(monitor);
124119
File generatedTestOutputDirectory = null;
125120
for(MojoExecution mojoExecution : mavenFacade.getMojoExecutions(COMPILER_PLUGIN_GROUP_ID,
126121
COMPILER_PLUGIN_ARTIFACT_ID, monitor, GOAL_TEST_COMPILE)) {
127-
generatedTestOutputDirectory = maven.getMojoParameterValue(mavenProject, mojoExecution,
122+
generatedTestOutputDirectory = mavenFacade.getMojoParameterValue(mojoExecution,
128123
TEST_OUTPUT_DIRECTORY_PARAMETER, File.class, monitor);
129124
}
130125
for(MojoExecution mojoExecution : mavenFacade.getMojoExecutions(COMPILER_PLUGIN_GROUP_ID,
131126
COMPILER_PLUGIN_ARTIFACT_ID, monitor, GOAL_COMPILE)) {
132-
File generatedOutputDirectory = maven.getMojoParameterValue(mavenProject, mojoExecution,
127+
File generatedOutputDirectory = mavenFacade.getMojoParameterValue(mojoExecution,
133128
OUTPUT_DIRECTORY_PARAMETER, File.class, monitor);
134129

135130
Map<String, String> options = new HashMap<>();
136131

137132
@SuppressWarnings("unchecked")
138-
Map<String, String> compilerArguments = maven.getMojoParameterValue(mavenProject, mojoExecution,
133+
Map<String, String> compilerArguments = mavenFacade.getMojoParameterValue(mojoExecution,
139134
"compilerArguments", Map.class, monitor);
140135
options.putAll(extractProcessorOptions(compilerArguments));
141136

142137
// the single compiler argument takes precedence in maven-compiler-plugin
143-
String compilerArgument = maven.getMojoParameterValue(mavenProject, mojoExecution, "compilerArgument",
138+
String compilerArgument = mavenFacade.getMojoParameterValue(mojoExecution, "compilerArgument",
144139
String.class, monitor);
145140
options.putAll(parseProcessorOptions(compilerArgument));
146141

147142
@SuppressWarnings("unchecked")
148-
List<String> compilerArgs = maven.getMojoParameterValue(mavenProject, mojoExecution, "compilerArgs", List.class,
143+
List<String> compilerArgs = mavenFacade.getMojoParameterValue(mojoExecution, "compilerArgs", List.class,
149144
monitor);
150145
options.putAll(ProjectUtils.parseProcessorOptions(compilerArgs));
151146

152147
sanitizeOptionNames(options.keySet(), mojoExecution);
153148

154149
boolean isAnnotationProcessingEnabled = (compilerArgument == null) || !compilerArgument.contains("-proc:none");
155150
if(isAnnotationProcessingEnabled) {
156-
String proc = maven.getMojoParameterValue(mavenProject, mojoExecution, "proc", String.class, monitor);
151+
String proc = mavenFacade.getMojoParameterValue(mojoExecution, "proc", String.class, monitor);
157152
isAnnotationProcessingEnabled = !"none".equals(proc);
158153
}
159154

160-
Dependency[] annotationProcessorPaths = maven.getMojoParameterValue(mavenProject, mojoExecution,
155+
Dependency[] annotationProcessorPaths = mavenFacade.getMojoParameterValue(mojoExecution,
161156
"annotationProcessorPaths", Dependency[].class, monitor);
162157

163158
boolean hasAnnotationProcessorPaths = annotationProcessorPaths.length > 0;

org.eclipse.m2e.apt.core/src/org/eclipse/m2e/apt/internal/processor/MavenProcessorBuildParticipant.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,9 @@
2727
import org.codehaus.plexus.util.Scanner;
2828

2929
import org.apache.maven.plugin.MojoExecution;
30-
import org.apache.maven.project.MavenProject;
3130

3231
import org.sonatype.plexus.build.incremental.BuildContext;
3332

34-
import org.eclipse.m2e.core.MavenPlugin;
35-
import org.eclipse.m2e.core.embedder.IMaven;
3633
import org.eclipse.m2e.core.project.IMavenProjectFacade;
3734
import org.eclipse.m2e.core.project.configurator.MojoExecutionBuildParticipant;
3835

@@ -58,11 +55,10 @@ public Set<IProject> build(int kind, IProgressMonitor monitor) throws Exception
5855

5956
//Modifying the pom triggers a build, otherwise, check for java source modifications
6057
IMavenProjectFacade mavenFacade = getMavenProjectFacade();
61-
MavenProject mavenProject = mavenFacade.getMavenProject();
6258
if(!buildContext.hasDelta(mavenFacade.getPomFile())) {
6359

6460
// check if any of the java files changed
65-
File source = getFileParameter(MavenProcessorJdtAptDelegate.SOURCE_DIRECTORY_PARAMETER, mavenProject);
61+
File source = getFileParameter(MavenProcessorJdtAptDelegate.SOURCE_DIRECTORY_PARAMETER, mavenFacade);
6662
Scanner ds = buildContext.newScanner(source); // delta or full scanner
6763
ds.scan();
6864
String[] includedFiles = ds.getIncludedFiles();
@@ -77,9 +73,9 @@ public Set<IProject> build(int kind, IProgressMonitor monitor) throws Exception
7773
Set<IProject> result = super.build(kind, monitor);
7874

7975
// tell m2e builder to refresh generated files
80-
File generated = getFileParameter(MavenProcessorJdtAptDelegate.OUTPUT_DIRECTORY_PARAMETER, mavenProject);
76+
File generated = getFileParameter(MavenProcessorJdtAptDelegate.OUTPUT_DIRECTORY_PARAMETER, mavenFacade);
8177
if(generated == null) {
82-
generated = getFileParameter(MavenProcessorJdtAptDelegate.DEFAULT_OUTPUT_DIRECTORY_PARAMETER, mavenProject);
78+
generated = getFileParameter(MavenProcessorJdtAptDelegate.DEFAULT_OUTPUT_DIRECTORY_PARAMETER, mavenFacade);
8379
}
8480
if(generated != null) {
8581
buildContext.refresh(generated);
@@ -88,8 +84,7 @@ public Set<IProject> build(int kind, IProgressMonitor monitor) throws Exception
8884
return result;
8985
}
9086

91-
private File getFileParameter(String propertyId, MavenProject mavenProject) throws CoreException {
92-
IMaven maven = MavenPlugin.getMaven();
93-
return maven.getMojoParameterValue(mavenProject, getMojoExecution(), propertyId, File.class, null);
87+
private File getFileParameter(String propertyId, IMavenProjectFacade mavenFacade) throws CoreException {
88+
return mavenFacade.getMojoParameterValue(getMojoExecution(), propertyId, File.class, null);
9489
}
9590
}

org.eclipse.m2e.core/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %Bundle-Name
44
Bundle-SymbolicName: org.eclipse.m2e.core;singleton:=true
5-
Bundle-Version: 2.7.900.qualifier
5+
Bundle-Version: 2.8.0.qualifier
66
Bundle-Activator: org.eclipse.m2e.core.internal.MavenPluginActivator
77
Bundle-Vendor: %Bundle-Vendor
88
Bundle-Localization: plugin

org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMaven.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,21 @@ MojoExecution setupMojoExecution(MavenProject project, MojoExecution execution,
170170
* @return the parameter value or {@code null} if the parameter with the given name was not found
171171
* @throws CoreException
172172
* @since 1.4
173+
* @deprecated use
174+
* {@link IMavenProjectFacade#getMojoParameterValue(MojoExecution, String, Class, IProgressMonitor)}
175+
* instead to avoid a direct dependency on {@link MavenProject}
173176
*/
177+
@Deprecated
174178
<T> T getMojoParameterValue(MavenProject project, MojoExecution mojoExecution, String parameter,
175179
Class<T> asType, IProgressMonitor monitor) throws CoreException;
176180

177181
/**
178182
* @since 1.4
183+
* @deprecated use
184+
* {@link IMavenProjectFacade#getMojoParameterValue(String, Class, Plugin, ConfigurationContainer, String, IProgressMonitor)}
185+
* instead to avoid a direct dependency on {@link MavenProject}
179186
*/
187+
@Deprecated
180188
<T> T getMojoParameterValue(MavenProject project, String parameter, Class<T> type, Plugin plugin,
181189
ConfigurationContainer configuration, String goal, IProgressMonitor monitor) throws CoreException;
182190

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
import org.apache.maven.lifecycle.DefaultLifecycles;
4444
import org.apache.maven.lifecycle.MavenExecutionPlan;
4545
import org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator;
46+
import org.apache.maven.model.ConfigurationContainer;
47+
import org.apache.maven.model.Plugin;
4648
import org.apache.maven.plugin.MojoExecution;
4749
import org.apache.maven.project.MavenProject;
4850

@@ -584,6 +586,21 @@ public List<MojoExecution> getMojoExecutions(String groupId, String artifactId,
584586
return result;
585587
}
586588

589+
@Override
590+
@SuppressWarnings("deprecation")
591+
public <T> T getMojoParameterValue(MojoExecution mojoExecution, String parameter, Class<T> asType,
592+
IProgressMonitor monitor) throws CoreException {
593+
return manager.maven.getMojoParameterValue(getMavenProject(monitor), mojoExecution, parameter, asType, monitor);
594+
}
595+
596+
@Override
597+
@SuppressWarnings("deprecation")
598+
public <T> T getMojoParameterValue(String parameter, Class<T> type, Plugin plugin,
599+
ConfigurationContainer configuration, String goal, IProgressMonitor monitor) throws CoreException {
600+
return manager.maven.getMojoParameterValue(getMavenProject(monitor), parameter, type, plugin, configuration, goal,
601+
monitor);
602+
}
603+
587604
/**
588605
* Returns cached list of MojoExecutions bound to project's clean, default and site lifecycles. Returned
589606
* MojoExecutions are not fully setup and {@link IMaven#setupMojoExecution(MavenSession, MavenProject, MojoExecution)}

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import org.eclipse.core.runtime.IProgressMonitor;
2727

2828
import org.apache.maven.lifecycle.MavenExecutionPlan;
29+
import org.apache.maven.model.ConfigurationContainer;
30+
import org.apache.maven.model.Plugin;
2931
import org.apache.maven.plugin.MojoExecution;
3032
import org.apache.maven.project.MavenProject;
3133

@@ -174,6 +176,40 @@ MojoExecution getMojoExecution(MojoExecutionKey mojoExecutionKey, IProgressMonit
174176
List<MojoExecution> getMojoExecutions(String groupId, String artifactId, IProgressMonitor monitor,
175177
String... goals) throws CoreException;
176178

179+
/**
180+
* Resolves a configuration parameter from the given {@code mojoExecution}. It coerces from String to the given type
181+
* and considers expressions and default values.
182+
*
183+
* @param <T>
184+
* @param mojoExecution the mojo execution from which to retrieve the configuration value
185+
* @param parameter the name of the parameter (may be nested with separating {@code .})
186+
* @param asType the type to coerce to
187+
* @param monitor the progress monitor
188+
* @return the parameter value or {@code null} if the parameter with the given name was not found
189+
* @throws CoreException
190+
* @since 2.8
191+
*/
192+
<T> T getMojoParameterValue(MojoExecution mojoExecution, String parameter, Class<T> asType,
193+
IProgressMonitor monitor) throws CoreException;
194+
195+
/**
196+
* Resolves a configuration parameter for the given {@code plugin}/{@code goal} combination. It coerces from String to
197+
* the given type and considers expressions and default values.
198+
*
199+
* @param <T>
200+
* @param parameter the name of the parameter (may be nested with separating {@code .})
201+
* @param type the type to coerce to
202+
* @param plugin the plugin declaring the parameter
203+
* @param configuration the configuration to look up the parameter value in
204+
* @param goal the goal of the plugin execution
205+
* @param monitor the progress monitor
206+
* @return the parameter value or {@code null} if the parameter with the given name was not found
207+
* @throws CoreException
208+
* @since 2.8
209+
*/
210+
<T> T getMojoParameterValue(String parameter, Class<T> type, Plugin plugin, ConfigurationContainer configuration,
211+
String goal, IProgressMonitor monitor) throws CoreException;
212+
177213
// lifecycle mapping
178214

179215
String getLifecycleMappingId();

org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/AbstractProjectConfigurator.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,10 @@ public static void addNature(IProject project, String natureId, int updateFlags,
178178

179179
/**
180180
* @since 1.4
181+
* @deprecated use {@link #getParameterValue(IMavenProjectFacade, String, Class, MojoExecution, IProgressMonitor)}
182+
* instead to avoid a direct dependency on {@link MavenProject}
181183
*/
184+
@Deprecated
182185
protected <T> T getParameterValue(MavenProject project, String parameter, Class<T> asType,
183186
MojoExecution mojoExecution, IProgressMonitor monitor) throws CoreException {
184187
PluginExecution execution = new PluginExecution();
@@ -187,6 +190,17 @@ protected <T> T getParameterValue(MavenProject project, String parameter, Class<
187190
mojoExecution.getGoal(), monitor);
188191
}
189192

193+
/**
194+
* @since 2.8
195+
*/
196+
protected <T> T getParameterValue(IMavenProjectFacade projectFacade, String parameter, Class<T> asType,
197+
MojoExecution mojoExecution, IProgressMonitor monitor) throws CoreException {
198+
PluginExecution execution = new PluginExecution();
199+
execution.setConfiguration(mojoExecution.getConfiguration());
200+
return projectFacade.getMojoParameterValue(parameter, asType, mojoExecution.getPlugin(), execution,
201+
mojoExecution.getGoal(), monitor);
202+
}
203+
190204
protected void assertHasNature(IProject project, String natureId) throws CoreException {
191205
if(project.getNature(natureId) == null) {
192206
throw new CoreException(Status.error(Messages.AbstractProjectConfigurator_error_missing_nature + ' ' + natureId));

0 commit comments

Comments
 (0)