Package berlin.yuna.clu.logic
Class Terminal
- java.lang.Object
-
- berlin.yuna.clu.logic.Terminal
-
public class Terminal extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTerminal.CommandOutput
-
Constructor Summary
Constructors Constructor Description Terminal()
-
Method Summary
Modifier and Type Method Description booleanbreakOnError()TerminalbreakOnError(boolean breakOnError)Will throwIllegalStateExceptionon error when trueTerminalclearConsole()Clears the console outputconsoleInfo()consoleError()java.lang.StringconsoleError()java.lang.StringconsoleInfo()TerminalconsumerError(java.util.function.Consumer<java.lang.String>... consumerError)TerminalconsumerErrorStream(java.util.function.Consumer<java.lang.String>... consumerError)TerminalconsumerInfo(java.util.function.Consumer<java.lang.String>... consumerError)TerminalconsumerInfoStream(java.util.function.Consumer<java.lang.String>... consumerInfo)static TerminalcopyOf(Terminal terminal)Clean copy of terminal with default consumer and clean console logintcountTerminalMessages()java.io.Filedir()Terminaldir(java.io.File dir)Terminaldir(java.lang.String dir)Terminaldir(java.nio.file.Path dir)Terminalexecute(java.lang.String command)Executes a command with (sh or cmd.exe) ant he help of theProcessBuilderDefault working directory: user.dirtimeoutMs(long)if timeout is neededTerminalexecute(java.lang.String command, long waitForMs)Executes a command with (sh or cmd.exe) ant he help of theProcessBuilderDefault working directory: user.dirtimeoutMs(long)if timeout is neededjava.lang.Processprocess()java.lang.Processprocess(java.lang.String command)Executes a command with (sh or cmd.exe) with the help of theProcessBuilderintstatus()longtimeoutMs()TerminaltimeoutMs(long timeoutMs)Alternative toProcess.waitFor()as sometimes a process can be to fast or to slow forProcess.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 happeninglongwaitFor()TerminalwaitFor(long waitForMs)
-
-
-
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
-
clearConsole
public Terminal clearConsole()
Clears the console outputconsoleInfo()consoleError()- Returns:
- Terminal
-
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 toProcess.waitFor()as sometimes a process can be to fast or to slow forProcess.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 throwIllegalStateExceptionon 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 theProcessBuilderDefault working directory: user.dirtimeoutMs(long)if timeout is needed- Parameters:
command- command to execute- Returns:
- a new
Processobject 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 theProcessBuilderDefault working directory: user.dirtimeoutMs(long)if timeout is needed- Parameters:
command- command to executewaitForMs- overwrites defaultwaitFor(long)for this call- Returns:
- a new
Processobject for managing the sub process
-
process
public java.lang.Process process(java.lang.String command) throws java.io.IOExceptionExecutes a command with (sh or cmd.exe) with the help of theProcessBuilder- Parameters:
command- command to execute- Returns:
- a new
Processobject 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()
-
-