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