Add SignalUtils to handle OS interrupts

Extract into a utility to be shared between Shell and RunMojo

Fixes gh-773
This commit is contained in:
Dave Syer
2014-05-02 19:54:28 +01:00
parent 888703cf26
commit 1b7d8d9ade
4 changed files with 55 additions and 17 deletions

View File

@@ -35,11 +35,9 @@ import org.springframework.boot.cli.command.CommandFactory;
import org.springframework.boot.cli.command.CommandRunner;
import org.springframework.boot.cli.command.core.HelpCommand;
import org.springframework.boot.cli.command.core.VersionCommand;
import org.springframework.boot.loader.tools.SignalUtils;
import org.springframework.util.StringUtils;
import sun.misc.Signal;
import sun.misc.SignalHandler;
/**
* A shell for Spring Boot. Drops the user into an event loop (REPL) where command line
* completion and history are available without relying on OS shell features.
@@ -48,7 +46,6 @@ import sun.misc.SignalHandler;
* @author Dave Syer
* @author Phillip Webb
*/
@SuppressWarnings("restriction")
public class Shell {
private static final Set<Class<?>> NON_FORKED_COMMANDS;
@@ -58,8 +55,6 @@ public class Shell {
NON_FORKED_COMMANDS = Collections.unmodifiableSet(nonForked);
}
private static final Signal SIG_INT = new Signal("INT");
private final ShellCommandRunner commandRunner;
private final ConsoleReader consoleReader;
@@ -123,9 +118,8 @@ public class Shell {
}
private void attachSignalHandler() {
Signal.handle(SIG_INT, new SignalHandler() {
@Override
public void handle(sun.misc.Signal signal) {
SignalUtils.attachSignalHandler(new Runnable() {
public void run() {
handleSigInt();
}
});