JAL-3210 Tidied more build.gradle. Different j2s versions for different eclipse versi...
[jalview.git] / build.gradle
index 48033f1..d259e13 100644 (file)
@@ -153,7 +153,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}"
   getdownAppDir = "${getdownWebsiteDir}/${getdown_app_dir}"
   //getdownJ11libDir = "${getdownWebsiteDir}/${getdown_j11lib_dir}"
   getdownResourceDir = "${getdownWebsiteDir}/${getdown_resource_dir}"
@@ -167,6 +166,7 @@ ext {
   gitHash = ""
   gitBranch = ""
 
   gitHash = ""
   gitBranch = ""
 
+  println("Using a ${CHANNEL} profile. appbase=${getdown_app_base}")
 }
 
 def JAVA_INTEGER_VERSION
 }
 
 def JAVA_INTEGER_VERSION
@@ -687,7 +687,7 @@ test {
   sourceCompatibility = compile_source_compatibility
   targetCompatibility = compile_target_compatibility
   jvmArgs += additional_compiler_args
   sourceCompatibility = compile_source_compatibility
   targetCompatibility = compile_target_compatibility
   jvmArgs += additional_compiler_args
-  print ("Setting target compatibility to "+targetCompatibility+"\n")
+
 }
 
 task buildIndices(type: JavaExec) {
 }
 
 task buildIndices(type: JavaExec) {
@@ -851,13 +851,13 @@ task getdownWebsite() {
 
     // go through properties looking for getdown_txt_...
     def props = project.properties.sort { it.key }
 
     // 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 ->
 
     props.put("getdown_txt_appbase", getdown_app_base)
     props.each{ prop, val ->
@@ -992,7 +992,7 @@ task getdownWebsite() {
     }
 
     copy {
     }
 
     copy {
-         from getdownResourceDir
+      from getdownResourceDir
       into "${project.ext.getdownFilesDir}/${getdown_resource_dir}"
     }
   }
       into "${project.ext.getdownFilesDir}/${getdown_resource_dir}"
     }
   }
@@ -1140,14 +1140,16 @@ task installers(type: com.install4j.gradle.Install4jTask) {
   dependsOn getdown
   dependsOn copyInstall4jTemplate
   projectFile = file(install4jConf)
   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
   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)
   }
 
   inputs.dir(project.ext.getdownWebsiteDir)
@@ -1155,7 +1157,6 @@ task installers(type: com.install4j.gradle.Install4jTask) {
   inputs.dir(macosJavaVMDir)
   inputs.dir(windowsJavaVMDir)
   outputs.dir("${jalviewDir}/${install4jBuildDir}/${JAVA_VERSION}")
   inputs.dir(macosJavaVMDir)
   inputs.dir(windowsJavaVMDir)
   outputs.dir("${jalviewDir}/${install4jBuildDir}/${JAVA_VERSION}")
-
 }
 
 clean {
 }
 
 clean {
@@ -1259,14 +1260,14 @@ task jalviewjsSitePath {
 def eclipseWorkspace
 task jalviewjsSetEclipseWorkspace {
   def propKey = "jalviewjs_eclipse_workspace"
 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)
   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)
   if (( eclipseWsDir == null || !file(eclipseWsDir).exists() ) && file(propsFileName).exists()) {
     def ins = new FileInputStream("${jalviewDirAbsolutePath}/${propsFileName}")
     props.load(ins)
@@ -1289,40 +1290,25 @@ task jalviewjsSetEclipseWorkspace {
   }
 
   eclipseWorkspace = file(eclipseWsDir)
   }
 
   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)
 }
 
 
   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 eclipseDropinsDir
+def utilsDropinsDir
 def eclipseBinary
 def eclipseVersion
 def eclipseBinary
 def eclipseVersion
