JAL-3210 Some tidying and now using swingjs/*
[jalview.git] / build.gradle
index 48033f1..815c6d2 100644 (file)
@@ -53,6 +53,22 @@ def compile_source_compatibility
 def compile_target_compatibility
 
 ext {
+  // 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 = project.properties.get(key) != null
+      project.properties.put(key, val)
+      if (over) {
+        println("Overriding property '${key}' with local.properties value")
+      }
+    }
+  }
   getdownWebsiteDir = "${jalviewDir}/${getdown_website_dir}/${JAVA_VERSION}"
   getdownDir = ""
   reportRsyncCmd = false
@@ -153,7 +169,6 @@ ext {
 
   }
 
-  println("Using a ${CHANNEL} profile. appbase=${getdown_app_base}")
   getdownAppDir = "${getdownWebsiteDir}/${getdown_app_dir}"
   //getdownJ11libDir = "${getdownWebsiteDir}/${getdown_j11lib_dir}"
   getdownResourceDir = "${getdownWebsiteDir}/${getdown_resource_dir}"
@@ -167,6 +182,7 @@ ext {
   gitHash = ""
   gitBranch = ""
 
+  println("Using a ${CHANNEL} profile.")
 }
 
 def JAVA_INTEGER_VERSION
@@ -631,8 +647,8 @@ task copyHelp(type: Copy) {
   }
   from(inputDir) {
     include '**/*.gif'
-      include '**/*.jpg'
-      include '**/*.png'
+    include '**/*.jpg'
+    include '**/*.png'
   }
   into outputDir
 
