8210555: create --source --target synonyms for -source -target

Reviewed-by: hannesw
This commit is contained in:
Jonathan Gibbons 2018-09-26 15:14:17 -07:00
parent 25ca76b4f9
commit 065fdac559
9 changed files with 42 additions and 109 deletions

View File

@ -328,7 +328,7 @@ public enum Option {
ENCODING("-encoding", "opt.arg.encoding", "opt.encoding", STANDARD, FILEMANAGER), 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 @Override
public void process(OptionHelper helper, String option, String operand) throws InvalidValueException { public void process(OptionHelper helper, String option, String operand) throws InvalidValueException {
Source source = Source.lookup(operand); Source source = Source.lookup(operand);
@ -349,7 +349,7 @@ public enum Option {
} }
}, },
TARGET("-target", "opt.arg.release", "opt.target", STANDARD, BASIC) { TARGET("--target -target", "opt.arg.release", "opt.target", STANDARD, BASIC) {
@Override @Override
public void process(OptionHelper helper, String option, String operand) throws InvalidValueException { public void process(OptionHelper helper, String option, String operand) throws InvalidValueException {
Target target = Target.lookup(operand); Target target = Target.lookup(operand);

View File

@ -380,8 +380,8 @@ public class Start extends ToolOption.Helper {
String platformString = compOpts.get("--release"); String platformString = compOpts.get("--release");
if (platformString != null) { if (platformString != null) {
if (compOpts.isSet("-source")) { if (compOpts.isSet(Option.SOURCE.primaryName)) {
usageError("main.release.bootclasspath.conflict", "-source"); usageError("main.release.bootclasspath.conflict", Option.SOURCE.primaryName);
} }
if (fileManagerOpts.containsKey(Option.BOOT_CLASS_PATH)) { if (fileManagerOpts.containsKey(Option.BOOT_CLASS_PATH)) {
usageError("main.release.bootclasspath.conflict", Option.BOOT_CLASS_PATH.getPrimaryName()); usageError("main.release.bootclasspath.conflict", Option.BOOT_CLASS_PATH.getPrimaryName());

View File

@ -172,6 +172,13 @@ public enum ToolOption {
}, },
SOURCE("-source", true) { SOURCE("-source", true) {
@Override
public void process(Helper helper, String arg) {
helper.setCompilerOpt("--source", arg);
}
},
SOURCE2("--source", true) {
@Override @Override
public void process(Helper helper, String arg) { public void process(Helper helper, String arg) {
helper.setCompilerOpt(opt, arg); helper.setCompilerOpt(opt, arg);

View File

@ -146,7 +146,7 @@ public enum ToolOption {
} }
}, },
SOURCE("-source", STANDARD, true) { SOURCE("--source -source", STANDARD, true) {
@Override @Override
public void process(Helper helper, String arg) throws InvalidValueException { public void process(Helper helper, String arg) throws InvalidValueException {
Option.SOURCE.process(helper.getOptionHelper(), primaryName, arg); Option.SOURCE.process(helper.getOptionHelper(), primaryName, arg);

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 6493690 * @bug 6493690 8210555
* @summary javadoc should have a javax.tools.Tool service provider * @summary javadoc should have a javax.tools.Tool service provider
* @modules java.compiler * @modules java.compiler
* jdk.compiler * jdk.compiler
@ -48,6 +48,8 @@ public class IsSupportedOptionTest extends APITest {
@Test @Test
public void test() throws Exception { public void test() throws Exception {
DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
check(tool, "-source", 1);
check(tool, "--source", 1);
check(tool, "-sourcepath", 1); check(tool, "-sourcepath", 1);
check(tool, "-verbose", 0); check(tool, "-verbose", 0);
check(tool, "-ZZZ", -1); check(tool, "-ZZZ", -1);

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -33,25 +33,20 @@
*/ */
/* /*
* TEST NOTE * In order to test whether or not the -source option is working
* With JDK9, this test has been transformed into a NEGATIVE test. * 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 * Parsing such code should be expected to fail; if the action
* one of the currently supported previous versions. In this manner, * passes, that means the -source option is (incorrectly) ineffective.
* a failure of the -source option to be honored would mean a pass of
* the test, and therefore a failure of the -source option.
* *
* For JDK9 and JDK10, both support 1.7, which did not support javac's * Additional actions are performed to ensure that the source
* 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
* provided is valid for the current release of the JDK. * provided is valid for the current release of the JDK.
* *
* fixVersion: JDK11 * As support for older versions of the platform are dropped, the
* replace ./p/LambdaConstructTest.java with a missing from * source code (currently p/LambdaConstructTest.java) will need to
* JDK8, JDK9, or JDK10. Set -source below appropriately. * be updated with a more recent feature.
*/ */
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 8189782 * @bug 8189782 8210555
* @summary Test for isSupportedOption * @summary Test for isSupportedOption
* @modules java.compiler * @modules java.compiler
* jdk.compiler * jdk.compiler
@ -44,6 +44,9 @@ public class IsSupportedOptionTest {
public void run() throws Exception { public void run() throws Exception {
JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
check(tool, "-source", 1); check(tool, "-source", 1);
check(tool, "--source", 1);
check(tool, "-target", 1);
check(tool, "--target", 1);
check(tool, "--add-modules", 1); check(tool, "--add-modules", 1);
check(tool, "-verbose", 0); check(tool, "-verbose", 0);
check(tool, "-proc:none", 0); check(tool, "-proc:none", 0);

View File

@ -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);
}
}

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -33,25 +33,20 @@
*/ */
/* /*
* TEST NOTE * In order to test whether or not the -source option is working
* With JDK9, this test has been transformed into a NEGATIVE test. * 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 * Parsing such code should be expected to fail; if the action
* one of the currently supported previous versions. In this manner, * passes, that means the -source option is (incorrectly) ineffective.
* a failure of the -source option to be honored would mean a pass of
* the test, and therefore a failure of the -source option.
* *
* For JDK9 and JDK10, both support 1.7, which did not support javac's * Additional actions are performed to ensure that the source
* 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
* provided is valid for the current release of the JDK. * provided is valid for the current release of the JDK.
* *
* fixVersion: JDK11 * As support for older versions of the platform are dropped, the
* replace ./p/LambdaConstructTest.java with a missing from * source code (currently p/LambdaConstructTest.java) will need to
* JDK8, JDK9, or JDK10. Set -source below appropriately. * be updated with a more recent feature.
*/ */
import com.sun.javadoc.*; import com.sun.javadoc.*;