From 13f12f643d1fd6866d5b1fef097e147f2ac0f6c9 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 12 Aug 2024 15:10:58 +0100 Subject: [PATCH] Throw RunFailedException when process run fails Fixes gh-86 --- .../maven/ProcessBuilderProcessRunner.java | 2 +- .../ProcessBuilderProcessRunnerTests.java | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 develocity-conventions-maven-extension/src/test/java/io/spring/develocity/conventions/maven/ProcessBuilderProcessRunnerTests.java diff --git a/develocity-conventions-maven-extension/src/main/java/io/spring/develocity/conventions/maven/ProcessBuilderProcessRunner.java b/develocity-conventions-maven-extension/src/main/java/io/spring/develocity/conventions/maven/ProcessBuilderProcessRunner.java index b97ce5b..f33eab8 100644 --- a/develocity-conventions-maven-extension/src/main/java/io/spring/develocity/conventions/maven/ProcessBuilderProcessRunner.java +++ b/develocity-conventions-maven-extension/src/main/java/io/spring/develocity/conventions/maven/ProcessBuilderProcessRunner.java @@ -44,7 +44,7 @@ public void run(Consumer configurer) { Files.copy(spec.output, spec.outputStream); } catch (Exception ex) { - throw new RuntimeException("Process failed", ex); + throw new RunFailedException(ex); } } diff --git a/develocity-conventions-maven-extension/src/test/java/io/spring/develocity/conventions/maven/ProcessBuilderProcessRunnerTests.java b/develocity-conventions-maven-extension/src/test/java/io/spring/develocity/conventions/maven/ProcessBuilderProcessRunnerTests.java new file mode 100644 index 0000000..1ba19c1 --- /dev/null +++ b/develocity-conventions-maven-extension/src/test/java/io/spring/develocity/conventions/maven/ProcessBuilderProcessRunnerTests.java @@ -0,0 +1,40 @@ +/* + * Copyright 2020-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.develocity.conventions.maven; + +import io.spring.develocity.conventions.core.ProcessRunner; +import io.spring.develocity.conventions.core.ProcessRunner.RunFailedException; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +/** + * Tests for {@link ProcessBuilderProcessRunner}. + * + * @author Andy Wilkinson + */ +class ProcessBuilderProcessRunnerTests { + + private final ProcessRunner processRunner = new ProcessBuilderProcessRunner(); + + @Test + void whenRunFailsThenRunFailedExceptionIsThrown() { + assertThatExceptionOfType(RunFailedException.class) + .isThrownBy(() -> this.processRunner.run((spec) -> spec.commandLine("does-not-exist"))); + } + +}