Commit e088ecd1 authored by Dave Syer's avatar Dave Syer

Re-order shutdown hook in BootRunTask

parent b5d65bfc
...@@ -30,7 +30,6 @@ import org.gradle.process.ExecResult; ...@@ -30,7 +30,6 @@ import org.gradle.process.ExecResult;
import org.gradle.process.internal.DefaultJavaExecAction; import org.gradle.process.internal.DefaultJavaExecAction;
import org.gradle.process.internal.ExecHandle; import org.gradle.process.internal.ExecHandle;
import org.springframework.boot.loader.tools.FileUtils; import org.springframework.boot.loader.tools.FileUtils;
import org.springframework.boot.loader.tools.SignalUtils;
import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils;
/** /**
...@@ -67,24 +66,29 @@ public class BootRunTask extends JavaExec { ...@@ -67,24 +66,29 @@ public class BootRunTask extends JavaExec {
} }
} }
private ExecResult executeReflectively() throws Exception { private ExecResult executeReflectively() throws Exception {
Field builder = ReflectionUtils.findField(JavaExec.class, "javaExecHandleBuilder"); Field builder = ReflectionUtils.findField(JavaExec.class, "javaExecHandleBuilder");
builder.setAccessible(true); builder.setAccessible(true);
DefaultJavaExecAction action = (DefaultJavaExecAction) builder.get(this); DefaultJavaExecAction action = (DefaultJavaExecAction) builder.get(this);
setMain(getMain()); setMain(getMain());
final ExecHandle execHandle = action.build(); final ExecHandle execHandle = action.build();
ExecResult execResult = execHandle.start().waitForFinish(); try {
if (!isIgnoreExitValue()) { Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
execResult.assertNormalExitValue();
} @Override
SignalUtils.attachSignalHandler(new Runnable() { public void run() {
@Override getLogger().info("Aborting java sub-process");
public void run() { execHandle.abort();
getLogger().info("Aborting java sub-process"); }
execHandle.abort(); }));
} } catch (Exception e) {
}); getLogger().warn("Could not attach shutdown hook (child process may be orphaned)");
return execResult; }
} ExecResult execResult = execHandle.start().waitForFinish();
if (!isIgnoreExitValue()) {
execResult.assertNormalExitValue();
}
return execResult;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment