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