author | tonyp |
Fri, 19 Jul 2019 12:39:31 -0400 | |
changeset 55751 | 014decdb5086 |
parent 52938 | 5ff7480c9e28 |
permissions | -rw-r--r-- |
32152
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
1 |
/* |
52938 | 2 |
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
32152
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
4 |
* |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
10 |
* |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
15 |
* accompanied this code). |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
16 |
* |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
20 |
* |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
23 |
* questions. |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
24 |
*/ |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
25 |
|
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
26 |
package jdk.nashorn.tools.jjs; |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
27 |
|
34735
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
28 |
import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; |
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
29 |
|
32242
bbc1ebbb5cdc
8133777: Use file based persistence for history instead of preferences
sundar
parents:
32241
diff
changeset
|
30 |
import java.io.File; |
32152
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
31 |
import java.io.InputStream; |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
32 |
import java.io.IOException; |
40479 | 33 |
import java.io.UncheckedIOException; |
32152
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
34 |
import java.io.OutputStream; |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
35 |
import java.io.PrintWriter; |
34735
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
36 |
import java.net.URI; |
47704
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
37 |
import java.security.AccessController; |
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
38 |
import java.security.PrivilegedAction; |
32324
b021cc36fd65
8134562: jjs history object should have methods to save/load history to/from given file and also allow reexecution of commands by a call
sundar
parents:
32320
diff
changeset
|
39 |
import java.util.function.Consumer; |
52938 | 40 |
|
41 |
import jdk.internal.org.jline.reader.UserInterruptException; |
|
32152
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
42 |
import jdk.nashorn.internal.objects.Global; |
34735
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
43 |
import jdk.nashorn.internal.objects.NativeJava; |
32152
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
44 |
import jdk.nashorn.internal.runtime.Context; |
34735
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
45 |
import jdk.nashorn.internal.runtime.NativeJavaPackage; |
32313
11b284f8c4c6
8133948: Add 'edit' function to allow external editing of scripts
sundar
parents:
32245
diff
changeset
|
46 |
import jdk.nashorn.internal.runtime.Property; |
32152
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
47 |
import jdk.nashorn.internal.runtime.ScriptEnvironment; |
34735
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
48 |
import jdk.nashorn.internal.runtime.ScriptFunction; |
40479 | 49 |
import jdk.nashorn.internal.runtime.ScriptingFunctions; |
34845
48ffe69dacef
8146253: jjs should look for "doc string" property to print documentation on shift-tab
sundar
parents:
34735
diff
changeset
|
50 |
import jdk.nashorn.internal.runtime.ScriptObject; |
32152
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
51 |
import jdk.nashorn.internal.runtime.ScriptRuntime; |
47704
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
52 |
import jdk.nashorn.internal.runtime.Source; |
32152
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
53 |
import jdk.nashorn.tools.Shell; |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
54 |
|
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
55 |
/** |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
56 |
* Interactive command line Shell for Nashorn. |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
57 |
*/ |
50878
fb7800b66c92
8204492: Add deprecation annotation to Nashorn APIs and warning to nashorn, jjs
sundar
parents:
48327
diff
changeset
|
58 |
@Deprecated(since="11", forRemoval=true) |
32152
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
59 |
public final class Main extends Shell { |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
60 |
private Main() {} |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
61 |
|
34845
48ffe69dacef
8146253: jjs should look for "doc string" property to print documentation on shift-tab
sundar
parents:
34735
diff
changeset
|
62 |
private static final String DOC_PROPERTY_NAME = "__doc__"; |
48ffe69dacef
8146253: jjs should look for "doc string" property to print documentation on shift-tab
sundar
parents:
34735
diff
changeset
|
63 |
|
32314
8f7d23d3b1ad
8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
32313
diff
changeset
|
64 |
static final boolean DEBUG = Boolean.getBoolean("nashorn.jjs.debug"); |
8f7d23d3b1ad
8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
32313
diff
changeset
|
65 |
|
32242
bbc1ebbb5cdc
8133777: Use file based persistence for history instead of preferences
sundar
parents:
32241
diff
changeset
|
66 |
// file where history is persisted. |
bbc1ebbb5cdc
8133777: Use file based persistence for history instead of preferences
sundar
parents:
32241
diff
changeset
|
67 |
private static final File HIST_FILE = new File(new File(System.getProperty("user.home")), ".jjs.history"); |
32152
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
68 |
|
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
69 |
/** |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
70 |
* Main entry point with the default input, output and error streams. |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
71 |
* |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
72 |
* @param args The command line arguments |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
73 |
*/ |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
74 |
public static void main(final String[] args) { |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
75 |
try { |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
76 |
final int exitCode = main(System.in, System.out, System.err, args); |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
77 |
if (exitCode != SUCCESS) { |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
78 |
System.exit(exitCode); |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
79 |
} |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
80 |
} catch (final IOException e) { |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
81 |
System.err.println(e); //bootstrapping, Context.err may not exist |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
82 |
System.exit(IO_ERROR); |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
83 |
} |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
84 |
} |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
85 |
|
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
86 |
/** |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
87 |
* Starting point for executing a {@code Shell}. Starts a shell with the |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
88 |
* given arguments and streams and lets it run until exit. |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
89 |
* |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
90 |
* @param in input stream for Shell |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
91 |
* @param out output stream for Shell |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
92 |
* @param err error stream for Shell |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
93 |
* @param args arguments to Shell |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
94 |
* |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
95 |
* @return exit code |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
96 |
* |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
97 |
* @throws IOException if there's a problem setting up the streams |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
98 |
*/ |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
99 |
public static int main(final InputStream in, final OutputStream out, final OutputStream err, final String[] args) throws IOException { |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
100 |
return new Main().run(in, out, err, args); |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
101 |
} |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
102 |
|
32245
80164edf8a10
8133872: Expression completion should work on contexts where an expression is accepted
sundar
parents:
32242
diff
changeset
|
103 |
|
32152
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
104 |
/** |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
105 |
* read-eval-print loop for Nashorn shell. |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
106 |
* |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
107 |
* @param context the nashorn context |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
108 |
* @param global global scope object to use |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
109 |
* @return return code |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
110 |
*/ |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
111 |
protected int readEvalPrint(final Context context, final Global global) { |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
112 |
final ScriptEnvironment env = context.getEnv(); |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
113 |
final String prompt = bundle.getString("shell.prompt"); |
32317
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
114 |
final String prompt2 = bundle.getString("shell.prompt2"); |
32152
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
115 |
final PrintWriter err = context.getErr(); |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
116 |
final Global oldGlobal = Context.getGlobal(); |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
117 |
final boolean globalChanged = (oldGlobal != global); |
38897
b92825d7708c
8158922: jjs tab completion of Java classes shows package-private, "hidden" classes too
sundar
parents:
34845
diff
changeset
|
118 |
final PropertiesHelper propsHelper = new PropertiesHelper(context); |
47492
560fab171dc7
8190698: jjs tool of jdk.scripting.nashorn.shell module should not statically depend on java.desktop
sundar
parents:
47216
diff
changeset
|
119 |
|
560fab171dc7
8190698: jjs tool of jdk.scripting.nashorn.shell module should not statically depend on java.desktop
sundar
parents:
47216
diff
changeset
|
120 |
if (globalChanged) { |
560fab171dc7
8190698: jjs tool of jdk.scripting.nashorn.shell module should not statically depend on java.desktop
sundar
parents:
47216
diff
changeset
|
121 |
Context.setGlobal(global); |
560fab171dc7
8190698: jjs tool of jdk.scripting.nashorn.shell module should not statically depend on java.desktop
sundar
parents:
47216
diff
changeset
|
122 |
} |
560fab171dc7
8190698: jjs tool of jdk.scripting.nashorn.shell module should not statically depend on java.desktop
sundar
parents:
47216
diff
changeset
|
123 |
|
47704
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
124 |
// jjs.js is read and evaluated. The result of the evaluation is an "exports" object. This is done |
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
125 |
// to avoid polluting javascript global scope. These are internal funtions are retrieved from the |
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
126 |
// 'exports' object and used from here. |
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
127 |
final ScriptObject jjsObj = (ScriptObject)context.eval(global, readJJSScript(), global, "<jjs.js>"); |
47492
560fab171dc7
8190698: jjs tool of jdk.scripting.nashorn.shell module should not statically depend on java.desktop
sundar
parents:
47216
diff
changeset
|
128 |
|
47704
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
129 |
final boolean isHeadless = (boolean) ScriptRuntime.apply((ScriptFunction) jjsObj.get("isHeadless"), null); |
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
130 |
final ScriptFunction fileChooserFunc = isHeadless? null : (ScriptFunction) jjsObj.get("chooseFile"); |
47492
560fab171dc7
8190698: jjs tool of jdk.scripting.nashorn.shell module should not statically depend on java.desktop
sundar
parents:
47216
diff
changeset
|
131 |
|
560fab171dc7
8190698: jjs tool of jdk.scripting.nashorn.shell module should not statically depend on java.desktop
sundar
parents:
47216
diff
changeset
|
132 |
final NashornCompleter completer = new NashornCompleter(context, global, this, propsHelper, fileChooserFunc); |
47704
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
133 |
final ScriptFunction browseFunc = isHeadless? null : (ScriptFunction) jjsObj.get("browse"); |
47492
560fab171dc7
8190698: jjs tool of jdk.scripting.nashorn.shell module should not statically depend on java.desktop
sundar
parents:
47216
diff
changeset
|
134 |
|
47704
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
135 |
final ScriptFunction javadoc = (ScriptFunction) jjsObj.get("javadoc"); |
32240
d7c7a5dc92d8
8133652: Implement tab-completion for member select expressions
sundar
parents:
32152
diff
changeset
|
136 |
|
34735
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
137 |
try (final Console in = new Console(System.in, System.out, HIST_FILE, completer, |
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
138 |
str -> { |
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
139 |
try { |
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
140 |
final Object res = context.eval(global, str, global, "<shell>"); |
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
141 |
if (res != null && res != UNDEFINED) { |
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
142 |
// Special case Java types: show the javadoc for the class. |
47492
560fab171dc7
8190698: jjs tool of jdk.scripting.nashorn.shell module should not statically depend on java.desktop
sundar
parents:
47216
diff
changeset
|
143 |
if (!isHeadless && NativeJava.isType(UNDEFINED, res)) { |
34735
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
144 |
final String typeName = NativeJava.typeName(UNDEFINED, res).toString(); |
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
145 |
final String url = typeName.replace('.', '/').replace('$', '.') + ".html"; |
47492
560fab171dc7
8190698: jjs tool of jdk.scripting.nashorn.shell module should not statically depend on java.desktop
sundar
parents:
47216
diff
changeset
|
146 |
openBrowserForJavadoc(browseFunc, url); |
560fab171dc7
8190698: jjs tool of jdk.scripting.nashorn.shell module should not statically depend on java.desktop
sundar
parents:
47216
diff
changeset
|
147 |
} else if (!isHeadless && res instanceof NativeJavaPackage) { |
34735
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
148 |
final String pkgName = ((NativeJavaPackage)res).getName(); |
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
149 |
final String url = pkgName.replace('.', '/') + "/package-summary.html"; |
47492
560fab171dc7
8190698: jjs tool of jdk.scripting.nashorn.shell module should not statically depend on java.desktop
sundar
parents:
47216
diff
changeset
|
150 |
openBrowserForJavadoc(browseFunc, url); |
47704
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
151 |
} else if (NativeJava.isJavaMethod(UNDEFINED, res)) { |
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
152 |
ScriptRuntime.apply(javadoc, UNDEFINED, res); |
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
153 |
return ""; // javadoc function already prints javadoc |
34845
48ffe69dacef
8146253: jjs should look for "doc string" property to print documentation on shift-tab
sundar
parents:
34735
diff
changeset
|
154 |
} else if (res instanceof ScriptObject) { |
48ffe69dacef
8146253: jjs should look for "doc string" property to print documentation on shift-tab
sundar
parents:
34735
diff
changeset
|
155 |
final ScriptObject sobj = (ScriptObject)res; |
48ffe69dacef
8146253: jjs should look for "doc string" property to print documentation on shift-tab
sundar
parents:
34735
diff
changeset
|
156 |
if (sobj.has(DOC_PROPERTY_NAME)) { |
48ffe69dacef
8146253: jjs should look for "doc string" property to print documentation on shift-tab
sundar
parents:
34735
diff
changeset
|
157 |
return toString(sobj.get(DOC_PROPERTY_NAME), global); |
48ffe69dacef
8146253: jjs should look for "doc string" property to print documentation on shift-tab
sundar
parents:
34735
diff
changeset
|
158 |
} else if (sobj instanceof ScriptFunction) { |
48ffe69dacef
8146253: jjs should look for "doc string" property to print documentation on shift-tab
sundar
parents:
34735
diff
changeset
|
159 |
return ((ScriptFunction)sobj).getDocumentation(); |
48ffe69dacef
8146253: jjs should look for "doc string" property to print documentation on shift-tab
sundar
parents:
34735
diff
changeset
|
160 |
} |
34735
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
161 |
} |
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
162 |
|
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
163 |
// FIXME: better than toString for other cases? |
34845
48ffe69dacef
8146253: jjs should look for "doc string" property to print documentation on shift-tab
sundar
parents:
34735
diff
changeset
|
164 |
return toString(res, global); |
34735
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
165 |
} |
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
166 |
} catch (Exception ignored) { |
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
167 |
} |
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
168 |
return null; |
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
169 |
})) { |
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
170 |
|
32152
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
171 |
global.addShellBuiltins(); |
32313
11b284f8c4c6
8133948: Add 'edit' function to allow external editing of scripts
sundar
parents:
32245
diff
changeset
|
172 |
|
40479 | 173 |
// redefine readLine to use jline Console's readLine! |
174 |
ScriptingFunctions.setReadLineHelper(str-> { |
|
175 |
try { |
|
52938 | 176 |
return in.readUserLine(str); |
40479 | 177 |
} catch (final IOException ioExp) { |
178 |
throw new UncheckedIOException(ioExp); |
|
179 |
} |
|
180 |
}); |
|
181 |
||
32313
11b284f8c4c6
8133948: Add 'edit' function to allow external editing of scripts
sundar
parents:
32245
diff
changeset
|
182 |
if (System.getSecurityManager() == null) { |
32324
b021cc36fd65
8134562: jjs history object should have methods to save/load history to/from given file and also allow reexecution of commands by a call
sundar
parents:
32320
diff
changeset
|
183 |
final Consumer<String> evaluator = str -> { |
b021cc36fd65
8134562: jjs history object should have methods to save/load history to/from given file and also allow reexecution of commands by a call
sundar
parents:
32320
diff
changeset
|
184 |
// could be called from different thread (GUI), we need to handle Context set/reset |
b021cc36fd65
8134562: jjs history object should have methods to save/load history to/from given file and also allow reexecution of commands by a call
sundar
parents:
32320
diff
changeset
|
185 |
final Global _oldGlobal = Context.getGlobal(); |
40576 | 186 |
final boolean _globalChanged = (_oldGlobal != global); |
32324
b021cc36fd65
8134562: jjs history object should have methods to save/load history to/from given file and also allow reexecution of commands by a call
sundar
parents:
32320
diff
changeset
|
187 |
if (_globalChanged) { |
b021cc36fd65
8134562: jjs history object should have methods to save/load history to/from given file and also allow reexecution of commands by a call
sundar
parents:
32320
diff
changeset
|
188 |
Context.setGlobal(global); |
b021cc36fd65
8134562: jjs history object should have methods to save/load history to/from given file and also allow reexecution of commands by a call
sundar
parents:
32320
diff
changeset
|
189 |
} |
b021cc36fd65
8134562: jjs history object should have methods to save/load history to/from given file and also allow reexecution of commands by a call
sundar
parents:
32320
diff
changeset
|
190 |
try { |
b021cc36fd65
8134562: jjs history object should have methods to save/load history to/from given file and also allow reexecution of commands by a call
sundar
parents:
32320
diff
changeset
|
191 |
evalImpl(context, global, str, err, env._dump_on_error); |
b021cc36fd65
8134562: jjs history object should have methods to save/load history to/from given file and also allow reexecution of commands by a call
sundar
parents:
32320
diff
changeset
|
192 |
} finally { |
b021cc36fd65
8134562: jjs history object should have methods to save/load history to/from given file and also allow reexecution of commands by a call
sundar
parents:
32320
diff
changeset
|
193 |
if (_globalChanged) { |
b021cc36fd65
8134562: jjs history object should have methods to save/load history to/from given file and also allow reexecution of commands by a call
sundar
parents:
32320
diff
changeset
|
194 |
Context.setGlobal(_oldGlobal); |
b021cc36fd65
8134562: jjs history object should have methods to save/load history to/from given file and also allow reexecution of commands by a call
sundar
parents:
32320
diff
changeset
|
195 |
} |
b021cc36fd65
8134562: jjs history object should have methods to save/load history to/from given file and also allow reexecution of commands by a call
sundar
parents:
32320
diff
changeset
|
196 |
} |
b021cc36fd65
8134562: jjs history object should have methods to save/load history to/from given file and also allow reexecution of commands by a call
sundar
parents:
32320
diff
changeset
|
197 |
}; |
b021cc36fd65
8134562: jjs history object should have methods to save/load history to/from given file and also allow reexecution of commands by a call
sundar
parents:
32320
diff
changeset
|
198 |
|
32313
11b284f8c4c6
8133948: Add 'edit' function to allow external editing of scripts
sundar
parents:
32245
diff
changeset
|
199 |
// expose history object for reflecting on command line history |
32324
b021cc36fd65
8134562: jjs history object should have methods to save/load history to/from given file and also allow reexecution of commands by a call
sundar
parents:
32320
diff
changeset
|
200 |
global.addOwnProperty("history", Property.NOT_ENUMERABLE, new HistoryObject(in.getHistory(), err, evaluator)); |
32313
11b284f8c4c6
8133948: Add 'edit' function to allow external editing of scripts
sundar
parents:
32245
diff
changeset
|
201 |
|
11b284f8c4c6
8133948: Add 'edit' function to allow external editing of scripts
sundar
parents:
32245
diff
changeset
|
202 |
// 'edit' command |
32324
b021cc36fd65
8134562: jjs history object should have methods to save/load history to/from given file and also allow reexecution of commands by a call
sundar
parents:
32320
diff
changeset
|
203 |
global.addOwnProperty("edit", Property.NOT_ENUMERABLE, new EditObject(in, err::println, evaluator)); |
32313
11b284f8c4c6
8133948: Add 'edit' function to allow external editing of scripts
sundar
parents:
32245
diff
changeset
|
204 |
} |
32152
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
205 |
|
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
206 |
while (true) { |
52938 | 207 |
String source; |
32152
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
208 |
try { |
52938 | 209 |
source = in.readLine(prompt, prompt2); |
32152
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
210 |
} catch (final IOException ioe) { |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
211 |
err.println(ioe.toString()); |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
212 |
if (env._dump_on_error) { |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
213 |
ioe.printStackTrace(err); |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
214 |
} |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
215 |
return IO_ERROR; |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
216 |
} catch (final UserInterruptException ex) { |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
217 |
break; |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
218 |
} |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
219 |
|
32896 | 220 |
if (source == null) { |
221 |
break; |
|
222 |
} |
|
223 |
||
32152
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
224 |
if (source.isEmpty()) { |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
225 |
continue; |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
226 |
} |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
227 |
|
32317
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
228 |
try { |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
229 |
final Object res = context.eval(global, source, global, "<shell>"); |
34735
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
230 |
if (res != UNDEFINED) { |
33690 | 231 |
err.println(toString(res, global)); |
32317
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
232 |
} |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
233 |
} catch (final Exception exp) { |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
234 |
// Is this a ECMAScript SyntaxError at last column (of the single line)? |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
235 |
// If so, it is because parser expected more input but got EOF. Try to |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
236 |
// to more lines from the user (multiline edit support). |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
237 |
|
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
238 |
if (completer.isSyntaxErrorAt(exp, 1, source.length())) { |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
239 |
final String fullSrc = completer.readMoreLines(source, exp, in, prompt2, err); |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
240 |
|
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
241 |
// check if we succeeded in getting complete code. |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
242 |
if (fullSrc != null && !fullSrc.isEmpty()) { |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
243 |
evalImpl(context, global, fullSrc, err, env._dump_on_error); |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
244 |
} // else ignore, error reported already by 'completer.readMoreLines' |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
245 |
} else { |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
246 |
|
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
247 |
// can't read more lines to have parseable/complete code. |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
248 |
err.println(exp); |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
249 |
if (env._dump_on_error) { |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
250 |
exp.printStackTrace(err); |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
251 |
} |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
252 |
} |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
253 |
} |
32152
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
254 |
} |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
255 |
} catch (final Exception e) { |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
256 |
err.println(e); |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
257 |
if (env._dump_on_error) { |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
258 |
e.printStackTrace(err); |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
259 |
} |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
260 |
} finally { |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
261 |
if (globalChanged) { |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
262 |
Context.setGlobal(oldGlobal); |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
263 |
} |
32314
8f7d23d3b1ad
8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
32313
diff
changeset
|
264 |
try { |
8f7d23d3b1ad
8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
32313
diff
changeset
|
265 |
propsHelper.close(); |
8f7d23d3b1ad
8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
32313
diff
changeset
|
266 |
} catch (final Exception exp) { |
8f7d23d3b1ad
8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
32313
diff
changeset
|
267 |
if (DEBUG) { |
8f7d23d3b1ad
8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
32313
diff
changeset
|
268 |
exp.printStackTrace(); |
8f7d23d3b1ad
8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
32313
diff
changeset
|
269 |
} |
8f7d23d3b1ad
8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
32313
diff
changeset
|
270 |
} |
32152
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
271 |
} |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
272 |
|
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
273 |
return SUCCESS; |
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
274 |
} |
32313
11b284f8c4c6
8133948: Add 'edit' function to allow external editing of scripts
sundar
parents:
32245
diff
changeset
|
275 |
|
32320
3e408f16c1c9
8134397: Features that require AWT, swing should handle headless mode properly
sundar
parents:
32317
diff
changeset
|
276 |
static String getMessage(final String id) { |
3e408f16c1c9
8134397: Features that require AWT, swing should handle headless mode properly
sundar
parents:
32317
diff
changeset
|
277 |
return bundle.getString(id); |
3e408f16c1c9
8134397: Features that require AWT, swing should handle headless mode properly
sundar
parents:
32317
diff
changeset
|
278 |
} |
3e408f16c1c9
8134397: Features that require AWT, swing should handle headless mode properly
sundar
parents:
32317
diff
changeset
|
279 |
|
32313
11b284f8c4c6
8133948: Add 'edit' function to allow external editing of scripts
sundar
parents:
32245
diff
changeset
|
280 |
private void evalImpl(final Context context, final Global global, final String source, |
11b284f8c4c6
8133948: Add 'edit' function to allow external editing of scripts
sundar
parents:
32245
diff
changeset
|
281 |
final PrintWriter err, final boolean doe) { |
11b284f8c4c6
8133948: Add 'edit' function to allow external editing of scripts
sundar
parents:
32245
diff
changeset
|
282 |
try { |
11b284f8c4c6
8133948: Add 'edit' function to allow external editing of scripts
sundar
parents:
32245
diff
changeset
|
283 |
final Object res = context.eval(global, source, global, "<shell>"); |
34735
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
284 |
if (res != UNDEFINED) { |
34845
48ffe69dacef
8146253: jjs should look for "doc string" property to print documentation on shift-tab
sundar
parents:
34735
diff
changeset
|
285 |
err.println(toString(res, global)); |
32313
11b284f8c4c6
8133948: Add 'edit' function to allow external editing of scripts
sundar
parents:
32245
diff
changeset
|
286 |
} |
11b284f8c4c6
8133948: Add 'edit' function to allow external editing of scripts
sundar
parents:
32245
diff
changeset
|
287 |
} catch (final Exception e) { |
11b284f8c4c6
8133948: Add 'edit' function to allow external editing of scripts
sundar
parents:
32245
diff
changeset
|
288 |
err.println(e); |
11b284f8c4c6
8133948: Add 'edit' function to allow external editing of scripts
sundar
parents:
32245
diff
changeset
|
289 |
if (doe) { |
11b284f8c4c6
8133948: Add 'edit' function to allow external editing of scripts
sundar
parents:
32245
diff
changeset
|
290 |
e.printStackTrace(err); |
11b284f8c4c6
8133948: Add 'edit' function to allow external editing of scripts
sundar
parents:
32245
diff
changeset
|
291 |
} |
11b284f8c4c6
8133948: Add 'edit' function to allow external editing of scripts
sundar
parents:
32245
diff
changeset
|
292 |
} |
11b284f8c4c6
8133948: Add 'edit' function to allow external editing of scripts
sundar
parents:
32245
diff
changeset
|
293 |
} |
34735
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
294 |
|
47927
a6b2d28c8094
8191810: jjs should avoid hard coded javadoc base url for shift-tab documentation feature
sundar
parents:
47704
diff
changeset
|
295 |
private static String JAVADOC_BASE = "https://docs.oracle.com/javase/%d/docs/api/"; |
47492
560fab171dc7
8190698: jjs tool of jdk.scripting.nashorn.shell module should not statically depend on java.desktop
sundar
parents:
47216
diff
changeset
|
296 |
private static void openBrowserForJavadoc(ScriptFunction browse, String relativeUrl) { |
34735
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
297 |
try { |
48327 | 298 |
final URI uri = new URI(String.format(JAVADOC_BASE, Runtime.version().feature()) + relativeUrl); |
47492
560fab171dc7
8190698: jjs tool of jdk.scripting.nashorn.shell module should not statically depend on java.desktop
sundar
parents:
47216
diff
changeset
|
299 |
ScriptRuntime.apply(browse, null, uri); |
34735
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
300 |
} catch (Exception ignored) { |
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
301 |
} |
0f41d334aa24
8145486: jjs should support documentation key shortcut in interactive mode
sundar
parents:
33690
diff
changeset
|
302 |
} |
47704
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
303 |
|
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
304 |
private static String readJJSScript() { |
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
305 |
return AccessController.doPrivileged( |
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
306 |
new PrivilegedAction<String>() { |
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
307 |
@Override |
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
308 |
public String run() { |
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
309 |
try { |
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
310 |
final InputStream resStream = Main.class.getResourceAsStream("resources/jjs.js"); |
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
311 |
if (resStream == null) { |
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
312 |
throw new RuntimeException("resources/jjs.js is missing!"); |
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
313 |
} |
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
314 |
return new String(Source.readFully(resStream)); |
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
315 |
} catch (final IOException exp) { |
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
316 |
throw new RuntimeException(exp); |
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
317 |
} |
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
318 |
} |
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
319 |
}); |
38aa08d2ec6c
8190795: jjs should show javadoc for java methods on shift-tab
sundar
parents:
47492
diff
changeset
|
320 |
} |
32152
705d4af0d4d7
8133347: Add makefiles support and basic session, persistence history navigation with jline
sundar
parents:
diff
changeset
|
321 |
} |