changeset 3724:f7187b5fe9e2

8166649: jshell tool: missing --add-modules and --module-path 8167462: jshell tool: /help /reload is wrong about re-executing commands Reviewed-by: jlahoda
author rfield
date Mon, 24 Oct 2016 19:59:35 -0700
parents d245e56f4a79
children 32444e1ad88a
files src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java src/jdk.jshell/share/classes/jdk/internal/jshell/tool/resources/l10n.properties test/jdk/jshell/ToolBasicTest.java
diffstat 3 files changed, 36 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java	Mon Oct 24 17:06:10 2016 -0700
+++ b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java	Mon Oct 24 19:59:35 2016 -0700
@@ -565,6 +565,8 @@
     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 @@
         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()
--- a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/resources/l10n.properties	Mon Oct 24 17:06:10 2016 -0700
+++ b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/resources/l10n.properties	Mon Oct 24 19:59:35 2016 -0700
@@ -158,6 +158,10 @@
 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 @@
 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\
--- a/test/jdk/jshell/ToolBasicTest.java	Mon Oct 24 17:06:10 2016 -0700
+++ b/test/jdk/jshell/ToolBasicTest.java	Mon Oct 24 19:59:35 2016 -0700
@@ -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 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();