Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Bricon2019-03-21 12:40:43 -0400
committerFred Bricon2019-03-24 12:14:53 -0400
commit418cc9ddb0b803f084fd15e9ef47a94614e6beac (patch)
tree283ea018ef94cd789d8a8d0f08d4dd808cff772e /org.eclipse.m2e.jdt
parentf9561ce437eb0664c71b9a15092e439951536318 (diff)
downloadm2e-core-418cc9ddb0b803f084fd15e9ef47a94614e6beac.tar.gz
m2e-core-418cc9ddb0b803f084fd15e9ef47a94614e6beac.tar.xz
m2e-core-418cc9ddb0b803f084fd15e9ef47a94614e6beac.zip
Bug 545470: add required --enable-preview during conversion
Change-Id: If0cc8e489b8f0d461e6c4d89b2450dc703506dc3 Signed-off-by: Fred Bricon <fbricon@gmail.com>
Diffstat (limited to 'org.eclipse.m2e.jdt')
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JavaProjectConversionParticipant.java33
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JavaSettingsUtils.java14
2 files changed, 42 insertions, 5 deletions
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 03cfd59c..baba097b 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
@@ -90,6 +90,8 @@ public class JavaProjectConversionParticipant extends AbstractProjectConversionP
private static final String RELEASE_KEY = "release"; //$NON-NLS-1$
+ private static final String COMPILER_ARGS_KEY = "compilerArgs"; //$NON-NLS-1$
+
private static final String CONFIGURATION_KEY = "configuration"; //$NON-NLS-1$
private static final float VERSION_9 = 9.0f;
@@ -113,8 +115,9 @@ public class JavaProjectConversionParticipant extends AbstractProjectConversionP
configureBuildSourceDirectories(model, javaProject);
//Read existing Eclipse compiler settings
- String source = javaProject.getOption(JavaCore.COMPILER_SOURCE, true);
- String target = javaProject.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true);
+ Map<String, String> options = javaProject.getOptions(true);
+ String source = options.get(JavaCore.COMPILER_SOURCE);
+ String target = options.get(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM);
boolean emptySource = isEmpty(source);
boolean emptyTarget = isEmpty(target);
@@ -137,7 +140,7 @@ public class JavaProjectConversionParticipant extends AbstractProjectConversionP
if(useProperties) {
configureProperties(model, source, target);
} else {
- configureCompilerPlugin(model, source, target);
+ configureCompilerPlugin(model, source, target, JavaSettingsUtils.hasPreviewFeatures(javaProject));
}
}
@@ -156,7 +159,7 @@ public class JavaProjectConversionParticipant extends AbstractProjectConversionP
}
}
- private void configureCompilerPlugin(Model model, String source, String target) {
+ private void configureCompilerPlugin(Model model, String source, String target, boolean usesPreviewFeatures) {
Build build = getOrCreateBuild(model);
model.setBuild(build);
@@ -190,6 +193,26 @@ public class JavaProjectConversionParticipant extends AbstractProjectConversionP
}
targetDom.setValue(target);
}
+
+ if(usesPreviewFeatures) {
+ Xpp3Dom compilerArgsDom = configuration.getChild(COMPILER_ARGS_KEY);
+ if(compilerArgsDom == null) {
+ compilerArgsDom = new Xpp3Dom(COMPILER_ARGS_KEY);
+ configuration.addChild(compilerArgsDom);
+ }
+ String argKey = "arg";
+ boolean addFlag = true;
+ if(compilerArgsDom.getChildCount() > 0) {
+ argKey = compilerArgsDom.getChild(0).getName();
+ addFlag = !Arrays.stream(compilerArgsDom.getChildren())
+ .filter(c -> JavaSettingsUtils.ENABLE_PREVIEW_JVM_FLAG.equals(c.getValue())).findAny().isPresent();
+ }
+ if(addFlag) {
+ Xpp3Dom previewFlagDom = new Xpp3Dom(argKey);
+ previewFlagDom.setValue(JavaSettingsUtils.ENABLE_PREVIEW_JVM_FLAG);
+ compilerArgsDom.addChild(previewFlagDom);
+ }
+ }
compiler.setConfiguration(configuration);
}
@@ -272,7 +295,7 @@ public class JavaProjectConversionParticipant extends AbstractProjectConversionP
if(ex.getCause() instanceof NonJavaResourceFoundException) {
hasNonJavaResources = true;
} else {
- log.error("An error occured while analysing {} : {}", folder, ex.getMessage());
+ log.error("An error occured while analysing {} : {}", folder, ex.getMessage());//$NON-NLS-1$
}
}
}
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JavaSettingsUtils.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JavaSettingsUtils.java
index 108df08e..9acf696a 100644
--- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JavaSettingsUtils.java
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JavaSettingsUtils.java
@@ -11,6 +11,7 @@
package org.eclipse.m2e.jdt.internal;
+import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
@@ -59,4 +60,17 @@ public class JavaSettingsUtils {
//No public instanciation
}
+ /**
+ * Checks if the given {@link IJavaProject} has preview features enabled.
+ *
+ * @param project the {@link IJavaProject}
+ * @return <code>true</code> if the project preferences have JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES=enabled,
+ * <code>false</code> otherwise.
+ */
+ public static boolean hasPreviewFeatures(IJavaProject project) {
+ if(project == null) {
+ return false;
+ }
+ return JavaCore.ENABLED.equals(project.getOption(COMPILER_PB_ENABLE_PREVIEW_FEATURES, true));
+ }
}

Back to the top