diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgVersionCommand.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgVersionCommand.java index 7ea5b97dde..2d4e44f5a7 100644 --- a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgVersionCommand.java +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgVersionCommand.java @@ -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 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); } diff --git a/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/spi/HgVersionCommandTest.java b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/spi/HgVersionCommandTest.java index 6c020efcc0..404e004fc2 100644 --- a/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/spi/HgVersionCommandTest.java +++ b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/spi/HgVersionCommandTest.java @@ -62,7 +62,7 @@ class HgVersionCommandTest { } @Test - void shouldReturnHgVersion() { + void shouldReturnHgVersion() throws InterruptedException { command("/usr/local/bin/hg", HgVersionCommand.HG_ARGS, "5.5.2", 0); command("/opt/python/bin/python", HgVersionCommand.PYTHON_ARGS, PYTHON_OUTPUT, 0); @@ -72,7 +72,7 @@ class HgVersionCommandTest { } @Test - void shouldReturnUnknownMercurialVersionOnNonZeroExitCode() { + void shouldReturnUnknownMercurialVersionOnNonZeroExitCode() throws InterruptedException { command("hg", HgVersionCommand.HG_ARGS, "", 1); command("python", HgVersionCommand.PYTHON_ARGS, PYTHON_OUTPUT, 0); @@ -82,7 +82,7 @@ class HgVersionCommandTest { } @Test - void shouldReturnUnknownPythonVersionOnNonZeroExitCode() { + void shouldReturnUnknownPythonVersionOnNonZeroExitCode() throws InterruptedException { command("hg", HgVersionCommand.HG_ARGS, "4.4.2", 0); command("python", HgVersionCommand.PYTHON_ARGS, "", 1); @@ -92,7 +92,7 @@ class HgVersionCommandTest { } @Test - void shouldReturnUnknownForInvalidPythonOutput() { + void shouldReturnUnknownForInvalidPythonOutput() throws InterruptedException { command("hg", HgVersionCommand.HG_ARGS, "1.0.0", 0); command("python", HgVersionCommand.PYTHON_ARGS, "abcdef", 0); @@ -112,10 +112,10 @@ class HgVersionCommandTest { assertThat(hgVersion.getPython()).isEqualTo(HgVersion.UNKNOWN); } - private Process command(String command, String[] args, String content, int exitValue) { + private Process command(String command, String[] args, String content, int exitValue) throws InterruptedException { Process process = mock(Process.class); when(process.getInputStream()).thenReturn(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))); - when(process.exitValue()).thenReturn(exitValue); + when(process.waitFor()).thenReturn(exitValue); List cmdLine = new ArrayList<>(); cmdLine.add(command);