Package berlin.yuna.clu.logic
Class Terminal
- java.lang.Object
-
- berlin.yuna.clu.logic.Terminal
-
public class Terminal extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTerminal.CommandOutput
-
Constructor Summary
Constructors Constructor Description Terminal()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanbreakOnError()TerminalbreakOnError(boolean breakOnError)Will throwIllegalStateExceptionon error when trueTerminalclearConsole()Clears the console outputconsoleInfo()consoleError()StringconsoleError()List<String>consoleErrorList()StringconsoleInfo()List<String>consoleInfoList()TerminalconsumerErrorStream(Consumer<String>... consumerError)TerminalconsumerInfoStream(Consumer<String>... consumerInfo)static TerminalcopyOf(Terminal terminal)Clean copy of terminal with default consumer and clean console logFiledir()Terminaldir(File dir)Terminaldir(String dir)Terminaldir(Path dir)Terminalexecute(String command)Executes a command with (sh or cmd.exe) ant he help of theProcessBuilderDefault working directory: user.dirtimeoutMs(long)if timeout is neededTerminalexecute(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 neededintmessageCount()Processprocess()Processprocess(String command)Executes a command with (sh or cmd.exe) with the help of theProcessBuilderbooleanrunning()intstatus()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 happeningStringtoString()longwaitFor()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(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(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
-
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=5)
- See Also:
execute(String, Long)
-
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
-
consoleError
public String consoleError()
- Returns:
- returns the console error output
-
execute
public Terminal execute(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(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 - null = async- Returns:
- a new
Processobject 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 theProcessBuilder- Parameters:
command- command to execute- Returns:
- a new
Processobject 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()
-
-