8134397: Features that require AWT, swing should handle headless mode properly

Reviewed-by: hannesw, attila
This commit is contained in:
Athijegannathan Sundararajan 2015-08-25 18:16:10 +05:30
parent a4e75d9f12
commit 1734a60ae0
4 changed files with 16 additions and 2 deletions

View File

@ -86,7 +86,7 @@ final class EditObject extends AbstractJSObject {
@Override
public void setMember(final String name, final Object value) {
if (name.equals("editor")) {
this.editor = JSType.toString(value);
this.editor = value != null && value != UNDEFINED? JSType.toString(value) : "";
}
}
@ -115,8 +115,10 @@ final class EditObject extends AbstractJSObject {
final SaveHandler saveHandler = new SaveHandler(initText);
if (editor != null && !editor.isEmpty()) {
ExternalEditor.edit(editor, errorHandler, initText, saveHandler, console);
} else {
} else if (! Main.HEADLESS) {
EditPad.edit(errorHandler, initText, saveHandler);
} else {
errorHandler.accept(Main.getMessage("no.editor"));
}
return UNDEFINED;
}

View File

@ -25,6 +25,7 @@
package jdk.nashorn.tools.jjs;
import java.awt.GraphicsEnvironment;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStream;
@ -50,6 +51,7 @@ public final class Main extends Shell {
private Main() {}
static final boolean DEBUG = Boolean.getBoolean("nashorn.jjs.debug");
static final boolean HEADLESS = GraphicsEnvironment.isHeadless();
// file where history is persisted.
private static final File HIST_FILE = new File(new File(System.getProperty("user.home")), ".jjs.history");
@ -202,6 +204,10 @@ public final class Main extends Shell {
return SUCCESS;
}
static String getMessage(final String id) {
return bundle.getString(id);
}
private void evalImpl(final Context context, final Global global, final String source,
final PrintWriter err, final boolean doe) {
try {

View File

@ -254,6 +254,11 @@ final class NashornCompleter implements Completer {
// read file name from the user using by showing a swing file chooser diablog
private static String readFileName(final PrintWriter err) {
// if running on AWT Headless mode, don't attempt swing dialog box!
if (Main.HEADLESS) {
return null;
}
final FutureTask<String> fileChooserTask = new FutureTask<String>(() -> {
// show a file chooser dialog box
final JFileChooser chooser = new JFileChooser();

View File

@ -31,3 +31,4 @@ shell.prompt=jjs>
shell.prompt2=...>
no.editor=AWT Headless mode set and no external editor is configured!