Class JShellShellSession
- All Implemented Interfaces:
ConsoleSession<Shell,,ShellRequest> ShellSession
ShellSession that builds and executes a JShell instance.
The associated JShell instance can be customized in two ways:
- Override
createBuilder()to customize theJavaShellToolBuilderused to create the JShell. - Override
modifyJShellParams()to customize the flags and parameters passed to JShell itself (these are the same as accepted by thejshell(1)command line tool). By default, the parameters passed are the the parameters given on the command line.
During execution, instances make themselves available to the current thread via getCurrent().
-
Field Summary
FieldsFields inherited from class org.dellroad.jct.core.AbstractShellSession
exitValue, in, outFields inherited from class org.dellroad.jct.core.AbstractConsoleSession
owner, request -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected PrintStreambuildOutputStream(org.jline.terminal.Terminal terminal) Get thePrintStreamto use for output from the givenTerminal.protected JavaShellToolBuilderCreate and configure the JShell builder for this new session.protected intExecute this session.static JShellShellSessionGet the instance associated with the current thread.getOwner()Get the owner, i.e., the console component that created this session.modifyJShellParams(List<String> params) Generate a list of command line flags and parameters to be passed to the JShell tool, given the arguments given on the shell command line for this command.voidConfigure a class loader to use withLocalContextExecutionControlProviderfor local execution.Methods inherited from class org.dellroad.jct.core.AbstractShellSession
buildInputStream, getExitValue, getInputStream, getOutputStream, setExitValueMethods inherited from class org.dellroad.jct.core.AbstractConsoleSession
doInterrupt, execute, getRequest, interruptMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.dellroad.jct.core.ConsoleSession
execute, getRequest, interruptMethods inherited from interface org.dellroad.jct.core.ShellSession
getErrorStream
-
Field Details
-
localContextClassLoader
-
-
Constructor Details
-
JShellShellSession
Constructor.- Parameters:
shell- owning shellrequest- shell request- Throws:
IllegalArgumentException- if any parameter is null
-
-
Method Details
-
getCurrent
Get the instance associated with the current thread.This value is stored in an
InheritableThreadLocalinitialized when the JShell tool is started. As a result, it is accessible not only from the main JShell loop but also from the separate snippet execution threads created by JShell.- Returns:
- session associated with the current thread, or null if not found
-
setLocalContextClassLoader
Configure a class loader to use withLocalContextExecutionControlProviderfor local execution.- Parameters:
loader- class loader, or null for none- See Also:
-
getOwner
Description copied from interface:ConsoleSessionGet the owner, i.e., the console component that created this session.- Specified by:
getOwnerin interfaceConsoleSession<Shell,ShellRequest> - Overrides:
getOwnerin classAbstractConsoleSession<Shell,ShellRequest> - Returns:
- owning component
-
buildOutputStream
Description copied from class:AbstractShellSessionGet thePrintStreamto use for output from the givenTerminal.- Overrides:
buildOutputStreamin classAbstractShellSession- Parameters:
terminal- terminal for shell- Returns:
- corresponding output stream
-
doExecute
Description copied from class:AbstractConsoleSessionExecute this session.This method is invoked by
AbstractConsoleSession.execute()to do the actual work.- Specified by:
doExecutein classAbstractConsoleSession<Shell,ShellRequest> - Returns:
- zero if successful, non-zero error code if an error occurred
- Throws:
InterruptedException- if the current thread is interrupted
-
createBuilder
Create and configure the JShell builder for this new session.- Returns:
- new builder
-
modifyJShellParams
Generate a list of command line flags and parameters to be passed to the JShell tool, given the arguments given on the shell command line for this command.If this method is overridden to add or change this command's flags and/or parameters, then the full constructor taking customized help detail should be used to describe the new usage.
The implementation in
JShellShellSessionjust returns the list unmodified unless a local context class loader has been configured, in which case the list is copied, modified byLocalContextExecutionControlProvider.modifyJShellFlags(java.lang.ClassLoader, java.util.List<java.lang.String>), and then returned.- Parameters:
params- parameters given to the shell command line- Returns:
- flags and parameters for JShell
- Throws:
IllegalArgumentException- ifcommandLineParamsis null- See Also:
-