Class CliSessionImpl

java.lang.Object
com.e1c.g5.v8.dt.internal.cli.api.CliSessionImpl
All Implemented Interfaces:
ICliSession

public class CliSessionImpl extends Object implements ICliSession
Implementation of ICliSession based on CommandSession and JobTracker.
  • Constructor Details

    • CliSessionImpl

      public CliSessionImpl(org.apache.felix.service.command.CommandSession commandSession, String commandName, Map<String,Object> rawArgs)
      Creates a new instance.
      Parameters:
      commandSession - command session, cannot be null.
      commandName - name of the command being executed, cannot be null.
      rawArgs - raw arguments to the command being executed, cannot be null.
  • Method Details

    • getCurrentNamespace

      public static String getCurrentNamespace(org.apache.felix.service.command.CommandSession commandSession)
      Returns the current namespace for the given session.
      Parameters:
      commandSession - command session, cannot be null.
      Returns:
      the current namespace, never null.
    • setCurrentNamespace

      public static void setCurrentNamespace(org.apache.felix.service.command.CommandSession commandSession, String namespace)
      Sets the current namespace for the given session.
      Parameters:
      commandSession - command session, cannot be null.
      namespace - new current namespace. If null or blank, the default namespace is set.
    • criticalSection

      public <T> T criticalSection(Callable<T> callable) throws Exception
      Description copied from interface: ICliSession
      Runs code in a critical section. Command execution will not be terminated by timeout while inside of a critical section. The timeout restarts when the execution leaves the critical section.
      Specified by:
      criticalSection in interface ICliSession
      Type Parameters:
      T - critical section return type.
      Parameters:
      callable - task to run in a critical section. It will run in the same thread.
      Returns:
      return value of the task.
      Throws:
      Exception - if the task throws exception, it will be thrown from this method.
      See Also:
    • criticalSection

      public void criticalSection(Runnable runnable)
      Description copied from interface: ICliSession
      Runs code in a critical section. Command execution will not be terminated by timeout while inside of a critical section. The timeout restarts when the execution leaves the critical section.
      Specified by:
      criticalSection in interface ICliSession
      Parameters:
      runnable - task to run in a critical section. It will run in the same thread.
      See Also:
    • readLine

      public String readLine(String printMessage) throws IOException
      Description copied from interface: ICliSession
      Reads a line of user input from the console:
           String userName = session.readLine("Please enter your name: ");
           ...
       

      This method prints the optional message to console and blocks until the user presses Enter. Then it returns the line user entered. This method does not count to the command's timeout. Do not wrap it in ICliSession.criticalSection(Callable).

      Specified by:
      readLine in interface ICliSession
      Parameters:
      printMessage - optional message to print to the user before waiting for their input. May be null.
      Returns:
      A String containing the contents of the line user entered, not including any line-termination characters. May be null, if the end of the console stream has been reached without reading any characters.
      Throws:
      IOException
    • getVariable

      public Object getVariable(String name)
      Description copied from interface: ICliSession
      Get the value of a variable.
      Specified by:
      getVariable in interface ICliSession
      Parameters:
      name - name of the variable.
      Returns:
      variable value, or null.
    • getVariable

      public <T> T getVariable(String name, Class<T> clazz)
      Description copied from interface: ICliSession
      Get the value of a variable casted to the given class.
      Specified by:
      getVariable in interface ICliSession
      Type Parameters:
      T - class to cast to.
      Parameters:
      name - name of the variable.
      clazz - class to cast to.
      Returns:
      variable value, or null.
    • getVariables

      public Set<String> getVariables()
      Description copied from interface: ICliSession
      Returns all variable names.
      Specified by:
      getVariables in interface ICliSession
      Returns:
      variable names, never null.
    • putVariable

      public Object putVariable(String name, Object value)
      Description copied from interface: ICliSession
      Set the value of a variable.
      Specified by:
      putVariable in interface ICliSession
      Parameters:
      name - name of the variable.
      value - value of the variable. Use null to delete variable.
      Returns:
      previous value of the variable, or null.
    • getCommandLine

      public String getCommandLine()
      Description copied from interface: ICliSession
      Returns the unparsed command line which is being executed now.
      Specified by:
      getCommandLine in interface ICliSession
      Returns:
      command line, never null.
    • getCommandName

      public String getCommandName()
      Description copied from interface: ICliSession
      Returns the name of the command being executed.
      Specified by:
      getCommandName in interface ICliSession
      Returns:
      command name, never null.
    • getRawCommandArguments

      public Map<String,Object> getRawCommandArguments()
      Description copied from interface: ICliSession
      Returns the raw (unprocessed) arguments of the command being executed. The types of them may differ from what the command method received.
      Specified by:
      getRawCommandArguments in interface ICliSession
      Returns:
      map of raw (unprocessed) arguments of the command being executed, never null. Keys are the command line keys of the arguments, values are the raw (unprocessed) values. For keyless (positional) argument (if any), the empty string is used for the key.
    • getCurrentWorkDir

      public Path getCurrentWorkDir()
      Description copied from interface: ICliSession
      Returns the current session's working directory. You should resolve all relative paths against this directory (except for workspace relative paths).

      This is not the workspace directory. Initially this value is set to be the directory the 1C:EDT CLI process is executed from. But the user (or other commands) can change it later for each session separately either by calling the builtin cd command, or by changing the _cwd session variable.

      Because of this you should not rely on the JVM process working directory (System.getProperty("user.dir") or File.getAbsolutePath() or other methods like this).

      Specified by:
      getCurrentWorkDir in interface ICliSession
      Returns:
      the current working directory of the current session. Never null.
      See Also:
    • setCurrentWorkDir

      public void setCurrentWorkDir(Path path)
      Description copied from interface: ICliSession
      Sets the new current working directory for this session.

      Internally this is done by setting the _cwd session variable. See ICliSession.getCurrentWorkDir() for the details about what the current session's working directory is and how to use it.

      Specified by:
      setCurrentWorkDir in interface ICliSession
      Parameters:
      path - new current working dir, cannot be null. Must be absolute.
      See Also:
    • getCurrentNamespace

      public String getCurrentNamespace()
      Description copied from interface: ICliSession
      Returns the current namespace for this session.
      Specified by:
      getCurrentNamespace in interface ICliSession
      Returns:
      the current namespace, never null.
    • setCurrentNamespace

      public void setCurrentNamespace(String namespace)
      Description copied from interface: ICliSession
      Sets the new current namespace for this session.

      Internally this is done by setting the SCOPE session variable.

      Specified by:
      setCurrentNamespace in interface ICliSession
      Parameters:
      namespace - new namespace, cannot be null.
      See Also:
    • getLastCommandException

      public Throwable getLastCommandException()
      Description copied from interface: ICliSession
      Returns exception of the last executed command.
      Specified by:
      getLastCommandException in interface ICliSession
      Returns:
      exception of the last executed command, may be null.
    • getLastCommandResult

      public Object getLastCommandResult()
      Description copied from interface: ICliSession
      Returns result of the last executed command.
      Specified by:
      getLastCommandResult in interface ICliSession
      Returns:
      result of the last executed command, may be null.