Package io.skodjob.testframe.executor
Class Exec
java.lang.Object
io.skodjob.testframe.executor.Exec
Utility class for executing external commands.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ExecBuilderbuilder()Creates a new ExecBuilder instance.static StringcutExecutorLog(String log) This method check the size of executor output log and cut it if it's too long.err()Getter for stdErrorOutputstatic ExecResultMethod executes external commandstatic ExecResultMethod executes external commandstatic ExecResultMethod executes external commandstatic ExecResultMethod executes external commandstatic ExecResultMethod executes external commandstatic ExecResultexec(String input, List<String> command, Set<io.fabric8.kubernetes.api.model.EnvVar> envVars, int timeout, boolean logToOutput, boolean throwErrors) Method executes external commandstatic ExecResultMethod executes external commandintexecute(String input, List<String> commands, Set<io.fabric8.kubernetes.api.model.EnvVar> envVars, long timeoutMs) Method executes external commandstatic booleanisExecutableOnPath(String cmd) Check if command is executableout()Getter for stdOutputvoidstop()Method kills process
-
Constructor Details
-
Exec
public Exec()Constructs a new Exec instance. -
Exec
Constructs a new Exec instance with a log path.- Parameters:
logPath- The path to log the output.
-
Exec
public Exec(boolean appendLineSeparator) Constructs a new Exec instance with the specified option to append line separator.- Parameters:
appendLineSeparator-trueto append line separator,falseotherwise.
-
-
Method Details
-
builder
Creates a new ExecBuilder instance.- Returns:
- A new ExecBuilder instance.
-
out
Getter for stdOutput- Returns:
- string stdOut
-
err
Getter for stdErrorOutput- Returns:
- string stdErr
-
exec
Method executes external command- Parameters:
command- arguments for command- Returns:
- execution results
-
exec
Method executes external command- Parameters:
logToOutput- enable output loggingcommand- arguments for command- Returns:
- execution results
-
exec
Method executes external command- Parameters:
command- arguments for command- Returns:
- execution results
-
exec
Method executes external command- Parameters:
input- log inputcommand- arguments for command- Returns:
- execution results
-
exec
Method executes external command- Parameters:
input- log inputcommand- arguments for commandtimeout- timeout for executionlogToOutput- log output or not- Returns:
- execution results
-
exec
public static ExecResult exec(String input, List<String> command, int timeout, boolean logToOutput, boolean throwErrors) Method executes external command- Parameters:
input- inputcommand- commandtimeout- timeout for commandlogToOutput- log to outputthrowErrors- throw error if exec fail- Returns:
- results
-
exec
public static ExecResult exec(String input, List<String> command, Set<io.fabric8.kubernetes.api.model.EnvVar> envVars, int timeout, boolean logToOutput, boolean throwErrors) Method executes external command- Parameters:
input- log inputcommand- arguments for commandenvVars- session environmenttimeout- timeout for executionlogToOutput- log output or notthrowErrors- look for errors in output and throws exception if true- Returns:
- execution results
-
execute
public int execute(String input, List<String> commands, Set<io.fabric8.kubernetes.api.model.EnvVar> envVars, long timeoutMs) throws IOException, InterruptedException, ExecutionException Method executes external command- Parameters:
input- log inputcommands- arguments for commandenvVars- session environmentstimeoutMs- timeout in ms for kill- Returns:
- returns ecode of execution
- Throws:
IOException- IOExceptionInterruptedException- InterruptedExceptionExecutionException- ExecutionException
-
stop
public void stop()Method kills process -
isExecutableOnPath
Check if command is executable- Parameters:
cmd- command- Returns:
- true.false
-
cutExecutorLog
This method check the size of executor output log and cut it if it's too long.- Parameters:
log- executor log- Returns:
- updated log if size is too big
-