diff --git a/src/de/uni_passau/fim/seibt/gitwrapper/process/ProcessExecutor.java b/src/de/uni_passau/fim/seibt/gitwrapper/process/ProcessExecutor.java index 7a098e266b850e64092463f3682aeec7dfb3407b..2ea20f800f99c61874675cfd518488a36ab30c4d 100644 --- a/src/de/uni_passau/fim/seibt/gitwrapper/process/ProcessExecutor.java +++ b/src/de/uni_passau/fim/seibt/gitwrapper/process/ProcessExecutor.java @@ -25,10 +25,16 @@ public class ProcessExecutor { /** * The result of a process execution. */ - public static class ExecRes { - public int exitCode; - public String stdOut; - public String stdErr; + public static final class ExecRes { + public final int exitCode; + public final String stdOut; + public final String stdErr; + + private ExecRes(int exitCode, String stdOut, String stdErr) { + this.exitCode = exitCode; + this.stdOut = stdOut; + this.stdErr = stdErr; + } } /** @@ -70,25 +76,28 @@ public class ProcessExecutor { LOG.fine(() -> String.format("Executing '%s' in '%s'.", cmd, builder.directory().getAbsolutePath())); try { - ExecRes res = new ExecRes(); Process p = builder.start(); - res.stdOut = IOUtils.toString(p.getInputStream(), StandardCharsets.UTF_8).trim(); - res.stdErr = IOUtils.toString(p.getErrorStream(), StandardCharsets.UTF_8).trim(); + String stdOut = IOUtils.toString(p.getInputStream(), StandardCharsets.UTF_8).trim(); + String stdErr = IOUtils.toString(p.getErrorStream(), StandardCharsets.UTF_8).trim(); IOUtils.closeQuietly(p.getInputStream()); IOUtils.closeQuietly(p.getErrorStream()); IOUtils.closeQuietly(p.getOutputStream()); + int exitCode; + try { - res.exitCode = p.waitFor(); + exitCode = p.waitFor(); } catch (InterruptedException e) { LOG.log(WARNING, e, () -> String.format("Interrupted while waiting for '%s' to finish.", cmd)); p.destroyForcibly(); - res.exitCode = EXIT_FAIL; + exitCode = EXIT_FAIL; } + ExecRes res = new ExecRes(exitCode, stdOut, stdErr); + LOG.fine(() -> String.format("Execution of '%s' returned exit code %d.", cmd, res.exitCode)); if (res.stdOut.isEmpty()) {