MCPcopy Create free account
hub / github.com/Dathin/JHusky / ProcessUtils

Class ProcessUtils

src/main/java/io/github/dathin/jhusky/ProcessUtils.java:12–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10import java.nio.file.Paths;
11
12public 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected