Class Terminal


  • public class Terminal
    extends java.lang.Object
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Terminal.CommandOutput  
    • Constructor Summary

      Constructors 
      Constructor Description
      Terminal()  
    • Method Summary

      Modifier and Type Method Description
      boolean breakOnError()  
      Terminal breakOnError​(boolean breakOnError)
      Will throw IllegalStateException on error when true
      Terminal clearConsole()
      Clears the console output consoleInfo() consoleError()
      java.lang.String consoleError()  
      java.lang.String consoleInfo()  
      Terminal consumerError​(java.util.function.Consumer<java.lang.String>... consumerError)  
      Terminal consumerErrorStream​(java.util.function.Consumer<java.lang.String>... consumerError)  
      Terminal consumerInfo​(java.util.function.Consumer<java.lang.String>... consumerError)  
      Terminal consumerInfoStream​(java.util.function.Consumer<java.lang.String>... consumerInfo)  
      static Terminal copyOf​(Terminal terminal)
      Clean copy of terminal with default consumer and clean console log
      int countTerminalMessages()  
      java.io.File dir()  
      Terminal dir​(java.io.File dir)  
      Terminal dir​(java.lang.String dir)  
      Terminal dir​(java.nio.file.Path dir)  
      Terminal execute​(java.lang.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
      Terminal execute​(java.lang.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
      java.lang.Process process()  
      java.lang.Process process​(java.lang.String command)
      Executes a command with (sh or cmd.exe) with the help of the ProcessBuilder
      int status()  
      long timeoutMs()  
      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
      long waitFor()  
      Terminal waitFor​(long waitForMs)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Terminal

        public Terminal()
    • Method Detail

      • 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
      • consumerInfoStream

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

        @SafeVarargs
        public final Terminal consumerErrorStream​(java.util.function.Consumer<java.lang.String>... consumerError)
        Parameters:
        consumerError - consumer for console error stream
        Returns:
        Terminal
      • consumerInfo

        @SafeVarargs
        public final Terminal consumerInfo​(java.util.function.Consumer<java.lang.String>... consumerError)
        Parameters:
        consumerError - consumer for console exit code info
        Returns:
        Terminal
      • consumerError

        @SafeVarargs
        public final Terminal consumerError​(java.util.function.Consumer<java.lang.String>... consumerError)
        Parameters:
        consumerError - consumer for console exit code errors
        Returns:
        Terminal
      • timeoutMs

        public long timeoutMs()
        Returns:
        timeout in milliseconds
        See Also:
        timeoutMs(long)
      • 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(boolean)
      • breakOnError

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

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

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

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

        public Terminal dir​(java.lang.String dir)
        Parameters:
        dir - sets the working directory
        Returns:
        Terminal
      • dir

        public Terminal dir​(java.io.File dir)
        Parameters:
        dir - sets the working directory
        Returns:
        Terminal
      • dir

        public Terminal dir​(java.nio.file.Path dir)
        Parameters:
        dir - sets the working directory
        Returns:
        Terminal
      • process

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

        public java.lang.String consoleInfo()
        Returns:
        returns the console output
      • consoleError

        public java.lang.String consoleError()
        Returns:
        returns the console error output
      • execute

        public Terminal execute​(java.lang.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​(java.lang.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
        Returns:
        a new Process object for managing the sub process
      • process

        public java.lang.Process process​(java.lang.String command)
                                  throws java.io.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:
        java.io.IOException - if an I/O error occurs
      • status

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

        public int countTerminalMessages()