Class Terminal

java.lang.Object
berlin.yuna.clu.logic.Terminal

public class Terminal extends Object
  • Constructor Details

    • Terminal

      public Terminal()
  • Method Details

    • copyOf

      public static Terminal copyOf(Terminal terminal)
      Clean copy of terminal with default consumer and clean console log
      Parameters:
      terminal - terminal to copy
      Returns:
      new terminal copy
    • clearConsole

      public Terminal clearConsole()
      Clears the console output consoleInfo() consoleError()
      Returns:
      Terminal
    • consumerInfoStream

      @SafeVarargs public final Terminal consumerInfoStream(Consumer<String>... consumerInfo)
      Parameters:
      consumerInfo - consumer for console info stream
      Returns:
      Terminal
    • consumerErrorStream

      @SafeVarargs public final Terminal consumerErrorStream(Consumer<String>... consumerError)
      Parameters:
      consumerError - consumer for console error stream
      Returns:
      Terminal
    • timeoutMs

      public long timeoutMs()
      Returns:
      timeout in milliseconds
      See Also:
    • timeoutMs

      public Terminal timeoutMs(long timeoutMs)
      Alternative to Process.waitFor() as sometimes a process can be to fast or to slow for Process.waitFor() or you need a timeout Its combined with (breakOnError(boolean)) Default : -1 (deactivated) Also activates a heartbeat check (timeoutMs / 40) which will also timeout if there is no output is happening
      Parameters:
      timeoutMs - timeout in milliseconds
      Returns:
      Terminal
    • breakOnError

      public boolean breakOnError()
      Returns:
      boolean of current state
      See Also:
    • breakOnError

      public Terminal breakOnError(boolean breakOnError)
      Will throw IllegalStateException on error when true
      Parameters:
      breakOnError - set state
      Returns:
      Terminal
    • dir

      public File dir()
      Returns:
      current working directory
      See Also:
    • waitFor

      public long waitFor()
      Returns:
      wait time after command exited
      See Also:
    • waitFor

      public Terminal waitFor(long waitForMs)
      Returns:
      set ms to wait after execution if the command is faster than logging its messages (default=5)
      See Also:
    • dir

      public Terminal dir(String dir)
      Parameters:
      dir - sets the working directory
      Returns:
      Terminal
    • dir

      public Terminal dir(File dir)
      Parameters:
      dir - sets the working directory
      Returns:
      Terminal
    • dir

      public Terminal dir(Path dir)
      Parameters:
      dir - sets the working directory
      Returns:
      Terminal
    • process

      public Process process()
      Returns:
      the currently used Process - return null when no command was executed
    • consoleInfo

      public String consoleInfo()
      Returns:
      returns the console output
    • consoleInfoList

      public List<String> consoleInfoList()
      Returns:
      returns the console output as list
    • consoleError

      public String consoleError()
      Returns:
      returns the console error output
    • consoleErrorList

      public List<String> consoleErrorList()
      Returns:
      returns the console error as list
    • execute

      public Terminal execute(String command)
      Executes a command with (sh or cmd.exe) ant he help of the ProcessBuilder Default working directory: user.dir timeoutMs(long) if timeout is needed
      Parameters:
      command - command to execute
      Returns:
      a new Process object for managing the sub process
    • execute

      public Terminal execute(String command, Long waitForMs)
      Executes a command with (sh or cmd.exe) ant he help of the ProcessBuilder Default working directory: user.dir timeoutMs(long) if timeout is needed
      Parameters:
      command - command to execute
      waitForMs - overwrites default waitFor(long) for this call - null = async
      Returns:
      a new Process object for managing the sub process
    • process

      public Process process(String command) throws IOException
      Executes a command with (sh or cmd.exe) with the help of the ProcessBuilder
      Parameters:
      command - command to execute
      Returns:
      a new Process object for managing the sub process
      Throws:
      IOException - if an I/O error occurs
    • status

      public int status()
      Returns:
      status code from last command Process.waitFor()
    • running

      public boolean running()
      Returns:
      returns true if process is still running
    • messageCount

      public int messageCount()
    • toString

      public String toString()
      Overrides:
      toString in class Object