Class Exec

java.lang.Object
io.skodjob.testframe.executor.Exec

public class Exec extends Object
Utility class for executing external commands.
  • Constructor Details

    • Exec

      public Exec()
      Constructs a new Exec instance.
    • Exec

      public Exec(Path logPath)
      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 - true to append line separator, false otherwise.
  • Method Details

    • builder

      public static ExecBuilder builder()
      Creates a new ExecBuilder instance.
      Returns:
      A new ExecBuilder instance.
    • out

      public String out()
      Getter for stdOutput
      Returns:
      string stdOut
    • err

      public String err()
      Getter for stdErrorOutput
      Returns:
      string stdErr
    • exec

      public static ExecResult exec(String... command)
      Method executes external command
      Parameters:
      command - arguments for command
      Returns:
      execution results
    • exec

      public static ExecResult exec(boolean logToOutput, String... command)
      Method executes external command
      Parameters:
      logToOutput - enable output logging
      command - arguments for command
      Returns:
      execution results
    • exec

      public static ExecResult exec(List<String> command)
      Method executes external command
      Parameters:
      command - arguments for command
      Returns:
      execution results
    • exec

      public static ExecResult exec(String input, List<String> command)
      Method executes external command
      Parameters:
      input - log input
      command - arguments for command
      Returns:
      execution results
    • exec

      public static ExecResult exec(String input, List<String> command, int timeout, boolean logToOutput)
      Method executes external command
      Parameters:
      input - log input
      command - arguments for command
      timeout - timeout for execution
      logToOutput - 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 - input
      command - command
      timeout - timeout for command
      logToOutput - log to output
      throwErrors - 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 input
      command - arguments for command
      envVars - session environment
      timeout - timeout for execution
      logToOutput - log output or not
      throwErrors - 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 input
      commands - arguments for command
      envVars - session environments
      timeoutMs - timeout in ms for kill
      Returns:
      returns ecode of execution
      Throws:
      IOException - IOException
      InterruptedException - InterruptedException
      ExecutionException - ExecutionException
    • stop

      public void stop()
      Method kills process
    • isExecutableOnPath

      public static boolean isExecutableOnPath(String cmd)
      Check if command is executable
      Parameters:
      cmd - command
      Returns:
      true.false
    • cutExecutorLog

      public static String cutExecutorLog(String log)
      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