JAL-3210 First commit for goomph powered jalviewjs build
[jalview.git] / build.gradle
index 184e71e..e6430f1 100644 (file)
@@ -7,8 +7,47 @@ plugins {
   id 'java'
   id 'application'
   id 'eclipse'
+  id 'com.diffplug.gradle.oomph.ide' version '3.18.0'
+  id 'com.diffplug.gradle.equinoxlaunch' version '3.18.0'
+
+  id 'com.diffplug.gradle.p2.asmaven' version '3.18.0'
 }
 
+
+
+def eclipseDeps = [
+/*
+    // The dependencies we actually use
+    'org.eclipse.jdt.core',
+    'org.eclipse.text',
+
+    // Their transitives
+    'org.eclipse.core.contenttype',
+    'org.eclipse.core.jobs',
+    'org.eclipse.core.runtime',
+    'org.eclipse.core.resources',
+    'org.eclipse.equinox.common',
+    'org.eclipse.equinox.preferences',
+*/
+    'org.eclipse.osgi'
+]
+
+p2AsMaven {
+  group 'p2', {
+    repoEclipse goomph_eclipse_version
+    eclipseDeps.each { p2.addIU(it) }
+    eclipseDeps.each { p2.addIU(it + '.source') }
+  }
+}
+
+dependencies {
+    eclipseDeps.each { compile "p2:${it}:+" }
+}
+
+
+
+
+
 repositories {
   jcenter()
   mavenCentral()
@@ -34,6 +73,8 @@ ext {
 
   gitHash = ""
   gitBranch = ""
+
+  jalviewjsServer = ""
 }
 
 def JAVA_INTEGER_VERSION
@@ -212,6 +253,88 @@ clean {
 }
 */
 
+
+
+
+
+
+
+
+
+
+
+oomphIde {
+  repoEclipse goomph_eclipse_version
+  jdt {
+    /*
+    installedJre {
+      //markDefault = true
+      //executionEnvironments = [ eclipse.jdt.javaRuntimeName ]
+    }
+    */
+    //compilerComplianceLevel( JAVA_INTEGER_VERSION )
+  }
+  //repo 'http://download.eclipse.org/buildship/updates/e45/milestones/3.x/'
+  repo goomph_repo_buildship
+       feature goomph_feature_buildship
+}
+
+equinoxLaunch {
+  headlessAppSetup {
+    launchTask 'ideJalviewjsBuild', {
+      //it.args = ["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", tempEclipseWorkspace, "-"+jalviewjs_eclipseBuildArg, eclipse_project_name ]
+      it.args = ["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-"+jalviewjs_eclipseBuildArg, eclipse_project_name ]
+    }
+  }
+}
+
+task ideCopyDropins (type: Copy) {
+  dependsOn ideSetupP2
+
+  def inputFiles = fileTree(jalviewjs_utils_dir+"/"+jalviewjs_eclipse_dropins_dir)
+  def outputDir = oomphIde.ideDir + "/" + com.diffplug.gradle.FileMisc.macContentsEclipse() + "/dropins"
+
+  from inputFiles
+  into outputDir
+  def outputFiles = []
+  rename { filename ->
+    outputFiles += outputDir+"/"+filename
+    println("COPYING ${filename} to ${outputFiles}")
+    null
+  }
+  outputs.files outputFiles
+  inputs.files inputFiles
+
+}
+
+ide.dependsOn ideCopyDropins
+ideJalviewjsBuild.dependsOn ideSetupWorkspace
+ideJalviewjsBuild.dependsOn ideCopyDropins
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+def tempEclipseWorkspace = ""
+
+task jalviewjsSetTempEclipseWorkspace {
+  tempEclipseWorkspace = file(jalviewjs_eclipse_workspace)
+  if (!tempEclipseWorkspace.exists()) {
+    tempEclipseWorkspace = File.createTempDir()
+    tempEclipseWorkspace.deleteOnExit()
+  }
+  println("ECLIPSE WORKSPACE: "+tempEclipseWorkspace.getPath())
+}
+
 task jalviewjsUnzipFiles {
   def zipFiles = fileTree(dir: jalviewjs_utils_dir+"/"+jalviewjs_libjs_dir).include("*.zip")
   zipFiles += jalviewjs_utils_dir+"/"+jalviewjs_swingjs_zip
@@ -286,17 +409,6 @@ task jalviewjsEclipseCopyPlugins (type: Copy) {
   inputs.files inputFiles
 }
 
-def tempEclipseWorkspace = ""
-
-task jalviewjsSetTempEclipseWorkspace {
-  tempEclipseWorkspace = file(jalviewjs_eclipse_workspace)
-  if (!tempEclipseWorkspace.exists()) {
-    tempEclipseWorkspace = File.createTempDir()
-    tempEclipseWorkspace.deleteOnExit()
-  }
-  println("ECLIPSE WORKSPACE: "+tempEclipseWorkspace.getPath())
-}
-
 task jalviewjsEclipseSetup {
   dependsOn jalviewjsEclipseCopyDropins
   dependsOn jalviewjsEclipseCopyPlugins
@@ -346,10 +458,12 @@ task jalviewjsCopySiteResources (type: Copy) {
 }
 
 task cleanJalviewjs {
+  /*
   delete jalviewDir+"/"+jalviewjs_site_dir
   delete jalviewDir+"/"+eclipse_bin_dir
   delete file(tempEclipseWorkspace.getAbsolutePath()+"/.metadata")
   delete jalviewDir+"/"+jalviewjs_j2s_settings
+  */
 }
 
 task jalviewjsProjectImport(type: Exec) {
@@ -407,24 +521,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 add = 0
-    def running = false
-    while(add < 1000) {
-      try {
-        HttpFileServer server = factory.start(new File(jalviewDirAbsolutePath+"/"+jalviewjs_site_dir), port)
-        running = true
-      } catch (Exception e) {
-        port++;
-        add++;
+
+    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++;
+        }
       }
+
     }
-    println("SERVER STARTED on http://localhost:"+port+"/ . Ctrc+C to kill it")
-    java.lang.Thread.sleep(Integer.valueOf(jalviewjs_server_wait)*1000);
+
+  }
+
+}
+
+/* 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.")
+    }
+
   }
 }
+*/