JAL-3449 Work in progress improving XML replacements by gradle
[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.XmlSlurper
8 import groovy.util.XmlParser
9 import groovy.xml.XmlUtil
10
11 buildscript {
12   dependencies {
13     classpath 'org.openclover:clover:4.3.1'
14   }
15 }
16
17 plugins {
18   id 'java'
19   id 'application'
20   id 'eclipse'
21   id 'com.github.johnrengelman.shadow' version '4.0.3'
22   id 'com.install4j.gradle' version '8.0.2'
23   id 'com.dorongold.task-tree' version '1.4' // only needed to display task dependency tree with  gradle task1 [task2 ...] taskTree
24 }
25
26 repositories {
27   jcenter()
28   mavenCentral()
29   mavenLocal()
30   flatDir {
31     dirs gradlePluginsDir
32   }
33 }
34
35 dependencies {
36   compile 'org.apache.commons:commons-compress:1.18'
37 }
38
39
40 // in ext the values are cast to Object. Ensure string values are cast as String (and not GStringImpl) for later use
41 def string(Object o) {
42   return o.toString()
43 }
44
45
46 ext {
47   jalviewDirAbsolutePath = file(jalviewDir).getAbsolutePath()
48   jalviewDirRelativePath = jalviewDir
49
50   // local build environment properties
51   def localProps = "${jalviewDirAbsolutePath}/local.properties"
52   if (file(localProps).exists()) {
53     try {
54       def p = new Properties()
55       def localPropsFIS = new FileInputStream(localProps)
56       p.load(localPropsFIS)
57       localPropsFIS.close()
58       p.each {
59         key, val -> 
60           def over = getProperty(key) != null
61           setProperty(key, val)
62           if (over) {
63             println("Overriding 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   getdownDir = string("")
120   reportRsyncCmd = false
121   buildDist = true
122   buildProperties = build_properties_file
123   getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher}")
124   switch (CHANNEL) {
125
126     case "BUILD":
127     // TODO: get bamboo build artifact URL for getdown artifacts
128     getdown_channel_base = bamboo_channelbase
129     getdown_channel_name = string("${bamboo_planKey}/${JAVA_VERSION}")
130     getdown_app_base = string("${bamboo_channelbase}/${bamboo_planKey}${bamboo_getdown_channel_suffix}/${JAVA_VERSION}")
131     getdown_app_dir = getdown_app_dir_alt
132     buildProperties = string("${classesDir}/${build_properties_file}")
133     break
134
135     case "RELEASE":
136     getdown_channel_name = CHANNEL.toLowerCase()
137     getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
138     getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
139     getdown_app_dir = getdown_app_dir_release
140     buildProperties = string("${classesDir}/${build_properties_file}")
141     reportRsyncCommand = true
142     break
143
144     case "ARCHIVE":
145     getdown_channel_name = CHANNEL.toLowerCase()+"/${JALVIEW_VERSION}"
146     getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
147     getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
148     getdown_app_dir = getdown_app_dir_alt
149     if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
150       print "Must provide an ARCHIVEDIR value to produce an archive distribution"
151       exit
152     } else {
153       packageDir = string("${ARCHIVEDIR}/${packageDir}")
154       buildProperties = string("${ARCHIVEDIR}/${classes_dir}/${build_properties_file}")
155       buildDist = false
156     }
157     reportRsyncCommand = true
158     break
159
160     case "ARCHIVELOCAL":
161     getdown_channel_name = string("archive/${JALVIEW_VERSION}")
162     getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
163     getdown_app_base = file(getdownWebsiteDir).toURI().toString()
164     getdown_app_dir = getdown_app_dir_alt
165     if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
166       print "Must provide an ARCHIVEDIR value to produce an archive distribution"
167       exit
168     } else {
169       packageDir = string("${ARCHIVEDIR}/${packageDir}")
170       buildProperties = string("${ARCHIVEDIR}/${classes_dir}/${build_properties_file}")
171       buildDist = false
172     }
173     reportRsyncCommand = true
174     getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
175     break
176
177     case "DEVELOP":
178     getdown_channel_name = CHANNEL.toLowerCase()
179     getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
180     getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
181     getdown_app_dir = getdown_app_dir_alt
182     buildProperties = string("${classesDir}/${build_properties_file}")
183     reportRsyncCommand = true
184     break
185
186     case "TEST-RELEASE":
187     getdown_channel_name = CHANNEL.toLowerCase()
188     getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
189     getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
190     getdown_app_dir = getdown_app_dir_alt
191     buildProperties = string("${classesDir}/${build_properties_file}")
192     reportRsyncCommand = true
193     break
194
195     case ~/^SCRATCH(|-[-\w]*)$/:
196     getdown_channel_name = CHANNEL
197     getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
198     getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
199     getdown_app_dir = getdown_app_dir_alt
200     buildProperties = string("${classesDir}/${build_properties_file}")
201     reportRsyncCommand = true
202     break
203
204     case "LOCAL":
205     getdown_app_base = file(getdownWebsiteDir).toURI().toString()
206     getdown_app_dir = getdown_app_dir_alt
207     buildProperties = string("${classesDir}/${build_properties_file}")
208     getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
209     break
210
211     default: // something wrong specified
212     print("CHANNEL must be one of BUILD, RELEASE, ARCHIVE, DEVELOP, TEST-RELEASE, SCRATCH-..., LOCAL [default]")
213     exit
214     break
215
216   }
217
218   getdownAppDir = string("${getdownWebsiteDir}/${getdown_app_dir}")
219   //getdownJ11libDir = "${getdownWebsiteDir}/${getdown_j11lib_dir}"
220   getdownResourceDir = string("${getdownWebsiteDir}/${getdown_resource_dir}")
221   getdownInstallDir = string("${getdownWebsiteDir}/${getdown_install_dir}")
222   getdownFilesDir = string("${jalviewDir}/${getdown_files_dir}/${JAVA_VERSION}/")
223   getdownFilesInstallDir = string("${getdownFilesDir}/${getdown_install_dir}")
224   /* compile without modules -- using classpath libraries
225   modules_compileClasspath = fileTree(dir: "${jalviewDir}/${j11modDir}", include: ["*.jar"])
226   modules_runtimeClasspath = modules_compileClasspath
227   */
228   gitHash = string("")
229   gitBranch = string("")
230
231   println("Using a ${CHANNEL} profile.")
232
233   additional_compiler_args = []
234   // configure classpath/args for j8/j11 compilation
235   if (JAVA_VERSION.equals("1.8")) {
236     JAVA_INTEGER_VERSION = string("8")
237     //libDir = j8libDir
238     libDir = j11libDir
239     libDistDir = j8libDir
240     compile_source_compatibility = 1.8
241     compile_target_compatibility = 1.8
242     // these are getdown.txt properties defined dependent on the JAVA_VERSION
243     getdown_alt_java_min_version = getdown_alt_java8_min_version
244     getdown_alt_java_max_version = getdown_alt_java8_max_version
245     // this property is assigned below and expanded to multiple lines in the getdown task
246     getdown_alt_multi_java_location = getdown_alt_java8_txt_multi_java_location
247     // this property is for the Java library used in eclipse
248     eclipse_java_runtime_name = string("JavaSE-1.8")
249   } else if (JAVA_VERSION.equals("11")) {
250     JAVA_INTEGER_VERSION = string("11")
251     libDir = j11libDir
252     libDistDir = j11libDir
253     compile_source_compatibility = 11
254     compile_target_compatibility = 11
255     getdown_alt_java_min_version = getdown_alt_java11_min_version
256     getdown_alt_java_max_version = getdown_alt_java11_max_version
257     getdown_alt_multi_java_location = getdown_alt_java11_txt_multi_java_location
258     eclipse_java_runtime_name = string("JavaSE-11")
259     /* compile without modules -- using classpath libraries
260     additional_compiler_args += [
261     '--module-path', modules_compileClasspath.asPath,
262     '--add-modules', j11modules
263     ]
264      */
265   } else if (JAVA_VERSION.equals("12") || JAVA_VERSION.equals("13")) {
266     JAVA_INTEGER_VERSION = JAVA_VERSION
267     libDir = j11libDir
268     libDistDir = j11libDir
269     compile_source_compatibility = JAVA_VERSION
270     compile_target_compatibility = JAVA_VERSION
271     getdown_alt_java_min_version = getdown_alt_java11_min_version
272     getdown_alt_java_max_version = getdown_alt_java11_max_version
273     getdown_alt_multi_java_location = getdown_alt_java11_txt_multi_java_location
274     eclipse_java_runtime_name = string("JavaSE-11")
275     /* compile without modules -- using classpath libraries
276     additional_compiler_args += [
277     '--module-path', modules_compileClasspath.asPath,
278     '--add-modules', j11modules
279     ]
280      */
281   } else {
282     throw new GradleException("JAVA_VERSION=${JAVA_VERSION} not currently supported by Jalview")
283   }
284
285
286   // for install4j
287   JAVA_MIN_VERSION = JAVA_VERSION
288   JAVA_MAX_VERSION = JAVA_VERSION
289   macosJavaVMDir = string("${System.env.HOME}/buildtools/jre/openjdk-java_vm/getdown/macos-jre${JAVA_VERSION}/jre")
290   macosJavaVMTgz = string("${System.env.HOME}/buildtools/jre/openjdk-java_vm/install4j/tgz/macos-jre${JAVA_VERSION}.tar.gz")
291   windowsJavaVMDir = string("${System.env.HOME}/buildtools/jre/openjdk-java_vm/getdown/windows-jre${JAVA_VERSION}/jre")
292   windowsJavaVMTgz = string("${System.env.HOME}/buildtools/jre/openjdk-java_vm/install4j/tgz/windows-jre${JAVA_VERSION}.tar.gz")
293   install4jDir = string("${jalviewDir}/${install4j_utils_dir}")
294   install4jConfFileName = string("jalview-installers-java${JAVA_VERSION}.install4j")
295   install4jConfFile = string("${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   helpDir = string("${help_dir}")
307   helpSourceDir = string("${helpParentDir}/${helpDir}")
308
309
310   relativeBuildDir = file(jalviewDirAbsolutePath).toPath().relativize(buildDir.toPath())
311   jalviewjsBuildDir = string("${relativeBuildDir}/jalviewjs")
312   jalviewjsSiteDir = string("${jalviewjsBuildDir}/${jalviewjs_site_dir}")
313   if (IN_ECLIPSE) {
314     jalviewjsTransferSiteJsDir = string(jalviewjsSiteDir)
315   } else {
316     jalviewjsTransferSiteJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_js")
317   }
318   jalviewjsTransferSiteLibDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_lib")
319   jalviewjsTransferSiteSwingJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_swingjs")
320   jalviewjsTransferSiteCoreDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_core")
321   jalviewjsJalviewCoreHtmlFile = string("")
322   jalviewjsJalviewCoreName = string(jalviewjs_core_name)
323   jalviewjsCoreClasslists = []
324   jalviewjsJalviewTemplateName = string(jalviewjs_name)
325   jalviewjsJ2sSettingsFileName = string("${jalviewDir}/${jalviewjs_j2s_settings}")
326   jalviewjsJ2sProps = null
327
328   eclipseWorkspace = null
329   eclipseBinary = string("")
330   eclipseVersion = string("")
331   eclipseDebug = false
332   // ENDEXT
333 }
334
335
336 sourceSets {
337   main {
338     java {
339       srcDirs sourceDir
340       outputDir = file(classesDir)
341     }
342
343     resources {
344       srcDirs resourceDir
345     }
346
347     jar.destinationDir = file("${jalviewDir}/${packageDir}")
348
349     compileClasspath = files(sourceSets.main.java.outputDir)
350     compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
351
352     runtimeClasspath = compileClasspath
353   }
354
355   clover {
356     java {
357       srcDirs = [ cloverInstrDir ]
358       outputDir = file("${buildDir}/${cloverClassesDir}")
359     }
360
361     resources {
362       srcDirs = sourceSets.main.resources.srcDirs
363     }
364     compileClasspath = configurations.cloverRuntime + files( sourceSets.clover.java.outputDir )
365     compileClasspath += files(sourceSets.main.java.outputDir)
366     compileClasspath += sourceSets.main.compileClasspath
367     compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["**/*.jar"])
368     compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
369
370     runtimeClasspath = compileClasspath
371   }
372
373   test {
374     java {
375       srcDirs testSourceDir
376       outputDir = file("${jalviewDir}/${testOutputDir}")
377     }
378
379     resources {
380       srcDirs = sourceSets.main.resources.srcDirs
381     }
382
383     compileClasspath = files( sourceSets.test.java.outputDir )
384
385     if (use_clover) {
386       compileClasspath += sourceSets.clover.compileClasspath
387     } else {
388       compileClasspath += files(sourceSets.main.java.outputDir)
389     }
390
391     compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
392     compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testnglibs", include: ["**/*.jar"])
393     compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testlibs", include: ["**/*.jar"])
394
395     runtimeClasspath = compileClasspath
396   }
397 }
398
399
400 // clover bits
401 dependencies {
402   if (use_clover) {
403     cloverCompile 'org.openclover:clover:4.3.1'
404     testCompile 'org.openclover:clover:4.3.1'
405   }
406 }
407
408
409 configurations {
410   cloverRuntime
411   cloverRuntime.extendsFrom cloverCompile
412 }
413
414 eclipse {
415   project {
416     name = eclipse_project_name
417
418     natures 'org.eclipse.jdt.core.javanature',
419     'org.eclipse.jdt.groovy.core.groovyNature',
420     'org.eclipse.buildship.core.gradleprojectnature'
421
422     buildCommand 'org.eclipse.jdt.core.javabuilder'
423     buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
424   }
425
426   classpath {
427     //defaultOutputDir = sourceSets.main.java.outputDir
428     def removeThese = []
429     configurations.each{
430       if (it.isCanBeResolved()) {
431         removeThese += it
432       }
433     }
434
435     minusConfigurations += removeThese
436     plusConfigurations = [ ]
437     file {
438
439       whenMerged { cp ->
440         def removeTheseToo = []
441         HashMap<String, Boolean> alreadyAddedSrcPath = new HashMap<>();
442         cp.entries.each { entry ->
443           // This conditional removes all src classpathentries that a) have already been added or b) aren't "src" or "test".
444           // e.g. this removes the resources dir being copied into bin/main, bin/test AND bin/clover
445           // we add the resources and help/help dirs in as libs afterwards (see below)
446           if (entry.kind == 'src') {
447             if (alreadyAddedSrcPath.getAt(entry.path) || !(entry.path == bareSourceDir || entry.path == bareTestSourceDir)) {
448               removeTheseToo += entry
449             } else {
450               alreadyAddedSrcPath.putAt(entry.path, true)
451             }
452           }
453
454         }
455         cp.entries.removeAll(removeTheseToo)
456
457         //cp.entries += new Output("${eclipse_bin_dir}/main")
458         if (file(helpSourceDir).isDirectory()) {
459           cp.entries += new Library(fileReference(helpSourceDir))
460         }
461         if (file(resourceDir).isDirectory()) {
462           cp.entries += new Library(fileReference(resourceDir))
463         }
464
465         HashMap<String, Boolean> alreadyAddedLibPath = new HashMap<>();
466
467         sourceSets.main.compileClasspath.findAll { it.name.endsWith(".jar") }.each {
468           //don't want to add outputDir as eclipse is using its own output dir in bin/main
469           if (it.isDirectory() || ! it.exists()) {
470             // don't add dirs to classpath, especially if they don't exist
471             return false // groovy "continue" in .any closure
472           }
473           def itPath = it.toString()
474           if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
475             // make relative path
476             itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
477           }
478           if (alreadyAddedLibPath.get(itPath)) {
479             //println("Not adding duplicate entry "+itPath)
480           } else {
481             //println("Adding entry "+itPath)
482             cp.entries += new Library(fileReference(itPath))
483             alreadyAddedLibPath.put(itPath, true)
484           }
485         }
486
487         //fileTree(dir: "$jalviewDir/$utilsDir", include: ["test*/*.jar"]).each {
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 = eclipse_java_runtime_name
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) // , fileTree(dir: 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   if ((pandoc == null || ! file(pandoc).exists()) && hostname.equals("jv-bamboo")) {
713     pandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
714   }
715
716   doFirst {
717     if (pandoc != null && file(pandoc).exists()) {
718         commandLine pandoc, '-s', '-o', buildingHTML, '--metadata', 'pagetitle="Building Jalview from Source"', '--toc', '-H', css, buildingMD
719     } else {
720         println("Cannot find pandoc. Skipping convert building.md to HTML")
721         throw new StopExecutionException("Cannot find pandoc. Skipping convert building.md to HTML")
722     }
723   }
724
725   ignoreExitValue true
726
727   inputs.file(buildingMD)
728   inputs.file(css)
729   outputs.file(buildingHTML)
730 }
731
732
733 clean {
734   doFirst {
735     delete buildingHTML
736   }
737 }
738
739
740 task syncDocs(type: Sync) {
741   dependsOn convertBuildingMD
742   def syncDir = "${classesDir}/${docDir}"
743   from fileTree("${jalviewDir}/${docDir}")
744   into syncDir
745
746 }
747
748
749 task copyHelp(type: Copy) {
750   def inputDir = helpSourceDir
751   def outputDir = "${classesDir}/${helpDir}"
752   from(inputDir) {
753     exclude '**/*.gif'
754     exclude '**/*.jpg'
755     exclude '**/*.png'
756     filter(ReplaceTokens,
757       beginToken: '$$',
758       endToken: '$$',
759       tokens: [
760         'Version-Rel': JALVIEW_VERSION,
761         'Year-Rel': getDate("yyyy")
762       ]
763     )
764   }
765   from(inputDir) {
766     include '**/*.gif'
767     include '**/*.jpg'
768     include '**/*.png'
769   }
770   into outputDir
771
772   inputs.dir(inputDir)
773   outputs.files(helpFile)
774   outputs.dir(outputDir)
775 }
776
777
778 task syncLib(type: Sync) {
779   def syncDir = "${classesDir}/${libDistDir}"
780   from fileTree("${jalviewDir}/${libDistDir}")
781   into syncDir
782 }
783
784
785 task syncResources(type: Sync) {
786   from resourceDir
787   include "**/*.*"
788   into "${classesDir}"
789   preserve {
790     include "**"
791   }
792 }
793
794
795 task prepare {
796   dependsOn syncResources
797   dependsOn syncDocs
798   dependsOn copyHelp
799 }
800
801
802 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
803 test {
804   dependsOn prepare
805   dependsOn compileJava
806   if (use_clover) {
807     dependsOn cloverInstr
808   }
809
810   if (use_clover) {
811     print("Running tests " + (use_clover?"WITH":"WITHOUT") + " clover [clover="+use_clover+"]\n")
812   }
813
814   useTestNG() {
815     includeGroups testngGroups
816     preserveOrder true
817     useDefaultListeners=true
818   }
819
820   workingDir = jalviewDir
821   //systemProperties 'clover.jar' System.properties.clover.jar
822   sourceCompatibility = compile_source_compatibility
823   targetCompatibility = compile_target_compatibility
824   jvmArgs += additional_compiler_args
825
826 }
827
828
829 task buildIndices(type: JavaExec) {
830   dependsOn copyHelp
831   classpath = sourceSets.main.compileClasspath
832   main = "com.sun.java.help.search.Indexer"
833   workingDir = "${classesDir}/${helpDir}"
834   def argDir = "html"
835   args = [ argDir ]
836   inputs.dir("${workingDir}/${argDir}")
837
838   outputs.dir("${classesDir}/doc")
839   outputs.dir("${classesDir}/help")
840   outputs.file("${workingDir}/JavaHelpSearch/DOCS")
841   outputs.file("${workingDir}/JavaHelpSearch/DOCS.TAB")
842   outputs.file("${workingDir}/JavaHelpSearch/OFFSETS")
843   outputs.file("${workingDir}/JavaHelpSearch/POSITIONS")
844   outputs.file("${workingDir}/JavaHelpSearch/SCHEMA")
845   outputs.file("${workingDir}/JavaHelpSearch/TMAP")
846 }
847
848
849 task compileLinkCheck(type: JavaCompile) {
850   options.fork = true
851   classpath = files("${jalviewDir}/${utilsDir}")
852   destinationDir = file("${jalviewDir}/${utilsDir}")
853   source = fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
854
855   inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
856   inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
857   outputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.class")
858   outputs.file("${jalviewDir}/${utilsDir}/BufferedLineReader.class")
859 }
860
861
862 task linkCheck(type: JavaExec) {
863   dependsOn prepare, compileLinkCheck
864
865   def helpLinksCheckerOutFile = file("${jalviewDir}/${utilsDir}/HelpLinksChecker.out")
866   classpath = files("${jalviewDir}/${utilsDir}")
867   main = "HelpLinksChecker"
868   workingDir = jalviewDir
869   def help = "${classesDir}/${helpDir}"
870   args = [ "${classesDir}/${helpDir}", "-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}/${helpDir}")
882   outputs.file(helpLinksCheckerOutFile)
883 }
884
885 // import the pubhtmlhelp target
886 ant.properties.basedir = "${jalviewDir}"
887 ant.properties.helpBuildDir = "${jalviewDirAbsolutePath}/${classes_dir}/${helpDir}"
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 getdownAppDir = getdownAppDir
987   def getdownResourceFilenames = []
988
989   doFirst {
990     // clean the getdown website and files dir before creating getdown folders
991     delete getdownWebsiteDir
992     delete getdownFilesDir
993
994     copy {
995       from buildProperties
996       rename(build_properties_file, getdown_build_properties)
997       into getdownAppDir
998     }
999     getdownWebsiteResourceFilenames += "${getdown_app_dir}/${getdown_build_properties}"
1000
1001     // go through properties looking for getdown_txt_...
1002     def props = project.properties.sort { it.key }
1003     if (getdown_alt_java_min_version.length() > 0) {
1004       props.put("getdown_txt_java_min_version", getdown_alt_java_min_version)
1005     }
1006     if (getdown_alt_java_max_version.length() > 0) {
1007       props.put("getdown_txt_java_max_version", getdown_alt_java_max_version)
1008     }
1009     props.put("getdown_txt_multi_java_location", getdown_alt_multi_java_location)
1010
1011     props.put("getdown_txt_appbase", getdown_app_base)
1012     props.each{ prop, val ->
1013       if (prop.startsWith("getdown_txt_") && val != null) {
1014         if (prop.startsWith("getdown_txt_multi_")) {
1015           def key = prop.substring(18)
1016           val.split(",").each{ v ->
1017             def line = "${key} = ${v}\n"
1018             getdownTextString += line
1019           }
1020         } else {
1021           // file values rationalised
1022           if (val.indexOf('/') > -1 || prop.startsWith("getdown_txt_resource")) {
1023             def r = null
1024             if (val.indexOf('/') == 0) {
1025               // absolute path
1026               r = file(val)
1027             } else if (val.indexOf('/') > 0) {
1028               // relative path (relative to jalviewDir)
1029               r = file( "${jalviewDir}/${val}" )
1030             }
1031             if (r.exists()) {
1032               val = "${getdown_resource_dir}/" + r.getName()
1033               getdownWebsiteResourceFilenames += val
1034               getdownResourceFilenames += r.getPath()
1035             }
1036           }
1037           if (! prop.startsWith("getdown_txt_resource")) {
1038             def line = prop.substring(12) + " = ${val}\n"
1039             getdownTextString += line
1040           }
1041         }
1042       }
1043     }
1044
1045     getdownWebsiteResourceFilenames.each{ filename ->
1046       getdownTextString += "resource = ${filename}\n"
1047     }
1048     getdownResourceFilenames.each{ filename ->
1049       copy {
1050         from filename
1051         into getdownResourceDir
1052       }
1053     }
1054
1055     def codeFiles = []
1056     fileTree(file(packageDir)).each{ f ->
1057       if (f.isDirectory()) {
1058         def files = fileTree(dir: f, include: ["*"]).getFiles()
1059         codeFiles += files
1060       } else if (f.exists()) {
1061         codeFiles += f
1062       }
1063     }
1064     codeFiles.sort().each{f ->
1065       def name = f.getName()
1066       def line = "code = ${getdown_app_dir}/${name}\n"
1067       getdownTextString += line
1068       copy {
1069         from f.getPath()
1070         into getdownAppDir
1071       }
1072     }
1073
1074     // NOT USING MODULES YET, EVERYTHING SHOULD BE IN dist
1075     /*
1076     if (JAVA_VERSION.equals("11")) {
1077     def j11libFiles = fileTree(dir: "${jalviewDir}/${j11libDir}", include: ["*.jar"]).getFiles()
1078     j11libFiles.sort().each{f ->
1079     def name = f.getName()
1080     def line = "code = ${getdown_j11lib_dir}/${name}\n"
1081     getdownTextString += line
1082     copy {
1083     from f.getPath()
1084     into getdownJ11libDir
1085     }
1086     }
1087     }
1088      */
1089
1090     // 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.
1091     //getdownTextString += "class = " + file(getdownLauncher).getName() + "\n"
1092     getdownTextString += "resource = ${getdown_launcher_new}\n"
1093     getdownTextString += "class = ${mainClass}\n"
1094
1095     def getdown_txt = file("${getdownWebsiteDir}/getdown.txt")
1096     getdown_txt.write(getdownTextString)
1097
1098     def launch_jvl = file("${getdownWebsiteDir}/${getdown_launch_jvl}")
1099     launch_jvl.write("appbase="+props.get("getdown_txt_appbase"))
1100
1101     copy {
1102       from getdownLauncher
1103       rename(file(getdownLauncher).getName(), getdown_launcher_new)
1104       into getdownWebsiteDir
1105     }
1106
1107     copy {
1108       from getdownLauncher
1109       if (file(getdownLauncher).getName() != getdown_launcher) {
1110         rename(file(getdownLauncher).getName(), getdown_launcher)
1111       }
1112       into getdownWebsiteDir
1113     }
1114
1115     if (! (CHANNEL.startsWith("ARCHIVE") || CHANNEL.startsWith("DEVELOP"))) {
1116       copy {
1117         from getdown_txt
1118         from getdownLauncher
1119         from "${getdownWebsiteDir}/${getdown_build_properties}"
1120         if (file(getdownLauncher).getName() != getdown_launcher) {
1121           rename(file(getdownLauncher).getName(), getdown_launcher)
1122         }
1123         into getdownInstallDir
1124       }
1125
1126       copy {
1127         from getdownInstallDir
1128         into getdownFilesInstallDir
1129       }
1130     }
1131
1132     copy {
1133       from getdown_txt
1134       from launch_jvl
1135       from getdownLauncher
1136       from "${getdownWebsiteDir}/${getdown_build_properties}"
1137       if (file(getdownLauncher).getName() != getdown_launcher) {
1138         rename(file(getdownLauncher).getName(), getdown_launcher)
1139       }
1140       into getdownFilesDir
1141     }
1142
1143     copy {
1144       from getdownResourceDir
1145       into "${getdownFilesDir}/${getdown_resource_dir}"
1146     }
1147   }
1148
1149   if (buildDist) {
1150     inputs.dir("${jalviewDir}/${packageDir}")
1151   }
1152   outputs.dir(getdownWebsiteDir)
1153   outputs.dir(getdownFilesDir)
1154 }
1155
1156
1157 task getdownDigest(type: JavaExec) {
1158   group = "distribution"
1159   description = "Digest the getdown website folder"
1160   dependsOn getdownWebsite
1161   doFirst {
1162     classpath = files("${getdownWebsiteDir}/${getdown_launcher}")
1163   }
1164   main = "com.threerings.getdown.tools.Digester"
1165   args getdownWebsiteDir
1166   inputs.dir(getdownWebsiteDir)
1167   outputs.file("${getdownWebsiteDir}/digest2.txt")
1168 }
1169
1170
1171 task getdown() {
1172   group = "distribution"
1173   description = "Create the minimal and full getdown app folder for installers and website and create digest file"
1174   dependsOn getdownDigest
1175   doLast {
1176     if (reportRsyncCommand) {
1177       def fromDir = getdownWebsiteDir + (getdownWebsiteDir.endsWith('/')?'':'/')
1178       def toDir = "${getdown_rsync_dest}/${getdownDir}" + (getdownDir.endsWith('/')?'':'/')
1179       println "LIKELY RSYNC COMMAND:"
1180       println "mkdir -p '$toDir'\nrsync -avh --delete '$fromDir' '$toDir'"
1181       if (RUNRSYNC == "true") {
1182         exec {
1183           commandLine "mkdir", "-p", toDir
1184         }
1185         exec {
1186           commandLine "rsync", "-avh", "--delete", fromDir, toDir
1187         }
1188       }
1189     }
1190   }
1191 }
1192
1193
1194 clean {
1195   doFirst {
1196     delete getdownWebsiteDir
1197     delete getdownFilesDir
1198   }
1199 }
1200
1201
1202 install4j {
1203   if (file(install4jHomeDir).exists()) {
1204     // good to go!
1205   } else if (file(System.getProperty("user.home")+"/buildtools/install4j").exists()) {
1206     install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
1207   } else if (file("/Applications/install4j.app/Contents/Resources/app").exists()) {
1208     install4jHomeDir = "/Applications/install4j.app/Contents/Resources/app"
1209   }
1210   installDir(file(install4jHomeDir))
1211
1212   mediaTypes = Arrays.asList(install4j_media_types.split(","))
1213 }
1214
1215
1216 task copyInstall4jTemplate(type: Copy) {
1217   dependsOn setGitVals
1218
1219   inputs.file("${install4jDir}/${install4j_template}")
1220   inputs.file("${install4jDir}/${install4j_installer_file_associations}")
1221   outputs.files(install4jConfFile)
1222
1223   from (install4jDir) {
1224     include install4j_template
1225     rename (install4j_template, install4jConfFileName)
1226     // TODO change these ReplaceTokens to something better.  Possibly ${compiler:variables} but also the ant.replaceregexp below, or perhaps a proper xmldom parse
1227
1228     /*
1229     if (OSX_KEYPASS == "") {
1230       filter(ReplaceTokens,
1231         beginToken: 'codeSigning macEnabled="',
1232         endToken: '"',
1233         tokens: [
1234           'true': 'codeSigning macEnabled="false"'
1235         ]
1236       )
1237       filter(ReplaceTokens,
1238         beginToken: 'runPostProcessor="true" ',
1239         endToken: 'Processor',
1240         tokens: [
1241           'post': 'runPostProcessor="false" postProcessor'
1242         ]
1243       )
1244     }
1245     */
1246   }
1247   into install4jDir
1248
1249   doLast {
1250     // include file associations in installer
1251     def install4jFileAssociationsFile = file("${install4jDir}/${install4j_installer_file_associations}")
1252     def install4jFileAssociationsText = install4jFileAssociationsFile.text
1253 /*
1254     ant.replaceregexp(
1255       byline: false,
1256       flags: "s",
1257       match: '<action name="EXTENSIONS_REPLACED_BY_GRADLE".*?</action>',
1258       replace: install4jFileAssociationsText,
1259       file: install4jConfFile
1260     )
1261 */
1262
1263     def install4jFileAssociations = new XmlParser().parseText('''
1264 <install4jFileAssociations>
1265 ${install4jFileAssociationsText}
1266 </install4jFileAssociations>
1267 '''
1268     )
1269
1270 println("TEXT=${install4jFileAssociationsText}")
1271 println("ACTIONS")
1272 install4jFileAssociationsXml.action.each { a ->
1273   println("ACTION="+XmlUtil.serialize(a))
1274 }
1275
1276
1277     def install4j = new XmlParser().parse(install4jConfFile)
1278
1279     if (OSX_KEYPASS == "") {
1280       install4j.application.codeSigning.each { codeSigning ->
1281         codeSigning.'@macEnabled' = "false"
1282       }
1283       install4j.mediaSets.windows.each { windows ->
1284         windows.'@runPostProcessor' = "false"
1285       }
1286     }
1287     // reparse
1288     //install4j = new XmlSlurper().parseText(XmlUtil.serialize(install4j))
1289
1290     install4j.'**'.action.each { a ->
1291       if (a.'@name' == 'EXTENSIONS_REPLACED_BY_GRADLE') {
1292         //a.replaceNode(install4jFileAssociationsXml.action[0])
1293       }
1294     }
1295     // reparse
1296     //install4j = new XmlSlurper().parseText(XmlUtil.serialize(install4j))
1297
1298     file(install4jConfFile).text = XmlUtil.serialize(install4j)
1299
1300     /*
1301     // include uninstaller applescript app files in dmg
1302     def installerDMGUninstallerXml = file("$install4jDir/$install4j_DMG_uninstaller_app_files").text
1303     ant.replaceregexp(
1304     byline: false,
1305     flags: "s",
1306     match: '<file name="UNINSTALL_OLD_JALVIEW_APP_REPLACED_IN_GRADLE" file=.*?>',
1307     replace: installerDMGUninstallerXml,
1308     file: install4jConfFile
1309     )
1310      */
1311   }
1312 }
1313
1314
1315 clean {
1316   doFirst {
1317     delete install4jConfFile
1318   }
1319 }
1320
1321
1322 task installers(type: com.install4j.gradle.Install4jTask) {
1323   group = "distribution"
1324   description = "Create the install4j installers"
1325   dependsOn getdown
1326   dependsOn copyInstall4jTemplate
1327   projectFile = file(install4jConfFile)
1328
1329   def install4jTemplateMd5 = ""
1330   def digest = MessageDigest.getInstance("MD5")
1331   digest.update(
1332     (file("${install4jDir}/${install4j_template}").text + 
1333     file("${install4jDir}/${install4j_info_plist_file_associations}").text +
1334     file("${install4jDir}/${install4j_installer_file_associations}").text).bytes)
1335   def filesMd5 = new BigInteger(1, digest.digest()).toString(16)
1336   if (filesMd5.length() >= 8) {
1337     filesMd5 = filesMd5.substring(0,8)
1338   }
1339   install4jTemplateMd5 += filesMd5
1340   install4jTemplateMd5 += "_${gitHash}"
1341   def install4jTemplateVersion = "${JALVIEW_VERSION}_${install4jTemplateMd5}"
1342   def infoPlistFileAssociations = file("${install4jDir}/${install4j_info_plist_file_associations}").text
1343
1344   variables = [
1345     'OSX_KEYSTORE': OSX_KEYSTORE,
1346     'JSIGN_SH': JSIGN_SH,
1347     'JALVIEW_VERSION': JALVIEW_VERSION,
1348     'JAVA_MIN_VERSION': JAVA_MIN_VERSION,
1349     'JAVA_MAX_VERSION': JAVA_MAX_VERSION,
1350     'JAVA_VERSION': JAVA_VERSION,
1351     'JAVA_INTEGER_VERSION': JAVA_INTEGER_VERSION,
1352     'VERSION': JALVIEW_VERSION,
1353     'MACOS_JAVA_VM_DIR': macosJavaVMDir,
1354     'MACOS_JAVA_VM_TGZ': macosJavaVMTgz,
1355     'WINDOWS_JAVA_VM_DIR': windowsJavaVMDir,
1356     'WINDOWS_JAVA_VM_TGZ': windowsJavaVMTgz,
1357     'INSTALL4JINFOPLISTFILEASSOCIATIONS': install4j_info_plist_file_associations,
1358     'INSTALLER_TEMPLATE_VERSION': install4jTemplateVersion,
1359     'COPYRIGHT_MESSAGE': install4j_copyright_message,
1360     'MACOS_BUNDLE_ID': install4j_macOS_bundle_id,
1361     'GETDOWN_RESOURCE_DIR': getdown_resource_dir,
1362     'GETDOWN_DIST_DIR': getdown_app_dir,
1363     'GETDOWN_ALT_DIR': getdown_app_dir_alt,
1364     'GETDOWN_INSTALL_DIR': getdown_install_dir,
1365     'INFO_PLIST_FILE_ASSOCIATIONS': infoPlistFileAssociations
1366   ]
1367   destination = "${jalviewDir}/${install4j_build_dir}/${JAVA_VERSION}"
1368   buildSelected = true
1369
1370   if (install4j_faster.equals("true") || CHANNEL.startsWith("DEVELOP") || CHANNEL.startsWith("LOCAL")) {
1371     // this doesn't seem to work
1372     faster = true
1373     disableSigning = true
1374   }
1375
1376   if (OSX_KEYPASS) {
1377     macKeystorePassword=OSX_KEYPASS
1378   }
1379
1380   doFirst {
1381     println("Using projectFile "+projectFile)
1382   }
1383
1384   inputs.dir(getdownWebsiteDir)
1385   inputs.file(install4jConfFile)
1386   inputs.file("${install4jDir}/${install4j_info_plist_file_associations}")
1387   inputs.dir(macosJavaVMDir)
1388   inputs.dir(windowsJavaVMDir)
1389   outputs.dir("${jalviewDir}/${install4j_build_dir}/${JAVA_VERSION}")
1390 }
1391
1392
1393 task sourceDist (type: Tar) {
1394   
1395   def VERSION_UNDERSCORES = JALVIEW_VERSION.replaceAll("\\.", "_")
1396   def outputFileName = "${project.name}_${VERSION_UNDERSCORES}.tar.gz"
1397   // cater for buildship < 3.1 [3.0.1 is max version in eclipse 2018-09]
1398   try {
1399     archiveFileName = outputFileName
1400   } catch (Exception e) {
1401     archiveName = outputFileName
1402   }
1403   
1404   compression Compression.GZIP
1405   
1406   into project.name
1407
1408   def EXCLUDE_FILES=["build/*","bin/*","test-output/","test-reports","tests","clover*/*"
1409   ,".*"
1410   ,"benchmarking/*"
1411   ,"**/.*"
1412   ,"*.class"
1413   ,"**/*.class","${j11modDir}/**/*.jar","appletlib","**/*locales"
1414   ,"*locales/**",
1415   ,"utils/InstallAnywhere"] 
1416   def PROCESS_FILES=[   "AUTHORS",
1417   "CITATION",
1418   "FEATURETODO",
1419   "JAVA-11-README",
1420   "FEATURETODO",
1421   "LICENSE",
1422   "**/README",
1423   "RELEASE",
1424   "THIRDPARTYLIBS","TESTNG",
1425   "build.gradle",
1426   "gradle.properties",
1427   "**/*.java",
1428   "**/*.html",
1429   "**/*.xml",
1430   "**/*.gradle",
1431   "**/*.groovy",
1432   "**/*.properties",
1433   "**/*.perl",
1434   "**/*.sh"]
1435
1436   from(jalviewDir) {
1437     exclude (EXCLUDE_FILES)
1438     include (PROCESS_FILES)
1439     filter(ReplaceTokens,
1440       beginToken: '$$',
1441       endToken: '$$',
1442       tokens: [
1443         'Version-Rel': JALVIEW_VERSION,
1444         'Year-Rel': getDate("yyyy")
1445       ]
1446     )
1447   }
1448   from(jalviewDir) {
1449     exclude (EXCLUDE_FILES)
1450     exclude (PROCESS_FILES)
1451     exclude ("appletlib")
1452     exclude ("**/*locales")
1453     exclude ("*locales/**")
1454     exclude ("utils/InstallAnywhere")
1455
1456     exclude (getdown_files_dir)
1457     exclude (getdown_website_dir)
1458
1459     // exluding these as not using jars as modules yet
1460     exclude ("${j11modDir}/**/*.jar")
1461   }
1462   //  from (jalviewDir) {
1463   //    // explicit includes for stuff that seemed to not get included
1464   //    include(fileTree("test/**/*."))
1465   //    exclude(EXCLUDE_FILES)
1466   //    exclude(PROCESS_FILES)
1467   //  }
1468 }
1469
1470
1471 task helppages  {
1472   dependsOn copyHelp
1473   dependsOn pubhtmlhelp
1474   
1475   inputs.dir("${classesDir}/${helpDir}")
1476   outputs.dir("${buildDir}/distributions/${helpDir}")
1477 }
1478
1479 // LARGE AMOUNT OF JALVIEWJS STUFF DELETED HERE
1480 task eclipseAutoBuildTask {}
1481 task eclipseSynchronizationTask {}