| 10 | import java.nio.file.Paths; |
| 11 | |
| 12 | public class ProcessUtils { |
| 13 | |
| 14 | private Log log; |
| 15 | |
| 16 | public ProcessUtils(Log log) { |
| 17 | this.log = log; |
| 18 | } |
| 19 | |
| 20 | public void runAndHandleProcess(String executionDirectory, String... command) |
| 21 | throws IOException, InterruptedException, MojoExecutionException { |
| 22 | ProcessBuilder processBuilder = new ProcessBuilder(command); |
| 23 | processBuilder.directory(Files.createDirectories(Paths.get(executionDirectory)).toFile()); |
| 24 | processBuilder.inheritIO().redirectOutput(ProcessBuilder.Redirect.PIPE); |
| 25 | |
| 26 | Process process = processBuilder.start(); |
| 27 | process.waitFor(); |
| 28 | |
| 29 | if (process.exitValue() != 0) { |
| 30 | BufferedReader buf = new BufferedReader(new InputStreamReader(process.getInputStream())); |
| 31 | String line = ""; |
| 32 | while ((line = buf.readLine()) != null) { |
| 33 | log.info(line); |
| 34 | } |
| 35 | throw new MojoExecutionException(String.format("Process exit value: %s", process.exitValue())); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | } |
nothing calls this directly
no outgoing calls
no test coverage detected