8196618: Create API to list supported values for javac --release option
8194308: jdeprscan will need updates to deal with the removal of the Java EE modules
Summary: Generalizing tests to run over all supported --release keys; fixing jdeprscan to work with --release 11.
Reviewed-by: smarks, vromero
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java Thu Jun 14 13:07:33 2018 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java Thu Jun 14 13:16:21 2018 +0200
@@ -317,7 +317,7 @@
.flatMap(provider -> StreamSupport.stream(provider.getSupportedPlatformNames()
.spliterator(),
false))
- .collect(Collectors.toCollection(TreeSet :: new));
+ .collect(Collectors.toCollection(LinkedHashSet :: new));
StringBuilder targets = new StringBuilder();
String delim = "";
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/platform/JDKPlatformProvider.java Thu Jun 14 13:07:33 2018 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/platform/JDKPlatformProvider.java Thu Jun 14 13:16:21 2018 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -39,6 +39,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.Comparator;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
@@ -89,9 +90,24 @@
private static final String[] symbolFileLocation = { "lib", "ct.sym" };
private static final Set<String> SUPPORTED_JAVA_PLATFORM_VERSIONS;
+ public static final Comparator<String> NUMERICAL_COMPARATOR = (s1, s2) -> {
+ int i1;
+ try {
+ i1 = Integer.parseInt(s1);
+ } catch (NumberFormatException ex) {
+ i1 = Integer.MAX_VALUE;
+ }
+ int i2;
+ try {
+ i2 = Integer.parseInt(s2);
+ } catch (NumberFormatException ex) {
+ i2 = Integer.MAX_VALUE;
+ }
+ return i1 != i2 ? i1 - i2 : s1.compareTo(s2);
+ };
static {
- SUPPORTED_JAVA_PLATFORM_VERSIONS = new TreeSet<>();
+ SUPPORTED_JAVA_PLATFORM_VERSIONS = new TreeSet<>(NUMERICAL_COMPARATOR);
Path ctSymFile = findCtSym();
if (Files.exists(ctSymFile)) {
try (FileSystem fs = FileSystems.newFileSystem(ctSymFile, null);
--- a/src/jdk.jdeps/share/classes/com/sun/tools/jdeprscan/Main.java Thu Jun 14 13:07:33 2018 +0200
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/jdeprscan/Main.java Thu Jun 14 13:16:21 2018 +0200
@@ -335,7 +335,7 @@
*/
boolean processSelf(Collection<String> classes) throws IOException {
options.add("--add-modules");
- options.add("java.se.ee,jdk.xml.bind"); // TODO why jdk.xml.bind?
+ options.add("java.se");
if (classes.isEmpty()) {
Path modules = FileSystems.getFileSystem(URI.create("jrt:/"))
@@ -358,21 +358,35 @@
* Process classes from a particular JDK release, using only information
* in this JDK.
*
- * @param release "6", "7", "8", "9", "10", or "11"
+ * @param release a supported release version, like "8" or "10".
* @param classes collection of classes to process, may be empty
* @return success value
*/
boolean processRelease(String release, Collection<String> classes) throws IOException {
+ boolean hasModules;
+ boolean hasJavaSE_EE;
+
+ try {
+ int releaseNum = Integer.parseInt(release);
+
+ hasModules = releaseNum >= 9;
+ hasJavaSE_EE = hasModules && releaseNum <= 10;
+ } catch (NumberFormatException ex) {
+ hasModules = true;
+ hasJavaSE_EE = false;
+ }
+
options.addAll(List.of("--release", release));
- if (release.equals("9") || release.equals("10") ||
- release.equals("11")) {
- List<String> rootMods = List.of("java.se", "java.se.ee");
+ if (hasModules) {
+ List<String> rootMods = hasJavaSE_EE ? List.of("java.se", "java.se.ee")
+ : List.of("java.se");
TraverseProc proc = new TraverseProc(rootMods);
JavaCompiler.CompilationTask task =
compiler.getTask(null, fm, this,
// options
- List.of("--add-modules", String.join(",", rootMods)),
+ List.of("--add-modules", String.join(",", rootMods),
+ "--release", release),
// classes
List.of("java.lang.Object"),
null);
@@ -507,7 +521,7 @@
case "--help":
case "-h":
case "-?":
- out.println(Messages.get("main.usage"));
+ printHelp(out);
out.println();
out.println(Messages.get("main.help"));
return true;
@@ -624,7 +638,7 @@
return false;
}
} catch (NoSuchElementException | UsageException ex) {
- err.println(Messages.get("main.usage"));
+ printHelp(err);
return false;
} catch (IOException ioe) {
if (verbose) {
@@ -680,6 +694,13 @@
return scanStatus;
}
+ private void printHelp(PrintStream out) {
+ JDKPlatformProvider pp = new JDKPlatformProvider();
+ String supportedReleases =
+ String.join("|", pp.getSupportedPlatformNames());
+ out.println(Messages.get("main.usage", supportedReleases));
+ }
+
/**
* Programmatic main entry point: initializes the tool instance to
* use stdout and stderr; runs the tool, passing command-line args;
--- a/src/jdk.jdeps/share/classes/com/sun/tools/jdeprscan/resources/jdeprscan.properties Thu Jun 14 13:07:33 2018 +0200
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/jdeprscan/resources/jdeprscan.properties Thu Jun 14 13:16:21 2018 +0200
@@ -7,7 +7,7 @@
\ --full-version\n\
\ -? -h --help\n\
\ -l --list\n\
-\ --release 6|7|8|9|10\n\
+\ --release {0}\n\
\ -v --verbose\n\
\ --version
--- a/test/langtools/ProblemList.txt Thu Jun 14 13:07:33 2018 +0200
+++ b/test/langtools/ProblemList.txt Thu Jun 14 13:16:21 2018 +0200
@@ -81,11 +81,3 @@
#
# jdeps
-tools/jdeprscan/tests/jdk/jdeprscan/TestNotFound.java 8193784 generic-all temporary until support for --release 11 is worked out
-###########################################################################
-#
-# Java EE Module Removal
-#
-tools/jdeprscan/tests/jdk/jdeprscan/TestRelease.java 8194308 generic-all Java EE Module Removal
-tools/jdeprscan/tests/jdk/jdeprscan/TestNotFound.java 8194308 generic-all Java EE Module Removal
-
--- a/test/langtools/tools/javac/modules/JavaBaseTest.java Thu Jun 14 13:07:33 2018 +0200
+++ b/test/langtools/tools/javac/modules/JavaBaseTest.java Thu Jun 14 13:16:21 2018 +0200
@@ -28,7 +28,9 @@
* @library /tools/lib
* @modules
* jdk.compiler/com.sun.tools.javac.api
+ * jdk.compiler/com.sun.tools.javac.jvm
* jdk.compiler/com.sun.tools.javac.main
+ * jdk.compiler/com.sun.tools.javac.platform
* jdk.jdeps/com.sun.tools.classfile
* @build toolbox.ToolBox toolbox.JavacTask
* @run main JavaBaseTest
@@ -37,10 +39,12 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
-import java.util.Arrays;
import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
+import java.util.stream.StreamSupport;
import com.sun.tools.classfile.Attribute;
import com.sun.tools.classfile.Attributes;
@@ -48,9 +52,11 @@
import com.sun.tools.classfile.ClassWriter;
import com.sun.tools.classfile.Module_attribute;
+import com.sun.tools.javac.jvm.Target;
+import com.sun.tools.javac.platform.JDKPlatformProvider;
+
import toolbox.JavacTask;
import toolbox.Task;
-import toolbox.Task.Expect;
import toolbox.ToolBox;
public class JavaBaseTest {
@@ -66,8 +72,6 @@
List.of("static", "transitive")
);
- final List<String> targets = List.of("9", "10", "current");
-
enum Mode { SOURCE, CLASS };
ToolBox tb = new ToolBox();
@@ -75,6 +79,14 @@
int errorCount = 0;
void run() throws Exception {
+ Set<String> targets = new LinkedHashSet<>();
+ StreamSupport.stream(new JDKPlatformProvider().getSupportedPlatformNames()
+ .spliterator(),
+ false)
+ .filter(p -> Integer.parseInt(p) >= 9)
+ .forEach(targets::add);
+ //run without --release:
+ targets.add("current");
for (List<String> mods : modifiers) {
for (String target : targets) {
for (Mode mode : Mode.values()) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/platform/NumericalComparatorTest.java Thu Jun 14 13:16:21 2018 +0200
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 8196618
+ * @summary Check that JDKPlatformProvider.NUMERICAL_COMPARATOR works correctly
+ * @library /tools/lib
+ * @modules jdk.compiler/com.sun.tools.javac.platform
+ * @run main NumericalComparatorTest
+ */
+
+import java.io.IOException;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import com.sun.tools.javac.platform.JDKPlatformProvider;
+
+public class NumericalComparatorTest {
+
+ public static void main(String... args) throws IOException {
+ new NumericalComparatorTest().run();
+ }
+
+ void run() throws IOException {
+ doTest(List.of("8", "10", "11", "9", "b1", "a1", "a2"),
+ List.of("8", "9", "10", "11", "a1", "a2", "b1"));
+ }
+
+ void doTest(List<String> input, List<String> expectedOutput) {
+ List<String> actual = input.stream()
+ .sorted(JDKPlatformProvider.NUMERICAL_COMPARATOR)
+ .collect(Collectors.toList());
+ if (!expectedOutput.equals(actual))
+ throw new AssertionError("Unexpected output: " + actual);
+ }
+
+}
--- a/test/langtools/tools/jdeprscan/tests/jdk/jdeprscan/TestRelease.java Thu Jun 14 13:07:33 2018 +0200
+++ b/test/langtools/tools/jdeprscan/tests/jdk/jdeprscan/TestRelease.java Thu Jun 14 13:16:21 2018 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -23,15 +23,19 @@
/*
* @test
- * @bug 8167965
+ * @bug 8167965 8194308
* @summary Test proper handling of the --release option.
- * @modules jdk.jdeps/com.sun.tools.jdeprscan
+ * @modules
+ * jdk.compiler/com.sun.tools.javac.jvm
+ * jdk.compiler/com.sun.tools.javac.platform
+ * jdk.jdeps/com.sun.tools.jdeprscan
* @build jdk.jdeprscan.TestRelease
* @run testng jdk.jdeprscan.TestRelease
*/
package jdk.jdeprscan;
+import com.sun.tools.javac.platform.JDKPlatformProvider;
import com.sun.tools.jdeprscan.Main;
import org.testng.annotations.Test;
@@ -45,11 +49,9 @@
@Test
public void testSuccess() {
- assertTrue(invoke("6"));
- assertTrue(invoke("7"));
- assertTrue(invoke("8"));
- assertTrue(invoke("9"));
- assertTrue(invoke("10"));
+ for (String target : new JDKPlatformProvider().getSupportedPlatformNames()) {
+ assertTrue(invoke(target));
+ }
}
@Test