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