1 import org.apache.tools.ant.filters.ReplaceTokens
2 import org.gradle.internal.os.OperatingSystem
6 classpath 'org.openclover:clover:4.3.1'
7 classpath 'org.apache.commons:commons-compress:1.18'
14 id 'com.github.johnrengelman.shadow' version '4.0.3'
15 id 'com.install4j.gradle' version '7.0.9'
27 mainClassName = launcherClass
28 def cloverInstrDir = file("$buildDir/$cloverSourcesInstrDir")
29 def classes = "$jalviewDir/$classesDir"
30 if (clover.equals("true")) {
32 classes = "$buildDir/$cloverClassesDir"
35 classes = "$jalviewDir/$classesDir"
40 def compile_source_compatibility
41 def compile_target_compatibility
42 def additional_compiler_args = []
43 def getdown_alt_java_min_version
44 if (JAVA_VERSION.equals("1.8")) {
47 compile_source_compatibility = 1.8
48 compile_target_compatibility = 1.8
49 getdown_alt_java_min_version = getdown_alt_java8_min_version
50 } else if (JAVA_VERSION.equals("11")) {
52 libDistDir = j11libDir
53 compile_source_compatibility = 11
54 compile_target_compatibility = 11
55 getdown_alt_java_min_version = getdown_alt_java11_min_version
56 additional_compiler_args += [
57 '--module-path', sourceSets.modules.compileClasspath.asPath,
58 '--add-modules', j11modules
61 throw new GradleException("JAVA_VERSION=$JAVA_VERSION not currently supported by Jalview")
68 srcDirs "$jalviewDir/$sourceDir"
69 outputDir = file("$classes")
73 srcDirs "$jalviewDir/$resourceDir"
74 srcDirs "$jalviewDir/$libDir"
77 jar.destinationDir = file("$jalviewDir/$packageDir")
79 compileClasspath = files(sourceSets.main.java.outputDir)
80 compileClasspath += fileTree(dir: "$jalviewDir/$libDir", include: ["*.jar"])
82 runtimeClasspath = compileClasspath
86 compileClasspath = fileTree(dir: "$jalviewDir/$j11modDir", include: ["*.jar"])
88 runtimeClasspath = compileClasspath
93 srcDirs = [ cloverInstrDir ]
94 outputDir = file("${buildDir}/${cloverClassesDir}")
98 srcDirs = sourceSets.main.resources.srcDirs
100 compileClasspath = configurations.cloverRuntime + files( sourceSets.clover.java.outputDir )
101 compileClasspath += fileTree(dir: "$jalviewDir/$utilsDir", include: ["**/*.jar"])
102 compileClasspath += fileTree(dir: "$jalviewDir/$libDir", include: ["*.jar"])
104 runtimeClasspath = compileClasspath
109 srcDirs "$jalviewDir/$testSourceDir"
110 outputDir = file("$jalviewDir/$testOutputDir")
114 srcDirs = sourceSets.main.resources.srcDirs
117 compileClasspath = files( sourceSets.test.java.outputDir )
119 compileClasspath += sourceSets.clover.compileClasspath
121 compileClasspath += sourceSets.main.compileClasspath
122 compileClasspath += files(sourceSets.main.java.outputDir)
124 compileClasspath += files( sourceSets.main.resources.srcDirs)
125 compileClasspath += fileTree(dir: "$jalviewDir/$utilsDir", include: ["**/*.jar"])
126 compileClasspath += fileTree(dir: "$jalviewDir/$libDir", include: ["*.jar"])
128 runtimeClasspath = compileClasspath
135 cloverCompile 'org.openclover:clover:4.3.1'
136 testCompile 'org.openclover:clover:4.3.1'
142 cloverRuntime.extendsFrom cloverCompile
146 // only instrument source, we build test classes as normal
147 inputs.files files (sourceSets.main.allJava) // , fileTree(dir:"$jalviewDir/$testSourceDir", include: ["**/*.java"]))
148 outputs.dir cloverInstrDir
151 delete cloverInstrDir
152 def argsList = ["--initstring", "${buildDir}/clover/clover.db",
153 "-d", "${buildDir}/${cloverSourcesInstrDir}"]
154 argsList.addAll(inputs.files.files.collect({ file ->
157 String[] args = argsList.toArray()
158 println("About to instrument "+args.length +" files")
159 com.atlassian.clover.CloverInstr.mainImpl(args)
165 inputs.dir "${buildDir}/clover"
166 outputs.dir "${reportsDir}/clover"
168 file("${buildDir}/clover/clover.db").exists()
171 def argsList = ["--initstring", "${buildDir}/clover/clover.db",
172 "-o", "${reportsDir}/clover"]
173 String[] args = argsList.toArray()
174 com.atlassian.clover.reporters.html.HtmlReporter.runReport(args)
176 // and generate ${reportsDir}/clover/clover.xml
177 args = ["--initstring", "${buildDir}/clover/clover.db",
178 "-o", "${reportsDir}/clover/clover.xml"].toArray()
179 com.atlassian.clover.reporters.xml.XMLReporter.runReport(args)
189 sourceCompatibility = compile_source_compatibility
190 targetCompatibility = compile_target_compatibility
191 options.compilerArgs = additional_compiler_args
192 print ("Setting target compatibility to "+targetCompatibility+"\n")
200 dependsOn compileCloverJava
201 classpath += configurations.cloverRuntime
203 classpath += sourceSets.main.runtimeClasspath
206 sourceCompatibility = compile_source_compatibility
207 targetCompatibility = compile_target_compatibility
208 options.compilerArgs = additional_compiler_args
209 print ("Setting target compatibility to "+targetCompatibility+"\n")
217 sourceCompatibility = compile_source_compatibility
218 targetCompatibility = compile_target_compatibility
219 options.compilerArgs += additional_compiler_args
220 print ("Setting target compatibility to "+targetCompatibility+"\n")
222 classpath += configurations.cloverRuntime
226 delete sourceSets.main.java.outputDir
230 delete sourceSets.test.java.outputDir
231 delete cloverInstrDir
234 def getDate(format) {
235 def date = new Date()
236 //return date.format("dd MMMM yyyy")
237 return date.format(format)
241 def stdout = new ByteArrayOutputStream()
243 commandLine "git", "rev-parse", "--short", "HEAD"
244 standardOutput = stdout
245 workingDir = jalviewDir
247 return stdout.toString().trim()
251 def stdout = new ByteArrayOutputStream()
253 commandLine "git", "rev-parse", "--abbrev-ref", "HEAD"
254 standardOutput = stdout
255 workingDir = jalviewDir
257 return stdout.toString().trim()
260 task createBuildProperties(type: WriteProperties) {
261 inputs.dir("$jalviewDir/$sourceDir")
262 inputs.dir("$jalviewDir/$resourceDir")
263 outputFile "$classes/$buildPropertiesFile"
264 /* taking time/date specific comment out to allow better incremental builds */
265 //comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd HH:mm:ss")
266 comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd")
267 property "BUILD_DATE", getDate("dd MMMM yyyy")
268 property "VERSION", JALVIEW_VERSION
269 property "INSTALLATION", INSTALLATION+" git-commit:"+getGitHash()+" ["+getGitBranch()+"]"
270 outputs.file(outputFile)
271 outputs.dir("$classes")
274 task syncDocs(type: Sync) {
275 def syncDir = "$classes/$docDir"
276 from fileTree("$jalviewDir/$docDir")
281 def helpFile = "$classes/$helpDir/help.jhm"
282 task syncHelp(type: Sync) {
283 inputs.files("$jalviewDir/$helpDir")
284 outputs.files(helpFile)
286 def syncDir = "$classes/$helpDir"
287 from fileTree("$jalviewDir/$helpDir")
291 task copyHelp(type: Copy) {
292 def inputDir = "$jalviewDir/$helpDir"
293 def outputDir = "$classes/$helpDir"
296 filter(ReplaceTokens, beginToken: '$$', endToken: '$$', tokens: ['Version-Rel': "USING_FILTER"])
298 outputs.files(helpFile)
299 outputs.dir(outputDir)
302 task syncLib(type: Sync) {
303 def syncDir = "$classes/$libDir"
304 from fileTree("$jalviewDir/$libDir")
308 task syncResources(type: Sync) {
309 from "$jalviewDir/$resourceDir"
319 dependsOn syncResources
325 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
328 dependsOn compileJava
330 dependsOn cloverInstr
332 print("Running tests " + (use_clover?"WITH":"WITHOUT") + " clover [clover="+use_clover+"]\n")
335 includeGroups testngGroups
337 useDefaultListeners=true
340 workingDir = jalviewDir
341 //systemProperties 'clover.jar' System.properties.clover.jar
342 sourceCompatibility = compile_source_compatibility
343 targetCompatibility = compile_target_compatibility
344 jvmArgs += additional_compiler_args
345 print ("Setting target compatibility to "+targetCompatibility+"\n")
348 task buildIndices(type: JavaExec) {
350 classpath = sourceSets.main.compileClasspath
351 main = "com.sun.java.help.search.Indexer"
352 workingDir = "$classes/$helpDir"
355 inputs.dir("$workingDir/$argDir")
357 outputs.dir("$classes/doc")
358 outputs.dir("$classes/help")
359 outputs.file("$workingDir/JavaHelpSearch/DOCS")
360 outputs.file("$workingDir/JavaHelpSearch/DOCS.TAB")
361 outputs.file("$workingDir/JavaHelpSearch/OFFSETS")
362 outputs.file("$workingDir/JavaHelpSearch/POSITIONS")
363 outputs.file("$workingDir/JavaHelpSearch/SCHEMA")
364 outputs.file("$workingDir/JavaHelpSearch/TMAP")
367 task compileLinkCheck(type: JavaCompile) {
369 classpath = files("$jalviewDir/$utilsDir")
370 destinationDir = file("$jalviewDir/$utilsDir")
371 source = fileTree(dir: "$jalviewDir/$utilsDir", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
373 outputs.file("$jalviewDir/$utilsDir/HelpLinksChecker.class")
374 outputs.file("$jalviewDir/$utilsDir/BufferedLineReader.class")
377 task linkCheck(type: JavaExec) {
378 dependsOn prepare, compileLinkCheck
379 classpath = files("$jalviewDir/$utilsDir")
380 main = "HelpLinksChecker"
381 workingDir = jalviewDir
382 def help = "$classes/$helpDir"
383 args = [ "$classes/$helpDir", "-nointernet" ]
384 //args = [ "$classesDir/$helpDir", "-nointernet" ]
387 standardOutput new FileOutputStream("$jalviewDir/$utilsDir/HelpLinksChecker.out")
390 outputs.file("$jalviewDir/$utilsDir/HelpLinksChecker.out")
393 task cleanPackageDir(type: Delete) {
394 delete fileTree("$jalviewDir/$packageDir").include("*.jar")
399 dependsOn buildIndices
400 dependsOn createBuildProperties
403 attributes "Main-Class": mainClass,
404 "Permissions": "all-permissions",
405 "Application-Name": "Jalview Desktop",
406 "Codebase": application_codebase
409 destinationDir = file("$jalviewDir/$packageDir")
410 archiveName = rootProject.name+".jar"
418 inputs.dir("$classes")
419 outputs.file("$jalviewDir/$packageDir/$archiveName")
422 task copyJars(type: Copy) {
423 from fileTree("$classes").include("**/*.jar").include("*.jar").files
424 into "$jalviewDir/$packageDir"
427 // doing a Sync instead of Copy as Copy doesn't deal with "outputs" very well
428 task syncJars(type: Sync) {
429 from fileTree("$jalviewDir/$libDir").include("**/*.jar").include("*.jar").files
430 into "$jalviewDir/$packageDir"
432 include jar.archiveName
437 // order of "cleanPackageDir", "copyJars", "jar" important!
438 jar.mustRunAfter cleanPackageDir
439 syncJars.mustRunAfter cleanPackageDir
440 dependsOn cleanPackageDir
443 outputs.dir("$jalviewDir/$packageDir")
447 dependsOn cleanPackageDir
454 if (JAVA_VERSION.equals("11")) {
455 from ("$jalviewDir/$j11libDir") {
459 mainClassName = shadowJarMainClass
466 getdownWebsiteDir = jalviewDir + '/' + getdown_website_dir
467 getdownAppDir = getdownWebsiteDir + '/' + getdown_app_dir
468 getdownJ11libDir = getdownWebsiteDir + '/' + getdown_j11lib_dir
469 getdownResourceDir = getdownWebsiteDir + '/' + getdown_resource_dir
470 getdownLauncher = jalviewDir + '/' + getdown_launcher
471 getdownFilesDir = jalviewDir + '/' + getdown_files_dir
472 getdownLib1 = jalviewDir + '/' + getdown_lib1
473 def getdownChannel = getdown_channel_name
474 if (getdown_channel_name.equals("COMMIT")) {
475 getdownChannel = getGitHash()
477 getdown_app_base = getdown_channel_base+"/"+JAVA_VERSION+"/"+getdownChannel+"/"
480 task getdownWebsite() {
482 def getdownWebsiteResourceFilenames = []
483 def getdownTextString = ""
484 def getdownResourceDir = project.ext.getdownResourceDir
485 def getdownAppDir = project.ext.getdownAppDir
486 def getdownResourceFilenames = []
488 // go through properties looking for getdown_txt_...
489 def props = project.properties.sort { it.key }
490 props.put("getdown_txt_java_min_version", getdown_alt_java_min_version)
491 props.put("getdown_txt_appbase", getdown_app_base)
492 props.each{ prop, val ->
493 if (prop.startsWith("getdown_txt_") && val != null) {
494 if (prop.startsWith("getdown_txt_multi_")) {
495 def key = prop.substring(18)
496 val.split(",").each{ v ->
497 def line = key + " = " + v + "\n"
498 getdownTextString += line
501 // file values rationalised
502 if (val.indexOf('/') > -1) {
504 if (val.indexOf('/') == 0) {
507 } else if (val.indexOf('/') > 0) {
508 // relative path (relative to jalviewDir)
509 r = file( jalviewDir + '/' + val )
512 val = getdown_resource_dir + '/' + r.getName()
513 getdownWebsiteResourceFilenames += val
514 getdownResourceFilenames += r.getPath()
517 def line = prop.substring(12) + " = " + val + "\n"
518 getdownTextString += line
523 getdownWebsiteResourceFilenames.each{ filename ->
524 getdownTextString += "resource = "+filename+"\n"
526 getdownResourceFilenames.each{ filename ->
529 into project.ext.getdownResourceDir
534 makeDist.outputs.files.each{ f ->
535 if (f.isDirectory()) {
536 def files = fileTree(dir: f, include: ["*"]).getFiles()
538 } else if (f.exists()) {
542 codeFiles.sort().each{f ->
543 def line = "code = " + getdown_app_dir + '/' + f.getName() + "\n"
544 getdownTextString += line
547 into project.ext.getdownAppDir
551 if (JAVA_VERSION.equals("11")) {
552 def j11libFiles = fileTree(dir: "$jalviewDir/$j11libDir", include: ["*.jar"]).getFiles()
553 j11libFiles.sort().each{f ->
554 def line = "code = " + getdown_j11lib_dir + '/' + f.getName() + "\n"
555 getdownTextString += line
558 into project.ext.getdownJ11libDir
563 getdownTextString += "code = " + file(getdownLauncher).getName() + "\n"
564 getdownTextString += "class = " + mainClass + "\n"
566 def getdown_txt = file(project.ext.getdownWebsiteDir + "/getdown.txt")
567 getdown_txt.write(getdownTextString)
571 into project.ext.getdownFilesDir
576 into project.ext.getdownWebsiteDir
581 into project.ext.getdownFilesDir
586 into project.ext.getdownFilesDir
591 into project.ext.getdownWebsiteDir
595 from jalviewDir + '/' + project.getProperty('getdown_txt_ui.background_image')
596 from jalviewDir + '/' + project.getProperty('getdown_txt_ui.error_background')
597 from jalviewDir + '/' + project.getProperty('getdown_txt_ui.progress_image')
598 from jalviewDir + '/' + project.getProperty('getdown_txt_ui.icon')
599 from jalviewDir + '/' + project.getProperty('getdown_txt_ui.mac_dock_icon')
600 into project.ext.getdownFilesDir + '/' + getdown_resource_dir
604 inputs.dir(jalviewDir + '/' + packageDir)
605 outputs.dir(project.ext.getdownWebsiteDir)
606 outputs.dir(project.ext.getdownFilesDir)
609 task getdownDigest(type: JavaExec) {
610 dependsOn getdownWebsite
611 classpath = files(jalviewDir + '/' + getdown_core)
612 classpath file(jalviewDir + '/' + getdown_lib1)
613 main = "com.threerings.getdown.tools.Digester"
614 args project.ext.getdownWebsiteDir
615 outputs.file(project.ext.getdownWebsiteDir + '/' + "digest2.txt")
619 dependsOn getdownDigest
623 delete project.ext.getdownWebsiteDir
624 delete project.ext.getdownFilesDir
628 def install4jHomeDir = "/opt/install4j"
629 def hostname = "hostname".execute().text.trim()
630 if (hostname.equals("jv-bamboo")) {
631 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
632 } else if (OperatingSystem.current().isMacOsX()) {
633 install4jHomeDir = '/Applications/install4j.app/Contents/Resources/app'
634 if (! file(install4jHomeDir).exists()) {
635 install4jHomeDir = System.getProperty("user.home")+install4jHomeDir
637 } else if (OperatingSystem.current().isLinux()) {
638 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
640 installDir = file(install4jHomeDir)
641 mediaTypes = Arrays.asList(install4jMediaTypes.split(","))
647 task copyInstall4jTemplate(type: Copy) {
648 def install4jDir = "$jalviewDir/$install4jResourceDir"
649 def install4jConfFile = "jalview-installers-java"+JAVA_VERSION+".install4j"
650 macosJavaVMDir = System.env.HOME+"/buildtools/jre/openjdk-java_vm/macos-jre"+JAVA_VERSION+"/java_vm"
651 windowsJavaVMDir = System.env.HOME+"/buildtools/jre/openjdk-java_vm/windows-jre"+JAVA_VERSION+"/java_vm"
652 from (install4jDir) {
653 include install4jTemplate
654 rename (install4jTemplate, install4jConfFile)
655 filter(ReplaceTokens, beginToken: '', endToken: '', tokens: ['9999999999': JAVA_VERSION])
656 filter(ReplaceTokens, beginToken: '$$', endToken: '$$', tokens: ['VERSION': JALVIEW_VERSION, 'MACOS_JAVA_VM_DIR': macosJavaVMDir, 'WINDOWS_JAVA_VM_DIR': windowsJavaVMDir])
659 install4jConf = "$install4jDir/$install4jConfFile"
660 inputs.files("$install4jDir/$install4jTemplate")
661 outputs.files(install4jConf)
664 task installers(type: com.install4j.gradle.Install4jTask) {
666 dependsOn copyInstall4jTemplate
667 projectFile = install4jConf
668 variables = [majorVersion: version.substring(2, 11), build: 001]
669 destination = "$jalviewDir/$install4jBuildDir"
671 inputs.dir(project.ext.getdownWebsiteDir)
672 inputs.file(install4jConf)
673 inputs.dir(macosJavaVMDir)
674 inputs.dir(windowsJavaVMDir)
675 outputs.dir("$jalviewDir/$install4jBuildDir")