Class ExecHelper

  • Direct Known Subclasses:
    ImmutableExecHelper

    @Immutable
    public abstract class ExecHelper
    extends Object
    An executor of external processes.
    • Constructor Detail

      • ExecHelper

        public ExecHelper()
    • Method Detail

      • createRandomDirectory

        public static File createRandomDirectory()
                                          throws IOException
        Generates a random name and creates a directory named like that in system temporary directory.
        Returns:
        A path to the created directory.
        Throws:
        IOException - When it was impossible to create the random directory.
      • workingDirectory

        public abstract Optional<File> workingDirectory()
        Returns:
        The working directory where to run the command in.
      • command

        public abstract String command()
        Returns:
        The command to run.
      • execute

        public ExecHelper.ExecutionResult execute()
                                           throws IOException
        Executes the command in a working directory (if provided) with environment setting (if provided).
        Returns:
        An object containing exit code with standard output and error streams.
        Throws:
        IOException - When it was impossible to run the external command.
      • environment

        @Default
        public Map<String,​String> environment()
        Returns:
        The environment variables to be set during external command running (default: empty).
      • arguments

        @Default
        public List<String> arguments()
        Returns:
        The list of arguments to the command (default: empty).