8164590: javac --inherit-runtime-environment fails with "cannot find modules: ALL-DEFAULT"
Reviewed-by: mchung
This commit is contained in:
parent
fe1b93aeab
commit
6e31f6440f
@ -707,7 +707,6 @@ public class Arguments {
|
||||
for (String moduleName : addModules.split(",")) {
|
||||
switch (moduleName) {
|
||||
case "":
|
||||
case "ALL-DEFAULT":
|
||||
case "ALL-SYSTEM":
|
||||
case "ALL-MODULE-PATH":
|
||||
break;
|
||||
@ -715,7 +714,7 @@ public class Arguments {
|
||||
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 @@ public class Arguments {
|
||||
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;
|
||||
}
|
||||
|
@ -682,11 +682,32 @@ public enum Option {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -2848,6 +2848,10 @@ compiler.err.duplicate.module.on.path=\
|
||||
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}
|
||||
|
@ -103,10 +103,10 @@ public class BadOptionsTest extends TestRunner {
|
||||
.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/");
|
||||
}
|
||||
|
||||
|
@ -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 { }
|
||||
|
@ -126,12 +126,12 @@ public class AddModulesTest extends ModuleTestBase {
|
||||
"--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
|
||||
|
86
langtools/test/tools/javac/modules/AllDefaultTest.java
Normal file
86
langtools/test/tools/javac/modules/AllDefaultTest.java
Normal file
@ -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();
|
||||
}
|
||||
}
|
@ -144,11 +144,11 @@ public class LimitModulesTest extends ModuleTestBase {
|
||||
"--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");
|
||||
}
|
||||
|
||||
|
@ -104,10 +104,10 @@ public class BadOptionsTest extends TestRunner {
|
||||
.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/");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user