From af2585a3cddbe4a02d6934260270b1153bafc956 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 11 Apr 2021 18:56:02 +0200 Subject: [PATCH] Add better uploadProject --- build.gradle | 47 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index 2fb8f9d..e789d1d 100644 --- a/build.gradle +++ b/build.gradle @@ -18,6 +18,7 @@ */ import org.apache.tools.ant.taskdefs.condition.Os +import org.codehaus.groovy.runtime.ProcessGroovyMethods plugins { // Adding the base plugin fixes the following gradle warnings in IntelliJ: @@ -97,15 +98,21 @@ if (project.hasProperty("hostname")) { group "Steamwar" doLast { - shell("scp ${libs}/${jarName} ${hostname}:~/Dev1.15/plugins") + await(shell("scp ${libs}/${jarName} ${hostname}:~/Dev1.15/plugins")) if (!answer("Start DEV server?")) { return } - shell("ssh ${hostname} \"./mc Dev1.15\"") + serverStart() } } } +def await(Process proc) { + def out = new StringBuilder() + def err = new StringBuilder() + proc.waitForProcessOutput(out, err) +} + /** * Executes a shell command and returns the stdout result. * @@ -119,13 +126,39 @@ def shell(String command) { } else { proc = ["cmd", "/c", command].execute() } - def out = new StringBuilder() - def err = new StringBuilder() - proc.waitForProcessOutput(out, err) - - return [out.toString().trim(), err.toString().trim(), proc.exitValue()] + return proc } +def serverStart() { + def proc = shell("ssh ${hostname} \"./mc Dev1.15\"") + + Thread outputThread = proc.consumeProcessOutputStream(System.out) + outputThread.setName("OutputThread") + + Thread inputThread = new Thread(new Runnable() { + @Override + void run() { + // Reader reader = System.in.newReader() + Writer writer = proc.getOutputStream().newWriter() + while (true) { + //String s = reader.readLine() + Thread.sleep(10000) + writer.write("stop\n") + writer.flush() + } + } + }) + inputThread.setName("InputThread") + inputThread.start() + + while (proc.alive) { + Thread.sleep(10) + } + + outputThread.interrupt() + inputThread.interrupt() +}; + def answer(String question) { while (System.in.available() > 0) System.in.read() println(question)