8023210: jjs tools should support a mode where it will load few command line scripts and then entering into interactive shell
Reviewed-by: hannesw, attila, lagergren, jlaskey
--- a/nashorn/src/jdk/nashorn/internal/runtime/options/Options.java Fri Aug 16 18:51:53 2013 +0200
+++ b/nashorn/src/jdk/nashorn/internal/runtime/options/Options.java Mon Aug 19 17:16:54 2013 +0530
@@ -408,13 +408,13 @@
final LinkedList<String> argList = new LinkedList<>();
Collections.addAll(argList, args);
- final String extra = getStringProperty(NASHORN_ARGS_PROPERTY, null);
- if (extra != null) {
- final StringTokenizer st = new StringTokenizer(extra);
- while (st.hasMoreTokens()) {
- argList.add(st.nextToken());
+ final String extra = getStringProperty(NASHORN_ARGS_PROPERTY, null);
+ if (extra != null) {
+ final StringTokenizer st = new StringTokenizer(extra);
+ while (st.hasMoreTokens()) {
+ argList.add(st.nextToken());
+ }
}
- }
while (!argList.isEmpty()) {
final String arg = argList.remove(0);
@@ -431,8 +431,9 @@
continue;
}
- // if it doesn't start with -, it's a file
- if (!arg.startsWith("-")) {
+ // If it doesn't start with -, it's a file. But, if it is just "-",
+ // then it is a file representing standard input.
+ if (!arg.startsWith("-") || arg.length() == 1) {
files.add(arg);
continue;
}
--- a/nashorn/src/jdk/nashorn/tools/Shell.java Fri Aug 16 18:51:53 2013 +0200
+++ b/nashorn/src/jdk/nashorn/tools/Shell.java Mon Aug 19 17:16:54 2013 +0530
@@ -292,6 +292,14 @@
// For each file on the command line.
for (final String fileName : files) {
+ if ("-".equals(fileName)) {
+ final int res = readEvalPrint(context, global);
+ if (res != SUCCESS) {
+ return res;
+ }
+ continue;
+ }
+
final File file = new File(fileName);
final ScriptFunction script = context.compileScript(new Source(fileName, file.toURI().toURL()), global);
if (script == null || errors.getNumberOfErrors() != 0) {