Class ShellExecutor
java.lang.Object
org.variantsync.diffdetective.shell.ShellExecutor
This class can execute
ShellCommands in a specific working directory and redirect their
output to a Java function.- Author:
- Alexander Schultheiß
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionShellExecutor(Consumer<String> outputReader, Consumer<String> errorReader) Constructs an executor ofShellCommands in the current working directory.Constructs an executor ofShellCommands in the current working directory. -
Method Summary
Modifier and TypeMethodDescriptionprivate RunnablecollectOutput(InputStream inputStream, Consumer<String> consumer) Feed the lines read frominputStreamtoconsumer.execute(ShellCommand command) Executecommandin the default working directory.execute(ShellCommand command, Path executionDir) Executecommandin the given working directory.
-
Field Details
-
outputReader
-
errorReader
-
workDir
-
-
Constructor Details
-
ShellExecutor
Constructs an executor ofShellCommands in the current working directory. The current working directory is the project/Git root by default when started through maven but this can be configured and is part of the contract between the caller of this function and the caller of DiffDetective.- Parameters:
outputReader- will be provided thestdoutof the executed commanderrorReader- will be provided thestderrof the executed command
-
ShellExecutor
Constructs an executor ofShellCommands in the current working directory.- Parameters:
outputReader- will be provided thestdoutof the executed commanderrorReader- will be provided thestderrof the executed commandworkDir- the default working directory for the executed commands
-
-
Method Details
-
execute
Executecommandin the default working directory. the default working directory is the directory given in theconstructoror the current working directory of this process of not given.- Parameters:
command- the command to execute- Throws:
ShellException- if the executable in command can't be executed or it exits with an error exit code
-
execute
Executecommandin the given working directory. The default working directory (given in theconstructor) isn't used.- Parameters:
command- the command to executeexecutionDir- the directory in whichcommandis executed (working directory)- Throws:
ShellException- if the executable incommandcan't be executed or it exits with an error exit code
-
collectOutput
Feed the lines read frominputStreamtoconsumer.
-