Skip to content

Commit 2e1aff1

Browse files
committed
Use enhanced Mojo-Configuration methods
1 parent 0dda8e4 commit 2e1aff1

File tree

4 files changed

+63
-76
lines changed

4 files changed

+63
-76
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
import org.eclipse.m2e.core.MavenPlugin;
3737
import org.eclipse.m2e.core.embedder.IMaven;
38+
import org.eclipse.m2e.core.embedder.IMaven.ConfigurationElement;
39+
import org.eclipse.m2e.core.embedder.IMaven.ConfigurationParameter;
3840
import org.eclipse.m2e.core.project.IMavenProjectFacade;
3941
import org.eclipse.m2e.core.project.configurator.MojoExecutionBuildParticipant;
4042

@@ -64,12 +66,13 @@ public Set<IProject> build(int kind, IProgressMonitor monitor) throws Exception
6466
//TODO check delta / scan source for *.java
6567
IMavenProjectFacade mavenProjectFacade = getMavenProjectFacade();
6668
MavenProject project = mavenProjectFacade.getMavenProject();
67-
String compilerArgument = maven.getMojoParameterValue(project, mojoExecution, "compilerArgument", String.class,
68-
null);
69-
boolean isAnnotationProcessingEnabled = (compilerArgument == null) || !compilerArgument.contains("-proc:none");
69+
ConfigurationElement config = maven.getMojoConfiguration(project, mojoExecution, null);
70+
ConfigurationParameter compilerArgumentConfig = config.get("compilerArgument");
71+
boolean isAnnotationProcessingEnabled = !compilerArgumentConfig.exists()
72+
|| !compilerArgumentConfig.as(String.class).contains("-proc:none");
7073
if(isAnnotationProcessingEnabled) {
71-
String proc = maven.getMojoParameterValue(project, mojoExecution, PROC, String.class, null);
72-
isAnnotationProcessingEnabled = !"none".equals(proc);
74+
ConfigurationParameter procConfig = config.get(PROC);
75+
isAnnotationProcessingEnabled = !procConfig.exists() || !"none".equals(procConfig.as(String.class));
7376
}
7477
if(!isAnnotationProcessingEnabled) {
7578
return Collections.emptySet();
@@ -112,8 +115,7 @@ public Set<IProject> build(int kind, IProgressMonitor monitor) throws Exception
112115
}
113116

114117
// tell m2e builder to refresh generated files
115-
File generated = maven.getMojoParameterValue(project, getMojoExecution(),
116-
MavenCompilerJdtAptDelegate.OUTPUT_DIRECTORY_PARAMETER, File.class, null);
118+
File generated = maven.getMojoConfiguration(project, getMojoExecution(), null).get(MavenCompilerJdtAptDelegate.OUTPUT_DIRECTORY_PARAMETER).as(File.class);
117119
if(generated != null) {
118120
buildContext.refresh(generated);
119121
}

org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import java.util.List;
3939
import java.util.ListIterator;
4040
import java.util.Map;
41-
import java.util.Map.Entry;
4241
import java.util.Objects;
4342
import java.util.Set;
4443
import java.util.jar.JarFile;
@@ -83,6 +82,8 @@
8382

