Fix broken HgVersionCommand

Use waitFor instead of exitValue to wait for process to finish
This commit is contained in:
Sebastian Sdorra
2020-11-27 10:46:37 +01:00
parent 8ee8c8b351
commit 136cdbb6b0
2 changed files with 15 additions and 9 deletions

View File

@@ -78,6 +78,9 @@ public class HgVersionCommand {
}
} catch (IOException ex) {
LOG.warn("failed to get python version", ex);
} catch (InterruptedException ex) {
LOG.warn("failed to get python version", ex);
Thread.currentThread().interrupt();
}
return HgVersion.UNKNOWN;
}
@@ -88,19 +91,22 @@ public class HgVersionCommand {
return exec(config.getHgBinary(), HG_ARGS).trim();
} catch (IOException ex) {
LOG.warn("failed to get mercurial version", ex);
return HgVersion.UNKNOWN;
} catch (InterruptedException ex) {
LOG.warn("failed to get mercurial version", ex);
Thread.currentThread().interrupt();
}
return HgVersion.UNKNOWN;
}
@SuppressWarnings("UnstableApiUsage")
private String exec(String command, String[] args) throws IOException {
private String exec(String command, String[] args) throws IOException, InterruptedException {
List<String> cmd = new ArrayList<>();
cmd.add(command);
cmd.addAll(Arrays.asList(args));
Process process = executor.execute(cmd);
byte[] bytes = ByteStreams.toByteArray(process.getInputStream());
int exitCode = process.exitValue();
int exitCode = process.waitFor();
if (exitCode != 0) {
throw new IOException("process ends with exit code " + exitCode);
}