diff --git a/build.gradle b/build.gradle index fb58d2c0..7114e195 100644 --- a/build.gradle +++ b/build.gradle @@ -39,6 +39,7 @@ dependencies { // Testing testCompile "junit:junit:$junitVersion" testCompile "org.mockito:mockito-core:$mockitoVersion" + testCompile "uk.co.modular-it:hamcrest-date:$hamcrestDateVersion" } sourceCompatibility = 1.5 diff --git a/gradle.properties b/gradle.properties index e53150ef..9003b9fd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,6 +14,7 @@ jansiVersion=1.8 # Testing junitVersion = 4.10 mockitoVersion = 1.8.5 +hamcrestDateVersion = 0.9.3 # -------------------- # Project wide version diff --git a/src/main/java/org/springframework/shell/Bootstrap.java b/src/main/java/org/springframework/shell/Bootstrap.java index cfd573a4..2bdd6e54 100644 --- a/src/main/java/org/springframework/shell/Bootstrap.java +++ b/src/main/java/org/springframework/shell/Bootstrap.java @@ -66,6 +66,10 @@ public class Bootstrap { System.exit(exitShellRequest.getExitCode()); } + public Bootstrap() { + this(null, CONTEXT_PATH); + } + public Bootstrap(String[] args) throws IOException { this(args, CONTEXT_PATH); } @@ -150,7 +154,7 @@ public class Bootstrap { } - protected ExitShellRequest run() { + public ExitShellRequest run() { String[] commandsToExecuteAndThenQuit = commandLine.getShellCommandsToExecute(); // The shell is used @@ -162,7 +166,7 @@ public class Bootstrap { exitShellRequest = ExitShellRequest.FATAL_EXIT; for (String cmd : commandsToExecuteAndThenQuit) { - successful = shell.executeCommand(cmd); + successful = shell.executeCommand(cmd).isSuccess(); if (!successful) break; } @@ -191,7 +195,7 @@ public class Bootstrap { return exitShellRequest; } - JLineShellComponent getJLineShellComponent() { + public JLineShellComponent getJLineShellComponent() { return ctx.getBean("shell", JLineShellComponent.class); } } \ No newline at end of file diff --git a/src/main/java/org/springframework/shell/core/AbstractShell.java b/src/main/java/org/springframework/shell/core/AbstractShell.java index cb097159..b15670e8 100644 --- a/src/main/java/org/springframework/shell/core/AbstractShell.java +++ b/src/main/java/org/springframework/shell/core/AbstractShell.java @@ -160,10 +160,10 @@ public abstract class AbstractShell extends AbstractShellStatusPublisher impleme * This method can be overridden by sub-classes to pre-process script lines. */ protected boolean executeScriptLine(final String line) { - return executeCommand(line); + return executeCommand(line).isSuccess(); } - public boolean executeCommand(String line) { + public CommandResult executeCommand(String line) { // Another command was attempted setShellStatus(ShellStatus.Status.PARSING); @@ -198,7 +198,7 @@ public abstract class AbstractShell extends AbstractShellStatusPublisher impleme } if (inBlockComment) { if (!line.contains("*/")) { - return true; + return new CommandResult(true); } blockCommentFinish(); line = line.substring(line.lastIndexOf("*/") + 2); @@ -212,11 +212,11 @@ public abstract class AbstractShell extends AbstractShellStatusPublisher impleme line = line.replace('\t', ' '); if ("".equals(line.trim())) { setShellStatus(Status.EXECUTION_SUCCESS); - return true; + return new CommandResult(true); } parseResult = getParser().parse(line); if (parseResult == null) { - return false; + return new CommandResult(false); } setShellStatus(Status.EXECUTING); @@ -234,14 +234,14 @@ public abstract class AbstractShell extends AbstractShellStatusPublisher impleme logCommandIfRequired(line, true); setShellStatus(Status.EXECUTION_SUCCESS, line, parseResult); - return true; + return new CommandResult(true, result, null); } catch (RuntimeException e) { setShellStatus(Status.EXECUTION_FAILED, line, parseResult); // We rely on execution strategy to log it try { logCommandIfRequired(line, false); } catch (Exception ignored) {} - return false; + return new CommandResult(false, null, e); } finally { setShellStatus(Status.USER_INPUT); } @@ -340,8 +340,7 @@ public abstract class AbstractShell extends AbstractShellStatusPublisher impleme @CliCommand(value = { "date" }, help = "Displays the local date and time") public String date() { - return DateFormat.getDateTimeInstance( - DateFormat.FULL, DateFormat.FULL,Locale.US) + return DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL,Locale.US) .format(new Date()); } diff --git a/src/main/java/org/springframework/shell/core/JLineShell.java b/src/main/java/org/springframework/shell/core/JLineShell.java index 40129d93..e0842c5d 100644 --- a/src/main/java/org/springframework/shell/core/JLineShell.java +++ b/src/main/java/org/springframework/shell/core/JLineShell.java @@ -145,7 +145,7 @@ public abstract class JLineShell extends AbstractShell implements CommandMarker, String rooArgs = System.getProperty("roo.args"); if (rooArgs != null && !"".equals(rooArgs)) { setShellStatus(Status.USER_INPUT); - boolean success = executeCommand(rooArgs); + boolean success = executeCommand(rooArgs).isSuccess(); if (exitShellRequest == null) { // The command itself did not specify an exit shell code, so we'll fall back to something sensible here executeCommand("quit"); // ROO-839 diff --git a/src/main/java/org/springframework/shell/core/Shell.java b/src/main/java/org/springframework/shell/core/Shell.java index 9dbf06ec..9fbce5e2 100644 --- a/src/main/java/org/springframework/shell/core/Shell.java +++ b/src/main/java/org/springframework/shell/core/Shell.java @@ -58,7 +58,7 @@ public interface Shell extends ShellStatusProvider, ShellPromptAccessor { * @param line to execute (required) * @return true if the command was successful, false if there was an exception */ - boolean executeCommand(String line); + CommandResult executeCommand(String line); /** * Indicates the shell should switch into a lower-level development mode. The exact meaning varies by