changeset 1390:4577d801c522

8134397: Features that require AWT, swing should handle headless mode properly Reviewed-by: hannesw, attila
author sundar
date Tue, 25 Aug 2015 18:16:10 +0530
parents fa839eaa06b0
children 5efd65e18b71
files src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/EditObject.java src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/Main.java src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/NashornCompleter.java src/jdk.scripting.nashorn/share/classes/jdk/nashorn/tools/resources/Shell.properties
diffstat 4 files changed, 16 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/EditObject.java	Tue Aug 25 14:47:42 2015 +0530
+++ b/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/EditObject.java	Tue Aug 25 18:16:10 2015 +0530
@@ -86,7 +86,7 @@
     @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 SaveHandler saveHandler = new SaveHandler(initText);
         if (editor != null && !editor.isEmpty()) {
             ExternalEditor.edit(editor, errorHandler, initText, saveHandler, console);
+        } else if (! Main.HEADLESS) {
+            EditPad.edit(errorHandler, initText, saveHandler);
         } else {
-            EditPad.edit(errorHandler, initText, saveHandler);
+            errorHandler.accept(Main.getMessage("no.editor"));
         }
         return UNDEFINED;
     }
--- a/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/Main.java	Tue Aug 25 14:47:42 2015 +0530
+++ b/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/Main.java	Tue Aug 25 18:16:10 2015 +0530
@@ -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 @@
     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 @@
         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 {
--- a/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/NashornCompleter.java	Tue Aug 25 14:47:42 2015 +0530
+++ b/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/NashornCompleter.java	Tue Aug 25 18:16:10 2015 +0530
@@ -254,6 +254,11 @@
 
     // 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();
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/tools/resources/Shell.properties	Tue Aug 25 14:47:42 2015 +0530
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/tools/resources/Shell.properties	Tue Aug 25 18:16:10 2015 +0530
@@ -31,3 +31,4 @@
 
 shell.prompt2=...> 
 
+no.editor=AWT Headless mode set and no external editor is configured!