mirror of
https://github.com/FancyInnovations/FancyPlugins.git
synced 2025-12-06 07:43: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();
|
StartServerService startServer = new StartServerService();
|
||||||
startServer.startServer(context);
|
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 final Configuration configuration;
|
||||||
private String actualBuildNumber;
|
private String actualBuildNumber;
|
||||||
|
|
||||||
private Path serverEnvPath;
|
private Path serverEnvPath;
|
||||||
private Path serverJarPath;
|
private Path serverJarPath;
|
||||||
private Path startScriptPath;
|
private Path startScriptPath;
|
||||||
|
|
||||||
|
private Process serverProcess;
|
||||||
|
|
||||||
public Context(Configuration configuration) {
|
public Context(Configuration configuration) {
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
this.actualBuildNumber = configuration.build();
|
this.actualBuildNumber = configuration.build();
|
||||||
@@ -54,4 +57,12 @@ public class Context {
|
|||||||
public void setStartScriptPath(Path startScriptPath) {
|
public void setStartScriptPath(Path startScriptPath) {
|
||||||
this.startScriptPath = 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 {
|
try {
|
||||||
Process process = processBuilder.start();
|
Process process = processBuilder.start();
|
||||||
process.waitFor();
|
context.setServerProcess(process);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user