Class ShellExecutor
java.lang.Object
org.variantsync.diffdetective.shell.ShellExecutor
This class can execute
ShellCommand
s in a specific working directory and redirect their
output to a Java function.- Author:
- Alexander Schultheiß
-
Field Summary
-
Constructor Summary
ConstructorDescriptionShellExecutor
(Consumer<String> outputReader, Consumer<String> errorReader) Constructs an executor ofShellCommand
s in the current working directory.Constructs an executor ofShellCommand
s in the current working directory. -
Method Summary
Modifier and TypeMethodDescriptionprivate Runnable
collectOutput
(InputStream inputStream, Consumer<String> consumer) Feed the lines read frominputStream
toconsumer
.execute
(ShellCommand command) Executecommand
in the default working directory.execute
(ShellCommand command, Path executionDir) Executecommand
in the given working directory.
-
Field Details
-
outputReader
-
errorReader
-
workDir
-
-
Constructor Details
-
ShellExecutor
Constructs an executor ofShellCommand
s 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 thestdout
of the executed commanderrorReader
- will be provided thestderr
of the executed command
-
ShellExecutor
Constructs an executor ofShellCommand
s in the current working directory.- Parameters:
outputReader
- will be provided thestdout
of the executed commanderrorReader
- will be provided thestderr
of the executed commandworkDir
- the default working directory for the executed commands
-
-
Method Details
-
execute
Executecommand
in the default working directory. the default working directory is the directory given in theconstructor
or 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
Executecommand
in the given working directory. The default working directory (given in theconstructor
) isn't used.- Parameters:
command
- the command to executeexecutionDir
- the directory in whichcommand
is executed (working directory)- Throws:
ShellException
- if the executable incommand
can't be executed or it exits with an error exit code
-
collectOutput
Feed the lines read frominputStream
toconsumer
.
-