Improve diagnostics when forked JVM exits with non-zero status
Closes gh-16869
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user