|
30 | 30 | import org.gradle.process.internal.DefaultJavaExecAction;
|
31 | 31 | import org.gradle.process.internal.ExecHandle;
|
32 | 32 | import org.springframework.boot.loader.tools.FileUtils;
|
33 |
| -import org.springframework.boot.loader.tools.SignalUtils; |
34 | 33 | import org.springframework.util.ReflectionUtils;
|
35 | 34 |
|
36 | 35 | /**
|
@@ -67,24 +66,29 @@ public void exec() {
|
67 | 66 | }
|
68 | 67 | }
|
69 | 68 |
|
70 |
| - private ExecResult executeReflectively() throws Exception { |
| 69 | + private ExecResult executeReflectively() throws Exception { |
71 | 70 | Field builder = ReflectionUtils.findField(JavaExec.class, "javaExecHandleBuilder");
|
72 | 71 | builder.setAccessible(true);
|
73 | 72 | DefaultJavaExecAction action = (DefaultJavaExecAction) builder.get(this);
|
74 | 73 | setMain(getMain());
|
75 |
| - final ExecHandle execHandle = action.build(); |
76 |
| - ExecResult execResult = execHandle.start().waitForFinish(); |
77 |
| - if (!isIgnoreExitValue()) { |
78 |
| - execResult.assertNormalExitValue(); |
79 |
| - } |
80 |
| - SignalUtils.attachSignalHandler(new Runnable() { |
81 |
| - @Override |
82 |
| - public void run() { |
83 |
| - getLogger().info("Aborting java sub-process"); |
84 |
| - execHandle.abort(); |
85 |
| - } |
86 |
| - }); |
87 |
| - return execResult; |
88 |
| - } |
| 74 | + final ExecHandle execHandle = action.build(); |
| 75 | + try { |
| 76 | + Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { |
| 77 | + |
| 78 | + @Override |
| 79 | + public void run() { |
| 80 | + getLogger().info("Aborting java sub-process"); |
| 81 | + execHandle.abort(); |
| 82 | + } |
| 83 | + })); |
| 84 | + } catch (Exception e) { |
| 85 | + getLogger().warn("Could not attach shutdown hook (child process may be orphaned)"); |
| 86 | + } |
| 87 | + ExecResult execResult = execHandle.start().waitForFinish(); |
| 88 | + if (!isIgnoreExitValue()) { |
| 89 | + execResult.assertNormalExitValue(); |
| 90 | + } |
| 91 | + return execResult; |
| 92 | + } |
89 | 93 |
|
90 | 94 | }
|
0 commit comments