SteamWar/BauSystem
Archiviert
13
0

Fix serverStart for canceling build to stop server

Dieser Commit ist enthalten in:
yoyosource 2021-04-12 10:02:17 +02:00
Ursprung d172aacde0
Commit 10db07e075

Datei anzeigen

@ -130,25 +130,35 @@ def serverStart(String serverName) {
Thread outputThread = proc.consumeProcessOutputStream(System.out) Thread outputThread = proc.consumeProcessOutputStream(System.out)
outputThread.setName("${serverName} - OutputThread") outputThread.setName("${serverName} - OutputThread")
Thread inputThread = new Thread(new Runnable() { Thread inputThread = new Thread({
@Override Reader reader = System.in.newReader()
void run() { Writer writer = proc.getOutputStream().newWriter()
Reader reader = System.in.newReader() try {
Writer writer = proc.getOutputStream().newWriter() while (proc.alive) {
try { String s = reader.readLine()
while (true) { writer.write(s + "\n")
String s = reader.readLine() writer.flush()
writer.write(s + "\n")
writer.flush()
}
} catch (InterruptedIOException e) {
} }
} catch (IOException e) {
// Ignored
} }
}) })
inputThread.setName("${serverName} - InputThread") inputThread.setName("${serverName} - InputThread")
inputThread.start() inputThread.start()
gradle.buildFinished { buildResult ->
if (!proc.alive) {
return
}
Writer writer = proc.getOutputStream().newWriter()
writer.write("stop\n")
writer.flush()
proc.closeStreams()
outputThread.interrupt()
inputThread.interrupt()
}
while (proc.alive) { while (proc.alive) {
Thread.sleep(10) Thread.sleep(10)
} }