Interface JavaShellToolBuilder
public interface JavaShellToolBuilder
Interface to configure and run a Java shell tool instance. An instance of the
builder is created with the static
builder() method. This builder can,
optionally, be configured with the configuration methods. All configuration
methods return the builder instance for use in chained initialization. All
configuration methods have sensible defaults which will be used if they are
not called.. After zero or more calls to configuration methods, the tool is
launched with a call to run(java.lang.String...).- Since:
- 9
-
Method Summary
Modifier and TypeMethodDescriptionstatic JavaShellToolBuilderbuilder()Create a builder for launching the JDK jshell tool.Set the source for environment variables.err(PrintStream error) Set the error channels.err(PrintStream cmdErr, PrintStream userErr) Set the error channels.in(InputStream cmdIn, InputStream userIn) Set the input channels.default JavaShellToolBuilderinteractiveTerminal(boolean terminal) Set to true to specify the inputs and outputs are connected to an interactive terminal that can interpret the ANSI escape codes.Set the locale.out(PrintStream output) Set the output channels.out(PrintStream cmdOut, PrintStream console, PrintStream userOut) Set the output channels.persistence(Map<String, String> prefsMap) Set the storage mechanism for persistent information which includes input history and retained settings.persistence(Preferences prefs) Set the storage mechanism for persistent information which includes input history and retained settings.promptCapture(boolean capture) Set to enable a command capturing prompt override.voidRun an instance of the Java shell tool as configured by the other methods in this interface.default intRun an instance of the Java shell tool as configured by the other methods in this interface.default JavaShellToolBuilderwindowSize(int columns, int rows) Provide a hint of the display window's dimensions when using an interactive terminal.
-
Method Details
-
builder
Create a builder for launching the JDK jshell tool.- Returns:
- a builder which can be used to configure and launch the jshell tool
-
in
Set the input channels.- Implementation Requirements:
- If this method is not called, the behavior should be
equivalent to calling
in(System.in, null). - Parameters:
cmdIn- source of command inputuserIn- source of input for running user code, ornullto extract user input from cmdIn- Returns:
- the
JavaShellToolBuilderinstance
-
out
Set the output channels. Same asout(output, output, output).- Implementation Requirements:
- If neither
outmethod is called, the behavior should be equivalent to callingout(System.out). - Parameters:
output- destination of command feedback, console interaction, and user code output- Returns:
- the
JavaShellToolBuilderinstance
-
out
Set the output channels.- Implementation Requirements:
- If neither
outmethod is called, the behavior should be equivalent to callingout(System.out, System.out, System.out). - Parameters:
cmdOut- destination of command feedback including error messages for usersconsole- destination of console interactionuserOut- destination of user code output. For example, user snippetSystem.out.println("Hello")when executedHellogoes to userOut.- Returns:
- the
JavaShellToolBuilderinstance
-
err
Set the error channels. Same aserr(error, error).- Implementation Requirements:
- If neither
errmethod is called, the behavior should be equivalent to callingerr(System.err). - Parameters:
error- destination of tool errors, and user code errors- Returns:
- the
JavaShellToolBuilderinstance
-
err
Set the error channels.- Implementation Requirements:
- If neither
errmethod is called, the behavior should be equivalent to callingerr(System.err, System.err, System.err). - Parameters:
cmdErr- destination of tool start-up and fatal errorsuserErr- destination of user code error output. For example, user snippetSystem.err.println("Oops")when executedOopsgoes to userErr.- Returns:
- the
JavaShellToolBuilderinstance
-
persistence
Set the storage mechanism for persistent information which includes input history and retained settings.- Implementation Requirements:
- If neither
persistencemethod is called, the behavior should be to use the tool's standard persistence mechanism. - Parameters:
prefs- an instance ofPreferencesthat is used to retrieve and store persistent information- Returns:
- the
JavaShellToolBuilderinstance
-
persistence
Set the storage mechanism for persistent information which includes input history and retained settings.- Implementation Requirements:
- If neither
persistencemethod is called, the behavior should be to use the tool's standard persistence mechanism. - Parameters:
prefsMap- an instance ofMapthat is used to retrieve and store persistent information- Returns:
- the
JavaShellToolBuilderinstance
-
env
Set the source for environment variables.- Implementation Requirements:
- If this method is not called, the behavior should be
equivalent to calling
env(System.getenv()). - Parameters:
vars- the Map of environment variable names to values- Returns:
- the
JavaShellToolBuilderinstance
-
locale
Set the locale.- Implementation Requirements:
- If this method is not called, the behavior should be
equivalent to calling
locale(Locale.getDefault()). - Parameters:
locale- the locale- Returns:
- the
JavaShellToolBuilderinstance
-
promptCapture
Set to enable a command capturing prompt override.- Implementation Requirements:
- If this method is not called, the behavior should be
equivalent to calling
promptCapture(false). - Parameters:
capture- iftrue, basic prompt is theENQcharacter and continuation prompt is theACKcharacter. If false, prompts are as set with set-up or user/setcommands.- Returns:
- the
JavaShellToolBuilderinstance
-
interactiveTerminal
Set to true to specify the inputs and outputs are connected to an interactive terminal that can interpret the ANSI escape codes. The characters sent to the output streams are assumed to be interpreted by a terminal and shown to the user, and the exact order and nature of characters sent to the outputs are unspecified. Set to false to specify a legacy simpler behavior whose output can be parsed by automatic tools. When the input stream for this Java Shell isSystem.in, this value is ignored, and the behavior is similar to specifyingtruein this method, but is more closely following the specific terminal connected toSystem.in.- Implementation Requirements:
- If this method is not called, the behavior should be
equivalent to calling
interactiveTerminal(false). The default implementation of this method returnsthis. - Parameters:
terminal- iftrue, an terminal that can interpret the ANSI escape codes is assumed to interpret the output. Iffalse, a simpler output is selected.- Returns:
- the
JavaShellToolBuilderinstance - Since:
- 17
-
windowSize
Provide a hint of the display window's dimensions when using an interactive terminal.When the input stream for this Java Shell is
System.in, this setting is ignored.- Implementation Requirements:
- Implementations may choose to ignore this method. The default implementation
of this method returns
this. - Parameters:
columns- number of displayed columnsrows- number of displayed rows- Returns:
- the
JavaShellToolBuilderinstance - Since:
- 24
-
run
Run an instance of the Java shell tool as configured by the other methods in this interface. This call is not destructive, more than one call of this method may be made from a configured builder. The exit code from the Java shell tool is ignored.- Parameters:
arguments- the command-line arguments (including options), if any- Throws:
Exception- an unexpected fatal exception
-
start
Run an instance of the Java shell tool as configured by the other methods in this interface. This call is not destructive, more than one call of this method may be made from a configured builder.- Implementation Requirements:
- The default implementation always returns zero. Implementations of this interface should override this method, returning the exit status.
- Parameters:
arguments- the command-line arguments (including options), if any- Returns:
- the exit status with which the tool explicitly exited (if any), otherwise 0 for success or 1 for failure
- Throws:
Exception- an unexpected fatal exception- Since:
- 10
-