8134397: Features that require AWT, swing should handle headless mode properly
authorsundar
Tue, 25 Aug 2015 18:16:10 +0530
changeset 32320 3e408f16c1c9
parent 32319 3f22ddeabc0e
child 32321 b883916a29ff
8134397: Features that require AWT, swing should handle headless mode properly Reviewed-by: hannesw, attila
nashorn/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/EditObject.java
nashorn/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/Main.java
nashorn/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/NashornCompleter.java
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/tools/resources/Shell.properties
--- a/nashorn/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/EditObject.java	Tue Aug 25 14:47:42 2015 +0530
+++ b/nashorn/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/nashorn/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/Main.java	Tue Aug 25 14:47:42 2015 +0530
+++ b/nashorn/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/nashorn/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/NashornCompleter.java	Tue Aug 25 14:47:42 2015 +0530
+++ b/nashorn/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/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/tools/resources/Shell.properties	Tue Aug 25 14:47:42 2015 +0530
+++ b/nashorn/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!