mirror of
https://github.com/FancyInnovations/FancyPlugins.git
synced 2025-12-05 23:33:36 +00:00
quick-e2e: Add shutdown hook and process management to Main class
This commit is contained in:
@@ -49,6 +49,20 @@ public class Main {
|
||||
|
||||
StartServerService startServer = new StartServerService();
|
||||
startServer.startServer(context);
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||
if (context.serverProcess().isAlive()) {
|
||||
context.serverProcess().destroy();
|
||||
}
|
||||
}));
|
||||
|
||||
if (context.serverProcess() != null && context.serverProcess().isAlive()) {
|
||||
try {
|
||||
context.serverProcess().waitFor();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,10 +6,13 @@ public class Context {
|
||||
|
||||
private final Configuration configuration;
|
||||
private String actualBuildNumber;
|
||||
|
||||
private Path serverEnvPath;
|
||||
private Path serverJarPath;
|
||||
private Path startScriptPath;
|
||||
|
||||
private Process serverProcess;
|
||||
|
||||
public Context(Configuration configuration) {
|
||||
this.configuration = configuration;
|
||||
this.actualBuildNumber = configuration.build();
|
||||
@@ -54,4 +57,12 @@ public class Context {
|
||||
public void setStartScriptPath(Path startScriptPath) {
|
||||
this.startScriptPath = startScriptPath;
|
||||
}
|
||||
|
||||
public Process serverProcess() {
|
||||
return serverProcess;
|
||||
}
|
||||
|
||||
public void setServerProcess(Process serverProcess) {
|
||||
this.serverProcess = serverProcess;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ public class StartServerService {
|
||||
|
||||
try {
|
||||
Process process = processBuilder.start();
|
||||
process.waitFor();
|
||||
context.setServerProcess(process);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user