From d3b72a00858d22eacb7d294035cee0f61359c3c6 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Fri, 17 Feb 2023 13:08:36 +0100 Subject: [PATCH] Ensure command shell exits when cmdfile is finished. Closes #31 --- .../springframework/data/release/Application.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/springframework/data/release/Application.java b/src/main/java/org/springframework/data/release/Application.java index 6bd62f0..3f8f690 100644 --- a/src/main/java/org/springframework/data/release/Application.java +++ b/src/main/java/org/springframework/data/release/Application.java @@ -19,6 +19,8 @@ import java.util.logging.Logger; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.shell.core.ExitShellRequest; import org.springframework.shell.support.logging.HandlerUtils; /** @@ -31,14 +33,20 @@ public class Application { SpringApplication application = new SpringApplication(Application.class); application.setAdditionalProfiles("local"); + ExitShellRequest exitShellRequest = null; + + try (ConfigurableApplicationContext context = application.run(args)) { + BootShim bs = new BootShim(args, context); + exitShellRequest = bs.run(); - try { - BootShim bs = new BootShim(args, application.run(args)); - bs.run(); } catch (RuntimeException e) { throw e; } finally { HandlerUtils.flushAllHandlers(Logger.getLogger("")); } + + if (exitShellRequest != null) { + System.exit(exitShellRequest.getExitCode()); + } } }