From 0210a246bf503771b40265bda0aeae305ec201ba Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Thu, 5 Sep 2019 09:14:54 +0100 Subject: [PATCH] JAL-3210 improved gradle jalviewjsServerStart --- build.gradle | 59 +++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 17 deletions(-) diff --git a/build.gradle b/build.gradle index f6d211a..62fa472 100644 --- a/build.gradle +++ b/build.gradle @@ -35,6 +35,8 @@ ext { gitHash = "" gitBranch = "" + + jalviewjsServer = "" } def JAVA_INTEGER_VERSION @@ -410,25 +412,48 @@ task jalviewjs { dependsOn jalviewjsBuildSite } -task jalviewjsServer { - //dependsOn jalviewjsBuildSite - +def jalviewjsServer = null +task jalviewjsServerStart { doLast { - SimpleHttpFileServerFactory factory = new SimpleHttpFileServerFactory() - def port = Integer.valueOf(jalviewjs_server_port) - def start = port - def running = false - HttpFileServer server -println "server wait = ${jalviewjs_server_wait}" - while(port < start+100 && !running) { - try { - server = factory.start(new File(jalviewDirAbsolutePath+"/"+jalviewjs_site_dir), port) - running = true - println("SERVER STARTED on "+server.getResourceUrl(jalviewjs_server_resource)+" for ${jalviewjs_server_wait} seconds. Ctrc+C to kill it.") - java.lang.Thread.sleep(Integer.valueOf(jalviewjs_server_wait)*1000); - } catch (Exception e) { - port++; + + if (jalviewjsServer != null) { + println("SERVER ALREADY RUNNING. Go to "+jalviewjsServer.getResourceUrl(jalviewjs_server_resource)+" . Run gradle jalviewjsServerStop to stop.") + } else { + + SimpleHttpFileServerFactory factory = new SimpleHttpFileServerFactory() + def port = Integer.valueOf(jalviewjs_server_port) + def start = port + def running = false + while(port < start+1000 && !running) { + try { + jalviewjsServer = factory.start(new File(jalviewDirAbsolutePath+"/"+jalviewjs_site_dir), port) + running = true + println("SERVER STARTED. Go to "+jalviewjsServer.getResourceUrl(jalviewjs_server_resource)+" . Run gradle jalviewjsServerStop to stop.") + //println("Ctrl-c to stop.");java.lang.Thread.sleep(Integer.valueOf(jalviewjs_server_wait)*1000); + } catch (Exception e) { + port++; + } } + } + } + } + +/* server persists in gradle daemon but reference is not accessible across builds +task jalviewjsServerStop { + doLast { + + if (jalviewjsServer != null) { + + println("SERVER ON PORT "+jalviewjsServer.getPort()+" STOPPING. Run gradle jalviewjsServerStart to start again.") + jalviewjsServer.stop() + + } else { + println("SERVER NOT RUNNING. Run gradle jalviewjsServerStart to start.") + } + + } +} +*/ -- 1.7.10.2