@@ -650,7 +666,6 @@ task syncLib(type: Sync) {
 task syncResources(type: Sync) {
   from "${jalviewDir}/${resourceDir}"
   include "**/*.*"
-  exclude "install4j"
   into "${classes}"
   preserve {
     include "**"
@@ -687,7 +702,7 @@ test {
   sourceCompatibility = compile_source_compatibility
   targetCompatibility = compile_target_compatibility
   jvmArgs += additional_compiler_args
-  print ("Setting target compatibility to "+targetCompatibility+"\n")
+
 }
 
 task buildIndices(type: JavaExec) {
@@ -851,13 +866,13 @@ task getdownWebsite() {
 
     // go through properties looking for getdown_txt_...
     def props = project.properties.sort { it.key }
-       if (getdown_alt_java_min_version.length() > 0) {
-               props.put("getdown_txt_java_min_version", getdown_alt_java_min_version)
-       }
-       if (getdown_alt_java_max_version.length() > 0) {
-               props.put("getdown_txt_java_max_version", getdown_alt_java_max_version)
-       }
-       props.put("getdown_txt_multi_java_location", getdown_alt_multi_java_location)
+    if (getdown_alt_java_min_version.length() > 0) {
+      props.put("getdown_txt_java_min_version", getdown_alt_java_min_version)
+    }
+    if (getdown_alt_java_max_version.length() > 0) {
+      props.put("getdown_txt_java_max_version", getdown_alt_java_max_version)
+    }
+    props.put("getdown_txt_multi_java_location", getdown_alt_multi_java_location)
 
     props.put("getdown_txt_appbase", getdown_app_base)
     props.each{ prop, val ->
@@ -992,7 +1007,7 @@ task getdownWebsite() {
     }
 
     copy {
-         from getdownResourceDir
+      from getdownResourceDir
       into "${project.ext.getdownFilesDir}/${getdown_resource_dir}"
     }
   }
@@ -1140,14 +1155,16 @@ task installers(type: com.install4j.gradle.Install4jTask) {
   dependsOn getdown
   dependsOn copyInstall4jTemplate
   projectFile = file(install4jConf)
-  println("Using projectFile "+projectFile)
   variables = [majorVersion: version.substring(2, 11), build: 001, OSX_KEYSTORE: OSX_KEYSTORE, JSIGN_SH: JSIGN_SH]
   destination = "${jalviewDir}/${install4jBuildDir}/${JAVA_VERSION}"
   buildSelected = true
 
   if (OSX_KEYPASS) {
     macKeystorePassword=OSX_KEYPASS
+  }
 
+  doFirst {
+    println("Using projectFile "+projectFile)
   }
 
   inputs.dir(project.ext.getdownWebsiteDir)
@@ -1155,7 +1172,6 @@ task installers(type: com.install4j.gradle.Install4jTask) {
   inputs.dir(macosJavaVMDir)
   inputs.dir(windowsJavaVMDir)
   outputs.dir("${jalviewDir}/${install4jBuildDir}/${JAVA_VERSION}")
-
 }
 
 clean {
@@ -1259,14 +1275,14 @@ task jalviewjsSitePath {
 def eclipseWorkspace
 task jalviewjsSetEclipseWorkspace {
   def propKey = "jalviewjs_eclipse_workspace"
-  def propsFileName = "${jalviewjsBuildDir}/${jalviewjs_eclipse_workspace_location_file}"
-  def props = new Properties()
-  def eclipseWsDir
   def propVal = null
   if (project.hasProperty(propKey)) {
     propVal = project.getProperty(propKey)
-    eclipseWsDir = propVal
   }
+  def propsFileName = "${jalviewjsBuildDir}/${jalviewjs_eclipse_workspace_location_file}"
+  def eclipseWsDir = propVal
+  def props = new Properties()
+
   if (( eclipseWsDir == null || !file(eclipseWsDir).exists() ) && file(propsFileName).exists()) {
     def ins = new FileInputStream("${jalviewDirAbsolutePath}/${propsFileName}")
     props.load(ins)
@@ -1289,41 +1305,25 @@ task jalviewjsSetEclipseWorkspace {
   }
 
   eclipseWorkspace = file(eclipseWsDir)
-    
-  println("ECLIPSE WORKSPACE: "+eclipseWorkspace.getPath())
 
-  inputs.property(propKey, propVal)
+  doFirst {
+    println("ECLIPSE WORKSPACE: "+eclipseWorkspace.getPath())
+  }
+  inputs.property(propKey, eclipseWsDir)
   outputs.file(propsFileName)
 }
 
 
-task jalviewjsUnzipFiles {
-  dependsOn jalviewjsSitePath
-
-  def zipFiles = fileTree(dir: "${jalviewjs_utils_dir}/${jalviewjs_libjs_dir}", include: "*.zip")
-  zipFiles += "${jalviewjs_utils_dir}/${jalviewjs_swingjs_zip}"
-
-  doLast {
-    zipFiles.each { file_zip -> 
-      copy {
-        from zipTree(file_zip)
-        into jalviewjsSiteDir
-      }
-    }
-  }
-
-  inputs.files zipFiles
-  outputs.dir jalviewjsSiteDir
-}
-
 def eclipseDropinsDir
+def utilsDropinsDir
 def eclipseBinary
 def eclipseVersion
-def fromDropinsDir
+def eclipseDebug = false
+def eclipseVersionSuffix = ""
 task jalviewjsEclipsePaths {
-  def eclipseRoot
   def eclipseProduct
-  eclipseRoot = jalviewjs_eclipse_root
+
+  def eclipseRoot = jalviewjs_eclipse_root
   if (eclipseRoot.startsWith("~")) {
     eclipseRoot = System.getProperty("user.home") + eclipseRoot.substring(1)
   }
@@ -1349,27 +1349,50 @@ task jalviewjsEclipsePaths {
   }
 
   eclipseVersion = "4.12" // default
+  def assumedVersion = true
   if (file(eclipseProduct).exists()) {
     def fis = new FileInputStream(eclipseProduct)
     def props = new Properties()
     props.load(fis)
     eclipseVersion = props.getProperty("version")
     fis.close()
-    println("ECLIPSE_VERSION=${eclipseVersion}")
+    assumedVersion = false
   }
+  /*
   String[] v = eclipseVersion.split("\\.")
   def v0 = Integer.valueOf(v[0])
   def v1 = Integer.valueOf(v[1])
   if (v0 < 4 || ( v0 == 4 && v1 < 13 )) {
-    fromDropinsDir = "eclipse/dropins_4.12"
+    eclipseVersionSuffix = "_4.12"
   } else {
-    fromDropinsDir = "eclipse/dropins_4.13"
-  } 
+    eclipseVersionSuffix = "_4.13"
+  }
+  utilsDropinsDir = "${jalviewDir}/${jalviewjs_eclipse_dropins_dir}${eclipseVersionSuffix}"
+  */
+
+  utilsDropinsDir = "${jalviewDir}/${jalviewjs_eclipse_dropins_dir}"
+  def propKey = "eclipse_debug"
+  eclipseDebug = (project.hasProperty(propKey) && project.getProperty(propKey).equals("true"))
+
+  doFirst {
+    if (!assumedVersion) {
+      println("ECLIPSE_VERSION=${eclipseVersion}")
+    }
+  }
 }
 
-task jalviewjsEclipseCopyDropins {
+task eclipseSetup {
+  dependsOn eclipseProject
+  dependsOn eclipseClasspath
+  dependsOn eclipseJdt
+}
+
+/* using the Copy task below
+task OLDjalviewjsEclipseCopyDropins {
   dependsOn jalviewjsEclipsePaths
-  def inputFiles = fileTree(dir: "${jalviewjs_utils_dir}/${fromDropinsDir}", include: "*.jar")
+  dependsOn jalviewjsCleanEclipse
+  def inputFiles = fileTree(dir: utilsDropinsDir, include: "*.jar")
+  inputFiles += file(jalviewjs_j2s_plugin)
   def outputDir = eclipseDropinsDir
 
   inputs.files inputFiles
@@ -1386,22 +1409,77 @@ task jalviewjsEclipseCopyDropins {
     }
   }
 }
+*/
 
 // this version (type: Copy) will delete anything in the eclipse dropins folder that isn't in fromDropinsDir
-task NEWjalviewjsEclipseCopyDropins(type: Copy) {
+task jalviewjsEclipseCopyDropins(type: Copy) {
   dependsOn jalviewjsEclipsePaths
-  from fromDropinsDir
+
+  from utilsDropinsDir
   into eclipseDropinsDir
+
+  doLast {
+    copy {
+      from jalviewjs_j2s_plugin
+      into eclipseDropinsDir
+    }
+  }
+}
+
+// this eclipse -clean doesn't actually work
+task jalviewjsCleanEclipse(type: Exec) {
+  dependsOn eclipseSetup
+  dependsOn jalviewjsEclipsePaths
+  dependsOn jalviewjsEclipseCopyDropins
+
+  executable(eclipseBinary)
+  args(["-nosplash", "--launcher.suppressErrors", "-data", eclipseWorkspace.getPath(), "-clean", "-console", "-consoleLog"])
+  if (eclipseDebug) {
+    args += "-debug"
+  }
+  args += "-l"
+
+  def inputString = """exit
+y
+"""
+  def inputByteStream = new ByteArrayInputStream(inputString.getBytes())
+  standardInput = inputByteStream
+
+  doFirst {
+    println("CLEAN ECLIPSE_DEBUG=${eclipseDebug}")
+  }
+}
+/* not really working yet
+jalviewjsEclipseCopyDropins.finalizedBy jalviewjsCleanEclipse
+*/
+
+task jalviewjsUnzipFiles {
+  dependsOn jalviewjsSitePath
+
+  def zipFiles = fileTree(dir: "${jalviewDir}/${jalviewjs_libjs_dir}", include: "*.zip")
+  zipFiles += "${jalviewDir}/${jalviewjs_swingjs_zip}"
+
+  doLast {
+    zipFiles.each { file_zip -> 
+      copy {
+        from zipTree(file_zip)
+        into jalviewjsSiteDir
+      }
+    }
+  }
+
+  inputs.files zipFiles
+  outputs.dir jalviewjsSiteDir
 }
 
 task jalviewjsCreateJ2sSettings(type: WriteProperties) {
   dependsOn jalviewjsSitePath
   outputFile ("${jalviewDir}/${jalviewjs_j2s_settings}")
-  def props = project.properties.sort { it.key }
+  def j2s_props = project.properties.findAll { it.key.startsWith("j2s.") }.sort { it.key }
   def siteDirProperty = "j2s.site.directory"
   def setSiteDir = false
-  props.each { prop, val ->
-    if (prop.startsWith("j2s.") && val != null) {
+  j2s_props.each { prop, val ->
+    if (val != null) {
       if (prop == siteDirProperty) {
         if (!(val.startsWith('/') || val.startsWith("file://") )) {
           val = "${jalviewjsTransferSiteDir}/${val}"
@@ -1410,11 +1488,11 @@ task jalviewjsCreateJ2sSettings(type: WriteProperties) {
       }
       property(prop,val)
     }
-    if (!setSiteDir) {
+    if (!setSiteDir) { // default site location, don't override specifically set property
       property(siteDirProperty,jalviewjsTransferSiteDir)
     }
   }
-  inputs.properties(props.findAll( { k, v -> k.startsWith("j2s.") } ))
+  inputs.properties(j2s_props)
   outputs.file(outputFile)
 }
 
@@ -1424,9 +1502,9 @@ task jalviewjsEclipseSetup {
   dependsOn jalviewjsCreateJ2sSettings
 }
 
-task jalviewjsCopyResources (type: Copy) {
+task jalviewjsCopyResources (type: Sync) {
   dependsOn jalviewjsSitePath
-  def inputFiles = fileTree(dir: jalviewjs_resource_dir)
+  def inputFiles = fileTree(dir: resourceDir)
   def outputDir = "${jalviewjsSiteDir}/${jalviewjs_j2s_subdir}"
 
   from inputFiles
@@ -1436,13 +1514,16 @@ task jalviewjsCopyResources (type: Copy) {
     outputFiles += "${outputDir}/${filename}"
     null
   }
+  preserve {
+    include "**"
+  }
   outputs.files outputFiles
   inputs.files inputFiles
 }
 
-task jalviewjsCopySiteResources (type: Copy) {
+task jalviewjsCopySiteResources (type: Sync) {
   dependsOn jalviewjsSitePath
-  def inputFiles = fileTree(dir: "${jalviewjs_utils_dir}/${jalviewjs_site_resource_dir}")
+  def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjs_site_resource_dir}")
   def outputDir = jalviewjsSiteDir
 
   from inputFiles
@@ -1452,24 +1533,29 @@ task jalviewjsCopySiteResources (type: Copy) {
     outputFiles += "${outputDir}/${filename}"
     null
   }
+  preserve {
+    include "**"
+  }
   outputs.files outputFiles
   inputs.files inputFiles
 }
 
 task jalviewjsProjectImport(type: Exec) {
-  // work out how to do this!
-  dependsOn eclipseProject
-  dependsOn eclipseClasspath
-  dependsOn eclipseJdt
+  dependsOn eclipseSetup
   dependsOn jalviewjsEclipsePaths
   dependsOn jalviewjsEclipseSetup
+
+  def projdir = eclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview/org.eclipse.jdt.core"
   executable(eclipseBinary)
   args(["-nosplash", "--launcher.suppressErrors", "-application", "com.seeq.eclipse.importprojects.headlessimport", "-data", eclipseWorkspace.getPath(), "-import", jalviewDirAbsolutePath])
-  if (eclipse_debug == "true") {
+  if (eclipseDebug) {
     args += "-debug"
   }
 
-  def projdir = eclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview/org.eclipse.jdt.core"
+  doFirst {
+    println("IMPORT ECLIPSE_DEBUG=${eclipseDebug}")
+  }
+
   inputs.file("${jalviewDir}/.project")
   outputs.dir(projdir)
   outputs.upToDateWhen { file(projdir).exists() }
@@ -1479,48 +1565,56 @@ task jalviewjsTranspile(type: Exec) {
   dependsOn jalviewjsEclipseSetup 
   dependsOn jalviewjsProjectImport
   dependsOn jalviewjsEclipsePaths
+
   executable(eclipseBinary)
-  args(["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", eclipseWorkspace, "-${jalviewjs_eclipseBuildArg}", eclipse_project_name ])
-  if (eclipse_debug == "true") {
+  args(["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", eclipseWorkspace, "-${jalviewjs_eclipse_build_arg}", eclipse_project_name ])
+  if (eclipseDebug) {
     args += "-debug"
   }
 
   def stdout
   def stderr
-  doFirst {
-    stdout = new ByteArrayOutputStream()
-    stderr = new ByteArrayOutputStream()
-
-    def logOutFileName = "${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_j2s_stdout}"
-    def logOutFile = file(logOutFileName)
-    logOutFile.createNewFile()
-    def logOutFOS = new FileOutputStream(logOutFile, false)
-    //def logErrFileName = "${jalviewjsBuildDir}/${jalviewjs_j2s_stderr}"
-    //def logErrFile = file(logFileName)
-    //logErrFile.createNewFile()
-    //def logErrFOS = new FileErrputStream(logErrFile, false)
-    // combine stdout and stderr
-    def logErrFOS = logOutFOS
-    if (jalviewjs_j2s_to_console.equals("true")) {
-      standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
-        new org.apache.tools.ant.util.TeeOutputStream(
-          logOutFOS,
-          stdout),
-        standardOutput)
+  stdout = new ByteArrayOutputStream()
+  stderr = new ByteArrayOutputStream()
+
+  def logOutFileName = "${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_j2s_stdout}"
+  def logOutFile = file(logOutFileName)
+  logOutFile.createNewFile()
+  logOutFile.text = """ROOT: ${jalviewjs_eclipse_root}
+BINARY: ${eclipseBinary}
+VERSION: ${eclipseVersion}
+WORKSPACE: ${eclipseWorkspace}
+DEBUG: ${eclipseDebug}
+----
+"""
+  def logOutFOS = new FileOutputStream(logOutFile, true) // true == append
+  //def logErrFileName = "${jalviewjsBuildDir}/${jalviewjs_j2s_stderr}"
+  //def logErrFile = file(logFileName)
+  //logErrFile.createNewFile()
+  //def logErrFOS = new FileErrputStream(logErrFile, false)
+  // combine stdout and stderr
+  def logErrFOS = logOutFOS
+
+  if (jalviewjs_j2s_to_console.equals("true")) {
+    standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
+      new org.apache.tools.ant.util.TeeOutputStream(
+        logOutFOS,
+        stdout),
+      standardOutput)
       errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
         new org.apache.tools.ant.util.TeeOutputStream(
           logErrFOS,
           stderr),
         errorOutput)
-    } else {
-      standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
-        logOutFOS,
-        stdout)
+  } else {
+    standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
+      logOutFOS,
+      stdout)
       errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
         logErrFOS,
         stderr)
-    }
   }
+
   doLast {
     if (stdout.toString().contains("Error processing ")) {
       // j2s did not complete transpile
@@ -1528,6 +1622,10 @@ task jalviewjsTranspile(type: Exec) {
     }
   }
 
+  doFirst {
+    println("TRANSPILE ECLIPSE_DEBUG=${eclipseDebug}")
+  }
+
   inputs.dir(sourceDir)
   outputs.dir("${eclipse_bin_dir}/main")
   outputs.dir(jalviewjsTransferSiteDir)
@@ -1628,11 +1726,14 @@ task cleanJalviewjsAll {
   group "JalviewJS"
   description "Delete all configuration and build artifacts to do with JalviewJS build"
   dependsOn cleanJalviewjsSite
+  dependsOn jalviewjsEclipsePaths
   
   doFirst {
     delete jalviewjsBuildDir
     delete "${jalviewDir}/${eclipse_bin_dir}"
-    delete file(eclipseWorkspace.getAbsolutePath()+"/.metadata")
+    if (eclipseWorkspace != null && file(eclipseWorkspace.getAbsolutePath()+"/.metadata").exists()) {
+      delete file(eclipseWorkspace.getAbsolutePath()+"/.metadata")
+    }
     delete "${jalviewDir}/${jalviewjs_j2s_settings}"
   }
 }