-def fromDropinsDir
+def eclipseDebug = false
+def eclipseVersionSuffix = ""
 task jalviewjsEclipsePaths {
   def eclipseRoot
   def eclipseProduct
 task jalviewjsEclipsePaths {
   def eclipseRoot
   def eclipseProduct
+
   eclipseRoot = jalviewjs_eclipse_root
   if (eclipseRoot.startsWith("~")) {
     eclipseRoot = System.getProperty("user.home") + eclipseRoot.substring(1)
   eclipseRoot = jalviewjs_eclipse_root
   if (eclipseRoot.startsWith("~")) {
     eclipseRoot = System.getProperty("user.home") + eclipseRoot.substring(1)
@@ -1349,27 +1335,38 @@ task jalviewjsEclipsePaths {
   }
 
   eclipseVersion = "4.12" // default
   }
 
   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()
   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 )) {
   }
   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 {
   } else {
-    fromDropinsDir = "eclipse/dropins_4.13"
-  } 
+    eclipseVersionSuffix = "_4.13"
+  }
+
+  utilsDropinsDir = "${jalviewjs_utils_dir}/${jalviewjs_eclipse_dropins_dir}${eclipseVersionSuffix}"
+  def propKey = "eclipse_debug"
+  eclipseDebug = (project.hasProperty(propKey) && project.getProperty(propKey).equals("true"))
+
+  doFirst {
+    if (!assumedVersion) {
+      println("ECLIPSE_VERSION=${eclipseVersion}")
+    }
+  }
 }
 
 task jalviewjsEclipseCopyDropins {
   dependsOn jalviewjsEclipsePaths
 }
 
 task jalviewjsEclipseCopyDropins {
   dependsOn jalviewjsEclipsePaths
-  def inputFiles = fileTree(dir: "${jalviewjs_utils_dir}/${fromDropinsDir}", include: "*.jar")
+  def inputFiles = fileTree(dir: utilsDropinsDir, include: "*.jar")
   def outputDir = eclipseDropinsDir
 
   inputs.files inputFiles
   def outputDir = eclipseDropinsDir
 
   inputs.files inputFiles
@@ -1390,18 +1387,37 @@ task jalviewjsEclipseCopyDropins {
 // this version (type: Copy) will delete anything in the eclipse dropins folder that isn't in fromDropinsDir
 task NEWjalviewjsEclipseCopyDropins(type: Copy) {
   dependsOn jalviewjsEclipsePaths
 // this version (type: Copy) will delete anything in the eclipse dropins folder that isn't in fromDropinsDir
 task NEWjalviewjsEclipseCopyDropins(type: Copy) {
   dependsOn jalviewjsEclipsePaths
-  from fromDropinsDir
+  from utilsDropinsDir
   into eclipseDropinsDir
 }
 
   into eclipseDropinsDir
 }
 
+task jalviewjsUnzipFiles {
+  dependsOn jalviewjsSitePath
+
+  def zipFiles = fileTree(dir: "${jalviewjs_utils_dir}/${jalviewjs_libjs_dir}", include: "*.zip")
+  zipFiles += "${jalviewjs_utils_dir}/${jalviewjs_swingjs_zip}${eclipseVersionSuffix}"
+
+  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}")
 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
   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}"
       if (prop == siteDirProperty) {
         if (!(val.startsWith('/') || val.startsWith("file://") )) {
           val = "${jalviewjsTransferSiteDir}/${val}"
@@ -1410,11 +1426,11 @@ task jalviewjsCreateJ2sSettings(type: WriteProperties) {
       }
       property(prop,val)
     }
       }
       property(prop,val)
     }
-    if (!setSiteDir) {
+    if (!setSiteDir) { // default site location, don't override specifically set property
       property(siteDirProperty,jalviewjsTransferSiteDir)
     }
   }
       property(siteDirProperty,jalviewjsTransferSiteDir)
     }
   }
-  inputs.properties(props.findAll( { k, v -> k.startsWith("j2s.") } ))
+  inputs.properties(j2s_props)
   outputs.file(outputFile)
 }
 
   outputs.file(outputFile)
 }
 
@@ -1457,19 +1473,23 @@ task jalviewjsCopySiteResources (type: Copy) {
 }
 
 task jalviewjsProjectImport(type: Exec) {
 }
 
 task jalviewjsProjectImport(type: Exec) {
-  // work out how to do this!
   dependsOn eclipseProject
   dependsOn eclipseClasspath
   dependsOn eclipseJdt
   dependsOn jalviewjsEclipsePaths
   dependsOn jalviewjsEclipseSetup
   dependsOn eclipseProject
   dependsOn eclipseClasspath
   dependsOn eclipseJdt
   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])
   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"
   }
 
     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() }
   inputs.file("${jalviewDir}/.project")
   outputs.dir(projdir)
   outputs.upToDateWhen { file(projdir).exists() }
@@ -1479,48 +1499,48 @@ task jalviewjsTranspile(type: Exec) {
   dependsOn jalviewjsEclipseSetup 
   dependsOn jalviewjsProjectImport
   dependsOn jalviewjsEclipsePaths
   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 ])
   executable(eclipseBinary)
   args(["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", eclipseWorkspace, "-${jalviewjs_eclipseBuildArg}", eclipse_project_name ])
-  if (eclipse_debug == "true") {
+  if (eclipseDebug) {
     args += "-debug"
   }
 
   def stdout
   def stderr
     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()
+  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)
       errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
         new org.apache.tools.ant.util.TeeOutputStream(
           logErrFOS,
           stderr),
         errorOutput)
       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)
       errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
         logErrFOS,
         stderr)
-    }
   }
   }
+
   doLast {
     if (stdout.toString().contains("Error processing ")) {
       // j2s did not complete transpile
   doLast {
     if (stdout.toString().contains("Error processing ")) {
       // j2s did not complete transpile
@@ -1528,6 +1548,10 @@ task jalviewjsTranspile(type: Exec) {
     }
   }
 
     }
   }
 
+  doFirst {
+    println("TRANSPILE ECLIPSE_DEBUG=${eclipseDebug}")
+  }
+
   inputs.dir(sourceDir)
   outputs.dir("${eclipse_bin_dir}/main")
   outputs.dir(jalviewjsTransferSiteDir)
   inputs.dir(sourceDir)
   outputs.dir("${eclipse_bin_dir}/main")
   outputs.dir(jalviewjsTransferSiteDir)
@@ -1628,11 +1652,14 @@ task cleanJalviewjsAll {
   group "JalviewJS"
   description "Delete all configuration and build artifacts to do with JalviewJS build"
   dependsOn cleanJalviewjsSite
   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}"
   
   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}"
   }
 }
     delete "${jalviewDir}/${jalviewjs_j2s_settings}"
   }
 }