JAL-3224 JAL-3225 Added lines to check for updates to getdown-launcher.jar into Jalvi...
[jalview.git] / build.gradle
1 import org.apache.tools.ant.filters.ReplaceTokens
2 import org.gradle.internal.os.OperatingSystem
3
4 buildscript {
5   dependencies {
6         classpath 'org.openclover:clover:4.3.1'
7         classpath 'org.apache.commons:commons-compress:1.18'
8   }
9 }
10
11 plugins {
12   id 'java'
13   id 'application'
14   id 'eclipse'
15   id 'com.github.johnrengelman.shadow' version '4.0.3'
16   id 'com.install4j.gradle' version '7.0.9'
17 }
18
19 repositories {
20   jcenter()
21   mavenCentral()
22   mavenLocal()
23   flatDir {
24     dirs gradlePluginsDir
25   }
26 }
27
28 mainClassName = launcherClass
29 def cloverInstrDir = file("$buildDir/$cloverSourcesInstrDir")
30 def classes = "$jalviewDir/$classesDir"
31
32 if (clover.equals("true")) {
33   use_clover = true
34   classes = "$buildDir/$cloverClassesDir"
35 } else {
36   use_clover = false
37   classes = "$jalviewDir/$classesDir"
38 }
39
40 // configure classpath/args for j8/j11 compilation
41
42 def jalviewDirAbsolutePath = file(jalviewDir).getAbsolutePath()
43 def libDir
44 def libDistDir
45 def compile_source_compatibility
46 def compile_target_compatibility
47
48 ext {
49   // where the getdown channel will be built. 
50   // TODO: consider allowing this expression to  be overrriden by -P arg
51   getdownWebsiteDir = jalviewDir + '/' + getdown_website_dir + '/' + JAVA_VERSION + '/'
52   getdownAppDir = getdownWebsiteDir + '/' + getdown_app_dir
53   getdownJ11libDir = getdownWebsiteDir + '/' + getdown_j11lib_dir
54   getdownResourceDir = getdownWebsiteDir + '/' + getdown_resource_dir
55   getdownLauncher = jalviewDir + '/' + getdown_launcher
56   getdownFilesDir = jalviewDir + '/' + getdown_files_dir + '/' + JAVA_VERSION + '/'
57   getdownLib1 = jalviewDir + '/' + getdown_lib1
58   def getdownChannel = getdown_channel_name
59   if (getdown_channel_name.equals("COMMIT")) {
60     getdownChannel = getGitHash()
61   }
62   getdown_app_base = getdown_channel_base+"/"+getdownChannel+"/"+JAVA_VERSION+"/"
63   modules_compileClasspath = fileTree(dir: "$jalviewDir/$j11modDir", include: ["*.jar"])
64   modules_runtimeClasspath = modules_compileClasspath
65 }
66
67 def additional_compiler_args = []
68 // these are getdown.txt properties defined dependent on the JAVA_VERSION 
69 def getdown_alt_java_min_version
70 // this property is assigned below and expanded to multiple lines in the getdown task
71 def getdown_alt_multi_java_location
72 if (JAVA_VERSION.equals("1.8")) {
73   libDir = j11libDir
74   libDistDir = j8libDir
75   compile_source_compatibility = 1.8
76   compile_target_compatibility = 1.8
77   getdown_alt_java_min_version = getdown_alt_java8_min_version
78   getdown_alt_multi_java_location = getdown_alt_java8_txt_multi_java_location
79 } else if (JAVA_VERSION.equals("11")) {
80   libDir = j11libDir
81   libDistDir = j11libDir
82   compile_source_compatibility = 11
83   compile_target_compatibility = 11
84   getdown_alt_java_min_version = getdown_alt_java11_min_version
85   getdown_alt_multi_java_location = getdown_alt_java11_txt_multi_java_location
86   additional_compiler_args += [
87     '--module-path', ext.modules_compileClasspath.asPath,
88     '--add-modules', j11modules
89   ]
90 } else {
91   throw new GradleException("JAVA_VERSION=$JAVA_VERSION not currently supported by Jalview")
92 }
93
94 sourceSets {
95
96   main {
97     java {
98       srcDirs "$jalviewDir/$sourceDir"
99       outputDir = file("$classes")
100     }
101
102     resources {
103       srcDirs "$jalviewDir/$resourceDir"
104       srcDirs "$jalviewDir/$libDistDir"
105     }
106
107     jar.destinationDir = file("$jalviewDir/$packageDir")
108
109     compileClasspath = files(sourceSets.main.java.outputDir)
110     compileClasspath += fileTree(dir: "$jalviewDir/$libDir", include: ["*.jar"])
111
112     runtimeClasspath = compileClasspath
113   }
114   clover {
115     java {
116         srcDirs = [ cloverInstrDir ]
117         outputDir = file("${buildDir}/${cloverClassesDir}")
118     }
119     
120     resources {
121       srcDirs = sourceSets.main.resources.srcDirs
122     }
123     compileClasspath = configurations.cloverRuntime + files( sourceSets.clover.java.outputDir )
124     compileClasspath += files(sourceSets.main.java.outputDir)
125     compileClasspath += sourceSets.main.compileClasspath
126     compileClasspath += fileTree(dir: "$jalviewDir/$utilsDir", include: ["**/*.jar"])
127     compileClasspath += fileTree(dir: "$jalviewDir/$libDir", include: ["*.jar"])
128
129     runtimeClasspath = compileClasspath
130   }
131   
132   test {
133     java {
134       srcDirs "$jalviewDir/$testSourceDir"
135       outputDir = file("$jalviewDir/$testOutputDir")
136     }
137
138     resources {
139       srcDirs = sourceSets.main.resources.srcDirs
140     }
141
142     compileClasspath = files( sourceSets.test.java.outputDir ) 
143
144     if (use_clover) {
145       compileClasspath += sourceSets.clover.compileClasspath
146     } else {
147       compileClasspath += files(sourceSets.main.java.outputDir)
148     }
149     compileClasspath += sourceSets.main.compileClasspath
150     compileClasspath += files( sourceSets.main.resources.srcDirs)
151     compileClasspath += fileTree(dir: "$jalviewDir/$utilsDir", include: ["**/*.jar"])
152     compileClasspath += fileTree(dir: "$jalviewDir/$libDir", include: ["*.jar"])
153
154     runtimeClasspath = compileClasspath
155   }
156 }
157
158 // clover bits
159 dependencies {
160   if (use_clover) {
161     cloverCompile 'org.openclover:clover:4.3.1'
162     testCompile 'org.openclover:clover:4.3.1'
163   }
164 }
165
166 configurations {
167     cloverRuntime
168     cloverRuntime.extendsFrom cloverCompile
169 }
170
171 eclipse {
172   project {
173     name = "Jalview with gradle build"
174
175     natures 'org.eclipse.jdt.core.javanature',
176         'org.eclipse.jdt.groovy.core.groovyNature',
177         'org.eclipse.buildship.core.gradleprojectnature'
178
179     buildCommand 'org.eclipse.jdt.core.javabuilder'
180     buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
181   }
182
183   classpath {
184     //defaultOutputDir = sourceSets.main.java.outputDir
185     def removeThese = []
186     configurations.each{ if (it.isCanBeResolved()) {
187         removeThese += it
188       }
189     }
190     containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
191     
192     minusConfigurations += removeThese
193     plusConfigurations = [ ]
194     file {
195
196       whenMerged { cp ->
197         def removeTheseToo = []
198         HashMap<String, Boolean> addedSrcPath = new HashMap<>();
199         cp.entries.each { entry ->
200           if (entry.kind == 'src') {
201             if (addedSrcPath.getAt(entry.path) || !(entry.path == "src" || entry.path == "test" || entry.path == "resources")) {
202               removeTheseToo += entry
203             } else {
204               addedSrcPath.putAt(entry.path, true)
205             }
206           }
207         }
208         cp.entries.removeAll(removeTheseToo)
209       }
210       
211       withXml {
212         def node = it.asNode()
213         def srcTestAttributes
214         node.children().each{ cpe ->
215           def attributes = cpe.attributes()
216           if (attributes.get("kind") == "src" && attributes.get("path") == "test") {
217             srcTestAttributes = cpe.find { a -> a.name() == "attributes" }
218             return
219           }
220         }
221         def addTestAttribute = true
222         srcTestAttributes.each{a ->
223           if (a.name() == "attribute" && a.attributes().getAt("name") == "test") {
224             addTestAttribute = false
225           }
226         }
227         if (addTestAttribute) {
228           srcTestAttributes.append(new Node(null, "attribute", [name:"test", value:"true"]))
229         }
230         
231         node.appendNode('classpathentry', [kind:"output", path:"bin/main"])
232         HashMap<String, Boolean> addedLibPath = new HashMap<>();
233         def allPaths = sourceSets.test.compileClasspath + sourceSets.main.compileClasspath
234         sourceSets.main.compileClasspath.each{
235           //if ((it.isDirectory() || ! it.exists()) && ! (it.equals(sourceSets.main.java.outputDir))) {
236           //no longer want to add outputDir as eclipse is using its own output dir in bin/main
237           if (it.isDirectory() || ! it.exists()) {
238             // don't add dirs to classpath
239             //println("Not adding directory "+it)
240             return
241           }
242           def itPath = it.toString()
243           if (itPath.startsWith(jalviewDirAbsolutePath+"/")) {
244             itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
245           }
246           if (addedLibPath.get(itPath)) {
247             //println("Not adding duplicate entry "+itPath)
248           } else {
249             //println("Adding entry "+itPath)
250             node.appendNode('classpathentry', [kind:"lib", path:itPath])
251             addedLibPath.put(itPath, true)
252           }
253         }
254         sourceSets.test.compileClasspath.each{
255           //if ((it.isDirectory() || ! it.exists()) && ! (it.equals(sourceSets.main.java.outputDir))) {
256           //no longer want to add outputDir as eclipse is using its own output dir in bin/main
257           if (it.isDirectory() || ! it.exists()) {
258             // don't add dirs to classpath
259             //println("Not adding directory "+it)
260             return
261           }
262           def itPath = it.toString()
263           if (itPath.startsWith(jalviewDirAbsolutePath+"/")) {
264             itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
265           }
266           if (addedLibPath.get(itPath)) {
267             //println("Not adding duplicate entry "+itPath)
268           } else {
269             //println("Adding entry "+itPath)
270             node.appendNode('classpathentry', [kind:"lib", path:itPath])
271               .appendNode('attributes')
272                 .appendNode('attribute', [name:"test", value:"true"])
273             addedLibPath.put(itPath, true)
274           }
275         }
276       }
277
278     }
279   }
280
281   jdt {
282     // for the IDE, use java 11 compatibility
283     sourceCompatibility = 11
284     targetCompatibility = 11
285     javaRuntimeName = "JavaSE-11"
286
287     file {
288       withProperties { props ->
289         def jalview_prefs = new Properties()
290                 def ins = new FileInputStream(eclipse_extra_jdt_prefs_file)
291                 jalview_prefs.load(ins)
292                 ins.close()
293                 jalview_prefs.forEach { t, v ->
294                         if (props.getAt(t) == null) {
295                                 props.putAt(t, v)
296                         }
297                 }
298       }
299     }
300   }
301
302 }
303
304 task cloverInstr() {
305   // only instrument source, we build test classes as normal
306     inputs.files files (sourceSets.main.allJava) // , fileTree(dir:"$jalviewDir/$testSourceDir", include: ["**/*.java"]))
307     outputs.dir cloverInstrDir
308
309     doFirst {
310         delete cloverInstrDir
311         def argsList = ["--initstring", "${buildDir}/clover/clover.db",
312                         "-d", "${buildDir}/${cloverSourcesInstrDir}"]
313         argsList.addAll(inputs.files.files.collect({ file ->
314             file.absolutePath
315         }))
316         String[] args = argsList.toArray()
317         println("About to instrument "+args.length +" files")
318         com.atlassian.clover.CloverInstr.mainImpl(args)
319     }
320 }
321
322  
323 task cloverReport {
324         group = "Verification"
325         description = "Createst the Clover report"
326     inputs.dir "${buildDir}/clover"
327     outputs.dir "${reportsDir}/clover"
328     onlyIf {
329         file("${buildDir}/clover/clover.db").exists()
330     }
331     doFirst {
332         def argsList = ["--initstring", "${buildDir}/clover/clover.db",
333                         "-o", "${reportsDir}/clover"]
334         String[] args = argsList.toArray()
335         com.atlassian.clover.reporters.html.HtmlReporter.runReport(args)
336         
337         // and generate ${reportsDir}/clover/clover.xml
338         args = ["--initstring", "${buildDir}/clover/clover.db",
339                         "-o", "${reportsDir}/clover/clover.xml"].toArray()
340         com.atlassian.clover.reporters.xml.XMLReporter.runReport(args)
341     }
342 }
343
344 // end clover bits
345
346
347 compileJava {
348
349   doFirst {
350     sourceCompatibility = compile_source_compatibility
351     targetCompatibility = compile_target_compatibility
352     options.compilerArgs = additional_compiler_args
353     print ("Setting target compatibility to "+targetCompatibility+"\n")
354   }
355
356 }
357
358 compileTestJava {
359   if (use_clover) {
360     dependsOn compileCloverJava
361     classpath += configurations.cloverRuntime
362   } else {
363     classpath += sourceSets.main.runtimeClasspath
364   }
365   doFirst {
366     sourceCompatibility = compile_source_compatibility
367     targetCompatibility = compile_target_compatibility
368     options.compilerArgs = additional_compiler_args
369     print ("Setting target compatibility to "+targetCompatibility+"\n")
370   }
371 }
372
373
374 compileCloverJava {
375
376   doFirst {
377     sourceCompatibility = compile_source_compatibility
378     targetCompatibility = compile_target_compatibility
379     options.compilerArgs += additional_compiler_args
380     print ("Setting target compatibility to "+targetCompatibility+"\n")
381   }
382   classpath += configurations.cloverRuntime
383 }
384
385 clean {
386   delete sourceSets.main.java.outputDir
387 }
388
389 cleanTest {
390   delete sourceSets.test.java.outputDir
391   delete cloverInstrDir
392 }
393
394 def getDate(format) {
395   def date = new Date()
396   //return date.format("dd MMMM yyyy")
397   return date.format(format)
398 }
399
400 def getGitHash() {
401   def stdout = new ByteArrayOutputStream()
402   exec {
403     commandLine "git", "rev-parse", "--short", "HEAD"
404     standardOutput = stdout
405     workingDir = jalviewDir
406   }
407   return stdout.toString().trim()
408 }
409
410 def getGitBranch() {
411   def stdout = new ByteArrayOutputStream()
412   exec {
413     commandLine "git", "rev-parse", "--abbrev-ref", "HEAD"
414     standardOutput = stdout
415     workingDir = jalviewDir
416   }
417   return stdout.toString().trim()
418 }
419
420 task createBuildProperties(type: WriteProperties) {
421   inputs.dir("$jalviewDir/$sourceDir")
422   inputs.dir("$jalviewDir/$resourceDir")
423   outputFile "$classes/$buildPropertiesFile"
424   /* taking time/date specific comment out to allow better incremental builds */
425   //comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd HH:mm:ss")
426   comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd")
427   property "BUILD_DATE", getDate("dd MMMM yyyy")
428   property "VERSION", JALVIEW_VERSION
429   property "INSTALLATION", INSTALLATION+" git-commit:"+getGitHash()+" ["+getGitBranch()+"]"
430   outputs.file(outputFile)
431   outputs.dir("$classes")
432 }
433
434 task syncDocs(type: Sync) {
435   def syncDir = "$classes/$docDir"
436   from fileTree("$jalviewDir/$docDir")
437   into syncDir
438
439 }
440
441 def helpFile = "$classes/$helpDir/help.jhm"
442 task syncHelp(type: Sync) {
443   inputs.files("$jalviewDir/$helpDir")
444   outputs.files(helpFile)
445
446   def syncDir = "$classes/$helpDir"
447   from fileTree("$jalviewDir/$helpDir")
448   into syncDir
449 }
450
451 task copyHelp(type: Copy) {
452   def inputDir = "$jalviewDir/$helpDir"
453   def outputDir = "$classes/$helpDir"
454   from inputDir
455   into outputDir
456   filter(ReplaceTokens, beginToken: '$$', endToken: '$$', tokens: ['Version-Rel': "USING_FILTER"])
457   inputs.dir(inputDir)
458   outputs.files(helpFile)
459   outputs.dir(outputDir)
460 }
461
462 task syncLib(type: Sync) {
463   def syncDir = "$classes/$libDistDir"
464   from fileTree("$jalviewDir/$libDistDir")
465   into syncDir
466 }
467
468 task syncResources(type: Sync) {
469   from "$jalviewDir/$resourceDir"
470   include "**/*.*"
471   exclude "install4j"
472   into "$classes"
473   preserve {
474     include "**"
475   }
476 }
477
478 task prepare {
479   dependsOn syncResources
480   dependsOn syncDocs
481   dependsOn copyHelp
482 }
483
484
485 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
486 test {
487   dependsOn prepare
488   dependsOn compileJava
489   if (use_clover) {
490     dependsOn cloverInstr
491   }
492
493   print("Running tests " + (use_clover?"WITH":"WITHOUT") + " clover [clover="+use_clover+"]\n") 
494   
495   useTestNG() {
496     includeGroups testngGroups
497     preserveOrder true
498     useDefaultListeners=true
499   }
500   
501   workingDir = jalviewDir
502   //systemProperties 'clover.jar' System.properties.clover.jar
503   sourceCompatibility = compile_source_compatibility
504   targetCompatibility = compile_target_compatibility
505   jvmArgs += additional_compiler_args
506   print ("Setting target compatibility to "+targetCompatibility+"\n")
507 }
508
509 task buildIndices(type: JavaExec) {
510   dependsOn copyHelp
511   classpath = sourceSets.main.compileClasspath
512   main = "com.sun.java.help.search.Indexer"
513   workingDir = "$classes/$helpDir"
514   def argDir = "html"
515   args = [ argDir ]
516   inputs.dir("$workingDir/$argDir")
517
518   outputs.dir("$classes/doc")
519   outputs.dir("$classes/help")
520   outputs.file("$workingDir/JavaHelpSearch/DOCS")
521   outputs.file("$workingDir/JavaHelpSearch/DOCS.TAB")
522   outputs.file("$workingDir/JavaHelpSearch/OFFSETS")
523   outputs.file("$workingDir/JavaHelpSearch/POSITIONS")
524   outputs.file("$workingDir/JavaHelpSearch/SCHEMA")
525   outputs.file("$workingDir/JavaHelpSearch/TMAP")
526 }
527
528 task compileLinkCheck(type: JavaCompile) {
529   options.fork = true
530   classpath = files("$jalviewDir/$utilsDir")
531   destinationDir = file("$jalviewDir/$utilsDir")
532   source = fileTree(dir: "$jalviewDir/$utilsDir", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
533
534   outputs.file("$jalviewDir/$utilsDir/HelpLinksChecker.class")
535   outputs.file("$jalviewDir/$utilsDir/BufferedLineReader.class")
536 }
537
538 def helplinkscheckeroutputfile = file("$jalviewDir/$utilsDir/HelpLinksChecker.out")
539 task linkCheck(type: JavaExec) {
540   dependsOn prepare, compileLinkCheck
541   classpath = files("$jalviewDir/$utilsDir")
542   main = "HelpLinksChecker"
543   workingDir = jalviewDir
544   def help = "$classes/$helpDir"
545   args = [ "$classes/$helpDir", "-nointernet" ]
546   //args = [ "$classesDir/$helpDir", "-nointernet" ]
547
548   doFirst {
549     helplinkscheckeroutputfile.createNewFile()
550     standardOutput new FileOutputStream(helplinkscheckeroutputfile, false)
551   }
552
553   outputs.file(helplinkscheckeroutputfile)
554 }
555
556 task cleanPackageDir(type: Delete) {
557   delete fileTree("$jalviewDir/$packageDir").include("*.jar")
558 }
559
560 jar {
561   dependsOn linkCheck
562   dependsOn buildIndices
563   dependsOn createBuildProperties
564
565   manifest {
566     attributes "Main-Class": mainClass,
567     "Permissions": "all-permissions",
568     "Application-Name": "Jalview Desktop",
569     "Codebase": application_codebase
570   }
571
572   destinationDir = file("$jalviewDir/$packageDir")
573   archiveName = rootProject.name+".jar"
574
575   exclude "cache*/**"
576   exclude "*.jar"
577   exclude "*.jar.*"
578   exclude "**/*.jar"
579   exclude "**/*.jar.*"
580
581   inputs.dir("$classes")
582   outputs.file("$jalviewDir/$packageDir/$archiveName")
583 }
584
585 task copyJars(type: Copy) {
586   from fileTree("$classes").include("**/*.jar").include("*.jar").files
587   into "$jalviewDir/$packageDir"
588 }
589
590 // doing a Sync instead of Copy as Copy doesn't deal with "outputs" very well
591 task syncJars(type: Sync) {
592   from fileTree("$jalviewDir/$libDistDir").include("**/*.jar").include("*.jar").files
593   into "$jalviewDir/$packageDir"
594   preserve {
595     include jar.archiveName
596   }
597 }
598
599 task makeDist {
600   group = "build"
601   description = "Put all required libraries in dist"
602   // order of "cleanPackageDir", "copyJars", "jar" important!
603   jar.mustRunAfter cleanPackageDir
604   syncJars.mustRunAfter cleanPackageDir
605   dependsOn cleanPackageDir
606   dependsOn syncJars
607   dependsOn jar
608   outputs.dir("$jalviewDir/$packageDir")
609 }
610
611 task cleanDist {
612   dependsOn cleanPackageDir
613   dependsOn cleanTest
614   dependsOn clean
615 }
616
617 shadowJar {
618   dependsOn makeDist
619   from ("$jalviewDir/$libDistDir") {
620       include("*.jar")
621   }
622   mainClassName = shadowJarMainClass
623   mergeServiceFiles()
624   classifier = "all-"+JAVA_VERSION
625   minimize()
626 }
627
628 task getdownWebsite() {
629   group = "distribution"
630   description = "Create the getdown minimal app folder, and website folder for this version of jalview. Website folder also used for offline app installer"
631   dependsOn makeDist
632   def getdownWebsiteResourceFilenames = []
633   def getdownTextString = ""
634   def getdownResourceDir = project.ext.getdownResourceDir
635   def getdownAppDir = project.ext.getdownAppDir
636   def getdownResourceFilenames = []
637   doFirst {
638     // go through properties looking for getdown_txt_...
639     def props = project.properties.sort { it.key }
640     props.put("getdown_txt_java_min_version", getdown_alt_java_min_version)
641     props.put("getdown_txt_multi_java_location", getdown_alt_multi_java_location)
642     
643     props.put("getdown_txt_appbase", getdown_app_base)
644     props.each{ prop, val ->
645       if (prop.startsWith("getdown_txt_") && val != null) {
646         if (prop.startsWith("getdown_txt_multi_")) {
647           def key = prop.substring(18)
648           val.split(",").each{ v ->
649             def line = key + " = " + v + "\n"
650             getdownTextString += line
651           }
652         } else {
653           // file values rationalised
654           if (val.indexOf('/') > -1) {
655             def r = null
656             if (val.indexOf('/') == 0) {
657               // absolute path
658               r = file(val)
659             } else if (val.indexOf('/') > 0) {
660               // relative path (relative to jalviewDir)
661               r = file( jalviewDir + '/' + val )
662             }
663             if (r.exists()) {
664               val = getdown_resource_dir + '/' + r.getName()
665               getdownWebsiteResourceFilenames += val
666               getdownResourceFilenames += r.getPath()
667             }
668           }
669           def line = prop.substring(12) + " = " + val + "\n"
670           getdownTextString += line
671         }
672       }
673     }
674
675     getdownWebsiteResourceFilenames.each{ filename ->
676       getdownTextString += "resource = "+filename+"\n"
677     }
678     getdownResourceFilenames.each{ filename ->
679       copy {
680         from filename
681         into project.ext.getdownResourceDir
682       }
683     }
684
685     def codeFiles = []
686     makeDist.outputs.files.each{ f ->
687       if (f.isDirectory()) {
688         def files = fileTree(dir: f, include: ["*"]).getFiles()
689         codeFiles += files
690       } else if (f.exists()) {
691         codeFiles += f
692       }
693     }
694     codeFiles.sort().each{f ->
695       def line = "code = " + getdown_app_dir + '/' + f.getName() + "\n"
696       getdownTextString += line
697       copy {
698         from f.getPath()
699         into project.ext.getdownAppDir
700       }
701     }
702
703     // NOT USING MODULES YET, EVERYTHING SHOULD BE IN dist
704     /*
705     if (JAVA_VERSION.equals("11")) {
706       def j11libFiles = fileTree(dir: "$jalviewDir/$j11libDir", include: ["*.jar"]).getFiles()
707       j11libFiles.sort().each{f ->
708         def line = "code = " + getdown_j11lib_dir + '/' + f.getName() + "\n"
709         getdownTextString += line
710         copy {
711           from f.getPath()
712           into project.ext.getdownJ11libDir
713         }
714       }
715     }
716     */
717
718     getdownTextString += "code = " + file(getdownLauncher).getName() + "\n"
719     getdownTextString += "class = " + mainClass + "\n"
720
721     def getdown_txt = file(project.ext.getdownWebsiteDir + "/getdown.txt")
722     getdown_txt.write(getdownTextString)
723
724     copy {
725       from getdown_txt
726       into project.ext.getdownFilesDir
727     }
728
729     copy {
730       from getdownLauncher
731       into project.ext.getdownFilesDir
732     }
733
734     copy {
735       from getdownLauncher
736       into project.ext.getdownWebsiteDir
737     }
738
739     copy {
740       from getdownLib1
741       into project.ext.getdownFilesDir + '/' + packageDir
742     }
743
744     copy {
745       from jalviewDir + '/' + project.getProperty('getdown_txt_ui.background_image')
746       from jalviewDir + '/' + project.getProperty('getdown_txt_ui.error_background')
747       from jalviewDir + '/' + project.getProperty('getdown_txt_ui.progress_image')
748       from jalviewDir + '/' + project.getProperty('getdown_txt_ui.icon')
749       from jalviewDir + '/' + project.getProperty('getdown_txt_ui.mac_dock_icon')
750       into project.ext.getdownFilesDir + '/' + getdown_resource_dir 
751     }
752   }
753
754   inputs.dir(jalviewDir + '/' + packageDir)
755   outputs.dir(project.ext.getdownWebsiteDir)
756   outputs.dir(project.ext.getdownFilesDir)
757 }
758
759 task getdownDigest(type: JavaExec) {
760   group = "distribution"
761   description = "Digest the getdown website folder"
762   dependsOn getdownWebsite
763   classpath = files(jalviewDir + '/' + getdown_core)
764   classpath file(jalviewDir + '/' + getdown_lib1)
765   main = "com.threerings.getdown.tools.Digester"
766   args project.ext.getdownWebsiteDir
767   outputs.file(project.ext.getdownWebsiteDir + '/' + "digest2.txt")
768 }
769
770 task getdown() {
771   group = "distribution"
772   description = "Create the minimal and full getdown app folder for installers and website and create digest file"
773   dependsOn getdownDigest
774 }
775
776 clean {
777   delete project.ext.getdownWebsiteDir
778   delete project.ext.getdownFilesDir
779 }
780
781 install4j {
782   def install4jHomeDir = "/opt/install4j"
783   def hostname = "hostname".execute().text.trim()
784   if (hostname.equals("jv-bamboo")) {
785     install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
786   } else if (OperatingSystem.current().isMacOsX()) {
787     install4jHomeDir = '/Applications/install4j.app/Contents/Resources/app'
788     if (! file(install4jHomeDir).exists()) {
789       install4jHomeDir = System.getProperty("user.home")+install4jHomeDir
790     }
791   } else if (OperatingSystem.current().isLinux()) {
792     install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
793   }
794   installDir = file(install4jHomeDir)
795   mediaTypes = Arrays.asList(install4jMediaTypes.split(","))
796 }
797
798 def install4jConf
799 def macosJavaVMDir
800 def windowsJavaVMDir
801 def install4jDir = "$jalviewDir/$install4jResourceDir"
802 def install4jConfFile = "jalview-installers-java"+JAVA_VERSION+".install4j"
803 install4jConf = "$install4jDir/$install4jConfFile"
804   
805 task copyInstall4jTemplate(type: Copy) {
806   macosJavaVMDir = System.env.HOME+"/buildtools/jre/openjdk-java_vm/macos-jre"+JAVA_VERSION+"/java_vm"
807   windowsJavaVMDir = System.env.HOME+"/buildtools/jre/openjdk-java_vm/windows-jre"+JAVA_VERSION+"/java_vm"
808   from (install4jDir) {
809     include install4jTemplate
810     rename (install4jTemplate, install4jConfFile)
811     filter(ReplaceTokens, beginToken: '', endToken: '', tokens: ['9999999999': JAVA_VERSION])
812     filter(ReplaceTokens, beginToken: '$$', endToken: '$$', tokens: ['JAVA_VERSION': JAVA_VERSION, 'VERSION': JALVIEW_VERSION, 'MACOS_JAVA_VM_DIR': macosJavaVMDir, 'WINDOWS_JAVA_VM_DIR': windowsJavaVMDir])
813   }
814   into install4jDir
815   inputs.files("$install4jDir/$install4jTemplate")
816   outputs.files(install4jConf)
817 }
818
819 task installers(type: com.install4j.gradle.Install4jTask) {
820   group = "distribution"
821   description = "Create the install4j installers"
822   dependsOn getdown
823   dependsOn copyInstall4jTemplate
824   projectFile = file(install4jConf)
825   println("Using projectFile "+projectFile)
826   variables = [majorVersion: version.substring(2, 11), build: 001]
827   destination = "$jalviewDir/$install4jBuildDir/$JAVA_VERSION"
828   buildSelected = true
829   inputs.dir(project.ext.getdownWebsiteDir)
830   inputs.file(install4jConf)
831   inputs.dir(macosJavaVMDir)
832   inputs.dir(windowsJavaVMDir)
833   outputs.dir("$jalviewDir/$install4jBuildDir/$JAVA_VERSION")
834 }
835
836 clean {
837   delete install4jConf
838 }