OpenJDK / portola / portola
changeset 42271:2537564a3031
Merge
author | jjg |
---|---|
date | Tue, 22 Nov 2016 16:31:03 -0800 |
parents | 3bd3e7e378b5 24a766b7c106 |
children | 82e273c4f2b3 |
files | langtools/test/tools/javac/diags/examples/BadNameForOption.java |
diffstat | 11 files changed, 178 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java Tue Nov 22 16:29:24 2016 -0800 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java Tue Nov 22 16:31:03 2016 -0800 @@ -707,7 +707,6 @@ for (String moduleName : addModules.split(",")) { switch (moduleName) { case "": - case "ALL-DEFAULT": case "ALL-SYSTEM": case "ALL-MODULE-PATH": break; @@ -715,7 +714,7 @@ default: if (!SourceVersion.isName(moduleName, sv)) { // syntactically invalid module name: e.g. --add-modules m1,m! - log.warning(Warnings.BadNameForOption(Option.ADD_MODULES, moduleName)); + log.error(Errors.BadNameForOption(Option.ADD_MODULES, moduleName)); } break; } @@ -739,7 +738,7 @@ default: if (!SourceVersion.isName(moduleName, sv)) { // syntactically invalid module name: e.g. --limit-modules m1,m! - log.warning(Warnings.BadNameForOption(Option.LIMIT_MODULES, moduleName)); + log.error(Errors.BadNameForOption(Option.LIMIT_MODULES, moduleName)); } break; }
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java Tue Nov 22 16:29:24 2016 -0800 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java Tue Nov 22 16:31:03 2016 -0800 @@ -682,11 +682,32 @@ Class.forName(JDK9Wrappers.VMHelper.VM_CLASSNAME); String[] runtimeArgs = JDK9Wrappers.VMHelper.getRuntimeArguments(); for (String arg : runtimeArgs) { + System.err.println("runtime arg: " + arg); // Handle any supported runtime options; ignore all others. // The runtime arguments always use the single token form, e.g. "--name=value". for (Option o : getSupportedRuntimeOptions()) { if (o.matches(arg)) { - o.handleOption(helper, arg, Collections.emptyIterator()); + switch (o) { + case ADD_MODULES: + int eq = arg.indexOf('='); + Assert.check(eq > 0, () -> ("invalid runtime option:" + arg)); + // --add-modules=ALL-DEFAULT is not supported at compile-time + // so remove it from list, and only process the rest + // if the set is non-empty. + // Note that --add-modules=ALL-DEFAULT is automatically added + // by the standard javac launcher. + String mods = Arrays.stream(arg.substring(eq + 1).split(",")) + .filter(s -> !s.isEmpty() && !s.equals("ALL-DEFAULT")) + .collect(Collectors.joining(",")); + if (!mods.isEmpty()) { + String updatedArg = arg.substring(0, eq + 1) + mods; + o.handleOption(helper, updatedArg, Collections.emptyIterator()); + } + break; + default: + o.handleOption(helper, arg, Collections.emptyIterator()); + break; + } break; } }
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties Tue Nov 22 16:29:24 2016 -0800 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties Tue Nov 22 16:31:03 2016 -0800 @@ -2848,6 +2848,10 @@ compiler.warn.bad.name.for.option=\ bad name in value for {0} option: ''{1}'' +# 0: option name, 1: string +compiler.err.bad.name.for.option=\ + bad name in value for {0} option: ''{1}'' + # 0: option name, 1: symbol compiler.warn.module.for.option.not.found=\ module name in {0} option not found: {1}
--- a/langtools/test/jdk/javadoc/tool/BadOptionsTest.java Tue Nov 22 16:29:24 2016 -0800 +++ b/langtools/test/jdk/javadoc/tool/BadOptionsTest.java Tue Nov 22 16:31:03 2016 -0800 @@ -103,10 +103,10 @@ .options("-quiet", "--add-modules", "123") .files(src.resolve("C.java")) - .run() + .run(Task.Expect.FAIL) .writeAll(); checkFound(result.getOutput(Task.OutputKind.DIRECT), - "warning: bad name in value for --add-modules option: '123'"); + "error: bad name in value for --add-modules option: '123'"); checkNotFound(result, "Exception", "at jdk.javadoc/"); }
--- a/langtools/test/tools/javac/diags/examples/BadNameForOption.java Tue Nov 22 16:29:24 2016 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -/* - * 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. - */ - -// key: compiler.warn.bad.name.for.option -// options: --add-exports Bad!Name/p=java.base - -class BadNameForOption { } -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/diags/examples/BadNameForOption_Error.java Tue Nov 22 16:31:03 2016 -0800 @@ -0,0 +1,28 @@ +/* + * 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. + */ + +// key: compiler.err.bad.name.for.option +// options: --add-modules Bad!Name + +class BadNameForOption { } +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/diags/examples/BadNameForOption_Warning.java Tue Nov 22 16:31:03 2016 -0800 @@ -0,0 +1,28 @@ +/* + * 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. + */ + +// key: compiler.warn.bad.name.for.option +// options: --add-exports Bad!Name/p=java.base + +class BadNameForOption { } +
--- a/langtools/test/tools/javac/modules/AddModulesTest.java Tue Nov 22 16:29:24 2016 -0800 +++ b/langtools/test/tools/javac/modules/AddModulesTest.java Tue Nov 22 16:31:03 2016 -0800 @@ -126,12 +126,12 @@ "--add-modules", "BadModule!") .outdir(classes) .files(findJavaFiles(src)) - .run() + .run(Task.Expect.FAIL) .writeAll() .getOutput(Task.OutputKind.DIRECT); checkOutputContains(log, - "- compiler.warn.bad.name.for.option: --add-modules, BadModule!"); + "- compiler.err.bad.name.for.option: --add-modules, BadModule!"); } @Test
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/modules/AllDefaultTest.java Tue Nov 22 16:31:03 2016 -0800 @@ -0,0 +1,86 @@ +/* + * 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 0000000 + * @summary Test use of ALL-DEFAULT token + * @library /tools/lib + * @modules + * jdk.compiler/com.sun.tools.javac.api + * jdk.compiler/com.sun.tools.javac.main + * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask toolbox.JavaTask ModuleTestBase + * @run main AllDefaultTest + */ + +import java.nio.file.Path; + +import toolbox.JavacTask; +import toolbox.Task; + +public class AllDefaultTest extends ModuleTestBase { + public static void main(String... args) throws Exception { + AllDefaultTest t = new AllDefaultTest(); + t.runTests(); + } + + @Test + public void testCompileTime_notAllowed(Path base) throws Exception { + tb.writeJavaFiles(base, "class C { }"); + String out = new JavacTask(tb) + .options("-XDrawDiagnostics", + "--add-modules=ALL-DEFAULT") + .files(tb.findJavaFiles(base)) + .run(Task.Expect.FAIL) + .writeAll() + .getOutput(Task.OutputKind.DIRECT); + + if (!out.contains("- compiler.err.bad.name.for.option: --add-modules, ALL-DEFAULT")) { + error("expected text not found"); + } + } + + @Test + public void testRuntimeTime_ignored_1(Path base) throws Exception { + tb.writeJavaFiles(base, "class C { }"); + new JavacTask(tb, Task.Mode.EXEC) + .options("-XDrawDiagnostics", + "-J--add-modules=ALL-DEFAULT", + "--inherit-runtime-environment") + .files(tb.findJavaFiles(base)) + .run() + .writeAll(); + } + + @Test + public void testRuntimeTime_ignored_2(Path base) throws Exception { + tb.writeJavaFiles(base, "class C { }"); + new JavacTask(tb, Task.Mode.EXEC) + .options("-XDrawDiagnostics", + "-J--add-modules=jdk.compiler", + "--inherit-runtime-environment") + .files(tb.findJavaFiles(base)) + .run() + .writeAll(); + } +}
--- a/langtools/test/tools/javac/modules/LimitModulesTest.java Tue Nov 22 16:29:24 2016 -0800 +++ b/langtools/test/tools/javac/modules/LimitModulesTest.java Tue Nov 22 16:31:03 2016 -0800 @@ -144,11 +144,11 @@ "--limit-modules", "BadModule!") .outdir(classes) .files(findJavaFiles(src)) - .run() + .run(Task.Expect.FAIL) .writeAll() .getOutput(Task.OutputKind.DIRECT); - if (!log.contains("- compiler.warn.bad.name.for.option: --limit-modules, BadModule!")) + if (!log.contains("- compiler.err.bad.name.for.option: --limit-modules, BadModule!")) throw new Exception("expected output not found"); }
--- a/langtools/test/tools/javadoc/BadOptionsTest.java Tue Nov 22 16:29:24 2016 -0800 +++ b/langtools/test/tools/javadoc/BadOptionsTest.java Tue Nov 22 16:31:03 2016 -0800 @@ -104,10 +104,10 @@ .options("-Xold", "-quiet", "--add-modules", "123") .files(src.resolve("C.java")) - .run() + .run(Task.Expect.FAIL) .writeAll(); checkFound(result.getOutput(Task.OutputKind.DIRECT), - "warning: bad name in value for --add-modules option: '123'"); + "error: bad name in value for --add-modules option: '123'"); checkNotFound(result, "Exception", "at jdk.javadoc/"); }