/** * Get the final exit code that should be returned based on all contained generators. * @return the final exit code. */ public int getExitCode() { int exitCode = 0; for (ExitCodeGenerator generator : this.generators) { try { int value = generator.getExitCode(); if (value > 0 && value > exitCode || value < 0 && value < exitCode) { exitCode = value; } } catch (Exception ex) { exitCode = (exitCode != 0) ? exitCode : 1; ex.printStackTrace(); } } return exitCode; }
private int getExitCodeFromExitCodeGeneratorException(Throwable exception) { if (exception == null) { return 0; } if (exception instanceof ExitCodeGenerator) { return ((ExitCodeGenerator) exception).getExitCode(); } return getExitCodeFromExitCodeGeneratorException(exception.getCause()); }
public static void main(String[] args) throws Exception { // spring boot application startup SpringApplication springApp = new SpringApplication(.. your context ..); // calling the run method returns the context // pass your program arguments ConfigurableApplicationContext context = springApp.run(args); // spring boot uses exitCode Generators to calculate the exit status // there should be one implementation of the ExitCodeGenerator interface // in your context. Per default SpringBoot uses the JobExecutionExitCodeGenerator ExitCodeGenerator exitCodeGen = context.getBean(ExitCodeGenerator.class); int code = exitCodeGen.getExitCode(); context.close(); System.exit(code); }
private int calcExitStatus() { int exitCode = 0; if (this.exitCodeEvent != null) { exitCode = this.exitCodeEvent.getExitCode(); } else if (this.listenerFailed || this.applicationFailedException != null) { Throwable exception = this.listenerException; if (exception instanceof TaskExecutionException) { TaskExecutionException taskExecutionException = (TaskExecutionException) exception; if (taskExecutionException.getCause() instanceof InvocationTargetException) { InvocationTargetException invocationTargetException = (InvocationTargetException) taskExecutionException .getCause(); if(invocationTargetException != null && invocationTargetException.getTargetException() != null) { exception = invocationTargetException.getTargetException(); } } } if (exception instanceof ExitCodeGenerator) { exitCode = ((ExitCodeGenerator) exception).getExitCode(); } else { exitCode = 1; } } return exitCode; }
private int calcExitStatus() { int exitCode = 0; if (this.exitCodeEvent != null) { exitCode = this.exitCodeEvent.getExitCode(); } else if (this.listenerFailed || this.applicationFailedException != null) { Throwable exception = this.listenerException; if (exception instanceof TaskExecutionException) { TaskExecutionException taskExecutionException = (TaskExecutionException) exception; if (taskExecutionException.getCause() instanceof InvocationTargetException) { InvocationTargetException invocationTargetException = (InvocationTargetException) taskExecutionException .getCause(); if(invocationTargetException != null && invocationTargetException.getTargetException() != null) { exception = invocationTargetException.getTargetException(); } } } if (exception instanceof ExitCodeGenerator) { exitCode = ((ExitCodeGenerator) exception).getExitCode(); } else { exitCode = 1; } } return exitCode; }