--- a/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java Wed Sep 28 09:05:20 2016 +0530
+++ b/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java Wed Sep 28 16:36:10 2016 +0900
@@ -199,6 +199,7 @@
private boolean feedbackInitialized = false;
private String commandLineFeedbackMode = null;
private List<String> remoteVMOptions = new ArrayList<>();
+ private List<String> compilerOptions = new ArrayList<>();
SourceCodeAnalysis analysis;
JShell state = null;
@@ -558,9 +559,14 @@
parser.accepts("s");
parser.accepts("v");
OptionSpec<String> r = parser.accepts("R").withRequiredArg();
+ OptionSpec<String> c = parser.accepts("C").withRequiredArg();
parser.acceptsAll(asList("h", "help"));
parser.accepts("version");
parser.accepts("full-version");
+
+ parser.accepts("X");
+ OptionSpec<String> addExports = parser.accepts("add-exports").withRequiredArg();
+
NonOptionArgumentSpec<String> loadFileSpec = parser.nonOptions();
OptionSet options;
@@ -585,6 +591,10 @@
printUsage();
return null;
}
+ if (options.has("X")) {
+ printUsageX();
+ return null;
+ }
if (options.has("version")) {
cmdout.printf("jshell %s\n", version());
return null;
@@ -630,7 +640,19 @@
commandLineFeedbackMode = "verbose";
}
if (options.has(r)) {
- remoteVMOptions = options.valuesOf(r);
+ remoteVMOptions.addAll(options.valuesOf(r));
+ }
+ if (options.has(c)) {
+ compilerOptions.addAll(options.valuesOf(c));
+ }
+
+ if (options.has(addExports)) {
+ List<String> exports = options.valuesOf(addExports).stream()
+ .map(mp -> mp + "=ALL-UNNAMED")
+ .flatMap(mp -> Stream.of("--add-exports", mp))
+ .collect(toList());
+ remoteVMOptions.addAll(exports);
+ compilerOptions.addAll(exports);
}
return options.valuesOf(loadFileSpec);
@@ -640,6 +662,10 @@
cmdout.print(getResourceString("help.usage"));
}
+ private void printUsageX() {
+ cmdout.print(getResourceString("help.usage.x"));
+ }
+
/**
* Message handler to use during initial start-up.
*/
@@ -683,7 +709,8 @@
.idGenerator((sn, i) -> (currentNameSpace == startNamespace || state.status(sn).isActive())
? currentNameSpace.tid(sn)
: errorNamespace.tid(sn))
- .remoteVMOptions(remoteVMOptions.toArray(new String[remoteVMOptions.size()]))
+ .remoteVMOptions(remoteVMOptions.stream().toArray(String[]::new))
+ .compilerOptions(compilerOptions.stream().toArray(String[]::new))
.build();
shutdownSubscription = state.onShutdown((JShell deadState) -> {
if (deadState == state) {
--- a/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/resources/l10n.properties Wed Sep 28 09:05:20 2016 +0530
+++ b/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/resources/l10n.properties Wed Sep 28 16:36:10 2016 +0900
@@ -164,8 +164,15 @@
\ Use one -J for each runtime flag or flag argument\n\
\ -R<flag> Pass <flag> to the remote runtime system.\n\
\ Use one -R for each remote flag or flag argument\n\
+\ -C<flag> Pass <flag> to the compiler.\n\
+\ Use one -C for each compiler flag or flag argument\n\
\ --help Print this synopsis of standard options\n\
-\ --version Version information\n
+\ --version Version information\n\
+\ -X Print help on non-standard options\n
+help.usage.x = \
+\ --add-exports <module>/<package> Export specified module-private package to snippets\n\
+\ \n\
+\These options are non-standard and subject to change without notice.\n
help.list.summary = list the source you have typed
help.list.args = [<name or id>|-all|-start]
--- a/langtools/test/jdk/jshell/ToolBasicTest.java Wed Sep 28 09:05:20 2016 +0530
+++ b/langtools/test/jdk/jshell/ToolBasicTest.java Wed Sep 28 16:36:10 2016 +0900
@@ -23,7 +23,7 @@
/*
* @test
- * @bug 8143037 8142447 8144095 8140265 8144906 8146138 8147887 8147886 8148316 8148317 8143955 8157953 8080347
+ * @bug 8143037 8142447 8144095 8140265 8144906 8146138 8147887 8147886 8148316 8148317 8143955 8157953 8080347 8154714
* @summary Tests for Basic tests for REPL tool
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
@@ -574,4 +574,20 @@
}
}
+ public void testAddExports() {
+ test(false, new String[]{"--no-startup"},
+ a -> assertCommandOutputStartsWith(a, "import jdk.internal.misc.VM;", "| Error:")
+ );
+ test(false, new String[]{"--no-startup",
+ "-R--add-exports", "-Rjava.base/jdk.internal.misc=ALL-UNNAMED",
+ "-C--add-exports", "-Cjava.base/jdk.internal.misc=ALL-UNNAMED"},
+ a -> assertImport(a, "import jdk.internal.misc.VM;", "", "jdk.internal.misc.VM"),
+ a -> assertCommand(a, "System.err.println(VM.isBooted())", "", "", null, "", "true\n")
+ );
+ test(false, new String[]{"--no-startup", "--add-exports", "java.base/jdk.internal.misc"},
+ a -> assertImport(a, "import jdk.internal.misc.VM;", "", "jdk.internal.misc.VM"),
+ a -> assertCommand(a, "System.err.println(VM.isBooted())", "", "", null, "", "true\n")
+ );
+ }
+
}