public static final class CommandContext.Builder extends Object
CommandContext
objects.Modifier and Type | Method and Description |
---|---|
CommandContext |
build()
Creates a new
CommandContext using the settings configured by
this builder. |
CommandContext.Builder |
discardOutput()
Discards all output from commands.
|
CommandContext.Builder |
environment(CommandEnvironment environment)
Sets the environment for commands
executed with this context.
|
CommandContext.Builder |
ignoreExitStatus()
Allows any exit status for commands executed with this context.
|
CommandContext.Builder |
outputWindowSizes(int stdoutWindow,
int stderrWindow)
Sets the window sizes for the process output streams.
|
CommandContext.Builder |
requireExitStatus(int status)
Sets the required exit status for commands executed with this
context.
|
CommandContext.Builder |
requireExitStatus(Predicate<Integer> exitStatusVerifier)
Indicates what the permissible exit status of a command execution is
through a Predicate.
|
CommandContext.Builder |
workingDirectory(Path path)
Sets the working directory for commands executed with this context.
|
CommandContext.Builder |
workingDirectory(UniformPath path)
Sets the working directory for commands executed with this context.
|
public CommandContext.Builder environment(CommandEnvironment environment)
environment
- the environmentpublic CommandContext.Builder requireExitStatus(int status)
CommandException
is thrown.
By default, an exit status of 0
is required.
status
- the required exit statuspublic CommandContext.Builder ignoreExitStatus()
CommandException
is never thrown.public CommandContext.Builder requireExitStatus(Predicate<Integer> exitStatusVerifier)
exitStatusVerifier
- The Predicate used to verify the exit
statuspublic CommandContext.Builder workingDirectory(UniformPath path)
path
- the working directory pathpublic CommandContext.Builder workingDirectory(Path path)
This method is equivalent to calling
workingDirectory(UniformPath)
after converting the path to a
UniformPath
.
path
- the working directory pathUniformPath.fromPath(Path)
public CommandContext.Builder discardOutput()
outputWindowSizes(0, 0)
.public CommandContext.Builder outputWindowSizes(int stdoutWindow, int stderrWindow)
The size of the window determines the amount of recent output buffered for reading. If data is written beyond the window size without corresponding reads, data older than the window is discarded. A window size of 0 discards all data.
By default, there is no window and buffering is limited by the
maximum size of the buffer array (effectively a window of size
Integer.MAX_VALUE
).
stdoutWindow
- the window for the output streamstderrWindow
- the window for the error streampublic CommandContext build()
CommandContext
using the settings configured by
this builder. The builder may be reused to create more contexts after
calling this method.