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 theJavaShellToolBuilder
used 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, out
Fields inherited from class org.dellroad.jct.core.AbstractConsoleSession
owner, request
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected PrintStream
buildOutputStream
(org.jline.terminal.Terminal terminal) Get thePrintStream
to use for output from the givenTerminal
.protected JavaShellToolBuilder
Create and configure the JShell builder for this new session.protected int
Execute this session.static JShellShellSession
Get 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.void
Configure a class loader to use withLocalContextExecutionControlProvider
for local execution.Methods inherited from class org.dellroad.jct.core.AbstractShellSession
buildInputStream, getExitValue, getInputStream, getOutputStream, setExitValue
Methods inherited from class org.dellroad.jct.core.AbstractConsoleSession
doInterrupt, execute, getRequest, interrupt
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.dellroad.jct.core.ConsoleSession
execute, getRequest, interrupt
Methods 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
InheritableThreadLocal
initialized 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 withLocalContextExecutionControlProvider
for local execution.- Parameters:
loader
- class loader, or null for none- See Also:
-
getOwner
Description copied from interface:ConsoleSession
Get the owner, i.e., the console component that created this session.- Specified by:
getOwner
in interfaceConsoleSession<Shell,
ShellRequest> - Overrides:
getOwner
in classAbstractConsoleSession<Shell,
ShellRequest> - Returns:
- owning component
-
buildOutputStream
Description copied from class:AbstractShellSession
Get thePrintStream
to use for output from the givenTerminal
.- Overrides:
buildOutputStream
in classAbstractShellSession
- Parameters:
terminal
- terminal for shell- Returns:
- corresponding output stream
-
doExecute
Description copied from class:AbstractConsoleSession
Execute this session.This method is invoked by
AbstractConsoleSession.execute()
to do the actual work.- Specified by:
doExecute
in 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
JShellShellSession
just 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
- ifcommandLineParams
is null- See Also:
-