Improve diagnostics when forked JVM exits with non-zero status

Closes gh-16869
This commit is contained in:
Andy Wilkinson
2019-05-20 15:58:09 +01:00
parent 2afc8af2bf
commit 64860e196c

View File

@@ -69,17 +69,22 @@ public class RunMojo extends AbstractRunMojo {
@Override
protected void runWithForkedJvm(File workingDirectory, List<String> args,
Map<String, String> environmentVariables) throws MojoExecutionException {
int exitCode = forkJvm(workingDirectory, args, environmentVariables);
if (exitCode == 0 || exitCode == EXIT_CODE_SIGINT) {
return;
}
throw new MojoExecutionException(
"Application finished with exit code: " + exitCode);
}
private int forkJvm(File workingDirectory, List<String> args,
Map<String, String> environmentVariables) throws MojoExecutionException {
try {
RunProcess runProcess = new RunProcess(workingDirectory,
new JavaExecutable().toString());
Runtime.getRuntime()
.addShutdownHook(new Thread(new RunProcessKiller(runProcess)));
int exitCode = runProcess.run(true, args, environmentVariables);
if (exitCode == 0 || exitCode == EXIT_CODE_SIGINT) {
return;
}
throw new MojoExecutionException(
"Application finished with exit code: " + exitCode);
return runProcess.run(true, args, environmentVariables);
}
catch (Exception ex) {
throw new MojoExecutionException("Could not exec java", ex);