8167965: (jdeprscan) using --release option with 8 or earlier throws exception
authorsmarks
Thu, 13 Oct 2016 17:31:01 -0700
changeset 41525 7f01e2b0619b
parent 41524 4c65c407ee8a
child 41526 265017792980
8167965: (jdeprscan) using --release option with 8 or earlier throws exception Reviewed-by: mchung
langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeprscan/Main.java
langtools/test/tools/jdeprscan/tests/jdk/jdeprscan/TestRelease.java
--- a/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeprscan/Main.java	Thu Oct 13 23:03:01 2016 +0000
+++ b/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeprscan/Main.java	Thu Oct 13 17:31:01 2016 -0700
@@ -384,14 +384,14 @@
                      .collect(toList()));
         } else {
             // TODO: kind of a hack...
-            // Create a throwaway compilation task with options "-release N"
+            // Create a throwaway compilation task with options "--release N"
             // which has the side effect of setting the file manager's
             // PLATFORM_CLASS_PATH to the right value.
             JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
             StandardJavaFileManager fm =
                 compiler.getStandardFileManager(this, null, StandardCharsets.UTF_8);
             JavaCompiler.CompilationTask task =
-                compiler.getTask(null, fm, this, List.of("-release", release), null, null);
+                compiler.getTask(null, fm, this, List.of("--release", release), null, null);
             List<Path> paths = new ArrayList<>();
             for (Path p : fm.getLocationAsPaths(StandardLocation.PLATFORM_CLASS_PATH)) {
                 try (Stream<Path> str = Files.walk(p)) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/jdeprscan/tests/jdk/jdeprscan/TestRelease.java	Thu Oct 13 17:31:01 2016 -0700
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2016, 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 8167965
+ * @summary Test proper handling of the --release option.
+ * @modules jdk.jdeps/com.sun.tools.jdeprscan
+ * @build jdk.jdeprscan.TestRelease
+ * @run testng jdk.jdeprscan.TestRelease
+ */
+
+package jdk.jdeprscan;
+
+import com.sun.tools.jdeprscan.Main;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+public class TestRelease {
+    static boolean invoke(String arg) {
+        return Main.call(System.out, System.err, "--list", "--release", arg);
+    }
+
+    @Test
+    public void testSuccess() {
+        assertTrue(invoke("6"));
+        assertTrue(invoke("7"));
+        assertTrue(invoke("8"));
+        assertTrue(invoke("9"));
+    }
+
+    @Test
+    public void testFailure() {
+        assertFalse(invoke("5"));
+    }
+}