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
123 compileClasspath += files( sourceSets.main.resources.srcDirs)
124 compileClasspath += fileTree(dir: "$jalviewDir/$utilsDir", include: ["**/*.jar"])
125 compileClasspath += fileTree(dir: "$jalviewDir/$libDir", include: ["*.jar"])
127 runtimeClasspath = compileClasspath
134 cloverCompile 'org.openclover:clover:4.3.1'
135 testCompile 'org.openclover:clover:4.3.1'
141 cloverRuntime.extendsFrom cloverCompile
145 // only instrument source, we build test classes as normal
146 inputs.files files (sourceSets.main.allJava) // , fileTree(dir:"$jalviewDir/$testSourceDir", include: ["**/*.java"]))
147 outputs.dir cloverInstrDir
150 delete cloverInstrDir
151 def argsList = ["--initstring", "${buildDir}/clover/clover.db",
152 "-d", "${buildDir}/${cloverSourcesInstrDir}"]
153 argsList.addAll(inputs.files.files.collect({ file ->
156 String[] args = argsList.toArray()
157 println("About to instrument "+args.length +" files")
158 com.atlassian.clover.CloverInstr.mainImpl(args)
164 inputs.dir "${buildDir}/clover"
165 outputs.dir "${reportsDir}/clover"
167 file("${buildDir}/clover/clover.db").exists()
170 def argsList = ["--initstring", "${buildDir}/clover/clover.db",
171 "-o", "${reportsDir}/clover"]
172 String[] args = argsList.toArray()
173 com.atlassian.clover.reporters.html.HtmlReporter.runReport(args)
175 // and generate ${reportsDir}/clover/clover.xml
176 args = ["--initstring", "${buildDir}/clover/clover.db",
177 "-o", "${reportsDir}/clover/clover.xml"].toArray()
178 com.atlassian.clover.reporters.xml.XMLReporter.runReport(args)
188 sourceCompatibility = compile_source_compatibility
189 targetCompatibility = compile_target_compatibility
190 options.compilerArgs = additional_compiler_args
191 print ("Setting target compatibility to "+targetCompatibility+"\n")
198 dependsOn compileCloverJava
199 classpath += configurations.cloverRuntime
202 sourceCompatibility = compile_source_compatibility
203 targetCompatibility = compile_target_compatibility
204 options.compilerArgs = additional_compiler_args
205 print ("Setting target compatibility to "+targetCompatibility+"\n")
213 sourceCompatibility = compile_source_compatibility
214 targetCompatibility = compile_target_compatibility
215 options.compilerArgs += additional_compiler_args
216 print ("Setting target compatibility to "+targetCompatibility+"\n")
218 classpath += configurations.cloverRuntime
222 delete sourceSets.main.java.outputDir
226 delete sourceSets.test.java.outputDir
227 delete cloverInstrDir
230 def getDate(format) {
231 def date = new Date()
232 //return date.format("dd MMMM yyyy")
233 return date.format(format)
237 def stdout = new ByteArrayOutputStream()
239 commandLine "git", "rev-parse", "--short", "HEAD"
240 standardOutput = stdout
241 workingDir = jalviewDir
243 return stdout.toString().trim()
247 def stdout = new ByteArrayOutputStream()
249 commandLine "git", "rev-parse", "--abbrev-ref", "HEAD"
250 standardOutput = stdout
251 workingDir = jalviewDir
253 return stdout.toString().trim()
256 task createBuildProperties(type: WriteProperties) {
257 inputs.dir("$jalviewDir/$sourceDir")
258 inputs.dir("$jalviewDir/$resourceDir")
259 outputFile "$classes/$buildPropertiesFile"
260 /* taking time/date specific comment out to allow better incremental builds */
261 //comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd HH:mm:ss")
262 comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd")
263 property "BUILD_DATE", getDate("dd MMMM yyyy")
264 property "VERSION", JALVIEW_VERSION
265 property "INSTALLATION", INSTALLATION+" git-commit:"+getGitHash()+" ["+getGitBranch()+"]"
266 outputs.file(outputFile)
267 outputs.dir("$classes")
270 task syncDocs(type: Sync) {
271 def syncDir = "$classes/$docDir"
272 from fileTree("$jalviewDir/$docDir")
277 def helpFile = "$classes/$helpDir/help.jhm"
278 task syncHelp(type: Sync) {
279 inputs.files("$jalviewDir/$helpDir")
280 outputs.files(helpFile)
282 def syncDir = "$classes/$helpDir"
283 from fileTree("$jalviewDir/$helpDir")
287 task copyHelp(type: Copy) {
288 def inputDir = "$jalviewDir/$helpDir"
289 def outputDir = "$classes/$helpDir"
292 filter(ReplaceTokens, beginToken: '$$', endToken: '$$', tokens: ['Version-Rel': "USING_FILTER"])
294 outputs.files(helpFile)
295 outputs.dir(outputDir)
298 task syncLib(type: Sync) {
299 def syncDir = "$classes/$libDir"
300 from fileTree("$jalviewDir/$libDir")
304 task syncResources(type: Sync) {
305 from "$jalviewDir/$resourceDir"
315 dependsOn syncResources
321 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
325 dependsOn cloverInstr
327 print("Running tests " + (clover?"WITH":"WITHOUT") + " clover [clover="+clover+"]\n")
330 includeGroups testngGroups
332 useDefaultListeners=true
335 workingDir = jalviewDir
336 //systemProperties 'clover.jar' System.properties.clover.jar
337 sourceCompatibility = compile_source_compatibility
338 targetCompatibility = compile_target_compatibility
339 jvmArgs += additional_compiler_args
340 print ("Setting target compatibility to "+targetCompatibility+"\n")
343 task buildIndices(type: JavaExec) {
345 classpath = sourceSets.main.compileClasspath
346 main = "com.sun.java.help.search.Indexer"
347 workingDir = "$classes/$helpDir"
350 inputs.dir("$workingDir/$argDir")
352 outputs.dir("$classes/doc")
353 outputs.dir("$classes/help")
354 outputs.file("$workingDir/JavaHelpSearch/DOCS")
355 outputs.file("$workingDir/JavaHelpSearch/DOCS.TAB")
356 outputs.file("$workingDir/JavaHelpSearch/OFFSETS")
357 outputs.file("$workingDir/JavaHelpSearch/POSITIONS")
358 outputs.file("$workingDir/JavaHelpSearch/SCHEMA")
359 outputs.file("$workingDir/JavaHelpSearch/TMAP")
362 task compileLinkCheck(type: JavaCompile) {
364 classpath = files("$jalviewDir/$utilsDir")
365 destinationDir = file("$jalviewDir/$utilsDir")
366 source = fileTree(dir: "$jalviewDir/$utilsDir", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
368 outputs.file("$jalviewDir/$utilsDir/HelpLinksChecker.class")
369 outputs.file("$jalviewDir/$utilsDir/BufferedLineReader.class")
372 task linkCheck(type: JavaExec) {
373 dependsOn prepare, compileLinkCheck
374 classpath = files("$jalviewDir/$utilsDir")
375 main = "HelpLinksChecker"
376 workingDir = jalviewDir
377 def help = "$classes/$helpDir"
378 args = [ "$classes/$helpDir", "-nointernet" ]
379 //args = [ "$classesDir/$helpDir", "-nointernet" ]
382 standardOutput new FileOutputStream("$jalviewDir/$utilsDir/HelpLinksChecker.out")
385 outputs.file("$jalviewDir/$utilsDir/HelpLinksChecker.out")
388 task cleanPackageDir(type: Delete) {
389 delete fileTree("$jalviewDir/$packageDir").include("*.jar")
394 dependsOn buildIndices
395 dependsOn createBuildProperties
398 attributes "Main-Class": mainClass,
399 "Permissions": "all-permissions",
400 "Application-Name": "Jalview Desktop",
401 "Codebase": application_codebase
404 destinationDir = file("$jalviewDir/$packageDir")
405 archiveName = rootProject.name+".jar"
413 inputs.dir("$classes")
414 outputs.file("$jalviewDir/$packageDir/$archiveName")
417 task copyJars(type: Copy) {
418 from fileTree("$classes").include("**/*.jar").include("*.jar").files
419 into "$jalviewDir/$packageDir"
422 // doing a Sync instead of Copy as Copy doesn't deal with "outputs" very well
423 task syncJars(type: Sync) {
424 from fileTree("$jalviewDir/$libDir").include("**/*.jar").include("*.jar").files
425 into "$jalviewDir/$packageDir"
427 include jar.archiveName
432 // order of "cleanPackageDir", "copyJars", "jar" important!
433 jar.mustRunAfter cleanPackageDir
434 syncJars.mustRunAfter cleanPackageDir
435 dependsOn cleanPackageDir
438 outputs.dir("$jalviewDir/$packageDir")
442 dependsOn cleanPackageDir
449 if (JAVA_VERSION.equals("11")) {
450 from ("$jalviewDir/$j11libDir") {
454 mainClassName = shadowJarMainClass
461 getdownWebsiteDir = jalviewDir + '/' + getdown_website_dir
462 getdownAppDir = getdownWebsiteDir + '/' + getdown_app_dir
463 getdownJ11libDir = getdownWebsiteDir + '/' + getdown_j11lib_dir
464 getdownResourceDir = getdownWebsiteDir + '/' + getdown_resource_dir
465 getdownLauncher = jalviewDir + '/' + getdown_launcher
466 getdownFilesDir = jalviewDir + '/' + getdown_files_dir
467 getdownLib1 = jalviewDir + '/' + getdown_lib1
468 def getdownChannel = getdown_channel_name
469 if (getdown_channel_name.equals("COMMIT")) {
470 getdownChannel = getGitHash()
472 getdown_app_base = getdown_channel_base+"/"+JAVA_VERSION+"/"+getdownChannel+"/"
475 task getdownWebsite() {
477 def getdownWebsiteResourceFilenames = []
478 def getdownTextString = ""
479 def getdownResourceDir = project.ext.getdownResourceDir
480 def getdownAppDir = project.ext.getdownAppDir
481 def getdownResourceFilenames = []
483 // go through properties looking for getdown_txt_...
484 def props = project.properties.sort { it.key }
485 props.put("getdown_txt_java_min_version", getdown_alt_java_min_version)
486 props.put("getdown_txt_appbase", getdown_app_base)
487 props.each{ prop, val ->
488 if (prop.startsWith("getdown_txt_") && val != null) {
489 if (prop.startsWith("getdown_txt_multi_")) {
490 def key = prop.substring(18)
491 val.split(",").each{ v ->
492 def line = key + " = " + v + "\n"
493 getdownTextString += line
496 // file values rationalised
497 if (val.indexOf('/') > -1) {
499 if (val.indexOf('/') == 0) {
502 } else if (val.indexOf('/') > 0) {
503 // relative path (relative to jalviewDir)
504 r = file( jalviewDir + '/' + val )
507 val = getdown_resource_dir + '/' + r.getName()
508 getdownWebsiteResourceFilenames += val
509 getdownResourceFilenames += r.getPath()
512 def line = prop.substring(12) + " = " + val + "\n"
513 getdownTextString += line
518 getdownWebsiteResourceFilenames.each{ filename ->
519 getdownTextString += "resource = "+filename+"\n"
521 getdownResourceFilenames.each{ filename ->
524 into project.ext.getdownResourceDir
529 makeDist.outputs.files.each{ f ->
530 if (f.isDirectory()) {
531 def files = fileTree(dir: f, include: ["*"]).getFiles()
533 } else if (f.exists()) {
537 codeFiles.sort().each{f ->
538 def line = "code = " + getdown_app_dir + '/' + f.getName() + "\n"
539 getdownTextString += line
542 into project.ext.getdownAppDir
546 if (JAVA_VERSION.equals("11")) {
547 def j11libFiles = fileTree(dir: "$jalviewDir/$j11libDir", include: ["*.jar"]).getFiles()
548 j11libFiles.sort().each{f ->
549 def line = "code = " + getdown_j11lib_dir + '/' + f.getName() + "\n"
550 getdownTextString += line
553 into project.ext.getdownJ11libDir
558 getdownTextString += "code = " + file(getdownLauncher).getName() + "\n"
559 getdownTextString += "class = " + mainClass + "\n"
561 def getdown_txt = file(project.ext.getdownWebsiteDir + "/getdown.txt")
562 getdown_txt.write(getdownTextString)
566 into project.ext.getdownFilesDir
571 into project.ext.getdownWebsiteDir
576 into project.ext.getdownFilesDir
581 into project.ext.getdownFilesDir
586 into project.ext.getdownWebsiteDir
590 from jalviewDir + '/' + project.getProperty('getdown_txt_ui.background_image')
591 from jalviewDir + '/' + project.getProperty('getdown_txt_ui.error_background')
592 from jalviewDir + '/' + project.getProperty('getdown_txt_ui.progress_image')
593 from jalviewDir + '/' + project.getProperty('getdown_txt_ui.icon')
594 from jalviewDir + '/' + project.getProperty('getdown_txt_ui.mac_dock_icon')
595 into project.ext.getdownFilesDir + '/' + getdown_resource_dir
599 inputs.dir(jalviewDir + '/' + packageDir)
600 outputs.dir(project.ext.getdownWebsiteDir)
601 outputs.dir(project.ext.getdownFilesDir)
604 task getdownDigest(type: JavaExec) {
605 dependsOn getdownWebsite
606 classpath = files(jalviewDir + '/' + getdown_core)
607 classpath file(jalviewDir + '/' + getdown_lib1)
608 main = "com.threerings.getdown.tools.Digester"
609 args project.ext.getdownWebsiteDir
610 outputs.file(project.ext.getdownWebsiteDir + '/' + "digest2.txt")
614 dependsOn getdownDigest
618 delete project.ext.getdownWebsiteDir
619 delete project.ext.getdownFilesDir
623 def install4jHomeDir = "/opt/install4j"
624 def hostname = "hostname".execute().text.trim()
625 if (hostname.equals("jv-bamboo")) {
626 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
627 } else if (OperatingSystem.current().isMacOsX()) {
628 install4jHomeDir = '/Applications/install4j.app/Contents/Resources/app'
629 if (! file(install4jHomeDir).exists()) {
630 install4jHomeDir = System.getProperty("user.home")+install4jHomeDir
632 } else if (OperatingSystem.current().isLinux()) {
633 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
635 installDir = file(install4jHomeDir)
636 mediaTypes = Arrays.asList(install4jMediaTypes.split(","))
642 task copyInstall4jTemplate(type: Copy) {
643 def install4jDir = "$jalviewDir/$install4jResourceDir"
644 def install4jConfFile = "jalview-installers-java"+JAVA_VERSION+".install4j"
645 macosJavaVMDir = System.env.HOME+"/buildtools/jre/openjdk-java_vm/macos-jre"+JAVA_VERSION+"/java_vm"
646 windowsJavaVMDir = System.env.HOME+"/buildtools/jre/openjdk-java_vm/windows-jre"+JAVA_VERSION+"/java_vm"
647 from (install4jDir) {
648 include install4jTemplate
649 rename (install4jTemplate, install4jConfFile)
650 filter(ReplaceTokens, beginToken: '', endToken: '', tokens: ['9999999999': JAVA_VERSION])
651 filter(ReplaceTokens, beginToken: '$$', endToken: '$$', tokens: ['VERSION': JALVIEW_VERSION, 'MACOS_JAVA_VM_DIR': macosJavaVMDir, 'WINDOWS_JAVA_VM_DIR': windowsJavaVMDir])
654 install4jConf = "$install4jDir/$install4jConfFile"
655 inputs.files("$install4jDir/$install4jTemplate")
656 outputs.files(install4jConf)
659 task installers(type: com.install4j.gradle.Install4jTask) {
661 dependsOn copyInstall4jTemplate
662 projectFile = install4jConf
663 variables = [majorVersion: version.substring(2, 11), build: 001]
664 destination = "$jalviewDir/$install4jBuildDir"
666 inputs.dir(project.ext.getdownWebsiteDir)
667 inputs.file(install4jConf)
668 inputs.dir(macosJavaVMDir)
669 inputs.dir(windowsJavaVMDir)
670 outputs.dir("$jalviewDir/$install4jBuildDir")