src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellToolBuilder.java

Print this page




 212      * Create a tool instance for testing. Not in JavaShellToolBuilder.
 213      *
 214      * @return the tool instance
 215      */
 216     public JShellTool rawTool() {
 217         if (prefs == null) {
 218             prefs = new PreferencesStorage(Preferences.userRoot().node(PREFERENCES_NODE));
 219         }
 220         if (vars == null) {
 221             vars = System.getenv();
 222         }
 223         JShellTool sh = new JShellTool(cmdIn, cmdOut, cmdErr, console, userIn,
 224                 userOut, userErr, prefs, vars, locale);
 225         sh.testPrompt = capturePrompt;
 226         return sh;
 227     }
 228 
 229     /**
 230      * Run an instance of the Java shell tool as configured by the other methods
 231      * in this interface.  This call is not destructive, more than one call of
 232      * this method may be made from a configured builder.

 233      *
 234      * @param arguments the command-line arguments (including options), if any
 235      * @throws Exception an unexpected fatal exception
 236      */
 237     @Override
 238     public void run(String... arguments) throws Exception {
 239         rawTool().start(arguments);














 240     }
 241 
 242     /**
 243      * Persistence stored in Preferences.
 244      */
 245     private static class PreferencesStorage implements PersistentStorage {
 246 
 247         final Preferences p;
 248 
 249         PreferencesStorage(Preferences p) {
 250             this.p = p;
 251         }
 252 
 253         @Override
 254         public void clear() {
 255             try {
 256                 p.clear();
 257             } catch (BackingStoreException ex) {
 258                 throw new IllegalStateException(ex);
 259             }




 212      * Create a tool instance for testing. Not in JavaShellToolBuilder.
 213      *
 214      * @return the tool instance
 215      */
 216     public JShellTool rawTool() {
 217         if (prefs == null) {
 218             prefs = new PreferencesStorage(Preferences.userRoot().node(PREFERENCES_NODE));
 219         }
 220         if (vars == null) {
 221             vars = System.getenv();
 222         }
 223         JShellTool sh = new JShellTool(cmdIn, cmdOut, cmdErr, console, userIn,
 224                 userOut, userErr, prefs, vars, locale);
 225         sh.testPrompt = capturePrompt;
 226         return sh;
 227     }
 228 
 229     /**
 230      * Run an instance of the Java shell tool as configured by the other methods
 231      * in this interface.  This call is not destructive, more than one call of
 232      * this method may be made from a configured builder. The  exit code from
 233      * the Java shell tool is ignored.
 234      *
 235      * @param arguments the command-line arguments (including options), if any
 236      * @throws Exception an unexpected fatal exception
 237      */
 238     @Override
 239     public void run(String... arguments) throws Exception {
 240         rawTool().start(arguments);
 241     }
 242 
 243     /**
 244      * Run an instance of the Java shell tool as configured by the other methods
 245      * in this interface.  This call is not destructive, more than one call of
 246      * this method may be made from a configured builder.
 247      *
 248      * @param arguments the command-line arguments (including options), if any
 249      * @throws Exception an unexpected fatal exception
 250      * @return the exit code
 251      */
 252     @Override
 253     public int start(String... arguments) throws Exception {
 254         return rawTool().start(arguments);
 255     }
 256 
 257     /**
 258      * Persistence stored in Preferences.
 259      */
 260     private static class PreferencesStorage implements PersistentStorage {
 261 
 262         final Preferences p;
 263 
 264         PreferencesStorage(Preferences p) {
 265             this.p = p;
 266         }
 267 
 268         @Override
 269         public void clear() {
 270             try {
 271                 p.clear();
 272             } catch (BackingStoreException ex) {
 273                 throw new IllegalStateException(ex);
 274             }