JAL-3210 Automatic buildship/eclipse update to site when making changes to code
[jalview.git] / build.gradle
index d45afa4..902b896 100644 (file)
@@ -22,17 +22,21 @@ plugins {
 // local build environment properties
 def localProps = "${jalviewDir}/local.properties"
 if (file(localProps).exists()) {
-  def p = new Properties()
-  def localPropsFIS = new FileInputStream(localProps)
-  p.load(localPropsFIS)
-  localPropsFIS.close()
-  p.each {
-    key, val -> 
-      def over = getProperty(key) != null
-      setProperty(key, val)
-      if (over) {
-        println("Overriding property '${key}' with local.properties value '${val}'")
-      }
+  try {
+    def p = new Properties()
+    def localPropsFIS = new FileInputStream(localProps)
+    p.load(localPropsFIS)
+    localPropsFIS.close()
+    p.each {
+      key, val -> 
+        def over = getProperty(key) != null
+        setProperty(key, val)
+        if (over) {
+          println("Overriding property '${key}' with local.properties value '${val}'")
+        }
+    }
+  } catch (Exception e) {
+    System.out.println("Exception reading local.properties")
   }
 }
 
@@ -441,6 +445,9 @@ eclipse {
     }
 
   } // jdt
+  
+  synchronizationTasks "eclipseSynchronizationTask"
+  autoBuildTasks "eclipseAutoBuildTask"
 
 }
 
@@ -1471,7 +1478,11 @@ task jalviewjsUnzipFiles {
 }
 
 task jalviewjsCreateJ2sSettings(type: WriteProperties) {
+  group "JalviewJS"
+  description "Create the .j2s file from the j2s.* properties"
+
   dependsOn jalviewjsSitePath
+
   outputFile ("${jalviewDir}/${jalviewjs_j2s_settings}")
   def j2s_props = project.properties.findAll { it.key.startsWith("j2s.") }.sort { it.key }
   def siteDirProperty = "j2s.site.directory"
@@ -1500,7 +1511,7 @@ task jalviewjsEclipseSetup {
   dependsOn jalviewjsCreateJ2sSettings
 }
 
-task jalviewjsCopyResources (type: Sync) {
+task jalviewjsSyncResources (type: Sync) {
   dependsOn jalviewjsSitePath
   def inputFiles = fileTree(dir: "${jalviewDir}/${resourceDir}")
   def outputDir = "${jalviewDir}/${jalviewjsSiteDir}/${jalviewjs_j2s_subdir}"
@@ -1519,7 +1530,7 @@ task jalviewjsCopyResources (type: Sync) {
   inputs.files inputFiles
 }
 
-task jalviewjsCopySiteResources (type: Sync) {
+task jalviewjsSyncSiteResources (type: Sync) {
   dependsOn jalviewjsSitePath
   def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjs_site_resource_dir}")
   def outputDir = "${jalviewDir}/${jalviewjsSiteDir}"
@@ -1630,17 +1641,31 @@ task jalviewjsCopyTransferSite(type: Copy) {
   into "${jalviewDir}/${jalviewjsSiteDir}"
 }
 
+// this Sync version is used by buildship to keep the website automatically up to date when a file changes
+task jalviewjsSyncTransferSite(type: Sync) {
+  from "${jalviewDir}/${jalviewjsTransferSiteDir}"
+  include "**/*.*"
+  into "${jalviewDir}/${jalviewjsSiteDir}"
+  preserve {
+    include "**"
+  }
+}
+
 jalviewjsUnzipFiles.mustRunAfter jalviewjsCopyTransferSite
-jalviewjsCopyResources.mustRunAfter jalviewjsCopyTransferSite
-jalviewjsCopySiteResources.mustRunAfter jalviewjsCopyTransferSite
+jalviewjsSyncResources.mustRunAfter jalviewjsCopyTransferSite
+jalviewjsSyncSiteResources.mustRunAfter jalviewjsCopyTransferSite
+
+jalviewjsUnzipFiles.mustRunAfter jalviewjsSyncTransferSite
+jalviewjsSyncResources.mustRunAfter jalviewjsSyncTransferSite
+jalviewjsSyncSiteResources.mustRunAfter jalviewjsSyncTransferSite
 
 task jalviewjsPrepareSite {
   group "JalviewJS"
   description "Prepares the website folder including unzipping files and copying resources"
   dependsOn jalviewjsSitePath
   dependsOn jalviewjsUnzipFiles
-  dependsOn jalviewjsCopyResources
-  dependsOn jalviewjsCopySiteResources
+  dependsOn jalviewjsSyncResources
+  dependsOn jalviewjsSyncSiteResources
 }
 
 task jalviewjsBuildSite {
@@ -1678,9 +1703,10 @@ task jalviewjsSiteTar(type: Tar) {
 
 task jalviewjsServer {
   group "JalviewJS"
-  description "Starts a webserver on localhost to test the website"
+  def filename = "jalviewjsTest.html"
+  description "Starts a webserver on localhost to test the website. See ${filename} to access local site on most recently used port."
   dependsOn jalviewjsSitePath
-  def htmlFile = "${jalviewDirAbsolutePath}/jalviewjsTest.html"
+  def htmlFile = "${jalviewDirAbsolutePath}/${filename}"
   doLast {
 
     SimpleHttpFileServerFactory factory = new SimpleHttpFileServerFactory()
@@ -1739,33 +1765,44 @@ task jalviewjs {
 }
 
 
-task jalviewjsIDECopyTransferSite(type: Copy) {
+task jalviewjsIDE_CopyTransferSite(type: Copy) {
   from "${jalviewDir}/${jalviewjsTransferSiteDir}"
   into "${jalviewDir}/${jalviewjsSiteDir}"
 }
 
-task jalviewjsIDEj2s {
-  group "JalviewJS in Eclipse"
+task jalviewjsIDE_j2s {
+  group "00 JalviewJS in Eclipse"
   description "Creates the .j2s file"
   dependsOn jalviewjsCreateJ2sSettings
 }
 
-task jalviewjsIDEBuildSite {
-  group "JalviewJS in Eclipse"
-  description "Copies the Eclipse transpiled site and unzips supporting zipfiles"
-  dependsOn jalviewjsIDECopyTransferSite
+task jalviewjsIDE_AssembleSite {
+  group "00 JalviewJS in Eclipse"
+  description "Assembles the Eclipse transpiled site and unzips supporting zipfiles"
+  dependsOn jalviewjsIDE_CopyTransferSite
   dependsOn jalviewjsPrepareSite
 }
 
-task jalviewjsIDESiteClean {
-  group "JalviewJS in Eclipse"
+task jalviewjsIDE_SiteClean {
+  group "00 JalviewJS in Eclipse"
   description "Deletes the Eclipse transpiled site"
   dependsOn cleanJalviewjsSite
 }
 
-task jalviewjsIDEServer {
-  group "JalviewJS in Eclipse"
+task jalviewjsIDE_Server {
+  group "00 JalviewJS in Eclipse"
   description "Starts a webserver on localhost to test the website"
   dependsOn jalviewjsServer
 }
 
+// buildship runs this at import
+task eclipseSynchronizationTask {
+  dependsOn eclipseSetup
+  dependsOn jalviewjsIDE_j2s
+}
+
+// buildship runs this at build time
+task eclipseAutoBuildTask {
+  dependsOn jalviewjsSyncTransferSite
+  dependsOn jalviewjsPrepareSite
+}