diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/Shell.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/Shell.java index 6e4f98f3923..e7d59dcce7a 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/Shell.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/Shell.java @@ -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> 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(); } }); diff --git a/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/RunProcess.java b/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/RunProcess.java index ea2819732b3..3a9f199209a 100644 --- a/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/RunProcess.java +++ b/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/RunProcess.java @@ -62,6 +62,12 @@ public class RunProcess { if (!inheritedIO) { redirectOutput(this.process); } + SignalUtils.attachSignalHandler(new Runnable() { + @Override + public void run() { + handleSigInt(); + } + }); try { this.process.waitFor(); } diff --git a/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/SignalUtils.java b/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/SignalUtils.java new file mode 100644 index 00000000000..dd1fd704bea --- /dev/null +++ b/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/SignalUtils.java @@ -0,0 +1,39 @@ +/* + * Copyright 2012-2013 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.loader.tools; + +import sun.misc.Signal; +import sun.misc.SignalHandler; + +/** + * @author Dave Syer + */ +@SuppressWarnings("restriction") +public class SignalUtils { + + private static final Signal SIG_INT = new Signal("INT"); + + public static void attachSignalHandler(final Runnable runnable) { + Signal.handle(SIG_INT, new SignalHandler() { + @Override + public void handle(Signal signal) { + runnable.run(); + } + }); + } + +} diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java b/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java index 5133f7d395a..67d4200bad6 100644 --- a/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java +++ b/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java @@ -48,8 +48,7 @@ import edu.emory.mathcs.backport.java.util.Arrays; * @author Phillip Webb * @author Stephane Nicoll */ -@Mojo(name = "run", requiresProject = true, defaultPhase = LifecyclePhase.VALIDATE, - requiresDependencyResolution = ResolutionScope.TEST) +@Mojo(name = "run", requiresProject = true, defaultPhase = LifecyclePhase.VALIDATE, requiresDependencyResolution = ResolutionScope.TEST) @Execute(phase = LifecyclePhase.TEST_COMPILE) public class RunMojo extends AbstractMojo { @@ -64,10 +63,10 @@ public class RunMojo extends AbstractMojo { /** * Add maven resources to the classpath directly, this allows live in-place editing or - * resources. Since resources will be added directly, and via the target/classes folder - * they will appear twice if {@code ClassLoader.getResources()} is called. In practice, - * however, most applications call {@code ClassLoader.getResource()} which will always - * return the first resource. + * resources. Since resources will be added directly, and via the target/classes + * folder they will appear twice if {@code ClassLoader.getResources()} is called. In + * practice, however, most applications call {@code ClassLoader.getResource()} which + * will always return the first resource. * @since 1.0 */ @Parameter(property = "run.addResources", defaultValue = "true") @@ -104,8 +103,8 @@ public class RunMojo extends AbstractMojo { private String mainClass; /** - * Additional folders besides the classes directory that should be added to - * the classpath. + * Additional folders besides the classes directory that should be added to the + * classpath. * @since 1.0 */ @Parameter