8483
import org.eclipse.m2e.core.MavenPlugin;
8584
import org.eclipse.m2e.core.embedder.IMaven;
85+
import org.eclipse.m2e.core.embedder.IMaven.ConfigurationElement;
86+
import org.eclipse.m2e.core.embedder.IMaven.ConfigurationParameter;
8687
import org.eclipse.m2e.core.internal.IMavenConstants;
8788
import org.eclipse.m2e.core.internal.MavenPluginActivator;
8889
import org.eclipse.m2e.core.internal.Messages;
@@ -705,14 +706,13 @@ private static List<PluginExecutionMetadata> applyParametersFilter(List<PluginEx
705706
private static boolean hasMatchingParameterValue(MavenProject mavenProject, MojoExecution execution,
706707
PluginExecutionMetadata metadata, IMaven maven, IProgressMonitor monitor) throws CoreException {
707708
Map<String, Object> parameters = metadata.getFilter().getParameters();
708-
for(Entry<String, Object> entry : parameters.entrySet()) {
709-
MojoExecution setupExecution = maven.setupMojoExecution(mavenProject, execution, monitor);
710-
String value = maven.getMojoParameterValue(mavenProject, setupExecution, entry.getKey(), String.class, monitor);
711-
if(!Objects.equals(entry.getValue(), value)) {
712-
return false;
713-
}
714-
}
715-
return true;
709+
MojoExecution setupExecution = maven.setupMojoExecution(mavenProject, execution, monitor);
710+
ConfigurationElement mojoConfig = maven.getMojoConfiguration(mavenProject, setupExecution, monitor);
711+
712+
return parameters.entrySet().stream().allMatch(e -> {
713+
ConfigurationParameter parameter = mojoConfig.get(e.getKey());
714+
return parameter.exists() && Objects.equals(parameter.as(String.class), e.getValue());
715+
});
716716
}
717717

718718
private static boolean isValidPluginExecutionMetadata(PluginExecutionMetadata metadata) {

org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java

Lines changed: 38 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
import org.apache.maven.project.MavenProject;
5656

5757
import org.eclipse.m2e.core.MavenPlugin;
58+
import org.eclipse.m2e.core.embedder.IMaven.ConfigurationElement;
59+
import org.eclipse.m2e.core.embedder.IMaven.ConfigurationParameter;
5860
import org.eclipse.m2e.core.internal.M2EUtils;
5961
import org.eclipse.m2e.core.project.IMavenProjectFacade;
6062
import org.eclipse.m2e.core.project.IProjectConfigurationManager;
@@ -311,57 +313,41 @@ protected void addProjectSourceFolders(IClasspathDescriptor classpath, Map<Strin
311313
IPath[] inclusionTest = new IPath[0];
312314
IPath[] exclusionTest = new IPath[0];
313315

314-
String mainSourceEncoding = null;
315-
String testSourceEncoding = null;
316+
ConfigurationParameter mainSourceEncoding = null;
317+
ConfigurationParameter testSourceEncoding = null;
316318

317319
String mainResourcesEncoding = null;
318320
String testResourcesEncoding = null;
319321

320322
List<MojoExecution> executions = getCompilerMojoExecutions(request, mon.newChild(1));
321323
for(MojoExecution compile : executions) {
322324
if(isCompileExecution(compile, mavenProject, options, monitor)) {
323-
mainSourceEncoding = maven.getMojoParameterValue(mavenProject, compile, "encoding", String.class, monitor); //$NON-NLS-1$
324-
try {
325-
inclusion = toPaths(
326-
maven.getMojoParameterValue(mavenProject, compile, "includes", String[].class, monitor)); //$NON-NLS-1$
327-
} catch(CoreException ex) {
328-
log.error("Failed to determine compiler inclusions, assuming defaults", ex);
329-
}
330-
try {
331-
exclusion = toPaths(
332-
maven.getMojoParameterValue(mavenProject, compile, "excludes", String[].class, monitor)); //$NON-NLS-1$
333-
} catch(CoreException ex) {
334-
log.error("Failed to determine compiler exclusions, assuming defaults", ex);
335-
}
325+
ConfigurationElement mojoConfig = maven.getMojoConfiguration(mavenProject, compile, monitor);
326+
mainSourceEncoding = mojoConfig.get("encoding"); //$NON-NLS-1$
327+
inclusion = toPaths(mojoConfig.get("includes")); //$NON-NLS-1$
328+
exclusion = toPaths(mojoConfig.get("excludes")); //$NON-NLS-1$
336329
}
337330
}
338331

339332
for(MojoExecution compile : executions) {
340333
if(isTestCompileExecution(compile, mavenProject, options, monitor)) {
341-
testSourceEncoding = maven.getMojoParameterValue(mavenProject, compile, "encoding", String.class, monitor); //$NON-NLS-1$
342-
try {
343-
inclusionTest = toPaths(
344-
maven.getMojoParameterValue(mavenProject, compile, "testIncludes", String[].class, monitor)); //$NON-NLS-1$
345-
} catch(CoreException ex) {
346-
log.error("Failed to determine compiler test inclusions, assuming defaults", ex);
347-
}
348-
try {
349-
exclusionTest = toPaths(
350-
maven.getMojoParameterValue(mavenProject, compile, "testExcludes", String[].class, monitor)); //$NON-NLS-1$
351-
} catch(CoreException ex) {
352-
log.error("Failed to determine compiler test exclusions, assuming defaults", ex);
353-
}
334+
ConfigurationElement mojoConfiguration = maven.getMojoConfiguration(mavenProject, compile, monitor);
335+
testSourceEncoding = mojoConfiguration.get("encoding");
336+
inclusionTest = toPaths(mojoConfiguration.get("testIncludes")); //$NON-NLS-1$
337+
exclusionTest = toPaths(mojoConfiguration.get("testExcludes")); //$NON-NLS-1$
354338
}
355339
}
356340

357341
for(MojoExecution resources : projectFacade.getMojoExecutions(RESOURCES_PLUGIN_GROUP_ID,
358342
RESOURCES_PLUGIN_ARTIFACT_ID, mon.newChild(1), GOAL_RESOURCES)) {
359-
mainResourcesEncoding = maven.getMojoParameterValue(mavenProject, resources, "encoding", String.class, monitor); //$NON-NLS-1$
343+
mainResourcesEncoding = maven.getMojoConfiguration(mavenProject, resources, monitor).get("encoding") //$NON-NLS-1$
344+
.as(String.class);
360345
}
361346

362347
for(MojoExecution resources : projectFacade.getMojoExecutions(RESOURCES_PLUGIN_GROUP_ID,
363348
RESOURCES_PLUGIN_ARTIFACT_ID, mon.newChild(1), GOAL_TESTRESOURCES)) {
364-
testResourcesEncoding = maven.getMojoParameterValue(mavenProject, resources, "encoding", String.class, monitor); //$NON-NLS-1$
349+
testResourcesEncoding = maven.getMojoConfiguration(mavenProject, resources, monitor).get("encoding") //$NON-NLS-1$
350+
.as(String.class);
365351
}
366352
addSourceDirs(classpath, project, mavenProject.getCompileSourceRoots(), classes.getFullPath(), inclusion,
367353
exclusion, mainSourceEncoding, mon.newChild(1), false);
@@ -391,16 +377,16 @@ protected boolean isCompileExecution(MojoExecution execution, MavenProject maven
391377

392378
private boolean isCompliant(MojoExecution execution, MavenProject mavenProject, Map<String, String> options,
393379
IProgressMonitor monitor) throws CoreException {
394-
String release = maven.getMojoParameterValue(mavenProject, execution, "release", String.class, monitor); //$NON-NLS-1$
380+
String release = maven.getMojoConfiguration(mavenProject, execution, monitor).get("release").as(String.class); //$NON-NLS-1$
395381
if(release != null && !sanitizeJavaVersion(release).equals(options.get(JavaCore.COMPILER_COMPLIANCE))) {
396382
return false;
397383
}
398384
if(release == null) {
399-
String source = maven.getMojoParameterValue(mavenProject, execution, "source", String.class, monitor); //$NON-NLS-1$
385+
String source = maven.getMojoConfiguration(mavenProject, execution, monitor).get("source").as(String.class); //$NON-NLS-1$
400386
if(source != null && !sanitizeJavaVersion(source).equals(options.get(JavaCore.COMPILER_SOURCE))) {
401387
return false;
402388
}
403-
String target = maven.getMojoParameterValue(mavenProject, execution, "target", String.class, monitor); //$NON-NLS-1$
389+
String target = maven.getMojoConfiguration(mavenProject, execution, monitor).get("target").as(String.class); //$NON-NLS-1$
404390
if(target != null
405391
&& !sanitizeJavaVersion(target).equals(options.get(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM))) {
406392
return false;
@@ -409,22 +395,17 @@ private boolean isCompliant(MojoExecution execution, MavenProject mavenProject,
409395
return true;
410396
}
411397

412-
private IPath[] toPaths(String[] values) {
413-
if(values == null) {
398+
private IPath[] toPaths(ConfigurationParameter configParameter) {
399+
if(!configParameter.exists()) {
414400
return new IPath[0];
415401
}
416-
IPath[] paths = new IPath[values.length];
417-
for(int i = 0; i < values.length; i++ ) {
418-
if(values[i] != null && !"".equals(values[i].trim())) {
419-
paths[i] = new Path(values[i]);
420-
}
421-
}
422-
return paths;
402+
return Arrays.stream(configParameter.as(String[].class)).filter(v -> v != null && !v.isBlank()).map(Path::new)
403+
.toArray(Path[]::new);
423404
}
424405

425406
private void addSourceDirs(IClasspathDescriptor classpath, IProject project, List<String> sourceRoots,
426-
IPath outputPath, IPath[] inclusion, IPath[] exclusion, String sourceEncoding, IProgressMonitor monitor,
427-
boolean addTestFlag) throws CoreException {
407+
IPath outputPath, IPath[] inclusion, IPath[] exclusion, ConfigurationParameter sourceEncoding,
408+
IProgressMonitor monitor, boolean addTestFlag) throws CoreException {
428409

429410
for(String sourceRoot : sourceRoots) {
430411
IFolder sourceFolder = getFolder(project, sourceRoot);
@@ -445,7 +426,7 @@ private void addSourceDirs(IClasspathDescriptor classpath, IProject project, Lis
445426

446427
// Set folder encoding (null = platform/container default)
447428
if(sourceFolder.exists()) {
448-
sourceFolder.setDefaultCharset(sourceEncoding, monitor);
429+
sourceFolder.setDefaultCharset(sourceEncoding.exists() ? sourceEncoding.as(String.class) : null, monitor);
449430
}
450431

451432
IClasspathEntryDescriptor enclosing = getEnclosingEntryDescriptor(classpath, sourceFolder.getFullPath());
@@ -619,8 +600,8 @@ protected void addJavaProjectOptions(Map<String, String> options, ProjectConfigu
619600
|| isEnablePreviewFeatures(request.mavenProject(), execution, monitor);
620601

621602
// process -err:+deprecation , -warn:-serial ...
622-
for(Object o : maven.getMojoParameterValue(request.mavenProject(), execution, "compilerArgs", List.class,
623-
monitor)) {
603+
for(Object o : maven.getMojoConfiguration(request.mavenProject(), execution, monitor).get("compilerArgs")
604+
.as(List.class)) {
624605
if(o instanceof String compilerArg) {
625606
boolean err = false/*, warn = false*/;
626607
String[] settings = new String[0];
@@ -706,15 +687,16 @@ private boolean isGenerateParameters(MavenProject mavenProject, MojoExecution ex
706687
Boolean generateParameters = null;
707688
//1st, check the parameters option
708689
try {
709-
generateParameters = maven.getMojoParameterValue(mavenProject, execution, "parameters", Boolean.class, monitor);//$NON-NLS-1$
690+
generateParameters = maven.getMojoConfiguration(mavenProject, execution, monitor).get("parameters") //$NON-NLS-1$
691+
.as(Boolean.class);
710692
} catch(Exception ex) {
711693
//ignore
712694
}
713695

714696
//2nd, check the parameters flag in the compilerArgs list
715697
if(!Boolean.TRUE.equals(generateParameters)) {
716698
try {
717-
List<?> args = maven.getMojoParameterValue(mavenProject, execution, "compilerArgs", List.class, monitor);//$NON-NLS-1$
699+
List<?> args = maven.getMojoConfiguration(mavenProject, execution, monitor).get("compilerArgs").as(List.class);//$NON-NLS-1$
718700
if(args != null) {
719701
generateParameters = args.contains(JavaSettingsUtils.PARAMETERS_JVM_FLAG);
720702
}
@@ -726,8 +708,8 @@ private boolean isGenerateParameters(MavenProject mavenProject, MojoExecution ex
726708
//3rd, check the parameters flag in the compilerArgument String
727709
if(!Boolean.TRUE.equals(generateParameters)) {
728710
try {
729-
String compilerArgument = maven.getMojoParameterValue(mavenProject, execution, "compilerArgument", String.class, //$NON-NLS-1$
730-
monitor);
711+
String compilerArgument = maven.getMojoConfiguration(mavenProject, execution, monitor).get("compilerArgument")
712+
.as(String.class);
731713
if(compilerArgument != null) {
732714
generateParameters = compilerArgument.contains(JavaSettingsUtils.PARAMETERS_JVM_FLAG);
733715
}
@@ -743,7 +725,7 @@ private boolean isEnablePreviewFeatures(MavenProject mavenProject, MojoExecution
743725
IProgressMonitor monitor) {
744726
//1st, check the --enable-preview flag in the compilerArgs list
745727
try {
746-
List<?> args = maven.getMojoParameterValue(mavenProject, execution, "compilerArgs", List.class, monitor);//$NON-NLS-1$
728+
List<?> args = maven.getMojoConfiguration(mavenProject, execution, monitor).get("compilerArgs").as(List.class);//$NON-NLS-1$
747729
if(args != null && args.contains(JavaSettingsUtils.ENABLE_PREVIEW_JVM_FLAG)) {
748730
return true;
749731
}
@@ -753,8 +735,8 @@ private boolean isEnablePreviewFeatures(MavenProject mavenProject, MojoExecution
753735

754736
//2nd, check the --enable-preview flag in the compilerArgument String
755737
try {
756-
String compilerArgument = maven.getMojoParameterValue(mavenProject, execution, "compilerArgument", String.class, //$NON-NLS-1$
757-
monitor);
738+
String compilerArgument = maven.getMojoConfiguration(mavenProject, execution, monitor).get("compilerArgument")
739+
.as(String.class);
758740
if(compilerArgument != null && compilerArgument.contains(JavaSettingsUtils.ENABLE_PREVIEW_JVM_FLAG)) {
759741
return true;
760742
}
@@ -804,7 +786,7 @@ private String getCompilerLevel(MavenProject mavenProject, MojoExecution executi
804786
int levelIdx = getLevelIndex(source, levels);
805787

806788
try {
807-
source = maven.getMojoParameterValue(mavenProject, execution, parameter, String.class, monitor);
789+
source = maven.getMojoConfiguration(mavenProject, execution, monitor).get(parameter).as(String.class);
808790
} catch(CoreException ex) {
809791
log.error("Failed to determine compiler " + parameter + " setting, assuming default", ex);
810792
}
@@ -958,7 +940,7 @@ private List<String> getCompilerArguments(MavenProject mavenProject, MojoExecuti
958940

959941
//1st, get the arguments in the compilerArgs list
960942
try {
961-
List<?> args = maven.getMojoParameterValue(mavenProject, execution, "compilerArgs", List.class, monitor);//$NON-NLS-1$
943+
List<?> args = maven.getMojoConfiguration(mavenProject, execution, monitor).get("compilerArgs").as(List.class);//$NON-NLS-1$
962944
if(args != null) {//$NON-NLS-1$
963945
args.stream().filter(a -> a != null).forEach(a -> arguments.add(a.toString()));
964946
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.eclipse.core.runtime.IProgressMonitor;
2323
import org.eclipse.m2e.core.MavenPlugin;
2424
import org.eclipse.m2e.core.embedder.IMaven;
25+
import org.eclipse.m2e.core.embedder.IMaven.ConfigurationParameter;
2526
import org.eclipse.m2e.core.internal.IMavenConstants;
2627
import org.eclipse.m2e.core.internal.markers.IMavenMarkerManager;
2728
import org.eclipse.m2e.core.internal.markers.MavenProblemInfo;
@@ -67,9 +68,10 @@ public void configure(ProjectConfigurationRequest request, IProgressMonitor moni
6768
if (isFelix(plugin)) {
6869
if (isFelixManifestGoal(execution)) {
6970
IMaven maven = MavenPlugin.getMaven();
70-
Boolean supportIncremental = maven.getMojoParameterValue(request.mavenProject(), execution,
71-
FELIX_PARAM_SUPPORTINCREMENTALBUILD, Boolean.class, monitor);
72-
if (supportIncremental == null || !supportIncremental.booleanValue()) {
71+
ConfigurationParameter incrementalBuildConfig = maven
72+
.getMojoConfiguration(request.mavenProject(), execution, monitor)
73+
.get(FELIX_PARAM_SUPPORTINCREMENTALBUILD);
74+
if (!incrementalBuildConfig.exists() || !incrementalBuildConfig.as(Boolean.class).booleanValue()) {
7375
createWarningMarker(request, execution, SourceLocationHelper.CONFIGURATION,
7476
"Incremental updates are currently disabled, set supportIncrementalBuild=true to support automatic manifest updates for this project.");
7577
}
@@ -138,7 +140,8 @@ private IPath getMetainfPath(IMavenProjectFacade facade, List<MojoExecution> exe
138140
Plugin plugin = execution.getPlugin();
139141
MavenProject project = facade.getMavenProject(monitor);
140142
String manifestParameter = isBND(plugin) ? BND_PARAM_MANIFESTLOCATION : FELIX_PARAM_MANIFESTLOCATION;
141-
File location = maven.getMojoParameterValue(project, execution, manifestParameter, File.class, monitor);
143+
File location = maven.getMojoConfiguration(project, execution, monitor).get(manifestParameter)
144+
.as(File.class);
142145
if (location != null) {
143146
return facade.getProjectRelativePath(location.getAbsolutePath());
144147
}

0 commit comments

Comments
 (0)