Skip to content
Snippets Groups Projects
Commit f69f7e91 authored by Georg Seibt's avatar Georg Seibt :nerd:
Browse files

make the fields in ExecRes final

parent 9a5ada2f
No related branches found
No related tags found
No related merge requests found
......@@ -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()) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment