changeset 51891:9d9ab30af97d

8210555: create --source --target synonyms for -source -target Reviewed-by: hannesw
author jjg
date Wed, 26 Sep 2018 15:14:17 -0700
parents 4147b929ea72
children 904c4e07cc22
files src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/Start.java src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/ToolOption.java src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/ToolOption.java test/langtools/jdk/javadoc/tool/api/basic/IsSupportedOptionTest.java test/langtools/jdk/javadoc/tool/sourceOption/SourceOption.java test/langtools/tools/javac/options/IsSupportedOptionTest.java test/langtools/tools/javadoc/api/basic/IsSupportedOptionTest.java test/langtools/tools/javadoc/sourceOption/SourceOption.java
diffstat 9 files changed, 42 insertions(+), 109 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java	Wed Sep 26 14:54:38 2018 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java	Wed Sep 26 15:14:17 2018 -0700
@@ -328,7 +328,7 @@
 
     ENCODING("-encoding", "opt.arg.encoding", "opt.encoding", STANDARD, FILEMANAGER),
 
-    SOURCE("-source", "opt.arg.release", "opt.source", STANDARD, BASIC) {
+    SOURCE("--source -source", "opt.arg.release", "opt.source", STANDARD, BASIC) {
         @Override
         public void process(OptionHelper helper, String option, String operand) throws InvalidValueException {
             Source source = Source.lookup(operand);
@@ -349,7 +349,7 @@
         }
     },
 
-    TARGET("-target", "opt.arg.release", "opt.target", STANDARD, BASIC) {
+    TARGET("--target -target", "opt.arg.release", "opt.target", STANDARD, BASIC) {
         @Override
         public void process(OptionHelper helper, String option, String operand) throws InvalidValueException {
             Target target = Target.lookup(operand);
--- a/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/Start.java	Wed Sep 26 14:54:38 2018 -0700
+++ b/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/Start.java	Wed Sep 26 15:14:17 2018 -0700
@@ -380,8 +380,8 @@
         String platformString = compOpts.get("--release");
 
         if (platformString != null) {
-            if (compOpts.isSet("-source")) {
-                usageError("main.release.bootclasspath.conflict", "-source");
+            if (compOpts.isSet(Option.SOURCE.primaryName)) {
+                usageError("main.release.bootclasspath.conflict", Option.SOURCE.primaryName);
             }
             if (fileManagerOpts.containsKey(Option.BOOT_CLASS_PATH)) {
                 usageError("main.release.bootclasspath.conflict", Option.BOOT_CLASS_PATH.getPrimaryName());
--- a/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/ToolOption.java	Wed Sep 26 14:54:38 2018 -0700
+++ b/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/ToolOption.java	Wed Sep 26 15:14:17 2018 -0700
@@ -174,6 +174,13 @@
     SOURCE("-source", true) {
         @Override
         public void process(Helper helper, String arg) {
+            helper.setCompilerOpt("--source", arg);
+        }
+    },
+
+    SOURCE2("--source", true) {
+        @Override
+        public void process(Helper helper, String arg) {
             helper.setCompilerOpt(opt, arg);
         }
     },
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/ToolOption.java	Wed Sep 26 14:54:38 2018 -0700
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/ToolOption.java	Wed Sep 26 15:14:17 2018 -0700
@@ -146,7 +146,7 @@
         }
     },
 
-    SOURCE("-source", STANDARD, true) {
+    SOURCE("--source -source", STANDARD, true) {
         @Override
         public void process(Helper helper, String arg) throws InvalidValueException {
             Option.SOURCE.process(helper.getOptionHelper(), primaryName, arg);
--- a/test/langtools/jdk/javadoc/tool/api/basic/IsSupportedOptionTest.java	Wed Sep 26 14:54:38 2018 -0700
+++ b/test/langtools/jdk/javadoc/tool/api/basic/IsSupportedOptionTest.java	Wed Sep 26 15:14:17 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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,7 +23,7 @@
 
 /*
  * @test
- * @bug 6493690
+ * @bug 6493690 8210555
  * @summary javadoc should have a javax.tools.Tool service provider
  * @modules java.compiler
  *          jdk.compiler
@@ -48,6 +48,8 @@
     @Test
     public void test() throws Exception {
         DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
+        check(tool, "-source", 1);
+        check(tool, "--source", 1);
         check(tool, "-sourcepath", 1);
         check(tool, "-verbose", 0);
         check(tool, "-ZZZ", -1);
--- a/test/langtools/jdk/javadoc/tool/sourceOption/SourceOption.java	Wed Sep 26 14:54:38 2018 -0700
+++ b/test/langtools/jdk/javadoc/tool/sourceOption/SourceOption.java	Wed Sep 26 15:14:17 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 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
@@ -33,25 +33,20 @@
  */
 
 /*
- * TEST NOTE
- * With JDK9, this test has been transformed into a NEGATIVE test.
+ * In order to test whether or not the -source option is working
+ * correctly, this test tries to parse source code that contains
+ * a feature that is not available in at least one of the currently
+ * supported previous versions.
  *
- * Generally speaking, this test should check a feature not in at least
- * one of the currently supported previous versions.  In this manner,
- * a failure of the -source option to be honored would mean a pass of
- * the test, and therefore a failure of the -source option.
+ * Parsing such code should be expected to fail; if the action
+ * passes, that means the -source option is (incorrectly) ineffective.
  *
- * For JDK9 and JDK10, both support 1.7, which did not support javac's
- * lambda construct.  So we set "-source 1.7" to compile a .java file
- * containing the lambda construct.  javac should fail, thus showing
- * -source to be working.  Thus the test passes.
- *
- * The second jtreg @run command checks to make sure that the source
+ * Additional actions are performed to ensure that the source
  * provided is valid for the current release of the JDK.
  *
- *  fixVersion: JDK11
- *      replace ./p/LambdaConstructTest.java with a missing from
- *      JDK8, JDK9, or JDK10.  Set -source below appropriately.
+ * As support for older versions of the platform are dropped, the
+ * source code (currently p/LambdaConstructTest.java) will need to
+ * be updated with a more recent feature.
  */
 
 import java.util.ArrayList;
--- a/test/langtools/tools/javac/options/IsSupportedOptionTest.java	Wed Sep 26 14:54:38 2018 -0700
+++ b/test/langtools/tools/javac/options/IsSupportedOptionTest.java	Wed Sep 26 15:14:17 2018 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8189782
+ * @bug 8189782 8210555
  * @summary Test for isSupportedOption
  * @modules java.compiler
  *          jdk.compiler
@@ -44,6 +44,9 @@
     public void run() throws Exception {
         JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
         check(tool, "-source", 1);
+        check(tool, "--source", 1);
+        check(tool, "-target", 1);
+        check(tool, "--target", 1);
         check(tool, "--add-modules", 1);
         check(tool, "-verbose", 0);
         check(tool, "-proc:none", 0);
--- a/test/langtools/tools/javadoc/api/basic/IsSupportedOptionTest.java	Wed Sep 26 14:54:38 2018 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-/*
- * Copyright (c) 2012, 2015, 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 6493690
- * @summary javadoc should have a javax.tools.Tool service provider
- * @modules java.compiler
- *          jdk.compiler
- * @build APITest
- * @run main IsSupportedOptionTest
- */
-
-import javax.tools.DocumentationTool;
-import javax.tools.ToolProvider;
-
-/**
- * Tests for DocumentationTool.usSupportedOption method.
- */
-public class IsSupportedOptionTest extends APITest {
-    public static void main(String... args) throws Exception {
-        new IsSupportedOptionTest().run();
-    }
-
-    /**
-     * Verify that isSupportedOption method can be invoked.
-     */
-    @Test
-    public void test() throws Exception {
-        DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
-        check(tool, "-sourcepath", 1);
-        check(tool, "-verbose", 0);
-        check(tool, "-ZZZ", -1);
-
-        try {
-            check(tool, null, -1);
-            error("null was accepted without exception");
-        } catch (NullPointerException e) {
-        }
-    }
-
-    private void check(DocumentationTool tool, String option, int numArgs) {
-        System.err.println("check " + option);
-        int n = tool.isSupportedOption(option);
-        if (n != numArgs)
-            error("unexpected result for option: " + option + ": " + n);
-    }
-}
-
--- a/test/langtools/tools/javadoc/sourceOption/SourceOption.java	Wed Sep 26 14:54:38 2018 -0700
+++ b/test/langtools/tools/javadoc/sourceOption/SourceOption.java	Wed Sep 26 15:14:17 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 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
@@ -33,25 +33,20 @@
  */
 
 /*
- * TEST NOTE
- * With JDK9, this test has been transformed into a NEGATIVE test.
+ * In order to test whether or not the -source option is working
+ * correctly, this test tries to parse source code that contains
+ * a feature that is not available in at least one of the currently
+ * supported previous versions.
  *
- * Generally speaking, this test should check a feature not in at least
- * one of the currently supported previous versions.  In this manner,
- * a failure of the -source option to be honored would mean a pass of
- * the test, and therefore a failure of the -source option.
+ * Parsing such code should be expected to fail; if the action
+ * passes, that means the -source option is (incorrectly) ineffective.
  *
- * For JDK9 and JDK10, both support 1.7, which did not support javac's
- * lambda construct.  So we set "-source 1.7" to compile a .java file
- * containing the lambda construct.  javac should fail, thus showing
- * -source to be working.  Thus the test passes.
- *
- * The second jtreg @run command checks to make sure that the source
+ * Additional actions are performed to ensure that the source
  * provided is valid for the current release of the JDK.
  *
- *  fixVersion: JDK11
- *      replace ./p/LambdaConstructTest.java with a missing from
- *      JDK8, JDK9, or JDK10.  Set -source below appropriately.
+ * As support for older versions of the platform are dropped, the
+ * source code (currently p/LambdaConstructTest.java) will need to
+ * be updated with a more recent feature.
  */
 
 import com.sun.javadoc.*;