From: Ben Soares Date: Thu, 5 Sep 2019 08:14:54 +0000 (+0100) Subject: JAL-3210 improved gradle jalviewjsServerStart X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=0210a246bf503771b40265bda0aeae305ec201ba;p=jalview.git JAL-3210 improved gradle jalviewjsServerStart --- 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.") + } + + } +} +*/