Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Bricon2019-03-21 12:34:44 -0400
committerFred Bricon2019-03-24 12:14:30 -0400
commitf9561ce437eb0664c71b9a15092e439951536318 (patch)
tree08024fc195866bba38c17529bac16b8783f41405 /org.eclipse.m2e.jdt
parent7400bf563885fdf122aaccf356c398a0a9120ffa (diff)
downloadm2e-core-f9561ce437eb0664c71b9a15092e439951536318.tar.gz
m2e-core-f9561ce437eb0664c71b9a15092e439951536318.tar.xz
m2e-core-f9561ce437eb0664c71b9a15092e439951536318.zip
Bug 545462: configure preview features according to he --enable-preview flag
The change is backward compatible with Eclipse 4.11 without Java 12 support. Change-Id: Ib49f5f258a94b38d0d4c21bb6b290ae92facd057 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/AbstractJavaProjectConfigurator.java49
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JavaSettingsUtils.java62
2 files changed, 106 insertions, 5 deletions
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java
index 7a739536..ab0ef29d 100644
--- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java
@@ -559,12 +559,17 @@ public abstract class AbstractJavaProjectConfigurator extends AbstractProjectCon
String release = null;
boolean generateParameters = false;
+
+ boolean enablePreviewFeatures = false;
+
for(MojoExecution execution : getCompilerMojoExecutions(request, monitor)) {
release = getCompilerLevel(request.getMavenProject(), execution, "release", release, RELEASES, monitor);
//XXX ignoring testRelease option, since JDT doesn't support main/test classpath separation - yet
source = getCompilerLevel(request.getMavenProject(), execution, "source", source, SOURCES, monitor); //$NON-NLS-1$
target = getCompilerLevel(request.getMavenProject(), execution, "target", target, TARGETS, monitor); //$NON-NLS-1$
- generateParameters = generateParameters || isGenerateParameters(request.getMavenProject(), execution, monitor); //$NON-NLS-1$
+ generateParameters = generateParameters || isGenerateParameters(request.getMavenProject(), execution, monitor);
+ enablePreviewFeatures = enablePreviewFeatures
+ || isEnablePreviewFeatures(request.getMavenProject(), execution, monitor);
}
if(release != null) {
@@ -595,11 +600,17 @@ public abstract class AbstractJavaProjectConfigurator extends AbstractProjectCon
if(generateParameters) {
options.put(JavaCore.COMPILER_CODEGEN_METHOD_PARAMETERS_ATTR, JavaCore.GENERATE);
}
-
// 360962 keep forbidden_reference severity set by the user
IJavaProject jp = JavaCore.create(request.getProject());
if(jp != null && jp.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, false) == null) {
- options.put(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, "warning"); //$NON-NLS-1$
+ options.put(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, JavaCore.WARNING);
+ }
+ if(JavaSettingsUtils.isPreviewFeatureAvailable) {
+ options.put(JavaSettingsUtils.COMPILER_PB_ENABLE_PREVIEW_FEATURES, enablePreviewFeatures ? JavaCore.ENABLED : JavaCore.DISABLED);
+ //preview features are enabled on purpose, so keep JDT quiet about it, unless specifically overridden by the user
+ if(jp != null && jp.getOption(JavaSettingsUtils.COMPILER_PB_REPORT_PREVIEW_FEATURES, false) == null) {
+ options.put(JavaSettingsUtils.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
+ }
}
}
@@ -617,7 +628,7 @@ public abstract class AbstractJavaProjectConfigurator extends AbstractProjectCon
try {
List<?> args = maven.getMojoParameterValue(mavenProject, execution, "compilerArgs", List.class, monitor);//$NON-NLS-1$
if(args != null) {
- generateParameters = args.contains("-parameters");//$NON-NLS-1$
+ generateParameters = args.contains(JavaSettingsUtils.PARAMETERS_JVM_FLAG);//$NON-NLS-1$
}
} catch(Exception ex) {
//ignore
@@ -630,7 +641,7 @@ public abstract class AbstractJavaProjectConfigurator extends AbstractProjectCon
String compilerArgument = maven.getMojoParameterValue(mavenProject, execution, "compilerArgument", String.class, //$NON-NLS-1$
monitor);
if(compilerArgument != null) {
- generateParameters = compilerArgument.contains("-parameters");//$NON-NLS-1$
+ generateParameters = compilerArgument.contains(JavaSettingsUtils.PARAMETERS_JVM_FLAG);//$NON-NLS-1$
}
} catch(CoreException ex) {
//ignore
@@ -640,6 +651,34 @@ public abstract class AbstractJavaProjectConfigurator extends AbstractProjectCon
return Boolean.TRUE.equals(generateParameters);
}
+ private boolean isEnablePreviewFeatures(MavenProject mavenProject, MojoExecution execution,
+ IProgressMonitor monitor) {
+ if(!JavaSettingsUtils.isPreviewFeatureAvailable) {
+ return false;
+ }
+ //1st, check the --enable-preview flag in the compilerArgs list
+ try {
+ List<?> args = maven.getMojoParameterValue(mavenProject, execution, "compilerArgs", List.class, monitor);//$NON-NLS-1$
+ if(args != null && args.contains(JavaSettingsUtils.ENABLE_PREVIEW_JVM_FLAG)) {//$NON-NLS-1$
+ return true;
+ }
+ } catch(Exception ex) {
+ //ignore
+ }
+
+ //2nd, check the --enable-preview flag in the compilerArgument String
+ try {
+ String compilerArgument = maven.getMojoParameterValue(mavenProject, execution, "compilerArgument", String.class, //$NON-NLS-1$
+ monitor);
+ if(compilerArgument != null && compilerArgument.contains(JavaSettingsUtils.ENABLE_PREVIEW_JVM_FLAG)) {//$NON-NLS-1$
+ return true;
+ }
+ } catch(CoreException ex) {
+ //ignore
+ }
+ return false;
+ }
+
private String sanitizeJavaVersion(String version) {
switch(version) {
case "5":
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
new file mode 100644
index 00000000..108df08e
--- /dev/null
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JavaSettingsUtils.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Red Hat, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.m2e.jdt.internal;
+
+import org.eclipse.jdt.core.JavaCore;
+
+
+/**
+ * Utility class related to Java project settings
+ *
+ * @author Fred Bricon
+ */
+public class JavaSettingsUtils {
+
+ /**
+ * @deprecated use JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES when it's available
+ */
+ @Deprecated
+ public static final String COMPILER_PB_ENABLE_PREVIEW_FEATURES = "org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures";
+
+ /**
+ * @deprecated use JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES when it's available
+ */
+ @Deprecated
+ public static final String COMPILER_PB_REPORT_PREVIEW_FEATURES = "org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures";
+
+ public static final String ENABLE_PREVIEW_JVM_FLAG = "--enable-preview";
+
+ public static final String PARAMETERS_JVM_FLAG = "-parameters";
+
+ /**
+ * Does this version of JDT support JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES? Will be removed once the minimum JDT
+ * requirement guarantees COMPILER_PB_ENABLE_PREVIEW_FEATURES is available.
+ */
+ @Deprecated
+ public static final boolean isPreviewFeatureAvailable;
+
+ static {
+ //TODO remove that once we depend on Eclipse 4.12
+ boolean hasField = false;
+ try {
+ JavaCore.class.getField("COMPILER_PB_ENABLE_PREVIEW_FEATURES");
+ hasField = true;
+ } catch(Exception ignore) {
+ }
+ isPreviewFeatureAvailable = hasField;
+ }
+
+ private JavaSettingsUtils() {
+ //No public instanciation
+ }
+
+}

Back to the top