Merge branch 'patch/JAL-3692enaEndpointFlatfile' into releases/Release_2_11_1_Branch
[jalview.git] / build.gradle
1 /* Convention for properties.  Read from gradle.properties, use lower_case_underlines for property names.
2  * For properties set within build.gradle, use camelCaseNoSpace.
3  */
4 import org.apache.tools.ant.filters.ReplaceTokens
5 import org.gradle.internal.os.OperatingSystem
6 import org.gradle.plugins.ide.eclipse.model.Output
7 import org.gradle.plugins.ide.eclipse.model.Library
8 import java.security.MessageDigest
9 import groovy.transform.ExternalizeMethods
10 import groovy.util.XmlParser
11 import groovy.xml.XmlUtil
12
13
14 buildscript {
15   repositories {
16     mavenCentral()
17     mavenLocal()
18   }
19 }
20
21
22 plugins {
23   id 'java'
24   id 'application'
25   id 'eclipse'
26   id 'com.github.johnrengelman.shadow' version '4.0.3'
27   id 'com.install4j.gradle' version '8.0.4'
28   id 'com.dorongold.task-tree' version '1.5' // only needed to display task dependency tree with  gradle task1 [task2 ...] taskTree
29 }
30
31 repositories {
32   jcenter()
33   mavenCentral()
34   mavenLocal()
35 }
36
37
38 // in ext the values are cast to Object. Ensure string values are cast as String (and not GStringImpl) for later use
39 def string(Object o) {
40   return o == null ? "" : o.toString()
41 }
42
43
44 ext {
45   jalviewDirAbsolutePath = file(jalviewDir).getAbsolutePath()
46   jalviewDirRelativePath = jalviewDir
47
48   // local build environment properties
49   // can be "projectDir/local.properties"
50   def localProps = "${projectDir}/local.properties"
51   def propsFile = null;
52   if (file(localProps).exists()) {
53     propsFile = localProps
54   }
55   // or "../projectDir_local.properties"
56   def dirLocalProps = projectDir.getParent() + "/" + projectDir.getName() + "_local.properties"
57   if (file(dirLocalProps).exists()) {
58     propsFile = dirLocalProps
59   }
60   if (propsFile != null) {
61     try {
62       def p = new Properties()
63       def localPropsFIS = new FileInputStream(propsFile)
64       p.load(localPropsFIS)
65       localPropsFIS.close()
66       p.each {
67         key, val -> 
68           def oldval = findProperty(key)
69           setProperty(key, val)
70           if (oldval != null) {
71             println("Overriding property '${key}' ('${oldval}') with ${file(propsFile).getName()} value '${val}'")
72           } else {
73             println("Setting unknown property '${key}' with ${file(propsFile).getName()}s value '${val}'")
74           }
75       }
76     } catch (Exception e) {
77       System.out.println("Exception reading local.properties")
78     }
79   }
80
81   ////  
82   // Import releaseProps from the RELEASE file
83   // or a file specified via JALVIEW_RELEASE_FILE if defined
84   // Expect jalview.version and target release branch in jalview.release        
85   def releaseProps = new Properties();
86   def releasePropFile = findProperty("JALVIEW_RELEASE_FILE");
87   def defaultReleasePropFile = "${jalviewDirAbsolutePath}/RELEASE";
88   try {
89     (new File(releasePropFile!=null ? releasePropFile : defaultReleasePropFile)).withInputStream { 
90      releaseProps.load(it)
91     }
92   } catch (Exception fileLoadError) {
93     throw new Error("Couldn't load release properties file "+(releasePropFile==null ? defaultReleasePropFile : "from custom location: releasePropFile"),fileLoadError);
94   }
95   ////
96   // Set JALVIEW_VERSION if it is not already set
97   if (findProperty(JALVIEW_VERSION)==null || "".equals(JALVIEW_VERSION)) {
98     JALVIEW_VERSION = releaseProps.get("jalview.version")
99   }
100   
101   // this property set when running Eclipse headlessly
102   j2sHeadlessBuildProperty = string("net.sf.j2s.core.headlessbuild")
103   // this property set by Eclipse
104   eclipseApplicationProperty = string("eclipse.application")
105   // CHECK IF RUNNING FROM WITHIN ECLIPSE
106   def eclipseApplicationPropertyVal = System.properties[eclipseApplicationProperty]
107   IN_ECLIPSE = eclipseApplicationPropertyVal != null && eclipseApplicationPropertyVal.startsWith("org.eclipse.ui.")
108   // BUT WITHOUT THE HEADLESS BUILD PROPERTY SET
109   if (System.properties[j2sHeadlessBuildProperty].equals("true")) {
110     println("Setting IN_ECLIPSE to ${IN_ECLIPSE} as System.properties['${j2sHeadlessBuildProperty}'] == '${System.properties[j2sHeadlessBuildProperty]}'")
111     IN_ECLIPSE = false
112   }
113   if (IN_ECLIPSE) {
114     println("WITHIN ECLIPSE IDE")
115   } else {
116     println("HEADLESS BUILD")
117   }
118   /* *-/
119   System.properties.sort { it.key }.each {
120     key, val -> println("SYSTEM PROPERTY ${key}='${val}'")
121   }
122   /-* *-/
123   if (false && IN_ECLIPSE) {
124     jalviewDir = jalviewDirAbsolutePath
125   }
126   */
127
128   // essentials
129   bareSourceDir = string(source_dir)
130   sourceDir = string("${jalviewDir}/${bareSourceDir}")
131   resourceDir = string("${jalviewDir}/${resource_dir}")
132   bareTestSourceDir = string(test_source_dir)
133   testDir = string("${jalviewDir}/${bareTestSourceDir}")
134
135   classesDir = string("${jalviewDir}/${classes_dir}")
136
137   // clover
138   useClover = clover.equals("true")
139   cloverBuildDir = "${buildDir}/clover"
140   cloverInstrDir = file("${cloverBuildDir}/clover-instr")
141   cloverClassesDir = file("${cloverBuildDir}/clover-classes")
142   cloverReportDir = file("${buildDir}/reports/clover")
143   cloverTestInstrDir = file("${cloverBuildDir}/clover-test-instr")
144   cloverTestClassesDir = file("${cloverBuildDir}/clover-test-classes")
145   //cloverTestClassesDir = cloverClassesDir
146   cloverDb = string("${cloverBuildDir}/clover.db")
147
148   resourceClassesDir = useClover ? cloverClassesDir : classesDir
149
150   testSourceDir = useClover ? cloverTestInstrDir : testDir
151   testClassesDir = useClover ? cloverTestClassesDir : "${jalviewDir}/${test_output_dir}"
152
153   getdownWebsiteDir = string("${jalviewDir}/${getdown_website_dir}/${JAVA_VERSION}")
154   buildDist = true
155
156   // the following values might be overridden by the CHANNEL switch
157   getdownChannelName = CHANNEL.toLowerCase()
158   getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
159   getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
160   getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher}")
161   getdownAppDistDir = getdown_app_dir_alt
162   buildProperties = string("${classesDir}/${build_properties_file}")
163   reportRsyncCommand = false
164   jvlChannelName = CHANNEL.toLowerCase()
165   install4jSuffix = CHANNEL.substring(0, 1).toUpperCase() + CHANNEL.substring(1).toLowerCase(); // BUILD -> Build
166   install4jDSStore = "DS_Store-NON-RELEASE"
167   install4jDMGBackgroundImage = "jalview_dmg_background-NON-RELEASE.png"
168   install4jInstallerName = "${jalview_name} Non-Release Installer"
169   install4jExecutableName = jalview_name.replaceAll("[^\\w]+", "_").toLowerCase()
170   install4jExtraScheme = "jalviewx"
171   switch (CHANNEL) {
172
173     case "BUILD":
174     // TODO: get bamboo build artifact URL for getdown artifacts
175     getdown_channel_base = bamboo_channelbase
176     getdownChannelName = string("${bamboo_planKey}/${JAVA_VERSION}")
177     getdownAppBase = string("${bamboo_channelbase}/${bamboo_planKey}${bamboo_getdown_channel_suffix}/${JAVA_VERSION}")
178     jvlChannelName += "_${getdownChannelName}"
179     // automatically add the test group Not-bamboo for exclusion 
180     if ("".equals(testng_excluded_groups)) { 
181       testng_excluded_groups = "Not-bamboo"
182     }
183     install4jExtraScheme = "jalviewb"
184     break
185
186     case "RELEASE":
187     getdownAppDistDir = getdown_app_dir_release
188     reportRsyncCommand = true
189     install4jSuffix = ""
190     install4jDSStore = "DS_Store"
191     install4jDMGBackgroundImage = "jalview_dmg_background.png"
192     install4jInstallerName = "${jalview_name} Installer"
193     break
194
195     case "ARCHIVE":
196     getdownChannelName = CHANNEL.toLowerCase()+"/${JALVIEW_VERSION}"
197     getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
198     getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
199     if (!file("${ARCHIVEDIR}/${package_dir}").exists()) {
200       throw new GradleException("Must provide an ARCHIVEDIR value to produce an archive distribution")
201     } else {
202       package_dir = string("${ARCHIVEDIR}/${package_dir}")
203       buildProperties = string("${ARCHIVEDIR}/${classes_dir}/${build_properties_file}")
204       buildDist = false
205     }
206     reportRsyncCommand = true
207     install4jExtraScheme = "jalviewa"
208     break
209
210     case "ARCHIVELOCAL":
211     getdownChannelName = string("archive/${JALVIEW_VERSION}")
212     getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
213     getdownAppBase = file(getdownWebsiteDir).toURI().toString()
214     if (!file("${ARCHIVEDIR}/${package_dir}").exists()) {
215       throw new GradleException("Must provide an ARCHIVEDIR value to produce an archive distribution")
216     } else {
217       package_dir = string("${ARCHIVEDIR}/${package_dir}")
218       buildProperties = string("${ARCHIVEDIR}/${classes_dir}/${build_properties_file}")
219       buildDist = false
220     }
221     reportRsyncCommand = true
222     getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
223     install4jSuffix = "Archive"
224     install4jExtraScheme = "jalviewa"
225     break
226
227     case "DEVELOP":
228     reportRsyncCommand = true
229     
230     // DEVELOP-RELEASE is usually associated with a Jalview release series so set the version
231     JALVIEW_VERSION=JALVIEW_VERSION+"-develop"
232     
233     install4jSuffix = "Develop"
234     install4jDSStore = "DS_Store-DEVELOP"
235     install4jDMGBackgroundImage = "jalview_dmg_background-DEVELOP.png"
236     install4jExtraScheme = "jalviewd"
237     install4jInstallerName = "${jalview_name} Develop Installer"
238     break
239
240     case "TEST-RELEASE":
241     reportRsyncCommand = true
242     
243     // TEST-RELEASE is usually associated with a Jalview release series so set the version
244     JALVIEW_VERSION=JALVIEW_VERSION+"-test"
245     
246     install4jSuffix = "Test"
247     install4jDSStore = "DS_Store-TEST-RELEASE"
248     install4jDMGBackgroundImage = "jalview_dmg_background-TEST.png"
249     install4jExtraScheme = "jalviewt"
250     install4jInstallerName = "${jalview_name} Test Installer"
251     break
252
253     case ~/^SCRATCH(|-[-\w]*)$/:
254     getdownChannelName = CHANNEL
255     getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
256     getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
257     reportRsyncCommand = true
258     install4jSuffix = "Scratch"
259     break
260
261     case "TEST-LOCAL":
262     if (!file("${LOCALDIR}").exists()) {
263       throw new GradleException("Must provide a LOCALDIR value to produce a local distribution")
264     } else {
265       getdownAppBase = file(file("${LOCALDIR}").getAbsolutePath()).toURI().toString()
266       getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
267     }
268     JALVIEW_VERSION = "TEST"
269     install4jSuffix = "Test-Local"
270     install4jDSStore = "DS_Store-TEST-RELEASE"
271     install4jDMGBackgroundImage = "jalview_dmg_background-TEST.png"
272     install4jExtraScheme = "jalviewt"
273     install4jInstallerName = "${jalview_name} Test Installer"
274     break
275
276     case "LOCAL":
277     getdownAppBase = file(getdownWebsiteDir).toURI().toString()
278     getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
279     install4jExtraScheme = "jalviewl"
280     break
281
282     default: // something wrong specified
283     throw new GradleException("CHANNEL must be one of BUILD, RELEASE, ARCHIVE, DEVELOP, TEST-RELEASE, SCRATCH-..., LOCAL [default]")
284     break
285
286   }
287   // override getdownAppBase if requested
288   if (findProperty("getdown_appbase_override") != null) {
289     getdownAppBase = string(getProperty("getdown_appbase_override"))
290     println("Overriding getdown appbase with '${getdownAppBase}'")
291   }
292   // sanitise file name for jalview launcher file for this channel
293   jvlChannelName = jvlChannelName.replaceAll("[^\\w\\-]+", "_")
294   // install4j application and folder names
295   if (install4jSuffix == "") {
296     install4jApplicationName = "${jalview_name}"
297     install4jBundleId = "${install4j_bundle_id}"
298     install4jWinApplicationId = install4j_release_win_application_id
299   } else {
300     install4jApplicationName = "${jalview_name} ${install4jSuffix}"
301     install4jBundleId = "${install4j_bundle_id}-" + install4jSuffix.toLowerCase()
302     // add int hash of install4jSuffix to the last part of the application_id
303     def id = install4j_release_win_application_id
304     def idsplitreverse = id.split("-").reverse()
305     idsplitreverse[0] = idsplitreverse[0].toInteger() + install4jSuffix.hashCode()
306     install4jWinApplicationId = idsplitreverse.reverse().join("-")
307   }
308   // sanitise folder and id names
309   // install4jApplicationFolder = e.g. "Jalview Build"
310   install4jApplicationFolder = install4jApplicationName
311                                     .replaceAll("[\"'~:/\\\\\\s]", "_") // replace all awkward filename chars " ' ~ : / \
312                                     .replaceAll("_+", "_") // collapse __
313   install4jInternalId = install4jApplicationName
314                                     .replaceAll(" ","_")
315                                     .replaceAll("[^\\w\\-\\.]", "_") // replace other non [alphanumeric,_,-,.]
316                                     .replaceAll("_+", "") // collapse __
317                                     //.replaceAll("_*-_*", "-") // collapse _-_
318   install4jUnixApplicationFolder = install4jApplicationName
319                                     .replaceAll(" ","_")
320                                     .replaceAll("[^\\w\\-\\.]", "_") // replace other non [alphanumeric,_,-,.]
321                                     .replaceAll("_+", "_") // collapse __
322                                     .replaceAll("_*-_*", "-") // collapse _-_
323                                     .toLowerCase()
324
325   getdownAppDir = string("${getdownWebsiteDir}/${getdownAppDistDir}")
326   //getdownJ11libDir = "${getdownWebsiteDir}/${getdown_j11lib_dir}"
327   getdownResourceDir = string("${getdownWebsiteDir}/${getdown_resource_dir}")
328   getdownInstallDir = string("${getdownWebsiteDir}/${getdown_install_dir}")
329   getdownFilesDir = string("${jalviewDir}/${getdown_files_dir}/${JAVA_VERSION}/")
330   getdownFilesInstallDir = string("${getdownFilesDir}/${getdown_install_dir}")
331   /* compile without modules -- using classpath libraries
332   modules_compileClasspath = fileTree(dir: "${jalviewDir}/${j11modDir}", include: ["*.jar"])
333   modules_runtimeClasspath = modules_compileClasspath
334   */
335   gitHash = string("")
336   gitBranch = string("")
337
338   println("Using a ${CHANNEL} profile.")
339
340   additional_compiler_args = []
341   // configure classpath/args for j8/j11 compilation
342   if (JAVA_VERSION.equals("1.8")) {
343     JAVA_INTEGER_VERSION = string("8")
344     //libDir = j8libDir
345     libDir = j11libDir
346     libDistDir = j8libDir
347     compile_source_compatibility = 1.8
348     compile_target_compatibility = 1.8
349     // these are getdown.txt properties defined dependent on the JAVA_VERSION
350     getdownAltJavaMinVersion = string(findProperty("getdown_alt_java8_min_version"))
351     getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java8_max_version"))
352     // this property is assigned below and expanded to multiple lines in the getdown task
353     getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java8_txt_multi_java_location"))
354     // this property is for the Java library used in eclipse
355     eclipseJavaRuntimeName = string("JavaSE-1.8")
356   } else if (JAVA_VERSION.equals("11")) {
357     JAVA_INTEGER_VERSION = string("11")
358     libDir = j11libDir
359     libDistDir = j11libDir
360     compile_source_compatibility = 11
361     compile_target_compatibility = 11
362     getdownAltJavaMinVersion = string(findProperty("getdown_alt_java11_min_version"))
363     getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java11_max_version"))
364     getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java11_txt_multi_java_location"))
365     eclipseJavaRuntimeName = string("JavaSE-11")
366     /* compile without modules -- using classpath libraries
367     additional_compiler_args += [
368     '--module-path', modules_compileClasspath.asPath,
369     '--add-modules', j11modules
370     ]
371      */
372   } else if (JAVA_VERSION.equals("12") || JAVA_VERSION.equals("13")) {
373     JAVA_INTEGER_VERSION = JAVA_VERSION
374     libDir = j11libDir
375     libDistDir = j11libDir
376     compile_source_compatibility = JAVA_VERSION
377     compile_target_compatibility = JAVA_VERSION
378     getdownAltJavaMinVersion = string(findProperty("getdown_alt_java11_min_version"))
379     getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java11_max_version"))
380     getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java11_txt_multi_java_location"))
381     eclipseJavaRuntimeName = string("JavaSE-11")
382     /* compile without modules -- using classpath libraries
383     additional_compiler_args += [
384     '--module-path', modules_compileClasspath.asPath,
385     '--add-modules', j11modules
386     ]
387      */
388   } else {
389     throw new GradleException("JAVA_VERSION=${JAVA_VERSION} not currently supported by Jalview")
390   }
391
392
393   // for install4j
394   JAVA_MIN_VERSION = JAVA_VERSION
395   JAVA_MAX_VERSION = JAVA_VERSION
396   def jreInstallsDir = string(jre_installs_dir)
397   if (jreInstallsDir.startsWith("~/")) {
398     jreInstallsDir = System.getProperty("user.home") + jreInstallsDir.substring(1)
399   }
400   macosJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-mac-x64/jre")
401   macosJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-mac-x64.tar.gz")
402   windowsJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-windows-x64/jre")
403   windowsJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-windows-x64.tar.gz")
404   linuxJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-linux-x64/jre")
405   linuxJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-linux-x64.tar.gz")
406   install4jDir = string("${jalviewDir}/${install4j_utils_dir}")
407   install4jConfFileName = string("jalview-install4j-conf.install4j")
408   install4jConfFile = file("${install4jDir}/${install4jConfFileName}")
409   install4jHomeDir = install4j_home_dir
410   if (install4jHomeDir.startsWith("~/")) {
411     install4jHomeDir = System.getProperty("user.home") + install4jHomeDir.substring(1)
412   }
413
414
415
416   buildingHTML = string("${jalviewDir}/${doc_dir}/building.html")
417   helpFile = string("${resourceClassesDir}/${help_dir}/help.jhm")
418   helpParentDir = string("${jalviewDir}/${help_parent_dir}")
419   helpSourceDir = string("${helpParentDir}/${help_dir}")
420
421
422   relativeBuildDir = file(jalviewDirAbsolutePath).toPath().relativize(buildDir.toPath())
423   jalviewjsBuildDir = string("${relativeBuildDir}/jalviewjs")
424   jalviewjsSiteDir = string("${jalviewjsBuildDir}/${jalviewjs_site_dir}")
425   if (IN_ECLIPSE) {
426     jalviewjsTransferSiteJsDir = string(jalviewjsSiteDir)
427   } else {
428     jalviewjsTransferSiteJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_js")
429   }
430   jalviewjsTransferSiteLibDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_lib")
431   jalviewjsTransferSiteSwingJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_swingjs")
432   jalviewjsTransferSiteCoreDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_core")
433   jalviewjsJalviewCoreHtmlFile = string("")
434   jalviewjsJalviewCoreName = string(jalviewjs_core_name)
435   jalviewjsCoreClasslists = []
436   jalviewjsJalviewTemplateName = string(jalviewjs_name)
437   jalviewjsJ2sSettingsFileName = string("${jalviewDir}/${jalviewjs_j2s_settings}")
438   jalviewjsJ2sProps = null
439
440   eclipseWorkspace = null
441   eclipseBinary = string("")
442   eclipseVersion = string("")
443   eclipseDebug = false
444   // ENDEXT
445 }
446
447
448 sourceSets {
449   main {
450     java {
451       srcDirs sourceDir
452       outputDir = file(classesDir)
453     }
454
455     resources {
456       srcDirs resourceDir
457       srcDirs += helpParentDir
458     }
459
460     jar.destinationDir = file("${jalviewDir}/${package_dir}")
461
462     compileClasspath = files(sourceSets.main.java.outputDir)
463     compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
464
465     runtimeClasspath = compileClasspath
466   }
467
468   clover {
469     java {
470       srcDirs cloverInstrDir
471       outputDir = cloverClassesDir
472     }
473
474     resources {
475       srcDirs = sourceSets.main.resources.srcDirs
476     }
477
478     compileClasspath = files( sourceSets.clover.java.outputDir )
479     //compileClasspath += files( testClassesDir )
480     compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
481     compileClasspath += fileTree(dir: "${jalviewDir}/${clover_lib_dir}", include: ["*.jar"])
482     compileClasspath += fileTree(dir: "${jalviewDir}/${utils_dir}/testnglibs", include: ["**/*.jar"])
483
484     runtimeClasspath = compileClasspath
485   }
486
487   test {
488     java {
489       srcDirs testSourceDir
490       outputDir = file(testClassesDir)
491     }
492
493     resources {
494       srcDirs = useClover ? sourceSets.clover.resources.srcDirs : sourceSets.main.resources.srcDirs
495     }
496
497     compileClasspath = files( sourceSets.test.java.outputDir )
498     compileClasspath += useClover ? sourceSets.clover.compileClasspath : sourceSets.main.compileClasspath
499     compileClasspath += fileTree(dir: "${jalviewDir}/${utils_dir}/testnglibs", include: ["**/*.jar"])
500
501     runtimeClasspath = compileClasspath
502   }
503
504 }
505
506
507 // eclipse project and settings files creation, also used by buildship
508 eclipse {
509   project {
510     name = eclipse_project_name
511
512     natures 'org.eclipse.jdt.core.javanature',
513     'org.eclipse.jdt.groovy.core.groovyNature',
514     'org.eclipse.buildship.core.gradleprojectnature'
515
516     buildCommand 'org.eclipse.jdt.core.javabuilder'
517     buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
518   }
519
520   classpath {
521     //defaultOutputDir = sourceSets.main.java.outputDir
522     def removeThese = []
523     configurations.each{
524       if (it.isCanBeResolved()) {
525         removeThese += it
526       }
527     }
528
529     minusConfigurations += removeThese
530     plusConfigurations = [ ]
531     file {
532
533       whenMerged { cp ->
534         def removeTheseToo = []
535         HashMap<String, Boolean> alreadyAddedSrcPath = new HashMap<>();
536         cp.entries.each { entry ->
537           // This conditional removes all src classpathentries that a) have already been added or b) aren't "src" or "test".
538           // e.g. this removes the resources dir being copied into bin/main, bin/test AND bin/clover
539           // we add the resources and help/help dirs in as libs afterwards (see below)
540           if (entry.kind == 'src') {
541             if (alreadyAddedSrcPath.getAt(entry.path) || !(entry.path == bareSourceDir || entry.path == bareTestSourceDir)) {
542               removeTheseToo += entry
543             } else {
544               alreadyAddedSrcPath.putAt(entry.path, true)
545             }
546           }
547
548         }
549         cp.entries.removeAll(removeTheseToo)
550
551         //cp.entries += new Output("${eclipse_bin_dir}/main")
552         if (file(helpParentDir).isDirectory()) {
553           cp.entries += new Library(fileReference(helpParentDir))
554         }
555         if (file(resourceDir).isDirectory()) {
556           cp.entries += new Library(fileReference(resourceDir))
557         }
558
559         HashMap<String, Boolean> alreadyAddedLibPath = new HashMap<>();
560
561         sourceSets.main.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
562           //don't want to add outputDir as eclipse is using its own output dir in bin/main
563           if (it.isDirectory() || ! it.exists()) {
564             // don't add dirs to classpath, especially if they don't exist
565             return false // groovy "continue" in .any closure
566           }
567           def itPath = it.toString()
568           if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
569             // make relative path
570             itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
571           }
572           if (alreadyAddedLibPath.get(itPath)) {
573             //println("Not adding duplicate entry "+itPath)
574           } else {
575             //println("Adding entry "+itPath)
576             cp.entries += new Library(fileReference(itPath))
577             alreadyAddedLibPath.put(itPath, true)
578           }
579         }
580
581         sourceSets.test.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
582           //no longer want to add outputDir as eclipse is using its own output dir in bin/main
583           if (it.isDirectory() || ! it.exists()) {
584             // don't add dirs to classpath
585             return false // groovy "continue" in .any closure
586           }
587
588           def itPath = it.toString()
589           if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
590             itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
591           }
592           if (alreadyAddedLibPath.get(itPath)) {
593             // don't duplicate
594           } else {
595             def lib = new Library(fileReference(itPath))
596             lib.entryAttributes["test"] = "true"
597             cp.entries += lib
598             alreadyAddedLibPath.put(itPath, true)
599           }
600         }
601
602       } // whenMerged
603
604     } // file
605
606     containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
607
608   } // classpath
609
610   jdt {
611     // for the IDE, use java 11 compatibility
612     sourceCompatibility = compile_source_compatibility
613     targetCompatibility = compile_target_compatibility
614     javaRuntimeName = eclipseJavaRuntimeName
615
616     // add in jalview project specific properties/preferences into eclipse core preferences
617     file {
618       withProperties { props ->
619         def jalview_prefs = new Properties()
620         def ins = new FileInputStream("${jalviewDirAbsolutePath}/${eclipse_extra_jdt_prefs_file}")
621         jalview_prefs.load(ins)
622         ins.close()
623         jalview_prefs.forEach { t, v ->
624           if (props.getAt(t) == null) {
625             props.putAt(t, v)
626           }
627         }
628       }
629     }
630
631   } // jdt
632
633   if (IN_ECLIPSE) {
634     // Don't want these to be activated if in headless build
635     synchronizationTasks "eclipseSynchronizationTask"
636     autoBuildTasks "eclipseAutoBuildTask"
637
638   }
639 }
640
641
642 // clover bits
643
644
645 task cleanClover {
646   doFirst {
647     delete cloverBuildDir
648     delete cloverReportDir
649   }
650 }
651
652
653 task cloverInstrJava(type: JavaExec) {
654   group = "Verification"
655   description = "Create clover instrumented source java files"
656
657   dependsOn cleanClover
658
659   inputs.files(sourceSets.main.allJava)
660   outputs.dir(cloverInstrDir)
661
662   //classpath = fileTree(dir: "${jalviewDir}/${clover_lib_dir}", include: ["*.jar"])
663   classpath = sourceSets.clover.compileClasspath
664   main = "com.atlassian.clover.CloverInstr"
665
666   def argsList = [
667     "--encoding",
668     "UTF-8",
669     "--initstring",
670     cloverDb,
671     "--destdir",
672     cloverInstrDir.getPath(),
673   ]
674   def srcFiles = sourceSets.main.allJava.files
675   argsList.addAll(
676     srcFiles.collect(
677       { file -> file.absolutePath }
678     )
679   )
680   args argsList.toArray()
681
682   doFirst {
683     delete cloverInstrDir
684     println("Clover: About to instrument "+srcFiles.size() +" files")
685   }
686 }
687
688
689 task cloverInstrTests(type: JavaExec) {
690   group = "Verification"
691   description = "Create clover instrumented source test files"
692
693   dependsOn cleanClover
694
695   inputs.files(testDir)
696   outputs.dir(cloverTestInstrDir)
697
698   classpath = sourceSets.clover.compileClasspath
699   main = "com.atlassian.clover.CloverInstr"
700
701   def argsList = [
702     "--encoding",
703     "UTF-8",
704     "--initstring",
705     cloverDb,
706     "--srcdir",
707     testDir,
708     "--destdir",
709     cloverTestInstrDir.getPath(),
710   ]
711   args argsList.toArray()
712
713   doFirst {
714     delete cloverTestInstrDir
715     println("Clover: About to instrument test files")
716   }
717 }
718
719
720 task cloverInstr {
721   group = "Verification"
722   description = "Create clover instrumented all source files"
723
724   dependsOn cloverInstrJava
725   dependsOn cloverInstrTests
726 }
727
728
729 cloverClasses.dependsOn cloverInstr
730
731
732 task cloverConsoleReport(type: JavaExec) {
733   group = "Verification"
734   description = "Creates clover console report"
735
736   onlyIf {
737     file(cloverDb).exists()
738   }
739
740   inputs.dir cloverClassesDir
741
742   classpath = sourceSets.clover.runtimeClasspath
743   main = "com.atlassian.clover.reporters.console.ConsoleReporter"
744
745   if (cloverreport_mem.length() > 0) {
746     maxHeapSize = cloverreport_mem
747   }
748   if (cloverreport_jvmargs.length() > 0) {
749     jvmArgs Arrays.asList(cloverreport_jvmargs.split(" "))
750   }
751
752   def argsList = [
753     "--alwaysreport",
754     "--initstring",
755     cloverDb,
756     "--unittests"
757   ]
758
759   args argsList.toArray()
760 }
761
762
763 task cloverHtmlReport(type: JavaExec) {
764   group = "Verification"
765   description = "Creates clover HTML report"
766
767   onlyIf {
768     file(cloverDb).exists()
769   }
770
771   def cloverHtmlDir = cloverReportDir
772   inputs.dir cloverClassesDir
773   outputs.dir cloverHtmlDir
774
775   classpath = sourceSets.clover.runtimeClasspath
776   main = "com.atlassian.clover.reporters.html.HtmlReporter"
777
778   if (cloverreport_mem.length() > 0) {
779     maxHeapSize = cloverreport_mem
780   }
781   if (cloverreport_jvmargs.length() > 0) {
782     jvmArgs Arrays.asList(cloverreport_jvmargs.split(" "))
783   }
784
785   def argsList = [
786     "--alwaysreport",
787     "--initstring",
788     cloverDb,
789     "--outputdir",
790     cloverHtmlDir
791   ]
792
793   if (cloverreport_html_options.length() > 0) {
794     argsList += cloverreport_html_options.split(" ")
795   }
796
797   args argsList.toArray()
798 }
799
800
801 task cloverXmlReport(type: JavaExec) {
802   group = "Verification"
803   description = "Creates clover XML report"
804
805   onlyIf {
806     file(cloverDb).exists()
807   }
808
809   def cloverXmlFile = "${cloverReportDir}/clover.xml"
810   inputs.dir cloverClassesDir
811   outputs.file cloverXmlFile
812
813   classpath = sourceSets.clover.runtimeClasspath
814   main = "com.atlassian.clover.reporters.xml.XMLReporter"
815
816   if (cloverreport_mem.length() > 0) {
817     maxHeapSize = cloverreport_mem
818   }
819   if (cloverreport_jvmargs.length() > 0) {
820     jvmArgs Arrays.asList(cloverreport_jvmargs.split(" "))
821   }
822
823   def argsList = [
824     "--alwaysreport",
825     "--initstring",
826     cloverDb,
827     "--outfile",
828     cloverXmlFile
829   ]
830
831   if (cloverreport_xml_options.length() > 0) {
832     argsList += cloverreport_xml_options.split(" ")
833   }
834
835   args argsList.toArray()
836 }
837
838
839 task cloverReport {
840   group = "Verification"
841   description = "Creates clover reports"
842
843   dependsOn cloverXmlReport
844   dependsOn cloverHtmlReport
845 }
846
847
848 compileCloverJava {
849
850   doFirst {
851     sourceCompatibility = compile_source_compatibility
852     targetCompatibility = compile_target_compatibility
853     options.compilerArgs += additional_compiler_args
854     print ("Setting target compatibility to "+targetCompatibility+"\n")
855   }
856   //classpath += configurations.cloverRuntime
857 }
858 // end clover bits
859
860
861 compileJava {
862
863   doFirst {
864     sourceCompatibility = compile_source_compatibility
865     targetCompatibility = compile_target_compatibility
866     options.compilerArgs = additional_compiler_args
867     print ("Setting target compatibility to "+targetCompatibility+"\n")
868   }
869
870 }
871
872
873 compileTestJava {
874   doFirst {
875     sourceCompatibility = compile_source_compatibility
876     targetCompatibility = compile_target_compatibility
877     options.compilerArgs = additional_compiler_args
878     print ("Setting target compatibility to "+targetCompatibility+"\n")
879   }
880 }
881
882
883 clean {
884   doFirst {
885     delete sourceSets.main.java.outputDir
886   }
887 }
888
889
890 cleanTest {
891   dependsOn cleanClover
892   doFirst {
893     delete sourceSets.test.java.outputDir
894   }
895 }
896
897
898 // format is a string like date.format("dd MMMM yyyy")
899 def getDate(format) {
900   def date = new Date()
901   return date.format(format)
902 }
903
904
905 task setGitVals {
906   def hashStdOut = new ByteArrayOutputStream()
907   exec {
908     commandLine "git", "rev-parse", "--short", "HEAD"
909     standardOutput = hashStdOut
910     ignoreExitValue true
911   }
912
913   def branchStdOut = new ByteArrayOutputStream()
914   exec {
915     commandLine "git", "rev-parse", "--abbrev-ref", "HEAD"
916     standardOutput = branchStdOut
917     ignoreExitValue true
918   }
919
920   gitHash = hashStdOut.toString().trim()
921   gitBranch = branchStdOut.toString().trim()
922
923   outputs.upToDateWhen { false }
924 }
925
926
927 task createBuildProperties(type: WriteProperties) {
928   dependsOn setGitVals
929   inputs.dir(sourceDir)
930   inputs.dir(resourceDir)
931   file(buildProperties).getParentFile().mkdirs()
932   outputFile (buildProperties)
933   // taking time specific comment out to allow better incremental builds
934   comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd HH:mm:ss")
935   //comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd")
936   property "BUILD_DATE", getDate("HH:mm:ss dd MMMM yyyy")
937   property "VERSION", JALVIEW_VERSION
938   property "INSTALLATION", INSTALLATION+" git-commit:"+gitHash+" ["+gitBranch+"]"
939   outputs.file(outputFile)
940 }
941
942
943 task cleanBuildingHTML(type: Delete) {
944   doFirst {
945     delete buildingHTML
946   }
947 }
948
949
950 task convertBuildingMD(type: Exec) {
951   dependsOn cleanBuildingHTML
952   def buildingMD = "${jalviewDir}/${doc_dir}/building.md"
953   def css = "${jalviewDir}/${doc_dir}/github.css"
954
955   def pandoc = null
956   pandoc_exec.split(",").each {
957     if (file(it.trim()).exists()) {
958       pandoc = it.trim()
959       return true
960     }
961   }
962
963   def hostname = "hostname".execute().text.trim()
964   def buildtoolsPandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
965   if ((pandoc == null || ! file(pandoc).exists()) && file(buildtoolsPandoc).exists()) {
966     pandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
967   }
968
969   doFirst {
970     if (pandoc != null && file(pandoc).exists()) {
971         commandLine pandoc, '-s', '-o', buildingHTML, '--metadata', 'pagetitle="Building Jalview from Source"', '--toc', '-H', css, buildingMD
972     } else {
973         println("Cannot find pandoc. Skipping convert building.md to HTML")
974         throw new StopExecutionException("Cannot find pandoc. Skipping convert building.md to HTML")
975     }
976   }
977
978   ignoreExitValue true
979
980   inputs.file(buildingMD)
981   inputs.file(css)
982   outputs.file(buildingHTML)
983 }
984
985
986 clean {
987   doFirst {
988     delete buildingHTML
989   }
990 }
991
992
993 task syncDocs(type: Sync) {
994   dependsOn convertBuildingMD
995   def syncDir = "${resourceClassesDir}/${doc_dir}"
996   from fileTree("${jalviewDir}/${doc_dir}")
997   into syncDir
998
999 }
1000
1001
1002 task copyHelp(type: Copy) {
1003   def inputDir = helpSourceDir
1004   def outputDir = "${resourceClassesDir}/${help_dir}"
1005   from(inputDir) {
1006     exclude '**/*.gif'
1007     exclude '**/*.jpg'
1008     exclude '**/*.png'
1009     filter(ReplaceTokens,
1010       beginToken: '$$',
1011       endToken: '$$',
1012       tokens: [
1013         'Version-Rel': JALVIEW_VERSION,
1014         'Year-Rel': getDate("yyyy")
1015       ]
1016     )
1017   }
1018   from(inputDir) {
1019     include '**/*.gif'
1020     include '**/*.jpg'
1021     include '**/*.png'
1022   }
1023   into outputDir
1024
1025   inputs.dir(inputDir)
1026   outputs.files(helpFile)
1027   outputs.dir(outputDir)
1028 }
1029
1030
1031 task syncLib(type: Sync) {
1032   def syncDir = "${resourceClassesDir}/${libDistDir}"
1033   from fileTree("${jalviewDir}/${libDistDir}")
1034   into syncDir
1035 }
1036
1037
1038 task syncResources(type: Sync) {
1039   from resourceDir
1040   include "**/*.*"
1041   into "${resourceClassesDir}"
1042   preserve {
1043     include "**"
1044   }
1045 }
1046
1047
1048 task prepare {
1049   dependsOn syncResources
1050   dependsOn syncDocs
1051   dependsOn copyHelp
1052 }
1053
1054
1055 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
1056 test {
1057   dependsOn prepare
1058   //dependsOn compileJava ////? DELETE
1059
1060   if (useClover) {
1061     dependsOn cloverClasses
1062    } else { //?
1063      dependsOn compileJava //?
1064   }
1065
1066   useTestNG() {
1067     includeGroups testng_groups
1068     excludeGroups testng_excluded_groups
1069     preserveOrder true
1070     useDefaultListeners=true
1071   }
1072
1073   maxHeapSize = "1024m"
1074
1075   workingDir = jalviewDir
1076   //systemProperties 'clover.jar' System.properties.clover.jar
1077   def testLaf = project.findProperty("test_laf")
1078   if (testLaf != null) {
1079     println("Setting Test LaF to '${testLaf}'")
1080     systemProperty "laf", testLaf
1081   }
1082   def testHiDPIScale = project.findProperty("test_HiDPIScale")
1083   if (testHiDPIScale != null) {
1084     println("Setting Test HiDPI Scale to '${testHiDPIScale}'")
1085     systemProperty "sun.java2d.uiScale", testHiDPIScale
1086   }
1087   sourceCompatibility = compile_source_compatibility
1088   targetCompatibility = compile_target_compatibility
1089   jvmArgs += additional_compiler_args
1090
1091   doFirst {
1092     if (useClover) {
1093       println("Running tests " + (useClover?"WITH":"WITHOUT") + " clover")
1094     }
1095   }
1096 }
1097
1098
1099 task buildIndices(type: JavaExec) {
1100   dependsOn copyHelp
1101   classpath = sourceSets.main.compileClasspath
1102   main = "com.sun.java.help.search.Indexer"
1103   workingDir = "${classesDir}/${help_dir}"
1104   def argDir = "html"
1105   args = [ argDir ]
1106   inputs.dir("${workingDir}/${argDir}")
1107
1108   outputs.dir("${classesDir}/doc")
1109   outputs.dir("${classesDir}/help")
1110   outputs.file("${workingDir}/JavaHelpSearch/DOCS")
1111   outputs.file("${workingDir}/JavaHelpSearch/DOCS.TAB")
1112   outputs.file("${workingDir}/JavaHelpSearch/OFFSETS")
1113   outputs.file("${workingDir}/JavaHelpSearch/POSITIONS")
1114   outputs.file("${workingDir}/JavaHelpSearch/SCHEMA")
1115   outputs.file("${workingDir}/JavaHelpSearch/TMAP")
1116 }
1117
1118
1119 task compileLinkCheck(type: JavaCompile) {
1120   options.fork = true
1121   classpath = files("${jalviewDir}/${utils_dir}")
1122   destinationDir = file("${jalviewDir}/${utils_dir}")
1123   source = fileTree(dir: "${jalviewDir}/${utils_dir}", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
1124
1125   inputs.file("${jalviewDir}/${utils_dir}/HelpLinksChecker.java")
1126   inputs.file("${jalviewDir}/${utils_dir}/HelpLinksChecker.java")
1127   outputs.file("${jalviewDir}/${utils_dir}/HelpLinksChecker.class")
1128   outputs.file("${jalviewDir}/${utils_dir}/BufferedLineReader.class")
1129 }
1130
1131
1132 task linkCheck(type: JavaExec) {
1133   dependsOn prepare, compileLinkCheck
1134
1135   def helpLinksCheckerOutFile = file("${jalviewDir}/${utils_dir}/HelpLinksChecker.out")
1136   classpath = files("${jalviewDir}/${utils_dir}")
1137   main = "HelpLinksChecker"
1138   workingDir = jalviewDir
1139   args = [ "${classesDir}/${help_dir}", "-nointernet" ]
1140
1141   def outFOS = new FileOutputStream(helpLinksCheckerOutFile, false) // false == don't append
1142   def errFOS = outFOS
1143   standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
1144     outFOS,
1145     standardOutput)
1146   errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
1147     outFOS,
1148     errorOutput)
1149
1150   inputs.dir("${classesDir}/${help_dir}")
1151   outputs.file(helpLinksCheckerOutFile)
1152 }
1153
1154 // import the pubhtmlhelp target
1155 ant.properties.basedir = "${jalviewDir}"
1156 ant.properties.helpBuildDir = "${jalviewDirAbsolutePath}/${classes_dir}/${help_dir}"
1157 ant.importBuild "${utils_dir}/publishHelp.xml"
1158
1159
1160 task cleanPackageDir(type: Delete) {
1161   doFirst {
1162     delete fileTree(dir: "${jalviewDir}/${package_dir}", include: "*.jar")
1163   }
1164 }
1165
1166 jar {
1167   dependsOn linkCheck
1168   dependsOn buildIndices
1169   dependsOn createBuildProperties
1170
1171   manifest {
1172     attributes "Main-Class": main_class,
1173     "Permissions": "all-permissions",
1174     "Application-Name": "Jalview Desktop",
1175     "Codebase": application_codebase
1176   }
1177
1178   destinationDir = file("${jalviewDir}/${package_dir}")
1179   archiveName = rootProject.name+".jar"
1180
1181   exclude "cache*/**"
1182   exclude "*.jar"
1183   exclude "*.jar.*"
1184   exclude "**/*.jar"
1185   exclude "**/*.jar.*"
1186
1187   inputs.dir(classesDir)
1188   outputs.file("${jalviewDir}/${package_dir}/${archiveName}")
1189 }
1190
1191
1192 task copyJars(type: Copy) {
1193   from fileTree(dir: classesDir, include: "**/*.jar").files
1194   into "${jalviewDir}/${package_dir}"
1195 }
1196
1197
1198 // doing a Sync instead of Copy as Copy doesn't deal with "outputs" very well
1199 task syncJars(type: Sync) {
1200   from fileTree(dir: "${jalviewDir}/${libDistDir}", include: "**/*.jar").files
1201   into "${jalviewDir}/${package_dir}"
1202   preserve {
1203     include jar.archiveName
1204   }
1205 }
1206
1207
1208 task makeDist {
1209   group = "build"
1210   description = "Put all required libraries in dist"
1211   // order of "cleanPackageDir", "copyJars", "jar" important!
1212   jar.mustRunAfter cleanPackageDir
1213   syncJars.mustRunAfter cleanPackageDir
1214   dependsOn cleanPackageDir
1215   dependsOn syncJars
1216   dependsOn jar
1217   outputs.dir("${jalviewDir}/${package_dir}")
1218 }
1219
1220
1221 task cleanDist {
1222   dependsOn cleanPackageDir
1223   dependsOn cleanTest
1224   dependsOn clean
1225 }
1226
1227 shadowJar {
1228   group = "distribution"
1229   if (buildDist) {
1230     dependsOn makeDist
1231   }
1232   from ("${jalviewDir}/${libDistDir}") {
1233     include("*.jar")
1234   }
1235   manifest {
1236     attributes 'Implementation-Version': JALVIEW_VERSION
1237   }
1238   mainClassName = shadow_jar_main_class
1239   mergeServiceFiles()
1240   classifier = "all-"+JALVIEW_VERSION+"-j"+JAVA_VERSION
1241   minimize()
1242 }
1243
1244
1245 task getdownWebsite() {
1246   group = "distribution"
1247   description = "Create the getdown minimal app folder, and website folder for this version of jalview. Website folder also used for offline app installer"
1248   if (buildDist) {
1249     dependsOn makeDist
1250   }
1251
1252   def getdownWebsiteResourceFilenames = []
1253   def getdownTextString = ""
1254   def getdownResourceDir = getdownResourceDir
1255   def getdownResourceFilenames = []
1256
1257   doFirst {
1258     // clean the getdown website and files dir before creating getdown folders
1259     delete getdownWebsiteDir
1260     delete getdownFilesDir
1261
1262     copy {
1263       from buildProperties
1264       rename(build_properties_file, getdown_build_properties)
1265       into getdownAppDir
1266     }
1267     getdownWebsiteResourceFilenames += "${getdownAppDistDir}/${getdown_build_properties}"
1268
1269     // set some getdown_txt_ properties then go through all properties looking for getdown_txt_...
1270     def props = project.properties.sort { it.key }
1271     if (getdownAltJavaMinVersion != null && getdownAltJavaMinVersion.length() > 0) {
1272       props.put("getdown_txt_java_min_version", getdownAltJavaMinVersion)
1273     }
1274     if (getdownAltJavaMaxVersion != null && getdownAltJavaMaxVersion.length() > 0) {
1275       props.put("getdown_txt_java_max_version", getdownAltJavaMaxVersion)
1276     }
1277     if (getdownAltMultiJavaLocation != null && getdownAltMultiJavaLocation.length() > 0) {
1278       props.put("getdown_txt_multi_java_location", getdownAltMultiJavaLocation)
1279     }
1280
1281     props.put("getdown_txt_title", jalview_name)
1282     props.put("getdown_txt_ui.name", install4jApplicationName)
1283
1284     // start with appbase
1285     getdownTextString += "appbase = ${getdownAppBase}\n"
1286     props.each{ prop, val ->
1287       if (prop.startsWith("getdown_txt_") && val != null) {
1288         if (prop.startsWith("getdown_txt_multi_")) {
1289           def key = prop.substring(18)
1290           val.split(",").each{ v ->
1291             def line = "${key} = ${v}\n"
1292             getdownTextString += line
1293           }
1294         } else {
1295           // file values rationalised
1296           if (val.indexOf('/') > -1 || prop.startsWith("getdown_txt_resource")) {
1297             def r = null
1298             if (val.indexOf('/') == 0) {
1299               // absolute path
1300               r = file(val)
1301             } else if (val.indexOf('/') > 0) {
1302               // relative path (relative to jalviewDir)
1303               r = file( "${jalviewDir}/${val}" )
1304             }
1305             if (r.exists()) {
1306               val = "${getdown_resource_dir}/" + r.getName()
1307               getdownWebsiteResourceFilenames += val
1308               getdownResourceFilenames += r.getPath()
1309             }
1310           }
1311           if (! prop.startsWith("getdown_txt_resource")) {
1312             def line = prop.substring(12) + " = ${val}\n"
1313             getdownTextString += line
1314           }
1315         }
1316       }
1317     }
1318
1319     getdownWebsiteResourceFilenames.each{ filename ->
1320       getdownTextString += "resource = ${filename}\n"
1321     }
1322     getdownResourceFilenames.each{ filename ->
1323       copy {
1324         from filename
1325         into getdownResourceDir
1326       }
1327     }
1328
1329     def codeFiles = []
1330     fileTree(file(package_dir)).each{ f ->
1331       if (f.isDirectory()) {
1332         def files = fileTree(dir: f, include: ["*"]).getFiles()
1333         codeFiles += files
1334       } else if (f.exists()) {
1335         codeFiles += f
1336       }
1337     }
1338     codeFiles.sort().each{f ->
1339       def name = f.getName()
1340       def line = "code = ${getdownAppDistDir}/${name}\n"
1341       getdownTextString += line
1342       copy {
1343         from f.getPath()
1344         into getdownAppDir
1345       }
1346     }
1347
1348     // NOT USING MODULES YET, EVERYTHING SHOULD BE IN dist
1349     /*
1350     if (JAVA_VERSION.equals("11")) {
1351     def j11libFiles = fileTree(dir: "${jalviewDir}/${j11libDir}", include: ["*.jar"]).getFiles()
1352     j11libFiles.sort().each{f ->
1353     def name = f.getName()
1354     def line = "code = ${getdown_j11lib_dir}/${name}\n"
1355     getdownTextString += line
1356     copy {
1357     from f.getPath()
1358     into getdownJ11libDir
1359     }
1360     }
1361     }
1362      */
1363
1364     // getdown-launcher.jar should not be in main application class path so the main application can move it when updated.  Listed as a resource so it gets updated.
1365     //getdownTextString += "class = " + file(getdownLauncher).getName() + "\n"
1366     getdownTextString += "resource = ${getdown_launcher_new}\n"
1367     getdownTextString += "class = ${mainClass}\n"
1368
1369     def getdown_txt = file("${getdownWebsiteDir}/getdown.txt")
1370     getdown_txt.write(getdownTextString)
1371
1372     def getdownLaunchJvl = getdown_launch_jvl_name + ( (jvlChannelName != null && jvlChannelName.length() > 0)?"-${jvlChannelName}":"" ) + ".jvl"
1373     def launchJvl = file("${getdownWebsiteDir}/${getdownLaunchJvl}")
1374     launchJvl.write("appbase=${getdownAppBase}")
1375
1376     copy {
1377       from getdownLauncher
1378       rename(file(getdownLauncher).getName(), getdown_launcher_new)
1379       into getdownWebsiteDir
1380     }
1381
1382     copy {
1383       from getdownLauncher
1384       if (file(getdownLauncher).getName() != getdown_launcher) {
1385         rename(file(getdownLauncher).getName(), getdown_launcher)
1386       }
1387       into getdownWebsiteDir
1388     }
1389
1390     if (! (CHANNEL.startsWith("ARCHIVE") || CHANNEL.startsWith("DEVELOP"))) {
1391       copy {
1392         from getdown_txt
1393         from getdownLauncher
1394         from "${getdownWebsiteDir}/${getdown_build_properties}"
1395         if (file(getdownLauncher).getName() != getdown_launcher) {
1396           rename(file(getdownLauncher).getName(), getdown_launcher)
1397         }
1398         into getdownInstallDir
1399       }
1400
1401       copy {
1402         from getdownInstallDir
1403         into getdownFilesInstallDir
1404       }
1405     }
1406
1407     copy {
1408       from getdown_txt
1409       from launchJvl
1410       from getdownLauncher
1411       from "${getdownWebsiteDir}/${getdown_build_properties}"
1412       if (file(getdownLauncher).getName() != getdown_launcher) {
1413         rename(file(getdownLauncher).getName(), getdown_launcher)
1414       }
1415       into getdownFilesDir
1416     }
1417
1418     copy {
1419       from getdownResourceDir
1420       into "${getdownFilesDir}/${getdown_resource_dir}"
1421     }
1422   }
1423
1424   if (buildDist) {
1425     inputs.dir("${jalviewDir}/${package_dir}")
1426   }
1427   outputs.dir(getdownWebsiteDir)
1428   outputs.dir(getdownFilesDir)
1429 }
1430
1431
1432 // a helper task to allow getdown digest of any dir: `gradle getdownDigestDir -PDIGESTDIR=/path/to/my/random/getdown/dir
1433 task getdownDigestDir(type: JavaExec) {
1434   group "Help"
1435   description "A task to run a getdown Digest on a dir with getdown.txt. Provide a DIGESTDIR property via -PDIGESTDIR=..."
1436
1437   def digestDirPropertyName = "DIGESTDIR"
1438   doFirst {
1439     classpath = files(getdownLauncher)
1440     def digestDir = findProperty(digestDirPropertyName)
1441     if (digestDir == null) {
1442       throw new GradleException("Must provide a DIGESTDIR value to produce an alternative getdown digest")
1443     }
1444     args digestDir
1445   }
1446   main = "com.threerings.getdown.tools.Digester"
1447 }
1448
1449
1450 task getdownDigest(type: JavaExec) {
1451   group = "distribution"
1452   description = "Digest the getdown website folder"
1453   dependsOn getdownWebsite
1454   doFirst {
1455     classpath = files(getdownLauncher)
1456   }
1457   main = "com.threerings.getdown.tools.Digester"
1458   args getdownWebsiteDir
1459   inputs.dir(getdownWebsiteDir)
1460   outputs.file("${getdownWebsiteDir}/digest2.txt")
1461 }
1462
1463
1464 task getdown() {
1465   group = "distribution"
1466   description = "Create the minimal and full getdown app folder for installers and website and create digest file"
1467   dependsOn getdownDigest
1468   doLast {
1469     if (reportRsyncCommand) {
1470       def fromDir = getdownWebsiteDir + (getdownWebsiteDir.endsWith('/')?'':'/')
1471       def toDir = "${getdown_rsync_dest}/${getdownDir}" + (getdownDir.endsWith('/')?'':'/')
1472       println "LIKELY RSYNC COMMAND:"
1473       println "mkdir -p '$toDir'\nrsync -avh --delete '$fromDir' '$toDir'"
1474       if (RUNRSYNC == "true") {
1475         exec {
1476           commandLine "mkdir", "-p", toDir
1477         }
1478         exec {
1479           commandLine "rsync", "-avh", "--delete", fromDir, toDir
1480         }
1481       }
1482     }
1483   }
1484 }
1485
1486
1487 clean {
1488   doFirst {
1489     delete getdownWebsiteDir
1490     delete getdownFilesDir
1491   }
1492 }
1493
1494
1495 install4j {
1496   if (file(install4jHomeDir).exists()) {
1497     // good to go!
1498   } else if (file(System.getProperty("user.home")+"/buildtools/install4j").exists()) {
1499     install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
1500   } else if (file("/Applications/install4j.app/Contents/Resources/app").exists()) {
1501     install4jHomeDir = "/Applications/install4j.app/Contents/Resources/app"
1502   }
1503   installDir(file(install4jHomeDir))
1504
1505   mediaTypes = Arrays.asList(install4j_media_types.split(","))
1506 }
1507
1508
1509 task copyInstall4jTemplate {
1510   def install4jTemplateFile = file("${install4jDir}/${install4j_template}")
1511   def install4jFileAssociationsFile = file("${install4jDir}/${install4j_installer_file_associations}")
1512   inputs.file(install4jTemplateFile)
1513   inputs.file(install4jFileAssociationsFile)
1514   inputs.property("CHANNEL", { CHANNEL })
1515   outputs.file(install4jConfFile)
1516
1517   doLast {
1518     def install4jConfigXml = new XmlParser().parse(install4jTemplateFile)
1519
1520     // turn off code signing if no OSX_KEYPASS
1521     if (OSX_KEYPASS == "") {
1522       install4jConfigXml.'**'.codeSigning.each { codeSigning ->
1523         codeSigning.'@macEnabled' = "false"
1524       }
1525       install4jConfigXml.'**'.windows.each { windows ->
1526         windows.'@runPostProcessor' = "false"
1527       }
1528     }
1529
1530     // turn off checksum creation for LOCAL channel
1531     def e = install4jConfigXml.application[0]
1532     if (CHANNEL == "LOCAL") {
1533       e.'@createChecksums' = "false"
1534     } else {
1535       e.'@createChecksums' = "true"
1536     }
1537
1538     // put file association actions where placeholder action is
1539     def install4jFileAssociationsText = install4jFileAssociationsFile.text
1540     def fileAssociationActions = new XmlParser().parseText("<actions>${install4jFileAssociationsText}</actions>")
1541     install4jConfigXml.'**'.action.any { a -> // .any{} stops after the first one that returns true
1542       if (a.'@name' == 'EXTENSIONS_REPLACED_BY_GRADLE') {
1543         def parent = a.parent()
1544         parent.remove(a)
1545         fileAssociationActions.each { faa ->
1546             parent.append(faa)
1547         }
1548         // don't need to continue in .any loop once replacements have been made
1549         return true
1550       }
1551     }
1552
1553     // use Windows Program Group with Examples folder for RELEASE, and Program Group without Examples for everything else
1554     // NB we're deleting the /other/ one!
1555     // Also remove the examples subdir from non-release versions
1556     def customizedIdToDelete = "PROGRAM_GROUP_RELEASE"
1557     // 2.11.1.0 NOT releasing with the Examples folder in the Program Group
1558     if (false && CHANNEL=="RELEASE") { // remove 'false && ' to include Examples folder in RELEASE channel
1559       customizedIdToDelete = "PROGRAM_GROUP_NON_RELEASE"
1560     } else {
1561       // remove the examples subdir from Full File Set
1562       def files = install4jConfigXml.files[0]
1563       def fileset = files.filesets.fileset.find { fs -> fs.'@customizedId' == "FULL_FILE_SET" }
1564       def root = files.roots.root.find { r -> r.'@fileset' == fileset.'@id' }
1565       def mountPoint = files.mountPoints.mountPoint.find { mp -> mp.'@root' == root.'@id' }
1566       def dirEntry = files.entries.dirEntry.find { de -> de.'@mountPoint' == mountPoint.'@id' && de.'@subDirectory' == "examples" }
1567       dirEntry.parent().remove(dirEntry)
1568     }
1569     install4jConfigXml.'**'.action.any { a ->
1570       if (a.'@customizedId' == customizedIdToDelete) {
1571         def parent = a.parent()
1572         parent.remove(a)
1573         return true
1574       }
1575     }
1576
1577     // remove the "Uninstall Old Jalview (optional)" symlink from DMG for non-release DS_Stores
1578     if (! (CHANNEL == "RELEASE" || CHANNEL == "TEST-RELEASE" ) ) {
1579       def symlink = install4jConfigXml.'**'.topLevelFiles.symlink.find { sl -> sl.'@name' == "Uninstall Old Jalview (optional).app" }
1580       symlink.parent().remove(symlink)
1581     }
1582
1583     // write install4j file
1584     install4jConfFile.text = XmlUtil.serialize(install4jConfigXml)
1585   }
1586 }
1587
1588
1589 clean {
1590   doFirst {
1591     delete install4jConfFile
1592   }
1593 }
1594
1595
1596 task installers(type: com.install4j.gradle.Install4jTask) {
1597   group = "distribution"
1598   description = "Create the install4j installers"
1599   dependsOn setGitVals
1600   dependsOn getdown
1601   dependsOn copyInstall4jTemplate
1602
1603   projectFile = install4jConfFile
1604
1605   // create an md5 for the input files to use as version for install4j conf file
1606   def digest = MessageDigest.getInstance("MD5")
1607   digest.update(
1608     (file("${install4jDir}/${install4j_template}").text + 
1609     file("${install4jDir}/${install4j_info_plist_file_associations}").text +
1610     file("${install4jDir}/${install4j_installer_file_associations}").text).bytes)
1611   def filesMd5 = new BigInteger(1, digest.digest()).toString(16)
1612   if (filesMd5.length() >= 8) {
1613     filesMd5 = filesMd5.substring(0,8)
1614   }
1615   def install4jTemplateVersion = "${JALVIEW_VERSION}_F${filesMd5}_C${gitHash}"
1616   // make install4jBuildDir relative to jalviewDir
1617   def install4jBuildDir = "${install4j_build_dir}/${JAVA_VERSION}"
1618
1619   variables = [
1620     'JALVIEW_NAME': jalview_name,
1621     'JALVIEW_APPLICATION_NAME': install4jApplicationName,
1622     'JALVIEW_DIR': "../..",
1623     'OSX_KEYSTORE': OSX_KEYSTORE,
1624     'JSIGN_SH': JSIGN_SH,
1625     'JRE_DIR': getdown_app_dir_java,
1626     'INSTALLER_TEMPLATE_VERSION': install4jTemplateVersion,
1627     'JALVIEW_VERSION': JALVIEW_VERSION,
1628     'JAVA_MIN_VERSION': JAVA_MIN_VERSION,
1629     'JAVA_MAX_VERSION': JAVA_MAX_VERSION,
1630     'JAVA_VERSION': JAVA_VERSION,
1631     'JAVA_INTEGER_VERSION': JAVA_INTEGER_VERSION,
1632     'VERSION': JALVIEW_VERSION,
1633     'MACOS_JAVA_VM_DIR': macosJavaVMDir,
1634     'WINDOWS_JAVA_VM_DIR': windowsJavaVMDir,
1635     'LINUX_JAVA_VM_DIR': linuxJavaVMDir,
1636     'MACOS_JAVA_VM_TGZ': macosJavaVMTgz,
1637     'WINDOWS_JAVA_VM_TGZ': windowsJavaVMTgz,
1638     'LINUX_JAVA_VM_TGZ': linuxJavaVMTgz,
1639     'COPYRIGHT_MESSAGE': install4j_copyright_message,
1640     'BUNDLE_ID': install4jBundleId,
1641     'INTERNAL_ID': install4jInternalId,
1642     'WINDOWS_APPLICATION_ID': install4jWinApplicationId,
1643     'MACOS_DS_STORE': install4jDSStore,
1644     'MACOS_DMG_BG_IMAGE': install4jDMGBackgroundImage,
1645     'INSTALLER_NAME': install4jInstallerName,
1646     'INSTALL4J_UTILS_DIR': install4j_utils_dir,
1647     'GETDOWN_WEBSITE_DIR': getdown_website_dir,
1648     'GETDOWN_FILES_DIR': getdown_files_dir,
1649     'GETDOWN_RESOURCE_DIR': getdown_resource_dir,
1650     'GETDOWN_DIST_DIR': getdownAppDistDir,
1651     'GETDOWN_ALT_DIR': getdown_app_dir_alt,
1652     'GETDOWN_INSTALL_DIR': getdown_install_dir,
1653     'INFO_PLIST_FILE_ASSOCIATIONS_FILE': install4j_info_plist_file_associations,
1654     'BUILD_DIR': install4jBuildDir,
1655     'APPLICATION_CATEGORIES': install4j_application_categories,
1656     'APPLICATION_FOLDER': install4jApplicationFolder,
1657     'UNIX_APPLICATION_FOLDER': install4jUnixApplicationFolder,
1658     'EXECUTABLE_NAME': install4jExecutableName,
1659     'EXTRA_SCHEME': install4jExtraScheme,
1660   ]
1661
1662   //println("INSTALL4J VARIABLES:")
1663   //variables.each{k,v->println("${k}=${v}")}
1664
1665   destination = "${jalviewDir}/${install4jBuildDir}"
1666   buildSelected = true
1667
1668   if (install4j_faster.equals("true") || CHANNEL.startsWith("LOCAL")) {
1669     faster = true
1670     disableSigning = true
1671   }
1672
1673   if (OSX_KEYPASS) {
1674     macKeystorePassword = OSX_KEYPASS
1675   }
1676
1677   doFirst {
1678     println("Using projectFile "+projectFile)
1679   }
1680
1681   inputs.dir(getdownWebsiteDir)
1682   inputs.file(install4jConfFile)
1683   inputs.file("${install4jDir}/${install4j_info_plist_file_associations}")
1684   inputs.dir(macosJavaVMDir)
1685   inputs.dir(windowsJavaVMDir)
1686   outputs.dir("${jalviewDir}/${install4j_build_dir}/${JAVA_VERSION}")
1687 }
1688
1689
1690 task sourceDist(type: Tar) {
1691   
1692   def VERSION_UNDERSCORES = JALVIEW_VERSION.replaceAll("\\.", "_")
1693   def outputFileName = "${project.name}_${VERSION_UNDERSCORES}.tar.gz"
1694   // cater for buildship < 3.1 [3.0.1 is max version in eclipse 2018-09]
1695   try {
1696     archiveFileName = outputFileName
1697   } catch (Exception e) {
1698     archiveName = outputFileName
1699   }
1700   
1701   compression Compression.GZIP
1702   
1703   into project.name
1704
1705   def EXCLUDE_FILES=[
1706     "build/*",
1707     "bin/*",
1708     "test-output/",
1709     "test-reports",
1710     "tests",
1711     "clover*/*",
1712     ".*",
1713     "benchmarking/*",
1714     "**/.*",
1715     "*.class",
1716     "**/*.class","$j11modDir/**/*.jar","appletlib","**/*locales",
1717     "*locales/**",
1718     "utils/InstallAnywhere",
1719     "**/*.log",
1720   ] 
1721   def PROCESS_FILES=[
1722     "AUTHORS",
1723     "CITATION",
1724     "FEATURETODO",
1725     "JAVA-11-README",
1726     "FEATURETODO",
1727     "LICENSE",
1728     "**/README",
1729     "RELEASE",
1730     "THIRDPARTYLIBS",
1731     "TESTNG",
1732     "build.gradle",
1733     "gradle.properties",
1734     "**/*.java",
1735     "**/*.html",
1736     "**/*.xml",
1737     "**/*.gradle",
1738     "**/*.groovy",
1739     "**/*.properties",
1740     "**/*.perl",
1741     "**/*.sh",
1742   ]
1743   def INCLUDE_FILES=[
1744     ".settings/org.eclipse.jdt.core.jalview.prefs",
1745   ]
1746
1747   from(jalviewDir) {
1748     exclude (EXCLUDE_FILES)
1749     include (PROCESS_FILES)
1750     filter(ReplaceTokens,
1751       beginToken: '$$',
1752       endToken: '$$',
1753       tokens: [
1754         'Version-Rel': JALVIEW_VERSION,
1755         'Year-Rel': getDate("yyyy")
1756       ]
1757     )
1758   }
1759   from(jalviewDir) {
1760     exclude (EXCLUDE_FILES)
1761     exclude (PROCESS_FILES)
1762     exclude ("appletlib")
1763     exclude ("**/*locales")
1764     exclude ("*locales/**")
1765     exclude ("utils/InstallAnywhere")
1766
1767     exclude (getdown_files_dir)
1768     exclude (getdown_website_dir)
1769
1770     // exluding these as not using jars as modules yet
1771     exclude ("$j11modDir/**/*.jar")
1772   }
1773   from(jalviewDir) {
1774     include(INCLUDE_FILES)
1775   }
1776 //  from (jalviewDir) {
1777 //    // explicit includes for stuff that seemed to not get included
1778 //    include(fileTree("test/**/*."))
1779 //    exclude(EXCLUDE_FILES)
1780 //    exclude(PROCESS_FILES)
1781 //  }
1782 }
1783
1784
1785 task helppages {
1786   dependsOn copyHelp
1787   dependsOn pubhtmlhelp
1788   
1789   inputs.dir("${classesDir}/${help_dir}")
1790   outputs.dir("${buildDir}/distributions/${help_dir}")
1791 }
1792
1793 // LARGE AMOUNT OF JALVIEWJS STUFF DELETED HERE
1794 task eclipseAutoBuildTask {}
1795 task eclipseSynchronizationTask {}