810 } else { |
810 } else { |
811 return s; |
811 return s; |
812 } |
812 } |
813 } |
813 } |
814 |
814 |
|
815 /** |
|
816 * The entry point into the JShell tool. |
|
817 * |
|
818 * @param args the command-line arguments |
|
819 * @throws Exception catastrophic fatal exception |
|
820 */ |
815 public void start(String[] args) throws Exception { |
821 public void start(String[] args) throws Exception { |
816 OptionParserCommandLine commandLineArgs = new OptionParserCommandLine(); |
822 OptionParserCommandLine commandLineArgs = new OptionParserCommandLine(); |
817 options = commandLineArgs.parse(args); |
823 options = commandLineArgs.parse(args); |
818 if (options == null) { |
824 if (options == null) { |
819 // Abort |
825 // Abort |
840 // if we haven't died, and the feedback mode wants fluff, print welcome |
846 // if we haven't died, and the feedback mode wants fluff, print welcome |
841 if (feedback.shouldDisplayCommandFluff()) { |
847 if (feedback.shouldDisplayCommandFluff()) { |
842 hardmsg("jshell.msg.welcome", version()); |
848 hardmsg("jshell.msg.welcome", version()); |
843 } |
849 } |
844 // Be sure history is always saved so that user code isn't lost |
850 // Be sure history is always saved so that user code isn't lost |
845 Runtime.getRuntime().addShutdownHook(new Thread() { |
851 Thread shutdownHook = new Thread() { |
846 @Override |
852 @Override |
847 public void run() { |
853 public void run() { |
848 replayableHistory.storeHistory(prefs); |
854 replayableHistory.storeHistory(prefs); |
849 } |
855 } |
850 }); |
856 }; |
|
857 Runtime.getRuntime().addShutdownHook(shutdownHook); |
851 // execute from user input |
858 // execute from user input |
852 try (IOContext in = new ConsoleIOContext(this, cmdin, console)) { |
859 try (IOContext in = new ConsoleIOContext(this, cmdin, console)) { |
853 start(in); |
860 while (regenerateOnDeath) { |
854 } |
861 if (!live) { |
855 } |
862 resetState(); |
856 } |
863 } |
857 |
864 run(in); |
858 private void start(IOContext in) { |
865 } |
859 try { |
866 } finally { |
860 while (regenerateOnDeath) { |
867 replayableHistory.storeHistory(prefs); |
861 if (!live) { |
868 closeState(); |
862 resetState(); |
869 try { |
863 } |
870 Runtime.getRuntime().removeShutdownHook(shutdownHook); |
864 run(in); |
871 } catch (Exception ex) { |
865 } |
872 // ignore, this probably caused by VM aready being shutdown |
866 } finally { |
873 // and this is the last act anyhow |
867 closeState(); |
874 } |
868 } |
875 } |
|
876 } |
|
877 closeState(); |
869 } |
878 } |
870 |
879 |
871 private EditorSetting configEditor() { |
880 private EditorSetting configEditor() { |
872 // Read retained editor setting (if any) |
881 // Read retained editor setting (if any) |
873 editor = EditorSetting.fromPrefs(prefs); |
882 editor = EditorSetting.fromPrefs(prefs); |