diff options
author | Fred Bricon | 2017-09-11 22:46:46 +0000 |
---|---|---|
committer | Fred Bricon | 2017-09-13 18:31:16 +0000 |
commit | 2f1326cfb184ac532eede28160d8bea4d876f05c (patch) | |
tree | 26d74a76cdf8567b7c985c518d2f5a89a8d57d1a | |
parent | b86fc6ca7f7b5f2c3e81faef7e3d347da1110fdb (diff) | |
download | m2e-core-2f1326cfb184ac532eede28160d8bea4d876f05c.tar.gz m2e-core-2f1326cfb184ac532eede28160d8bea4d876f05c.tar.xz m2e-core-2f1326cfb184ac532eede28160d8bea4d876f05c.zip |
521638 : use <release> setting in maven-compiler-plugin, when converting a Java 9 project
Signed-off-by: Fred Bricon <fbricon@gmail.com>
-rw-r--r-- | org.eclipse.m2e.editor.xml/plugin.xml | 2 | ||||
-rw-r--r-- | org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JavaProjectConversionParticipant.java | 73 |
2 files changed, 49 insertions, 26 deletions
diff --git a/org.eclipse.m2e.editor.xml/plugin.xml b/org.eclipse.m2e.editor.xml/plugin.xml index bbceba08..2147f8cb 100644 --- a/org.eclipse.m2e.editor.xml/plugin.xml +++ b/org.eclipse.m2e.editor.xml/plugin.xml @@ -189,7 +189,7 @@ <pattern><plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> - <version>3.6.2</version> + <version>3.7.0</version> <configuration> <!-- http://maven.apache.org/plugins/maven-compiler-plugin/ --> <source>${cursor}1.8</source> diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JavaProjectConversionParticipant.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JavaProjectConversionParticipant.java index 688afb4e..53398299 100644 --- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JavaProjectConversionParticipant.java +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JavaProjectConversionParticipant.java @@ -11,6 +11,8 @@ package org.eclipse.m2e.jdt.internal; +import static org.apache.maven.shared.utils.StringUtils.isEmpty; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -80,14 +82,18 @@ public class JavaProjectConversionParticipant extends AbstractProjectConversionP private static final String COMPILER_ARTIFACT_ID = "maven-compiler-plugin"; //$NON-NLS-1$ - private static final String DEFAULT_COMPILER_VERSION = "3.6.2"; //$NON-NLS-1$ + private static final String DEFAULT_COMPILER_VERSION = "3.7.0"; //$NON-NLS-1$ private static final String TARGET_KEY = "target"; //$NON-NLS-1$ private static final String SOURCE_KEY = "source"; //$NON-NLS-1$ + private static final String RELEASE_KEY = "release"; //$NON-NLS-1$ + private static final String CONFIGURATION_KEY = "configuration"; //$NON-NLS-1$ + private static final String VERSION_9 = "9";//to be replaced by JavaCore.VERSION_9 + public boolean accept(IProject project) throws CoreException { boolean accepts = project != null && project.isAccessible() && project.hasNature(JavaCore.NATURE_ID); return accepts; @@ -109,7 +115,17 @@ public class JavaProjectConversionParticipant extends AbstractProjectConversionP //Read existing Eclipse compiler settings String source = javaProject.getOption(JavaCore.COMPILER_SOURCE, true); String target = javaProject.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true); + boolean emptySource = isEmpty(source); + boolean emptyTarget = isEmpty(target); + if(emptySource && emptyTarget) { + return; + } + if(emptySource) { + source = target; + } else if(emptyTarget) { + target = source; + } //We want to keep pom.xml configuration to a minimum so we rely on convention. If the java version == 1.5, //we shouldn't need to add anything as recent maven-compiler-plugin versions target Java 1.5 by default if(DEFAULT_JAVA_VERSION.equals(source) && DEFAULT_JAVA_VERSION.equals(target)) { @@ -132,22 +148,15 @@ public class JavaProjectConversionParticipant extends AbstractProjectConversionP properties = new Properties(); model.setProperties(properties); } - properties.setProperty("maven.compiler.source", source); //$NON-NLS-1$ - properties.setProperty("maven.compiler.target", target); //$NON-NLS-1$ + if(canUseReleaseProperty(source, target)) { + properties.setProperty("maven.compiler.release", source); //$NON-NLS-1$ + } else { + properties.setProperty("maven.compiler.source", source); //$NON-NLS-1$ + properties.setProperty("maven.compiler.target", target); //$NON-NLS-1$ + } } private void configureCompilerPlugin(Model model, String source, String target) { - boolean emptySource = source == null || source.isEmpty(); - boolean emptyTarget = target == null || target.isEmpty(); - - if(emptySource && emptyTarget) { - return; - } - if(emptySource) { - source = target; - } else if(emptyTarget) { - target = source; - } Build build = getOrCreateBuild(model); model.setBuild(build); @@ -159,22 +168,36 @@ public class JavaProjectConversionParticipant extends AbstractProjectConversionP compiler.setConfiguration(configuration); } - Xpp3Dom sourceDom = configuration.getChild(SOURCE_KEY); - if(sourceDom == null) { - sourceDom = new Xpp3Dom(SOURCE_KEY); - configuration.addChild(sourceDom); - } - sourceDom.setValue(source); + if(canUseReleaseProperty(source, target)) { + Xpp3Dom releaseDom = configuration.getChild(RELEASE_KEY); + if(releaseDom == null) { + releaseDom = new Xpp3Dom(RELEASE_KEY); + configuration.addChild(releaseDom); + } + releaseDom.setValue(source); + } else { + Xpp3Dom sourceDom = configuration.getChild(SOURCE_KEY); + if(sourceDom == null) { + sourceDom = new Xpp3Dom(SOURCE_KEY); + configuration.addChild(sourceDom); + } + sourceDom.setValue(source); - Xpp3Dom targetDom = configuration.getChild(TARGET_KEY); - if(targetDom == null) { - targetDom = new Xpp3Dom(TARGET_KEY); - configuration.addChild(targetDom); + Xpp3Dom targetDom = configuration.getChild(TARGET_KEY); + if(targetDom == null) { + targetDom = new Xpp3Dom(TARGET_KEY); + configuration.addChild(targetDom); + } + targetDom.setValue(target); } - targetDom.setValue(target); compiler.setConfiguration(configuration); } + private boolean canUseReleaseProperty(String source, String target) { + //source and target are guaranteed to be not null at this point + return source.equals(target) && source.compareTo(VERSION_9) >= 0; + } + private Plugin getOrCreateCompilerPlugin(Build build) { build.flushPluginMap();//We need to force the re-generation of the plugin map as it may be stale Plugin compiler = build.getPluginsAsMap().get(COMPILER_GROUP_ID + ":" + COMPILER_ARTIFACT_ID); //$NON-NLS-1$ |