Class JShellShellSession

java.lang.Object
org.dellroad.jct.core.AbstractConsoleSession<org.dellroad.jct.core.Shell,org.dellroad.jct.core.ShellRequest>
org.dellroad.jct.core.AbstractShellSession
org.dellroad.jct.jshell.JShellShellSession
All Implemented Interfaces:
org.dellroad.jct.core.ConsoleSession<org.dellroad.jct.core.Shell,org.dellroad.jct.core.ShellRequest>, org.dellroad.jct.core.ShellSession

public class JShellShellSession extends org.dellroad.jct.core.AbstractShellSession
A ShellSession that builds and executes a JShell instance.

The associated JShell instance can be customized in two ways:

  • Override createBuilder() to customize the JavaShellToolBuilder used to create the JShell.
  • Override modifyJShellParams() to customize the flags and parameters passed to JShell itself (these are the same as accepted by the jshell(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

    Fields
    Modifier and Type
    Field
    Description
    protected ClassLoader
     

    Fields 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
    Constructor
    Description
    JShellShellSession(JShellShell shell, org.dellroad.jct.core.ShellRequest request)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected PrintStream
    buildOutputStream(org.jline.terminal.Terminal terminal)
     
    Create and configure the JShell builder for this new session.
    protected int
     
    Get the instance associated with the current thread.
     
    protected List<String>
    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 with LocalContextExecutionControlProvider 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

      protected ClassLoader localContextClassLoader
  • Constructor Details

    • JShellShellSession

      public JShellShellSession(JShellShell shell, org.dellroad.jct.core.ShellRequest request)
      Constructor.
      Parameters:
      shell - owning shell
      request - shell request
      Throws:
      IllegalArgumentException - if any parameter is null
  • Method Details

    • getCurrent

      public static JShellShellSession getCurrent()
      Get the instance associated with the current thread.
      Returns:
      session associated with the current thread, or null if not found
    • setLocalContextClassLoader

      public void setLocalContextClassLoader(ClassLoader loader)
      Configure a class loader to use with LocalContextExecutionControlProvider for local execution.
      Parameters:
      loader - class loader, or null for none
      See Also:
    • getOwner

      public JShellShell getOwner()
      Specified by:
      getOwner in interface org.dellroad.jct.core.ConsoleSession<org.dellroad.jct.core.Shell,org.dellroad.jct.core.ShellRequest>
      Overrides:
      getOwner in class org.dellroad.jct.core.AbstractConsoleSession<org.dellroad.jct.core.Shell,org.dellroad.jct.core.ShellRequest>
    • buildOutputStream

      protected PrintStream buildOutputStream(org.jline.terminal.Terminal terminal)
      Overrides:
      buildOutputStream in class org.dellroad.jct.core.AbstractShellSession
    • doExecute

      protected int doExecute() throws InterruptedException
      Specified by:
      doExecute in class org.dellroad.jct.core.AbstractConsoleSession<org.dellroad.jct.core.Shell,org.dellroad.jct.core.ShellRequest>
      Throws:
      InterruptedException
    • createBuilder

      protected JavaShellToolBuilder createBuilder()
      Create and configure the JShell builder for this new session.
      Returns:
      new builder
    • modifyJShellParams

      protected List<String> 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.

      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 by LocalContextExecutionControlProvider.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 - if commandLineParams is null
      See Also: