JavaShellToolBuilder (Java SE 15 & JDK 15) (original) (raw)
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
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 toolin
Set the input channels.
Implementation Requirements:
If this method is not called, the behavior should be equivalent to callingin(System.in, null)
.
Parameters:
cmdIn
- source of command input
userIn
- source of input for running user code, ornull
to extract user input from cmdIn
Returns:
theJavaShellToolBuilder
instanceout
Set the output channels. Same as
out(output, output, output)
.
Implementation Requirements:
If neitherout
method is called, the behavior should be equivalent to callingout(System.out)
.
Parameters:
output
- destination of command feedback, console interaction, and user code output
Returns:
theJavaShellToolBuilder
instanceout
Set the output channels.
Implementation Requirements:
If neitherout
method 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 users
console
- destination of console interaction
userOut
- destination of user code output. For example, user snippetSystem.out.println("Hello")
when executedHello
goes to userOut.
Returns:
theJavaShellToolBuilder
instanceerr
Set the error channels. Same as
err(error, error)
.
Implementation Requirements:
If neithererr
method is called, the behavior should be equivalent to callingerr(System.err)
.
Parameters:
error
- destination of tool errors, and user code errors
Returns:
theJavaShellToolBuilder
instanceerr
Set the error channels.
Implementation Requirements:
If neithererr
method is called, the behavior should be equivalent to callingerr(System.err, System.err, System.err)
.
Parameters:
cmdErr
- destination of tool start-up and fatal errors
userErr
- destination of user code error output. For example, user snippetSystem.err.println("Oops")
when executedOops
goes to userErr.
Returns:
theJavaShellToolBuilder
instancepersistence
Set the storage mechanism for persistent information which includes input history and retained settings.
Implementation Requirements:
If neitherpersistence
method is called, the behavior should be to use the tool's standard persistence mechanism.
Parameters:
prefs
- an instance of Preferences that is used to retrieve and store persistent information
Returns:
theJavaShellToolBuilder
instancepersistence
Set the storage mechanism for persistent information which includes input history and retained settings.
Implementation Requirements:
If neitherpersistence
method is called, the behavior should be to use the tool's standard persistence mechanism.
Parameters:
prefsMap
- an instance of Map that is used to retrieve and store persistent information
Returns:
theJavaShellToolBuilder
instanceenv
Set the source for environment variables.
Implementation Requirements:
If this method is not called, the behavior should be equivalent to callingenv(System.getenv())
.
Parameters:
vars
- the Map of environment variable names to values
Returns:
theJavaShellToolBuilder
instancelocale
Set the locale.
Implementation Requirements:
If this method is not called, the behavior should be equivalent to callinglocale(Locale.getDefault())
.
Parameters:
locale
- the locale
Returns:
theJavaShellToolBuilder
instancepromptCapture
Set to enable a command capturing prompt override.
Implementation Requirements:
If this method is not called, the behavior should be equivalent to callingpromptCapture(false)
.
Parameters:
capture
- iftrue
, basic prompt is theENQ
character and continuation prompt is theACK
character. If false, prompts are as set with set-up or user/set
commands.
Returns:
theJavaShellToolBuilder
instancerun
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](../../../../java.base/java/lang/Exception.html "class in java.lang")
- an unexpected fatal exceptionstart
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](../../../../java.base/java/lang/Exception.html "class in java.lang")
- an unexpected fatal exception