Skip to content

Commit c97abf3

Browse files
authored
Fail build if external process returns non-zero exit code (#582)
Otherwise the build may fail silently.
1 parent f9a0584 commit c97abf3

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
@@ -310,19 +310,25 @@ String[] toArray() {
310310
}
311311
}
312312

313-
int run(String tool, String... args) {
313+
void run(String tool, String... args) {
314314
printCommandDetails("run", tool, args);
315-
return ToolProvider.findFirst(tool).get().run(System.out, System.err, args);
315+
checkExitCode(ToolProvider.findFirst(tool).get().run(System.out, System.err, args));
316316
}
317317

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

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

0 commit comments

Comments
 (0)