diff --git a/src/main/java/org/springframework/shell/Bootstrap.java b/src/main/java/org/springframework/shell/Bootstrap.java index 06c91e56..bc52d804 100644 --- a/src/main/java/org/springframework/shell/Bootstrap.java +++ b/src/main/java/org/springframework/shell/Bootstrap.java @@ -32,6 +32,7 @@ public class Bootstrap { private static Bootstrap bootstrap; private JLineShellComponent shell; + private Thread shellThread; private ConfigurableApplicationContext ctx; private static StopWatch sw = new StopWatch("Spring Sehll"); @@ -84,8 +85,11 @@ public class Bootstrap { } + shellThread = new Thread(shell,"Spring Shell"); + shellThread.start(); shell.start(); - //TODO use listener and latch.. + + //TODO use listener and latch.. while(true) { //System.out.println("shell status = " + shell.getShellStatus().getStatus()); if (shell.getShellStatus().getStatus().equals(ShellStatus.Status.USER_INPUT)) { @@ -99,6 +103,7 @@ public class Bootstrap { } } } + } private void createApplicationContext(String applicationContextLocation) { @@ -180,13 +185,19 @@ public class Bootstrap { exitShellRequest = ExitShellRequest.NORMAL_EXIT; } } else { - shell.promptLoop(); + //shell.promptLoop(); exitShellRequest = shell.getExitShellRequest(); if (exitShellRequest == null) { // shouldn't really happen, but we'll fallback to this anyway exitShellRequest = ExitShellRequest.NORMAL_EXIT; } } + + try { + shellThread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } ctx.close(); sw.stop(); diff --git a/src/main/java/org/springframework/shell/JLineShell.java b/src/main/java/org/springframework/shell/JLineShell.java index ecbf195a..172f51f9 100644 --- a/src/main/java/org/springframework/shell/JLineShell.java +++ b/src/main/java/org/springframework/shell/JLineShell.java @@ -157,6 +157,7 @@ public abstract class JLineShell extends AbstractShell implements CommandMarker, }, "Spring Roo JLine Shutdown Hook")); // Handle any "execute-then-quit" operation + String rooArgs = System.getProperty("roo.args"); if (rooArgs != null && !"".equals(rooArgs)) { setShellStatus(Status.USER_INPUT); @@ -172,6 +173,7 @@ public abstract class JLineShell extends AbstractShell implements CommandMarker, // Normal RPEL processing promptLoop(); } + } public String getStartupNotifications() { @@ -430,11 +432,12 @@ public abstract class JLineShell extends AbstractShell implements CommandMarker, } executeCommand(line); + //System.out.println("executed command:" + line); } } catch (IOException ioe) { throw new IllegalStateException("Shell line reading failure", ioe); } - + System.out.println("shuting down"); setShellStatus(Status.SHUTTING_DOWN); } diff --git a/src/main/java/org/springframework/shell/JLineShellComponent.java b/src/main/java/org/springframework/shell/JLineShellComponent.java index 4f15422f..2ad0aaa1 100644 --- a/src/main/java/org/springframework/shell/JLineShellComponent.java +++ b/src/main/java/org/springframework/shell/JLineShellComponent.java @@ -35,11 +35,11 @@ public class JLineShellComponent extends JLineShell implements Lifecycle { return parser; } + public void start() { - Thread thread = new Thread(this, "Spring Roo JLine Shell"); - thread.start(); running=true; } + public void stop() { closeShell();