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)
outputThread.setName("${serverName} - OutputThread")
Thread inputThread = new Thread(new Runnable() {
@Override
void run() {
Reader reader = System.in.newReader()
Writer writer = proc.getOutputStream().newWriter()
try {
while (true) {
String s = reader.readLine()
writer.write(s + "\n")
writer.flush()
}
} catch (InterruptedIOException e) {
Thread inputThread = new Thread({
Reader reader = System.in.newReader()
Writer writer = proc.getOutputStream().newWriter()
try {
while (proc.alive) {
String s = reader.readLine()
writer.write(s + "\n")
writer.flush()
}
} catch (IOException e) {
// Ignored
}
})
inputThread.setName("${serverName} - InputThread")
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) {
Thread.sleep(10)
}