diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/Command.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/Command.java index 6a04bd9747..f52088731d 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/Command.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/Command.java @@ -19,6 +19,7 @@ package org.springframework.boot.cli.command; import java.util.Collection; import org.springframework.boot.cli.command.options.OptionHelp; +import org.springframework.boot.cli.command.status.ExitStatus; /** * A single command that can be run from the CLI. @@ -64,83 +65,4 @@ public interface Command { */ ExitStatus run(String... args) throws Exception; - /** - * Encapsulation of the outcome of a command. - * - * @author Dave Syer - * - * @see ExitStatus#OK - * @see ExitStatus#ERROR - * - */ - public static class ExitStatus { - /** - * Generic "OK" exit status with zero exit code and hangup=fa;se - */ - public static ExitStatus OK = new ExitStatus(0, "OK"); - /** - * Generic "not OK" exit status with non-zero exit code and hangup=true - */ - public static ExitStatus ERROR = new ExitStatus(-1, "ERROR", true); - private int code; - private String name; - private boolean hangup; - - /** - * Create a new ExitStatus with an exit code and name as specified. - * - * @param code the exit code - * @param name the name - */ - public ExitStatus(int code, String name) { - this(code, name, false); - } - - /** - * @param code the exit code - * @param name the name - * @param hangup true if it is OK for the caller to hangup - */ - public ExitStatus(int code, String name, boolean hangup) { - this.code = code; - this.name = name; - this.hangup = hangup; - } - - /** - * An exit code appropriate for use in System.exit() - * @return an exit code - */ - public int getCode() { - return code; - } - - /** - * A name describing the outcome - * @return a name - */ - public String getName() { - return name; - } - - /** - * Flag to signal that the caller can (or should) hangup. A server process with - * non-daemon threads should set this to false. - * @return the flag - */ - public boolean isHangup() { - return hangup; - } - - /** - * Convert the existing code to a hangup. - * - * @return a new ExitStatus with hangup=true - */ - public ExitStatus hangup() { - return new ExitStatus(this.code, this.name, true); - } - - } - } diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/CommandRunner.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/CommandRunner.java index 5c93f331f2..8e43ab01b6 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/CommandRunner.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/CommandRunner.java @@ -24,7 +24,7 @@ import java.util.Iterator; import java.util.List; import java.util.Set; -import org.springframework.boot.cli.command.Command.ExitStatus; +import org.springframework.boot.cli.command.status.ExitStatus; import org.springframework.boot.cli.util.Log; import org.springframework.util.Assert; import org.springframework.util.StringUtils; diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/OptionParsingCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/OptionParsingCommand.java index 199cbcc652..9a8426591b 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/OptionParsingCommand.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/OptionParsingCommand.java @@ -20,6 +20,7 @@ import java.util.Collection; import org.springframework.boot.cli.command.options.OptionHandler; import org.springframework.boot.cli.command.options.OptionHelp; +import org.springframework.boot.cli.command.status.ExitStatus; /** * Base class for a {@link Command} that parse options using an {@link OptionHandler}. diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/core/HelpCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/core/HelpCommand.java index 3722bf919a..aa20cafc19 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/core/HelpCommand.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/core/HelpCommand.java @@ -28,6 +28,7 @@ import org.springframework.boot.cli.command.CommandRunner; import org.springframework.boot.cli.command.NoHelpCommandArgumentsException; import org.springframework.boot.cli.command.NoSuchCommandException; import org.springframework.boot.cli.command.options.OptionHelp; +import org.springframework.boot.cli.command.status.ExitStatus; import org.springframework.boot.cli.util.Log; /** diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/core/HintCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/core/HintCommand.java index 2ea18f1e76..15e5b4d433 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/core/HintCommand.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/core/HintCommand.java @@ -24,6 +24,7 @@ import org.springframework.boot.cli.command.AbstractCommand; import org.springframework.boot.cli.command.Command; import org.springframework.boot.cli.command.CommandRunner; import org.springframework.boot.cli.command.options.OptionHelp; +import org.springframework.boot.cli.command.status.ExitStatus; import org.springframework.boot.cli.util.Log; /** diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/core/VersionCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/core/VersionCommand.java index 59bfac001b..3fb17a9df3 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/core/VersionCommand.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/core/VersionCommand.java @@ -18,6 +18,7 @@ package org.springframework.boot.cli.command.core; import org.springframework.boot.cli.command.AbstractCommand; import org.springframework.boot.cli.command.Command; +import org.springframework.boot.cli.command.status.ExitStatus; import org.springframework.boot.cli.util.Log; /** diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/grab/GrabCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/grab/GrabCommand.java index 7607221e74..d02bd3fefe 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/grab/GrabCommand.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/grab/GrabCommand.java @@ -25,6 +25,7 @@ import org.springframework.boot.cli.command.OptionParsingCommand; import org.springframework.boot.cli.command.options.CompilerOptionHandler; import org.springframework.boot.cli.command.options.OptionSetGroovyCompilerConfiguration; import org.springframework.boot.cli.command.options.SourceOptions; +import org.springframework.boot.cli.command.status.ExitStatus; import org.springframework.boot.cli.compiler.GroovyCompiler; import org.springframework.boot.cli.compiler.GroovyCompilerConfiguration; import org.springframework.boot.cli.compiler.RepositoryConfigurationFactory; diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/jar/JarCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/jar/JarCommand.java index 11854907a6..ebd5b9b79a 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/jar/JarCommand.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/jar/JarCommand.java @@ -47,6 +47,7 @@ import org.springframework.boot.cli.command.jar.ResourceMatcher.MatchedResource; import org.springframework.boot.cli.command.options.CompilerOptionHandler; import org.springframework.boot.cli.command.options.OptionSetGroovyCompilerConfiguration; import org.springframework.boot.cli.command.options.SourceOptions; +import org.springframework.boot.cli.command.status.ExitStatus; import org.springframework.boot.cli.compiler.GroovyCompiler; import org.springframework.boot.cli.compiler.GroovyCompilerConfiguration; import org.springframework.boot.cli.compiler.RepositoryConfigurationFactory; diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/options/OptionHandler.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/options/OptionHandler.java index 1c6e1dc0a0..e1b4ecb89b 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/options/OptionHandler.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/options/OptionHandler.java @@ -38,8 +38,8 @@ import joptsimple.OptionParser; import joptsimple.OptionSet; import joptsimple.OptionSpecBuilder; -import org.springframework.boot.cli.command.Command.ExitStatus; import org.springframework.boot.cli.command.OptionParsingCommand; +import org.springframework.boot.cli.command.status.ExitStatus; /** * Delegate used by {@link OptionParsingCommand} to parse options and run the command. diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/run/RunCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/run/RunCommand.java index 018a0b36df..76e2e94f9a 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/run/RunCommand.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/run/RunCommand.java @@ -28,6 +28,7 @@ import org.springframework.boot.cli.command.OptionParsingCommand; import org.springframework.boot.cli.command.options.CompilerOptionHandler; import org.springframework.boot.cli.command.options.OptionSetGroovyCompilerConfiguration; import org.springframework.boot.cli.command.options.SourceOptions; +import org.springframework.boot.cli.command.status.ExitStatus; import org.springframework.boot.cli.compiler.GroovyCompilerScope; import org.springframework.boot.cli.compiler.RepositoryConfigurationFactory; import org.springframework.boot.cli.compiler.grape.RepositoryConfiguration; diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/ClearCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/ClearCommand.java index 4aa367a421..92b9d577c5 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/ClearCommand.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/ClearCommand.java @@ -19,6 +19,7 @@ package org.springframework.boot.cli.command.shell; import jline.console.ConsoleReader; import org.springframework.boot.cli.command.AbstractCommand; +import org.springframework.boot.cli.command.status.ExitStatus; /** * Clear the {@link Shell} screen. diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/ExitCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/ExitCommand.java index adf445de35..efec82f58b 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/ExitCommand.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/ExitCommand.java @@ -18,6 +18,7 @@ package org.springframework.boot.cli.command.shell; import org.springframework.boot.cli.command.AbstractCommand; import org.springframework.boot.cli.command.Command; +import org.springframework.boot.cli.command.status.ExitStatus; /** * {@link Command} to quit the {@link Shell}. diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/ForkProcessCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/ForkProcessCommand.java index 4d210d2aaa..a056e8b923 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/ForkProcessCommand.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/ForkProcessCommand.java @@ -23,6 +23,7 @@ import java.util.List; import org.springframework.boot.cli.command.Command; import org.springframework.boot.cli.command.options.OptionHelp; +import org.springframework.boot.cli.command.status.ExitStatus; import org.springframework.boot.loader.tools.JavaExecutable; /** diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/PromptCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/PromptCommand.java index f0dfd5e25b..d4db437f95 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/PromptCommand.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/PromptCommand.java @@ -18,6 +18,7 @@ package org.springframework.boot.cli.command.shell; import org.springframework.boot.cli.command.AbstractCommand; import org.springframework.boot.cli.command.Command; +import org.springframework.boot.cli.command.status.ExitStatus; /** * {@link Command} to change the {@link Shell} prompt. diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/RunProcessCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/RunProcessCommand.java index 3dd2baabc3..adca668667 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/RunProcessCommand.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/RunProcessCommand.java @@ -22,6 +22,7 @@ import java.util.Collection; import org.springframework.boot.cli.command.AbstractCommand; import org.springframework.boot.cli.command.Command; +import org.springframework.boot.cli.command.status.ExitStatus; import org.springframework.boot.loader.tools.RunProcess; /** diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/ShellCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/ShellCommand.java index 284ab800bc..10f073cb7d 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/ShellCommand.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/ShellCommand.java @@ -18,6 +18,7 @@ package org.springframework.boot.cli.command.shell; import org.springframework.boot.cli.command.AbstractCommand; import org.springframework.boot.cli.command.Command; +import org.springframework.boot.cli.command.status.ExitStatus; /** * {@link Command} to start a nested REPL shell. diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/status/ExitStatus.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/status/ExitStatus.java new file mode 100644 index 0000000000..03a6ff5238 --- /dev/null +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/status/ExitStatus.java @@ -0,0 +1,100 @@ +/* + * Copyright 2012-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.cli.command.status; + +/** + * Encapsulation of the outcome of a command. + * + * @author Dave Syer + * @see ExitStatus#OK + * @see ExitStatus#ERROR + * + */ +public final class ExitStatus { + + /** + * Generic "OK" exit status with zero exit code and hangup=fa;se + */ + public static ExitStatus OK = new ExitStatus(0, "OK"); + + /** + * Generic "not OK" exit status with non-zero exit code and hangup=true + */ + public static ExitStatus ERROR = new ExitStatus(-1, "ERROR", true); + + private final int code; + + private final String name; + + private final boolean hangup; + + /** + * Create a new ExitStatus with an exit code and name as specified. + * + * @param code the exit code + * @param name the name + */ + public ExitStatus(int code, String name) { + this(code, name, false); + } + + /** + * @param code the exit code + * @param name the name + * @param hangup true if it is OK for the caller to hangup + */ + public ExitStatus(int code, String name, boolean hangup) { + this.code = code; + this.name = name; + this.hangup = hangup; + } + + /** + * An exit code appropriate for use in System.exit() + * @return an exit code + */ + public int getCode() { + return this.code; + } + + /** + * A name describing the outcome + * @return a name + */ + public String getName() { + return this.name; + } + + /** + * Flag to signal that the caller can (or should) hangup. A server process with + * non-daemon threads should set this to false. + * @return the flag + */ + public boolean isHangup() { + return this.hangup; + } + + /** + * Convert the existing code to a hangup. + * + * @return a new ExitStatus with hangup=true + */ + public ExitStatus hangup() { + return new ExitStatus(this.code, this.name, true); + } + +} diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/test/TestCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/test/TestCommand.java index bb00b3289e..2bbded91c1 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/test/TestCommand.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/test/TestCommand.java @@ -23,6 +23,7 @@ import org.springframework.boot.cli.command.OptionParsingCommand; import org.springframework.boot.cli.command.options.CompilerOptionHandler; import org.springframework.boot.cli.command.options.OptionSetGroovyCompilerConfiguration; import org.springframework.boot.cli.command.options.SourceOptions; +import org.springframework.boot.cli.command.status.ExitStatus; /** * {@link Command} to run a groovy test script or scripts. diff --git a/spring-boot-cli/src/test/java/cli/command/CustomCommand.java b/spring-boot-cli/src/test/java/cli/command/CustomCommand.java index e2dc0cf954..7749968f6e 100644 --- a/spring-boot-cli/src/test/java/cli/command/CustomCommand.java +++ b/spring-boot-cli/src/test/java/cli/command/CustomCommand.java @@ -17,6 +17,7 @@ package cli.command; import org.springframework.boot.cli.command.AbstractCommand; +import org.springframework.boot.cli.command.status.ExitStatus; /** * @author Dave Syer