From f69f7e9187e916953f0d13b3d490a64471a2f019 Mon Sep 17 00:00:00 2001 From: Georg Seibt <seibt@fim.uni-passau.de> Date: Wed, 4 May 2016 18:06:19 +0200 Subject: [PATCH] make the fields in ExecRes final --- .../gitwrapper/process/ProcessExecutor.java | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) 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 7a098e2..2ea20f8 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()) { -- GitLab