Skip to content

Commit e17cd6e

Browse files
committed
Fail build if external process returns non-zero exit code
1 parent 952600d commit e17cd6e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

junit-modular-world/src/build/Project.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,19 +309,25 @@ String[] toArray() {
309309
}
310310
}
311311

312-
int run(String tool, String... args) {
312+
void run(String tool, String... args) {
313313
printCommandDetails("run", tool, args);
314-
return ToolProvider.findFirst(tool).get().run(System.out, System.err, args);
314+
checkExitCode(ToolProvider.findFirst(tool).get().run(System.out, System.err, args));
315315
}
316316

317-
int exe(String executable, String... args) throws Exception {
317+
void exe(String executable, String... args) throws Exception {
318318
printCommandDetails("exe", executable, args);
319319
ProcessBuilder processBuilder = new ProcessBuilder(executable);
320320
Arrays.stream(args).forEach(processBuilder.command()::add);
321321
processBuilder.redirectErrorStream(true);
322322
Process process = processBuilder.start();
323323
process.getInputStream().transferTo(System.out);
324-
return process.waitFor();
324+
checkExitCode(process.waitFor());
325+
}
326+
327+
private void checkExitCode(int exitCode) {
328+
if (exitCode != 0) {
329+
System.exit(exitCode);
330+
}
325331
}
326332

327333
void printCommandDetails(String context, String command, String... args) {

0 commit comments

Comments
 (0)