JAL-3449 helper task to perform getdown digest on any dir
[jalview.git] / build.gradle
1 import org.apache.tools.ant.filters.ReplaceTokens
2 import org.gradle.internal.os.OperatingSystem
3 import org.gradle.plugins.ide.eclipse.model.Output
4 import org.gradle.plugins.ide.eclipse.model.Library
5 import java.security.MessageDigest
6 import groovy.transform.ExternalizeMethods
7 import groovy.util.XmlParser
8 import groovy.xml.XmlUtil
9
10 buildscript {
11   dependencies {
12     classpath 'org.openclover:clover:4.4.1'
13   }
14 }
15
16 plugins {
17   id 'java'
18   id 'application'
19   id 'eclipse'
20   id 'com.github.johnrengelman.shadow' version '4.0.3'
21   id 'com.install4j.gradle' version '8.0.2'
22   id 'com.dorongold.task-tree' version '1.5' // only needed to display task dependency tree with  gradle task1 [task2 ...] taskTree
23 }
24
25 repositories {
26   jcenter()
27   mavenCentral()
28   mavenLocal()
29   flatDir {
30     dirs gradlePluginsDir
31   }
32 }
33
34 dependencies {
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   def localProps = "${jalviewDirAbsolutePath}/local.properties"
50   if (file(localProps).exists()) {
51     try {
52       def p = new Properties()
53       def localPropsFIS = new FileInputStream(localProps)
54       p.load(localPropsFIS)
55       localPropsFIS.close()
56       p.each {
57         key, val -> 
58           def oldval = findProperty(key)
59           setProperty(key, val)
60           if (oldval != null) {
61             println("Overriding property '${key}' ('${oldval}') with local.properties value '${val}'")
62           } else {
63             println("Setting unknown property '${key}' with local.properties value '${val}'")
64           }
65       }
66     } catch (Exception e) {
67       System.out.println("Exception reading local.properties")
68     }
69   }
70
71   // this property set when running Eclipse headlessly
72   j2sHeadlessBuildProperty = string("net.sf.j2s.core.headlessbuild")
73   // this property set by Eclipse
74   eclipseApplicationProperty = string("eclipse.application")
75   // CHECK IF RUNNING FROM WITHIN ECLIPSE
76   def eclipseApplicationPropertyVal = System.properties[eclipseApplicationProperty]
77   IN_ECLIPSE = eclipseApplicationPropertyVal != null && eclipseApplicationPropertyVal.startsWith("org.eclipse.ui.")
78   // BUT WITHOUT THE HEADLESS BUILD PROPERTY SET
79   if (System.properties[j2sHeadlessBuildProperty].equals("true")) {
80     println("Setting IN_ECLIPSE to ${IN_ECLIPSE} as System.properties['${j2sHeadlessBuildProperty}'] == '${System.properties[j2sHeadlessBuildProperty]}'")
81     IN_ECLIPSE = false
82   }
83   if (IN_ECLIPSE) {
84     println("WITHIN ECLIPSE IDE")
85   } else {
86     println("HEADLESS BUILD")
87   }
88   /* *-/
89   System.properties.sort { it.key }.each {
90     key, val -> println("SYSTEM PROPERTY ${key}='${val}'")
91   }
92   /-* *-/
93   if (false && IN_ECLIPSE) {
94     jalviewDir = jalviewDirAbsolutePath
95   }
96   */
97
98   // essentials
99   bareSourceDir = string(source_dir)
100   sourceDir = string("${jalviewDir}/${bareSourceDir}")
101   resourceDir = string("${jalviewDir}/${resource_dir}")
102   bareTestSourceDir = string(test_source_dir)
103   testSourceDir = string("${jalviewDir}/${bareTestSourceDir}")
104
105   // clover
106   cloverInstrDir = file("${buildDir}/${cloverSourcesInstrDir}")
107   classesDir = string("${jalviewDir}/${classes_dir}")
108   if (clover.equals("true")) {
109     use_clover = true
110     classesDir = string("${buildDir}/${cloverClassesDir}")
111   } else {
112     use_clover = false
113     classesDir = string("${jalviewDir}/${classes_dir}")
114   }
115
116   classes = classesDir
117
118   getdownWebsiteDir = string("${jalviewDir}/${getdown_website_dir}/${JAVA_VERSION}")
119   buildDist = true
120
121   // the following values might be overridden by the CHANNEL switch
122   getdownChannelName = CHANNEL.toLowerCase()
123   getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
124   getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
125   getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher}")
126   getdownAppDistDir = getdown_app_dir_alt
127   buildProperties = string("${classesDir}/${build_properties_file}")
128   reportRsyncCmd = false
129   switch (CHANNEL) {
130
131     case "BUILD":
132     // TODO: get bamboo build artifact URL for getdown artifacts
133     getdown_channel_base = bamboo_channelbase
134     getdownChannelName = string("${bamboo_planKey}/${JAVA_VERSION}")
135     getdownAppBase = string("${bamboo_channelbase}/${bamboo_planKey}${bamboo_getdown_channel_suffix}/${JAVA_VERSION}")
136     break
137
138     case "RELEASE":
139     getdownAppDistDir = getdown_app_dir_release
140     reportRsyncCommand = true
141     break
142
143     case "ARCHIVE":
144     getdownChannelName = CHANNEL.toLowerCase()+"/${JALVIEW_VERSION}"
145     getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
146     getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
147     if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
148       throw new GradleException("Must provide an ARCHIVEDIR value to produce an archive distribution")
149     } else {
150       packageDir = string("${ARCHIVEDIR}/${packageDir}")
151       buildProperties = string("${ARCHIVEDIR}/${classes_dir}/${build_properties_file}")
152       buildDist = false
153     }
154     reportRsyncCommand = true
155     break
156
157     case "ARCHIVELOCAL":
158     getdownChannelName = string("archive/${JALVIEW_VERSION}")
159     getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
160     getdownAppBase = file(getdownWebsiteDir).toURI().toString()
161     if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
162       throw new GradleException("Must provide an ARCHIVEDIR value to produce an archive distribution")
163     } else {
164       packageDir = string("${ARCHIVEDIR}/${packageDir}")
165       buildProperties = string("${ARCHIVEDIR}/${classes_dir}/${build_properties_file}")
166       buildDist = false
167     }
168     reportRsyncCommand = true
169     getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
170     break
171
172     case "DEVELOP":
173     reportRsyncCommand = true
174     break
175
176     case "TEST-RELEASE":
177     reportRsyncCommand = true
178     break
179
180     case ~/^SCRATCH(|-[-\w]*)$/:
181     getdownChannelName = CHANNEL
182     getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
183     getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
184     reportRsyncCommand = true
185     break
186
187     case "TEST-LOCAL":
188     if (!file("${LOCALDIR}").exists()) {
189       throw new GradleException("Must provide a LOCALDIR value to produce a local distribution")
190     } else {
191       getdownAppBase = file(file("${LOCALDIR}").getAbsolutePath()).toURI().toString()
192       getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
193     }
194     break
195
196     case "LOCAL":
197     getdownAppBase = file(getdownWebsiteDir).toURI().toString()
198     getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
199     break
200
201     default: // something wrong specified
202     throw new GradleException("CHANNEL must be one of BUILD, RELEASE, ARCHIVE, DEVELOP, TEST-RELEASE, SCRATCH-..., LOCAL [default]")
203     break
204
205   }
206   // override getdownAppBase if requested
207   if (findProperty("getdown_appbase_override") != null) {
208     getdownAppBase = string(getProperty("getdown_appbase_override"))
209     println("Overriding getdown appbase with '${getdownAppBase}'")
210   }
211
212   getdownAppDir = string("${getdownWebsiteDir}/${getdownAppDistDir}")
213   //getdownJ11libDir = "${getdownWebsiteDir}/${getdown_j11lib_dir}"
214   getdownResourceDir = string("${getdownWebsiteDir}/${getdown_resource_dir}")
215   getdownInstallDir = string("${getdownWebsiteDir}/${getdown_install_dir}")
216   getdownFilesDir = string("${jalviewDir}/${getdown_files_dir}/${JAVA_VERSION}/")
217   getdownFilesInstallDir = string("${getdownFilesDir}/${getdown_install_dir}")
218   /* compile without modules -- using classpath libraries
219   modules_compileClasspath = fileTree(dir: "${jalviewDir}/${j11modDir}", include: ["*.jar"])
220   modules_runtimeClasspath = modules_compileClasspath
221   */
222   gitHash = string("")
223   gitBranch = string("")
224
225   println("Using a ${CHANNEL} profile.")
226
227   additional_compiler_args = []
228   // configure classpath/args for j8/j11 compilation
229   if (JAVA_VERSION.equals("1.8")) {
230     JAVA_INTEGER_VERSION = string("8")
231     //libDir = j8libDir
232     libDir = j11libDir
233     libDistDir = j8libDir
234     compile_source_compatibility = 1.8
235     compile_target_compatibility = 1.8
236     // these are getdown.txt properties defined dependent on the JAVA_VERSION
237     getdownAltJavaMinVersion = string(findProperty("getdown_alt_java8_min_version"))
238     getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java8_max_version"))
239     // this property is assigned below and expanded to multiple lines in the getdown task
240     getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java8_txt_multi_java_location"))
241     // this property is for the Java library used in eclipse
242     eclipseJavaRuntimeName = string("JavaSE-1.8")
243   } else if (JAVA_VERSION.equals("11")) {
244     JAVA_INTEGER_VERSION = string("11")
245     libDir = j11libDir
246     libDistDir = j11libDir
247     compile_source_compatibility = 11
248     compile_target_compatibility = 11
249     getdownAltJavaMinVersion = string(findProperty("getdown_alt_java11_min_version"))
250     getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java11_max_version"))
251     getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java11_txt_multi_java_location"))
252     eclipseJavaRuntimeName = string("JavaSE-11")
253     /* compile without modules -- using classpath libraries
254     additional_compiler_args += [
255     '--module-path', modules_compileClasspath.asPath,
256     '--add-modules', j11modules
257     ]
258      */
259   } else if (JAVA_VERSION.equals("12") || JAVA_VERSION.equals("13")) {
260     JAVA_INTEGER_VERSION = JAVA_VERSION
261     libDir = j11libDir
262     libDistDir = j11libDir
263     compile_source_compatibility = JAVA_VERSION
264     compile_target_compatibility = JAVA_VERSION
265     getdownAltJavaMinVersion = string(findProperty("getdown_alt_java11_min_version"))
266     getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java11_max_version"))
267     getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java11_txt_multi_java_location"))
268     eclipseJavaRuntimeName = string("JavaSE-11")
269     /* compile without modules -- using classpath libraries
270     additional_compiler_args += [
271     '--module-path', modules_compileClasspath.asPath,
272     '--add-modules', j11modules
273     ]
274      */
275   } else {
276     throw new GradleException("JAVA_VERSION=${JAVA_VERSION} not currently supported by Jalview")
277   }
278
279
280   // for install4j
281   JAVA_MIN_VERSION = JAVA_VERSION
282   JAVA_MAX_VERSION = JAVA_VERSION
283   def jreInstallsDir = string(jre_installs_dir)
284   if (jreInstallsDir.startsWith("~/")) {
285     jreInstallsDir = System.getProperty("user.home") + jreInstallsDir.substring(1)
286   }
287   macosJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-mac-x64/jre")
288   macosJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-mac-x64.tar.gz")
289   windowsJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-windows-x64/jre")
290   windowsJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-windows-x64.tar.gz")
291   linuxJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-linux-x64/jre")
292   linuxJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-linux-x64.tar.gz")
293   install4jDir = string("${jalviewDir}/${install4j_utils_dir}")
294   install4jConfFileName = string("jalview-install4j-conf.install4j")
295   install4jConfFile = file("${install4jDir}/${install4jConfFileName}")
296   install4jHomeDir = install4j_home_dir
297   if (install4jHomeDir.startsWith("~/")) {
298     install4jHomeDir = System.getProperty("user.home") + install4jHomeDir.substring(1)
299   }
300
301
302
303   buildingHTML = string("${jalviewDir}/${docDir}/building.html")
304   helpFile = string("${classesDir}/${help_dir}/help.jhm")
305   helpParentDir = string("${jalviewDir}/${help_parent_dir}")
306   helpSourceDir = string("${helpParentDir}/${help_dir}")
307
308
309   relativeBuildDir = file(jalviewDirAbsolutePath).toPath().relativize(buildDir.toPath())
310   jalviewjsBuildDir = string("${relativeBuildDir}/jalviewjs")
311   jalviewjsSiteDir = string("${jalviewjsBuildDir}/${jalviewjs_site_dir}")
312   if (IN_ECLIPSE) {
313     jalviewjsTransferSiteJsDir = string(jalviewjsSiteDir)
314   } else {
315     jalviewjsTransferSiteJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_js")
316   }
317   jalviewjsTransferSiteLibDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_lib")
318   jalviewjsTransferSiteSwingJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_swingjs")
319   jalviewjsTransferSiteCoreDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_core")
320   jalviewjsJalviewCoreHtmlFile = string("")
321   jalviewjsJalviewCoreName = string(jalviewjs_core_name)
322   jalviewjsCoreClasslists = []
323   jalviewjsJalviewTemplateName = string(jalviewjs_name)
324   jalviewjsJ2sSettingsFileName = string("${jalviewDir}/${jalviewjs_j2s_settings}")
325   jalviewjsJ2sProps = null
326
327   eclipseWorkspace = null
328   eclipseBinary = string("")
329   eclipseVersion = string("")
330   eclipseDebug = false
331   // ENDEXT
332 }
333
334
335 sourceSets {
336   main {
337     java {
338       srcDirs sourceDir
339       outputDir = file(classesDir)
340     }
341
342     resources {
343       srcDirs resourceDir
344       srcDirs += helpParentDir
345     }
346
347     jar.destinationDir = file("${jalviewDir}/${packageDir}")
348
349     compileClasspath = files(sourceSets.main.java.outputDir)
350     //compileClasspath += files(sourceSets.main.resources.srcDirs)
351     compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
352
353     runtimeClasspath = compileClasspath
354   }
355
356   clover {
357     java {
358       srcDirs = [ cloverInstrDir ]
359       outputDir = file("${buildDir}/${cloverClassesDir}")
360     }
361
362     resources {
363       srcDirs = sourceSets.main.resources.srcDirs
364     }
365     compileClasspath = configurations.cloverRuntime + files( sourceSets.clover.java.outputDir )
366     compileClasspath += files(sourceSets.main.java.outputDir)
367     compileClasspath += sourceSets.main.compileClasspath
368     compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["**/*.jar"])
369     compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
370
371     runtimeClasspath = compileClasspath
372   }
373
374   test {
375     java {
376       srcDirs testSourceDir
377       outputDir = file("${jalviewDir}/${testOutputDir}")
378     }
379
380     resources {
381       srcDirs = sourceSets.main.resources.srcDirs
382     }
383
384     compileClasspath = files( sourceSets.test.java.outputDir )
385
386     if (use_clover) {
387       compileClasspath = sourceSets.clover.compileClasspath
388     } else {
389       compileClasspath += files(sourceSets.main.java.outputDir)
390     }
391
392     compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
393     compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testnglibs", include: ["**/*.jar"])
394     compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testlibs", include: ["**/*.jar"])
395
396     runtimeClasspath = compileClasspath
397   }
398 }
399
400
401 // clover bits
402 dependencies {
403   if (use_clover) {
404     cloverCompile 'org.openclover:clover:4.4.1'
405     testCompile 'org.openclover:clover:4.4.1'
406   }
407 }
408
409
410 configurations {
411   cloverRuntime
412   cloverRuntime.extendsFrom cloverCompile
413 }
414
415 eclipse {
416   project {
417     name = eclipse_project_name
418
419     natures 'org.eclipse.jdt.core.javanature',
420     'org.eclipse.jdt.groovy.core.groovyNature',
421     'org.eclipse.buildship.core.gradleprojectnature'
422
423     buildCommand 'org.eclipse.jdt.core.javabuilder'
424     buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
425   }
426
427   classpath {
428     //defaultOutputDir = sourceSets.main.java.outputDir
429     def removeThese = []
430     configurations.each{
431       if (it.isCanBeResolved()) {
432         removeThese += it
433       }
434     }
435
436     minusConfigurations += removeThese
437     plusConfigurations = [ ]
438     file {
439
440       whenMerged { cp ->
441         def removeTheseToo = []
442         HashMap<String, Boolean> alreadyAddedSrcPath = new HashMap<>();
443         cp.entries.each { entry ->
444           // This conditional removes all src classpathentries that a) have already been added or b) aren't "src" or "test".
445           // e.g. this removes the resources dir being copied into bin/main, bin/test AND bin/clover
446           // we add the resources and help/help dirs in as libs afterwards (see below)
447           if (entry.kind == 'src') {
448             if (alreadyAddedSrcPath.getAt(entry.path) || !(entry.path == bareSourceDir || entry.path == bareTestSourceDir)) {
449               removeTheseToo += entry
450             } else {
451               alreadyAddedSrcPath.putAt(entry.path, true)
452             }
453           }
454
455         }
456         cp.entries.removeAll(removeTheseToo)
457
458         //cp.entries += new Output("${eclipse_bin_dir}/main")
459         if (file(helpParentDir).isDirectory()) {
460           cp.entries += new Library(fileReference(helpParentDir))
461         }
462         if (file(resourceDir).isDirectory()) {
463           cp.entries += new Library(fileReference(resourceDir))
464         }
465
466         HashMap<String, Boolean> alreadyAddedLibPath = new HashMap<>();
467
468         sourceSets.main.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
469           //don't want to add outputDir as eclipse is using its own output dir in bin/main
470           if (it.isDirectory() || ! it.exists()) {
471             // don't add dirs to classpath, especially if they don't exist
472             return false // groovy "continue" in .any closure
473           }
474           def itPath = it.toString()
475           if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
476             // make relative path
477             itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
478           }
479           if (alreadyAddedLibPath.get(itPath)) {
480             //println("Not adding duplicate entry "+itPath)
481           } else {
482             //println("Adding entry "+itPath)
483             cp.entries += new Library(fileReference(itPath))
484             alreadyAddedLibPath.put(itPath, true)
485           }
486         }
487
488         sourceSets.test.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
489           //no longer want to add outputDir as eclipse is using its own output dir in bin/main
490           if (it.isDirectory() || ! it.exists()) {
491             // don't add dirs to classpath
492             return false // groovy "continue" in .any closure
493           }
494
495           def itPath = it.toString()
496           if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
497             itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
498           }
499           if (alreadyAddedLibPath.get(itPath)) {
500             // don't duplicate
501           } else {
502             def lib = new Library(fileReference(itPath))
503             lib.entryAttributes["test"] = "true"
504             cp.entries += lib
505             alreadyAddedLibPath.put(itPath, true)
506           }
507         }
508
509       } // whenMerged
510
511     } // file
512
513     containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
514
515   } // classpath
516
517   jdt {
518     // for the IDE, use java 11 compatibility
519     sourceCompatibility = compile_source_compatibility
520     targetCompatibility = compile_target_compatibility
521     javaRuntimeName = eclipseJavaRuntimeName
522
523     // add in jalview project specific properties/preferences into eclipse core preferences
524     file {
525       withProperties { props ->
526         def jalview_prefs = new Properties()
527         def ins = new FileInputStream("${jalviewDirAbsolutePath}/${eclipse_extra_jdt_prefs_file}")
528         jalview_prefs.load(ins)
529         ins.close()
530         jalview_prefs.forEach { t, v ->
531           if (props.getAt(t) == null) {
532             props.putAt(t, v)
533           }
534         }
535       }
536     }
537
538   } // jdt
539
540   if (IN_ECLIPSE) {
541     // Don't want these to be activated if in headless build
542     synchronizationTasks "eclipseSynchronizationTask"
543     autoBuildTasks "eclipseAutoBuildTask"
544
545   }
546 }
547
548
549 task cloverInstr() {
550   // only instrument source, we build test classes as normal
551   inputs.files files (sourceSets.main.allJava,sourceSets.test.allJava) // , fileTree(dir:"$jalviewDir/$testSourceDir", include: ["**/*.java"]))
552   outputs.dir cloverInstrDir
553
554   doFirst {
555     delete cloverInstrDir
556     def argsList = ["--initstring", "${buildDir}/clover/clover.db",
557     "-d", "${buildDir}/${cloverSourcesInstrDir}"]
558     argsList.addAll(inputs.files.files.collect({ file ->
559       file.absolutePath
560     }))
561     String[] args = argsList.toArray()
562     println("About to instrument "+args.length +" files")
563     com.atlassian.clover.CloverInstr.mainImpl(args)
564   }
565 }
566
567
568 task cloverReport {
569   group = "Verification"
570     description = "Createst the Clover report"
571     inputs.dir "${buildDir}/clover"
572     outputs.dir "${reportsDir}/clover"
573     onlyIf {
574       file("${buildDir}/clover/clover.db").exists()
575     }
576   doFirst {
577     def argsList = ["--initstring", "${buildDir}/clover/clover.db",
578     "-o", "${reportsDir}/clover"]
579     String[] args = argsList.toArray()
580     com.atlassian.clover.reporters.html.HtmlReporter.runReport(args)
581
582     // and generate ${reportsDir}/clover/clover.xml
583     args = ["--initstring", "${buildDir}/clover/clover.db",
584     "-o", "${reportsDir}/clover/clover.xml"].toArray()
585     com.atlassian.clover.reporters.xml.XMLReporter.runReport(args)
586   }
587 }
588 // end clover bits
589
590
591 compileJava {
592
593   doFirst {
594     sourceCompatibility = compile_source_compatibility
595     targetCompatibility = compile_target_compatibility
596     options.compilerArgs = additional_compiler_args
597     print ("Setting target compatibility to "+targetCompatibility+"\n")
598   }
599
600 }
601
602
603 compileTestJava {
604   if (use_clover) {
605     dependsOn compileCloverJava
606     classpath += configurations.cloverRuntime
607   } else {
608     classpath += sourceSets.main.runtimeClasspath
609   }
610   doFirst {
611     sourceCompatibility = compile_source_compatibility
612     targetCompatibility = compile_target_compatibility
613     options.compilerArgs = additional_compiler_args
614     print ("Setting target compatibility to "+targetCompatibility+"\n")
615   }
616 }
617
618
619 compileCloverJava {
620
621   doFirst {
622     sourceCompatibility = compile_source_compatibility
623     targetCompatibility = compile_target_compatibility
624     options.compilerArgs += additional_compiler_args
625     print ("Setting target compatibility to "+targetCompatibility+"\n")
626   }
627   classpath += configurations.cloverRuntime
628 }
629
630
631 clean {
632   doFirst {
633     delete sourceSets.main.java.outputDir
634   }
635 }
636
637
638 cleanTest {
639   doFirst {
640     delete sourceSets.test.java.outputDir
641     delete cloverInstrDir
642   }
643 }
644
645
646 // format is a string like date.format("dd MMMM yyyy")
647 def getDate(format) {
648   def date = new Date()
649   return date.format(format)
650 }
651
652
653 task setGitVals {
654   def hashStdOut = new ByteArrayOutputStream()
655   exec {
656     commandLine "git", "rev-parse", "--short", "HEAD"
657     standardOutput = hashStdOut
658     ignoreExitValue true
659   }
660
661   def branchStdOut = new ByteArrayOutputStream()
662   exec {
663     commandLine "git", "rev-parse", "--abbrev-ref", "HEAD"
664     standardOutput = branchStdOut
665     ignoreExitValue true
666   }
667
668   gitHash = hashStdOut.toString().trim()
669   gitBranch = branchStdOut.toString().trim()
670
671   outputs.upToDateWhen { false }
672 }
673
674
675 task createBuildProperties(type: WriteProperties) {
676   dependsOn setGitVals
677   inputs.dir(sourceDir)
678   inputs.dir(resourceDir)
679   file(buildProperties).getParentFile().mkdirs()
680   outputFile (buildProperties)
681   // taking time specific comment out to allow better incremental builds
682   comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd HH:mm:ss")
683   //comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd")
684   property "BUILD_DATE", getDate("HH:mm:ss dd MMMM yyyy")
685   property "VERSION", JALVIEW_VERSION
686   property "INSTALLATION", INSTALLATION+" git-commit:"+gitHash+" ["+gitBranch+"]"
687   outputs.file(outputFile)
688 }
689
690
691 task cleanBuildingHTML(type: Delete) {
692   doFirst {
693     delete buildingHTML
694   }
695 }
696
697
698 task convertBuildingMD(type: Exec) {
699   dependsOn cleanBuildingHTML
700   def buildingMD = "${jalviewDir}/${docDir}/building.md"
701   def css = "${jalviewDir}/${docDir}/github.css"
702
703   def pandoc = null
704   pandoc_exec.split(",").each {
705     if (file(it.trim()).exists()) {
706       pandoc = it.trim()
707       return true
708     }
709   }
710
711   def hostname = "hostname".execute().text.trim()
712   def buildtoolsPandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
713   if ((pandoc == null || ! file(pandoc).exists()) && file(buildtoolsPandoc).exists()) {
714     pandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
715   }
716
717   doFirst {
718     if (pandoc != null && file(pandoc).exists()) {
719         commandLine pandoc, '-s', '-o', buildingHTML, '--metadata', 'pagetitle="Building Jalview from Source"', '--toc', '-H', css, buildingMD
720     } else {
721         println("Cannot find pandoc. Skipping convert building.md to HTML")
722         throw new StopExecutionException("Cannot find pandoc. Skipping convert building.md to HTML")
723     }
724   }
725
726   ignoreExitValue true
727
728   inputs.file(buildingMD)
729   inputs.file(css)
730   outputs.file(buildingHTML)
731 }
732
733
734 clean {
735   doFirst {
736     delete buildingHTML
737   }
738 }
739
740
741 task syncDocs(type: Sync) {
742   dependsOn convertBuildingMD
743   def syncDir = "${classesDir}/${docDir}"
744   from fileTree("${jalviewDir}/${docDir}")
745   into syncDir
746
747 }
748
749
750 task copyHelp(type: Copy) {
751   def inputDir = helpSourceDir
752   def outputDir = "${classesDir}/${help_dir}"
753   from(inputDir) {
754     exclude '**/*.gif'
755     exclude '**/*.jpg'
756     exclude '**/*.png'
757     filter(ReplaceTokens,
758       beginToken: '$$',
759       endToken: '$$',
760       tokens: [
761         'Version-Rel': JALVIEW_VERSION,
762         'Year-Rel': getDate("yyyy")
763       ]
764     )
765   }
766   from(inputDir) {
767     include '**/*.gif'
768     include '**/*.jpg'
769     include '**/*.png'
770   }
771   into outputDir
772
773   inputs.dir(inputDir)
774   outputs.files(helpFile)
775   outputs.dir(outputDir)
776 }
777
778
779 task syncLib(type: Sync) {
780   def syncDir = "${classesDir}/${libDistDir}"
781   from fileTree("${jalviewDir}/${libDistDir}")
782   into syncDir
783 }
784
785
786 task syncResources(type: Sync) {
787   from resourceDir
788   include "**/*.*"
789   into "${classesDir}"
790   preserve {
791     include "**"
792   }
793 }
794
795
796 task prepare {
797   dependsOn syncResources
798   dependsOn syncDocs
799   dependsOn copyHelp
800 }
801
802
803 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
804 test {
805   dependsOn prepare
806   dependsOn compileJava
807   if (use_clover) {
808     dependsOn cloverInstr
809   }
810
811   if (use_clover) {
812     print("Running tests " + (use_clover?"WITH":"WITHOUT") + " clover [clover="+use_clover+"]\n")
813   }
814
815   useTestNG() {
816     includeGroups testngGroups
817     preserveOrder true
818     useDefaultListeners=true
819   }
820
821   workingDir = jalviewDir
822   //systemProperties 'clover.jar' System.properties.clover.jar
823   sourceCompatibility = compile_source_compatibility
824   targetCompatibility = compile_target_compatibility
825   jvmArgs += additional_compiler_args
826
827 }
828
829
830 task buildIndices(type: JavaExec) {
831   dependsOn copyHelp
832   classpath = sourceSets.main.compileClasspath
833   main = "com.sun.java.help.search.Indexer"
834   workingDir = "${classesDir}/${help_dir}"
835   def argDir = "html"
836   args = [ argDir ]
837   inputs.dir("${workingDir}/${argDir}")
838
839   outputs.dir("${classesDir}/doc")
840   outputs.dir("${classesDir}/help")
841   outputs.file("${workingDir}/JavaHelpSearch/DOCS")
842   outputs.file("${workingDir}/JavaHelpSearch/DOCS.TAB")
843   outputs.file("${workingDir}/JavaHelpSearch/OFFSETS")
844   outputs.file("${workingDir}/JavaHelpSearch/POSITIONS")
845   outputs.file("${workingDir}/JavaHelpSearch/SCHEMA")
846   outputs.file("${workingDir}/JavaHelpSearch/TMAP")
847 }
848
849
850 task compileLinkCheck(type: JavaCompile) {
851   options.fork = true
852   classpath = files("${jalviewDir}/${utilsDir}")
853   destinationDir = file("${jalviewDir}/${utilsDir}")
854   source = fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
855
856   inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
857   inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
858   outputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.class")
859   outputs.file("${jalviewDir}/${utilsDir}/BufferedLineReader.class")
860 }
861
862
863 task linkCheck(type: JavaExec) {
864   dependsOn prepare, compileLinkCheck
865
866   def helpLinksCheckerOutFile = file("${jalviewDir}/${utilsDir}/HelpLinksChecker.out")
867   classpath = files("${jalviewDir}/${utilsDir}")
868   main = "HelpLinksChecker"
869   workingDir = jalviewDir
870   args = [ "${classesDir}/${help_dir}", "-nointernet" ]
871
872   def outFOS = new FileOutputStream(helpLinksCheckerOutFile, false) // false == don't append
873   def errFOS = outFOS
874   standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
875     outFOS,
876     standardOutput)
877   errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
878     outFOS,
879     errorOutput)
880
881   inputs.dir("${classesDir}/${help_dir}")
882   outputs.file(helpLinksCheckerOutFile)
883 }
884
885 // import the pubhtmlhelp target
886 ant.properties.basedir = "${jalviewDir}"
887 ant.properties.helpBuildDir = "${jalviewDirAbsolutePath}/${classes_dir}/${help_dir}"
888 ant.importBuild "${utilsDir}/publishHelp.xml"
889
890
891 task cleanPackageDir(type: Delete) {
892   doFirst {
893     delete fileTree(dir: "${jalviewDir}/${packageDir}", include: "*.jar")
894   }
895 }
896
897 jar {
898   dependsOn linkCheck
899   dependsOn buildIndices
900   dependsOn createBuildProperties
901
902   manifest {
903     attributes "Main-Class": mainClass,
904     "Permissions": "all-permissions",
905     "Application-Name": "Jalview Desktop",
906     "Codebase": application_codebase
907   }
908
909   destinationDir = file("${jalviewDir}/${packageDir}")
910   archiveName = rootProject.name+".jar"
911
912   exclude "cache*/**"
913   exclude "*.jar"
914   exclude "*.jar.*"
915   exclude "**/*.jar"
916   exclude "**/*.jar.*"
917
918   inputs.dir(classesDir)
919   outputs.file("${jalviewDir}/${packageDir}/${archiveName}")
920 }
921
922
923 task copyJars(type: Copy) {
924   from fileTree(dir: classesDir, include: "**/*.jar").files
925   into "${jalviewDir}/${packageDir}"
926 }
927
928
929 // doing a Sync instead of Copy as Copy doesn't deal with "outputs" very well
930 task syncJars(type: Sync) {
931   from fileTree(dir: "${jalviewDir}/${libDistDir}", include: "**/*.jar").files
932   into "${jalviewDir}/${packageDir}"
933   preserve {
934     include jar.archiveName
935   }
936 }
937
938
939 task makeDist {
940   group = "build"
941   description = "Put all required libraries in dist"
942   // order of "cleanPackageDir", "copyJars", "jar" important!
943   jar.mustRunAfter cleanPackageDir
944   syncJars.mustRunAfter cleanPackageDir
945   dependsOn cleanPackageDir
946   dependsOn syncJars
947   dependsOn jar
948   outputs.dir("${jalviewDir}/${packageDir}")
949 }
950
951
952 task cleanDist {
953   dependsOn cleanPackageDir
954   dependsOn cleanTest
955   dependsOn clean
956 }
957
958 shadowJar {
959   group = "distribution"
960   if (buildDist) {
961     dependsOn makeDist
962   }
963   from ("${jalviewDir}/${libDistDir}") {
964     include("*.jar")
965   }
966   manifest {
967     attributes 'Implementation-Version': JALVIEW_VERSION
968   }
969   mainClassName = shadowJarMainClass
970   mergeServiceFiles()
971   classifier = "all-"+JALVIEW_VERSION+"-j"+JAVA_VERSION
972   minimize()
973 }
974
975
976 task getdownWebsite() {
977   group = "distribution"
978   description = "Create the getdown minimal app folder, and website folder for this version of jalview. Website folder also used for offline app installer"
979   if (buildDist) {
980     dependsOn makeDist
981   }
982
983   def getdownWebsiteResourceFilenames = []
984   def getdownTextString = ""
985   def getdownResourceDir = getdownResourceDir
986   def getdownResourceFilenames = []
987
988   doFirst {
989     // clean the getdown website and files dir before creating getdown folders
990     delete getdownWebsiteDir
991     delete getdownFilesDir
992
993     copy {
994       from buildProperties
995       rename(build_properties_file, getdown_build_properties)
996       into getdownAppDir
997     }
998     getdownWebsiteResourceFilenames += "${getdownAppDistDir}/${getdown_build_properties}"
999
1000     // go through properties looking for getdown_txt_...
1001     def props = project.properties.sort { it.key }
1002     if (getdownAltJavaMinVersion != null && getdownAltJavaMinVersion.length() > 0) {
1003       props.put("getdown_txt_java_min_version", getdownAltJavaMinVersion)
1004     }
1005     if (getdownAltJavaMaxVersion != null && getdownAltJavaMaxVersion.length() > 0) {
1006       props.put("getdown_txt_java_max_version", getdownAltJavaMaxVersion)
1007     }
1008     if (getdownAltMultiJavaLocation != null && getdownAltMultiJavaLocation.length() > 0) {
1009       props.put("getdown_txt_multi_java_location", getdownAltMultiJavaLocation)
1010     }
1011
1012     props.put("getdown_txt_appbase", getdownAppBase)
1013     props.each{ prop, val ->
1014       if (prop.startsWith("getdown_txt_") && val != null) {
1015         if (prop.startsWith("getdown_txt_multi_")) {
1016           def key = prop.substring(18)
1017           val.split(",").each{ v ->
1018             def line = "${key} = ${v}\n"
1019             getdownTextString += line
1020           }
1021         } else {
1022           // file values rationalised
1023           if (val.indexOf('/') > -1 || prop.startsWith("getdown_txt_resource")) {
1024             def r = null
1025             if (val.indexOf('/') == 0) {
1026               // absolute path
1027               r = file(val)
1028             } else if (val.indexOf('/') > 0) {
1029               // relative path (relative to jalviewDir)
1030               r = file( "${jalviewDir}/${val}" )
1031             }
1032             if (r.exists()) {
1033               val = "${getdown_resource_dir}/" + r.getName()
1034               getdownWebsiteResourceFilenames += val
1035               getdownResourceFilenames += r.getPath()
1036             }
1037           }
1038           if (! prop.startsWith("getdown_txt_resource")) {
1039             def line = prop.substring(12) + " = ${val}\n"
1040             getdownTextString += line
1041           }
1042         }
1043       }
1044     }
1045
1046     getdownWebsiteResourceFilenames.each{ filename ->
1047       getdownTextString += "resource = ${filename}\n"
1048     }
1049     getdownResourceFilenames.each{ filename ->
1050       copy {
1051         from filename
1052         into getdownResourceDir
1053       }
1054     }
1055
1056     def codeFiles = []
1057     fileTree(file(packageDir)).each{ f ->
1058       if (f.isDirectory()) {
1059         def files = fileTree(dir: f, include: ["*"]).getFiles()
1060         codeFiles += files
1061       } else if (f.exists()) {
1062         codeFiles += f
1063       }
1064     }
1065     codeFiles.sort().each{f ->
1066       def name = f.getName()
1067       def line = "code = ${getdownAppDistDir}/${name}\n"
1068       getdownTextString += line
1069       copy {
1070         from f.getPath()
1071         into getdownAppDir
1072       }
1073     }
1074
1075     // NOT USING MODULES YET, EVERYTHING SHOULD BE IN dist
1076     /*
1077     if (JAVA_VERSION.equals("11")) {
1078     def j11libFiles = fileTree(dir: "${jalviewDir}/${j11libDir}", include: ["*.jar"]).getFiles()
1079     j11libFiles.sort().each{f ->
1080     def name = f.getName()
1081     def line = "code = ${getdown_j11lib_dir}/${name}\n"
1082     getdownTextString += line
1083     copy {
1084     from f.getPath()
1085     into getdownJ11libDir
1086     }
1087     }
1088     }
1089      */
1090
1091     // 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.
1092     //getdownTextString += "class = " + file(getdownLauncher).getName() + "\n"
1093     getdownTextString += "resource = ${getdown_launcher_new}\n"
1094     getdownTextString += "class = ${mainClass}\n"
1095
1096     def getdown_txt = file("${getdownWebsiteDir}/getdown.txt")
1097     getdown_txt.write(getdownTextString)
1098
1099     def getdownLaunchJvl = ( (getdownChannelName != null && getdownChannelName.length() > 0)?"${getdownChannelName}_":"" ) + getdown_launch_jvl
1100     def launch_jvl = file("${getdownWebsiteDir}/${getdown_launch_jvl}")
1101     launch_jvl.write("appbase="+props.get("getdown_txt_appbase"))
1102
1103     copy {
1104       from getdownLauncher
1105       rename(file(getdownLauncher).getName(), getdown_launcher_new)
1106       into getdownWebsiteDir
1107     }
1108
1109     copy {
1110       from getdownLauncher
1111       if (file(getdownLauncher).getName() != getdown_launcher) {
1112         rename(file(getdownLauncher).getName(), getdown_launcher)
1113       }
1114       into getdownWebsiteDir
1115     }
1116
1117     if (! (CHANNEL.startsWith("ARCHIVE") || CHANNEL.startsWith("DEVELOP"))) {
1118       copy {
1119         from getdown_txt
1120         from getdownLauncher
1121         from "${getdownWebsiteDir}/${getdown_build_properties}"
1122         if (file(getdownLauncher).getName() != getdown_launcher) {
1123           rename(file(getdownLauncher).getName(), getdown_launcher)
1124         }
1125         into getdownInstallDir
1126       }
1127
1128       copy {
1129         from getdownInstallDir
1130         into getdownFilesInstallDir
1131       }
1132     }
1133
1134     copy {
1135       from getdown_txt
1136       from launch_jvl
1137       from getdownLauncher
1138       from "${getdownWebsiteDir}/${getdown_build_properties}"
1139       if (file(getdownLauncher).getName() != getdown_launcher) {
1140         rename(file(getdownLauncher).getName(), getdown_launcher)
1141       }
1142       into getdownFilesDir
1143     }
1144
1145     copy {
1146       from getdownResourceDir
1147       into "${getdownFilesDir}/${getdown_resource_dir}"
1148     }
1149   }
1150
1151   if (buildDist) {
1152     inputs.dir("${jalviewDir}/${packageDir}")
1153   }
1154   outputs.dir(getdownWebsiteDir)
1155   outputs.dir(getdownFilesDir)
1156 }
1157
1158
1159 // a helper task to allow getdown digest of any dir: `gradle getdownDigestDir -PDIGESTDIR=/path/to/my/random/getdown/dir
1160 task getdownDigestDir(type: JavaExec) {
1161   def digestDirPropertyName = "DIGESTDIR"
1162   description = "Digest a local dir (-P${digestDirPropertyName}=...) for getdown"
1163   doFirst {
1164     classpath = files(getdownLauncher)
1165     def digestDir = findProperty(digestDirPropertyName)
1166     if (digestDir == null) {
1167       throw new GradleException("Must provide a DIGESTDIR value to produce an alternative getdown digest")
1168     }
1169     args digestDir
1170   }
1171   main = "com.threerings.getdown.tools.Digester"
1172 }
1173
1174
1175 task getdownDigest(type: JavaExec) {
1176   group = "distribution"
1177   description = "Digest the getdown website folder"
1178   dependsOn getdownWebsite
1179   doFirst {
1180     classpath = files(getdownLauncher)
1181   }
1182   main = "com.threerings.getdown.tools.Digester"
1183   args getdownWebsiteDir
1184   inputs.dir(getdownWebsiteDir)
1185   outputs.file("${getdownWebsiteDir}/digest2.txt")
1186 }
1187
1188
1189 task getdown() {
1190   group = "distribution"
1191   description = "Create the minimal and full getdown app folder for installers and website and create digest file"
1192   dependsOn getdownDigest
1193   doLast {
1194     if (reportRsyncCommand) {
1195       def fromDir = getdownWebsiteDir + (getdownWebsiteDir.endsWith('/')?'':'/')
1196       def toDir = "${getdown_rsync_dest}/${getdownDir}" + (getdownDir.endsWith('/')?'':'/')
1197       println "LIKELY RSYNC COMMAND:"
1198       println "mkdir -p '$toDir'\nrsync -avh --delete '$fromDir' '$toDir'"
1199       if (RUNRSYNC == "true") {
1200         exec {
1201           commandLine "mkdir", "-p", toDir
1202         }
1203         exec {
1204           commandLine "rsync", "-avh", "--delete", fromDir, toDir
1205         }
1206       }
1207     }
1208   }
1209 }
1210
1211
1212 clean {
1213   doFirst {
1214     delete getdownWebsiteDir
1215     delete getdownFilesDir
1216   }
1217 }
1218
1219
1220 install4j {
1221   if (file(install4jHomeDir).exists()) {
1222     // good to go!
1223   } else if (file(System.getProperty("user.home")+"/buildtools/install4j").exists()) {
1224     install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
1225   } else if (file("/Applications/install4j.app/Contents/Resources/app").exists()) {
1226     install4jHomeDir = "/Applications/install4j.app/Contents/Resources/app"
1227   }
1228   installDir(file(install4jHomeDir))
1229
1230   mediaTypes = Arrays.asList(install4j_media_types.split(","))
1231 }
1232
1233
1234 task copyInstall4jTemplate {
1235   def install4jTemplateFile = file("${install4jDir}/${install4j_template}")
1236   def install4jFileAssociationsFile = file("${install4jDir}/${install4j_installer_file_associations}")
1237   inputs.file(install4jTemplateFile)
1238   inputs.file(install4jFileAssociationsFile)
1239   outputs.file(install4jConfFile)
1240
1241   doLast {
1242     def install4jConfigXml = new XmlParser().parse(install4jTemplateFile)
1243
1244     // turn off code signing if no OSX_KEYPASS
1245     if (OSX_KEYPASS == "") {
1246       install4jConfigXml.'**'.codeSigning.each { codeSigning ->
1247         codeSigning.'@macEnabled' = "false"
1248       }
1249       install4jConfigXml.'**'.windows.each { windows ->
1250         windows.'@runPostProcessor' = "false"
1251       }
1252     }
1253
1254     // turn off checksum creation for LOCAL channel
1255     def e = install4jConfigXml.application[0]
1256     if (CHANNEL == "LOCAL") {
1257       e.'@createChecksums' = "false"
1258     } else {
1259       e.'@createChecksums' = "true"
1260     }
1261
1262     // put file association actions where placeholder action is
1263     def install4jFileAssociationsText = install4jFileAssociationsFile.text
1264     def fileAssociationActions = new XmlParser().parseText("<actions>${install4jFileAssociationsText}</actions>")
1265     install4jConfigXml.'**'.action.any { a ->
1266       if (a.'@name' == 'EXTENSIONS_REPLACED_BY_GRADLE') {
1267         def parent = a.parent()
1268         parent.remove(a)
1269         fileAssociationActions.each { faa ->
1270             parent.append(faa)
1271         }
1272         // don't need to continue in .any loop once replacements have been made
1273         return true
1274       }
1275     }
1276
1277     // write install4j file
1278     install4jConfFile.text = XmlUtil.serialize(install4jConfigXml)
1279   }
1280 }
1281
1282
1283 clean {
1284   doFirst {
1285     delete install4jConfFile
1286   }
1287 }
1288
1289
1290 task installers(type: com.install4j.gradle.Install4jTask) {
1291   group = "distribution"
1292   description = "Create the install4j installers"
1293   dependsOn setGitVals
1294   dependsOn getdown
1295   dependsOn copyInstall4jTemplate
1296
1297   projectFile = install4jConfFile
1298
1299   // create an md5 for the input files to use as version for install4j conf file
1300   def digest = MessageDigest.getInstance("MD5")
1301   digest.update(
1302     (file("${install4jDir}/${install4j_template}").text + 
1303     file("${install4jDir}/${install4j_info_plist_file_associations}").text +
1304     file("${install4jDir}/${install4j_installer_file_associations}").text).bytes)
1305   def filesMd5 = new BigInteger(1, digest.digest()).toString(16)
1306   if (filesMd5.length() >= 8) {
1307     filesMd5 = filesMd5.substring(0,8)
1308   }
1309   def install4jTemplateVersion = "${JALVIEW_VERSION}_F${filesMd5}_C${gitHash}"
1310   // make install4jBuildDir relative to jalviewDir
1311   def install4jBuildDir = "${install4j_build_dir}/${JAVA_VERSION}"
1312
1313   variables = [
1314     'JALVIEW_NAME': getdown_txt_title,
1315     'JALVIEW_DIR': "../..",
1316     'OSX_KEYSTORE': OSX_KEYSTORE,
1317     'JSIGN_SH': JSIGN_SH,
1318     'JRE_DIR': getdown_app_dir_java,
1319     'INSTALLER_TEMPLATE_VERSION': install4jTemplateVersion,
1320     'JALVIEW_VERSION': JALVIEW_VERSION,
1321     'JAVA_MIN_VERSION': JAVA_MIN_VERSION,
1322     'JAVA_MAX_VERSION': JAVA_MAX_VERSION,
1323     'JAVA_VERSION': JAVA_VERSION,
1324     'JAVA_INTEGER_VERSION': JAVA_INTEGER_VERSION,
1325     'VERSION': JALVIEW_VERSION,
1326     'MACOS_JAVA_VM_DIR': macosJavaVMDir,
1327     'WINDOWS_JAVA_VM_DIR': windowsJavaVMDir,
1328     'LINUX_JAVA_VM_DIR': linuxJavaVMDir,
1329     'MACOS_JAVA_VM_TGZ': macosJavaVMTgz,
1330     'WINDOWS_JAVA_VM_TGZ': windowsJavaVMTgz,
1331     'LINUX_JAVA_VM_TGZ': linuxJavaVMTgz,
1332     'COPYRIGHT_MESSAGE': install4j_copyright_message,
1333     'MACOS_BUNDLE_ID': install4j_macOS_bundle_id,
1334     'INSTALLER_NAME': install4j_installer_name,
1335     'INSTALL4J_UTILS_DIR': install4j_utils_dir,
1336     'GETDOWN_WEBSITE_DIR': getdown_website_dir,
1337     'GETDOWN_FILES_DIR': getdown_files_dir,
1338     'GETDOWN_RESOURCE_DIR': getdown_resource_dir,
1339     'GETDOWN_DIST_DIR': getdownAppDistDir,
1340     'GETDOWN_ALT_DIR': getdown_app_dir_alt,
1341     'GETDOWN_INSTALL_DIR': getdown_install_dir,
1342     'INFO_PLIST_FILE_ASSOCIATIONS_FILE': install4j_info_plist_file_associations,
1343     'BUILD_DIR': install4jBuildDir,
1344   ]
1345
1346   destination = "${jalviewDir}/${install4jBuildDir}"
1347   buildSelected = true
1348
1349   if (install4j_faster.equals("true") || CHANNEL.startsWith("LOCAL")) {
1350     faster = true
1351     disableSigning = true
1352   }
1353
1354   if (OSX_KEYPASS) {
1355     macKeystorePassword = OSX_KEYPASS
1356   }
1357
1358   doFirst {
1359     println("Using projectFile "+projectFile)
1360   }
1361
1362   inputs.dir(getdownWebsiteDir)
1363   inputs.file(install4jConfFile)
1364   inputs.file("${install4jDir}/${install4j_info_plist_file_associations}")
1365   inputs.dir(macosJavaVMDir)
1366   inputs.dir(windowsJavaVMDir)
1367   outputs.dir("${jalviewDir}/${install4j_build_dir}/${JAVA_VERSION}")
1368 }
1369
1370
1371 task sourceDist(type: Tar) {
1372   
1373   def VERSION_UNDERSCORES = JALVIEW_VERSION.replaceAll("\\.", "_")
1374   def outputFileName = "${project.name}_${VERSION_UNDERSCORES}.tar.gz"
1375   // cater for buildship < 3.1 [3.0.1 is max version in eclipse 2018-09]
1376   try {
1377     archiveFileName = outputFileName
1378   } catch (Exception e) {
1379     archiveName = outputFileName
1380   }
1381   
1382   compression Compression.GZIP
1383   
1384   into project.name
1385
1386   def EXCLUDE_FILES=["build/*","bin/*","test-output/","test-reports","tests","clover*/*"
1387   ,".*"
1388   ,"benchmarking/*"
1389   ,"**/.*"
1390   ,"*.class"
1391   ,"**/*.class","${j11modDir}/**/*.jar","appletlib","**/*locales"
1392   ,"*locales/**",
1393   ,"utils/InstallAnywhere"] 
1394   def PROCESS_FILES=[   "AUTHORS",
1395   "CITATION",
1396   "FEATURETODO",
1397   "JAVA-11-README",
1398   "FEATURETODO",
1399   "LICENSE",
1400   "**/README",
1401   "RELEASE",
1402   "THIRDPARTYLIBS","TESTNG",
1403   "build.gradle",
1404   "gradle.properties",
1405   "**/*.java",
1406   "**/*.html",
1407   "**/*.xml",
1408   "**/*.gradle",
1409   "**/*.groovy",
1410   "**/*.properties",
1411   "**/*.perl",
1412   "**/*.sh"]
1413
1414   from(jalviewDir) {
1415     exclude (EXCLUDE_FILES)
1416     include (PROCESS_FILES)
1417     filter(ReplaceTokens,
1418       beginToken: '$$',
1419       endToken: '$$',
1420       tokens: [
1421         'Version-Rel': JALVIEW_VERSION,
1422         'Year-Rel': getDate("yyyy")
1423       ]
1424     )
1425   }
1426   from(jalviewDir) {
1427     exclude (EXCLUDE_FILES)
1428     exclude (PROCESS_FILES)
1429     exclude ("appletlib")
1430     exclude ("**/*locales")
1431     exclude ("*locales/**")
1432     exclude ("utils/InstallAnywhere")
1433
1434     exclude (getdown_files_dir)
1435     exclude (getdown_website_dir)
1436
1437     // exluding these as not using jars as modules yet
1438     exclude ("${j11modDir}/**/*.jar")
1439   }
1440   //  from (jalviewDir) {
1441   //    // explicit includes for stuff that seemed to not get included
1442   //    include(fileTree("test/**/*."))
1443   //    exclude(EXCLUDE_FILES)
1444   //    exclude(PROCESS_FILES)
1445   //  }
1446 }
1447
1448
1449 task helppages {
1450   dependsOn copyHelp
1451   dependsOn pubhtmlhelp
1452   
1453   inputs.dir("${classesDir}/${help_dir}")
1454   outputs.dir("${buildDir}/distributions/${help_dir}")
1455 }
1456
1457 // LARGE AMOUNT OF JALVIEWJS STUFF DELETED HERE
1458 task eclipseAutoBuildTask {}
1459 task eclipseSynchronizationTask {}