8166649: jshell tool: missing --add-modules and --module-path

8167462: jshell tool: /help /reload is wrong about re-executing commands

Reviewed-by: jlahoda
This commit is contained in:
Robert Field 2016-10-24 19:59:35 -07:00
parent 7b77bd9dcf
commit ac9d25d027
3 changed files with 36 additions and 3 deletions

View File

@ -565,6 +565,8 @@ public class JShellTool implements MessageHandler {
private List<String> processCommandArgs(String[] args) {
OptionParser parser = new OptionParser();
OptionSpec<String> cp = parser.accepts("class-path").withRequiredArg();
OptionSpec<String> mpath = parser.accepts("module-path").withRequiredArg();
OptionSpec<String> amods = parser.accepts("add-modules").withRequiredArg();
OptionSpec<String> st = parser.accepts("startup").withRequiredArg();
parser.acceptsAll(asList("n", "no-startup"));
OptionSpec<String> fb = parser.accepts("feedback").withRequiredArg();
@ -658,6 +660,18 @@ public class JShellTool implements MessageHandler {
if (options.has(c)) {
compilerOptions.addAll(options.valuesOf(c));
}
if (options.has(mpath)) {
compilerOptions.add("--module-path");
compilerOptions.addAll(options.valuesOf(mpath));
remoteVMOptions.add("--module-path");
remoteVMOptions.addAll(options.valuesOf(mpath));
}
if (options.has(amods)) {
compilerOptions.add("--add-modules");
compilerOptions.addAll(options.valuesOf(amods));
remoteVMOptions.add("--add-modules");
remoteVMOptions.addAll(options.valuesOf(amods));
}
if (options.has(addExports)) {
List<String> exports = options.valuesOf(addExports).stream()

View File

@ -158,6 +158,10 @@ help.usage = \
Usage: jshell <options> <load files>\n\
where possible options include:\n\
\ --class-path <path> Specify where to find user class files\n\
\ --module-path <path> Specify where to find application modules\n\
\ --add-modules <module>(,<module>)*\n\
\ Specify modules to resolve, or all modules on the\n\
\ module path if <module> is ALL-MODULE-PATHs\n\
\ --startup <file> One run replacement for the start-up definitions\n\
\ --no-startup Do not run the start-up definitions\n\
\ --feedback <mode> Specify the initial feedback mode. The mode may be\n\
@ -316,8 +320,8 @@ Save any work before using this command
help.reload.summary = reset and replay relevant history -- current or previous (-restore)
help.reload.args = [-restore] [-quiet]
help.reload =\
Reset the jshell tool code and execution state then replay each\n\
jshell valid command and valid snippet in the order they were entered.\n\
Reset the jshell tool code and execution state then replay each valid snippet\n\
and any /drop or /classpath commands in the order they were entered.\n\
\n\
/reload\n\t\
Reset and replay the valid history since jshell was entered, or\n\t\

View File

@ -23,7 +23,7 @@
/*
* @test
* @bug 8143037 8142447 8144095 8140265 8144906 8146138 8147887 8147886 8148316 8148317 8143955 8157953 8080347 8154714
* @bug 8143037 8142447 8144095 8140265 8144906 8146138 8147887 8147886 8148316 8148317 8143955 8157953 8080347 8154714 8166649
* @summary Tests for Basic tests for REPL tool
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
@ -289,6 +289,21 @@ public class ToolBasicTest extends ReplToolTesting {
);
}
public void testModulePath() {
Compiler compiler = new Compiler();
Path modsDir = Paths.get("mods");
Path outDir = Paths.get("mods", "org.astro");
compiler.compile(outDir, "package org.astro; public class World { public static String name() { return \"world\"; } }");
compiler.compile(outDir, "module org.astro { exports org.astro; }");
Path modsPath = compiler.getPath(modsDir);
test(new String[] { "--module-path", modsPath.toString(), "--add-modules", "org.astro" },
(a) -> assertCommand(a, "import org.astro.World;", ""),
(a) -> evaluateExpression(a, "String",
"String.format(\"Greetings %s!\", World.name());",
"\"Greetings world!\"")
);
}
public void testStartupFileOption() {
try {
Compiler compiler = new Compiler();