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"
38 // configure classpath/args for j8/j11 compilation
42 def compile_source_compatibility
43 def compile_target_compatibility
44 def additional_compiler_args = []
45 def getdown_alt_java_min_version
46 if (JAVA_VERSION.equals("1.8")) {
49 compile_source_compatibility = 1.8
50 compile_target_compatibility = 1.8
51 getdown_alt_java_min_version = getdown_alt_java8_min_version
52 } else if (JAVA_VERSION.equals("11")) {
54 libDistDir = j11libDir
55 compile_source_compatibility = 11
56 compile_target_compatibility = 11
57 getdown_alt_java_min_version = getdown_alt_java11_min_version
58 additional_compiler_args += [
59 '--module-path', file("$jalviewDir/$j11modDir").getAbsolutePath(),
60 '--add-modules', j11modules
63 throw new GradleException("JAVA_VERSION=$JAVA_VERSION not currently supported by Jalview")
70 srcDirs "$jalviewDir/$sourceDir"
71 outputDir = file("$classes")
75 srcDirs "$jalviewDir/$resourceDir"
76 srcDirs "$jalviewDir/$libDir"
79 jar.destinationDir = file("$jalviewDir/$packageDir")
81 compileClasspath = files(sourceSets.main.java.outputDir)
82 compileClasspath += fileTree(dir: "$jalviewDir/$libDir", include: ["*.jar"])
84 runtimeClasspath = compileClasspath
89 srcDirs = [ cloverInstrDir ]
90 outputDir = file("${buildDir}/${cloverClassesDir}")
94 srcDirs = sourceSets.main.resources.srcDirs
96 compileClasspath = configurations.cloverRuntime + files( sourceSets.clover.java.outputDir )
97 compileClasspath += fileTree(dir: "$jalviewDir/$utilsDir", include: ["**/*.jar"])
98 compileClasspath += fileTree(dir: "$jalviewDir/$libDir", include: ["*.jar"])
100 runtimeClasspath = compileClasspath
105 srcDirs "$jalviewDir/$testSourceDir"
106 outputDir = file("$jalviewDir/$testOutputDir")
110 srcDirs = sourceSets.main.resources.srcDirs
113 compileClasspath = files( sourceSets.test.java.outputDir )
115 compileClasspath += sourceSets.clover.compileClasspath
117 compileClasspath += sourceSets.main.compileClasspath
118 compileClasspath += files(sourceSets.main.java.outputDir)
120 compileClasspath += files( sourceSets.main.resources.srcDirs)
121 compileClasspath += fileTree(dir: "$jalviewDir/$utilsDir", include: ["**/*.jar"])
122 compileClasspath += fileTree(dir: "$jalviewDir/$libDir", include: ["*.jar"])
124 runtimeClasspath = compileClasspath
131 cloverCompile 'org.openclover:clover:4.3.1'
132 testCompile 'org.openclover:clover:4.3.1'
138 cloverRuntime.extendsFrom cloverCompile
142 // only instrument source, we build test classes as normal
143 inputs.files files (sourceSets.main.allJava) // , fileTree(dir:"$jalviewDir/$testSourceDir", include: ["**/*.java"]))
144 outputs.dir cloverInstrDir
147 delete cloverInstrDir
148 def argsList = ["--initstring", "${buildDir}/clover/clover.db",
149 "-d", "${buildDir}/${cloverSourcesInstrDir}"]
150 argsList.addAll(inputs.files.files.collect({ file ->
153 String[] args = argsList.toArray()
154 println("About to instrument "+args.length +" files")
155 com.atlassian.clover.CloverInstr.mainImpl(args)
161 inputs.dir "${buildDir}/clover"
162 outputs.dir "${reportsDir}/clover"
164 file("${buildDir}/clover/clover.db").exists()
167 def argsList = ["--initstring", "${buildDir}/clover/clover.db",
168 "-o", "${reportsDir}/clover"]
169 String[] args = argsList.toArray()
170 com.atlassian.clover.reporters.html.HtmlReporter.runReport(args)
172 // and generate ${reportsDir}/clover/clover.xml
173 args = ["--initstring", "${buildDir}/clover/clover.db",
174 "-o", "${reportsDir}/clover/clover.xml"].toArray()
175 com.atlassian.clover.reporters.xml.XMLReporter.runReport(args)
185 sourceCompatibility = compile_source_compatibility
186 targetCompatibility = compile_target_compatibility
187 options.compilerArgs = additional_compiler_args
188 print ("Setting target compatibility to "+targetCompatibility+"\n")
196 dependsOn compileCloverJava
197 classpath += configurations.cloverRuntime
199 classpath += sourceSets.main.runtimeClasspath
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
324 dependsOn compileJava
326 dependsOn cloverInstr
328 print("Running tests " + (use_clover?"WITH":"WITHOUT") + " clover [clover="+use_clover+"]\n")
331 includeGroups testngGroups
333 useDefaultListeners=true
336 workingDir = jalviewDir
337 //systemProperties 'clover.jar' System.properties.clover.jar
338 sourceCompatibility = compile_source_compatibility
339 targetCompatibility = compile_target_compatibility
340 jvmArgs += additional_compiler_args
341 print ("Setting target compatibility to "+targetCompatibility+"\n")
344 task buildIndices(type: JavaExec) {
346 classpath = sourceSets.main.compileClasspath
347 main = "com.sun.java.help.search.Indexer"
348 workingDir = "$classes/$helpDir"
351 inputs.dir("$workingDir/$argDir")
353 outputs.dir("$classes/doc")
354 outputs.dir("$classes/help")
355 outputs.file("$workingDir/JavaHelpSearch/DOCS")
356 outputs.file("$workingDir/JavaHelpSearch/DOCS.TAB")
357 outputs.file("$workingDir/JavaHelpSearch/OFFSETS")
358 outputs.file("$workingDir/JavaHelpSearch/POSITIONS")
359 outputs.file("$workingDir/JavaHelpSearch/SCHEMA")
360 outputs.file("$workingDir/JavaHelpSearch/TMAP")
363 task compileLinkCheck(type: JavaCompile) {
365 classpath = files("$jalviewDir/$utilsDir")
366 destinationDir = file("$jalviewDir/$utilsDir")
367 source = fileTree(dir: "$jalviewDir/$utilsDir", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
369 outputs.file("$jalviewDir/$utilsDir/HelpLinksChecker.class")
370 outputs.file("$jalviewDir/$utilsDir/BufferedLineReader.class")
373 task linkCheck(type: JavaExec) {
374 dependsOn prepare, compileLinkCheck
375 classpath = files("$jalviewDir/$utilsDir")
376 main = "HelpLinksChecker"
377 workingDir = jalviewDir
378 def help = "$classes/$helpDir"
379 args = [ "$classes/$helpDir", "-nointernet" ]
380 //args = [ "$classesDir/$helpDir", "-nointernet" ]
383 standardOutput new FileOutputStream("$jalviewDir/$utilsDir/HelpLinksChecker.out")
386 outputs.file("$jalviewDir/$utilsDir/HelpLinksChecker.out")
389 task cleanPackageDir(type: Delete) {
390 delete fileTree("$jalviewDir/$packageDir").include("*.jar")
395 dependsOn buildIndices
396 dependsOn createBuildProperties
399 attributes "Main-Class": mainClass,
400 "Permissions": "all-permissions",
401 "Application-Name": "Jalview Desktop",
402 "Codebase": application_codebase
405 destinationDir = file("$jalviewDir/$packageDir")
406 archiveName = rootProject.name+".jar"
414 inputs.dir("$classes")
415 outputs.file("$jalviewDir/$packageDir/$archiveName")
418 task copyJars(type: Copy) {
419 from fileTree("$classes").include("**/*.jar").include("*.jar").files
420 into "$jalviewDir/$packageDir"
423 // doing a Sync instead of Copy as Copy doesn't deal with "outputs" very well
424 task syncJars(type: Sync) {
425 from fileTree("$jalviewDir/$libDir").include("**/*.jar").include("*.jar").files
426 into "$jalviewDir/$packageDir"
428 include jar.archiveName
433 // order of "cleanPackageDir", "copyJars", "jar" important!
434 jar.mustRunAfter cleanPackageDir
435 syncJars.mustRunAfter cleanPackageDir
436 dependsOn cleanPackageDir
439 outputs.dir("$jalviewDir/$packageDir")
443 dependsOn cleanPackageDir
450 if (JAVA_VERSION.equals("11")) {
451 from ("$jalviewDir/$j11libDir") {
455 mainClassName = shadowJarMainClass
462 getdownWebsiteDir = jalviewDir + '/' + getdown_website_dir
463 getdownAppDir = getdownWebsiteDir + '/' + getdown_app_dir
464 getdownJ11libDir = getdownWebsiteDir + '/' + getdown_j11lib_dir
465 getdownResourceDir = getdownWebsiteDir + '/' + getdown_resource_dir
466 getdownLauncher = jalviewDir + '/' + getdown_launcher
467 getdownFilesDir = jalviewDir + '/' + getdown_files_dir
468 getdownLib1 = jalviewDir + '/' + getdown_lib1
469 def getdownChannel = getdown_channel_name
470 if (getdown_channel_name.equals("COMMIT")) {
471 getdownChannel = getGitHash()
473 getdown_app_base = getdown_channel_base+"/"+JAVA_VERSION+"/"+getdownChannel+"/"
476 task getdownWebsite() {
478 def getdownWebsiteResourceFilenames = []
479 def getdownTextString = ""
480 def getdownResourceDir = project.ext.getdownResourceDir
481 def getdownAppDir = project.ext.getdownAppDir
482 def getdownResourceFilenames = []
484 // go through properties looking for getdown_txt_...
485 def props = project.properties.sort { it.key }
486 props.put("getdown_txt_java_min_version", getdown_alt_java_min_version)
487 props.put("getdown_txt_appbase", getdown_app_base)
488 props.each{ prop, val ->
489 if (prop.startsWith("getdown_txt_") && val != null) {
490 if (prop.startsWith("getdown_txt_multi_")) {
491 def key = prop.substring(18)
492 val.split(",").each{ v ->
493 def line = key + " = " + v + "\n"
494 getdownTextString += line
497 // file values rationalised
498 if (val.indexOf('/') > -1) {
500 if (val.indexOf('/') == 0) {
503 } else if (val.indexOf('/') > 0) {
504 // relative path (relative to jalviewDir)
505 r = file( jalviewDir + '/' + val )
508 val = getdown_resource_dir + '/' + r.getName()
509 getdownWebsiteResourceFilenames += val
510 getdownResourceFilenames += r.getPath()
513 def line = prop.substring(12) + " = " + val + "\n"
514 getdownTextString += line
519 getdownWebsiteResourceFilenames.each{ filename ->
520 getdownTextString += "resource = "+filename+"\n"
522 getdownResourceFilenames.each{ filename ->
525 into project.ext.getdownResourceDir
530 makeDist.outputs.files.each{ f ->
531 if (f.isDirectory()) {
532 def files = fileTree(dir: f, include: ["*"]).getFiles()
534 } else if (f.exists()) {
538 codeFiles.sort().each{f ->
539 def line = "code = " + getdown_app_dir + '/' + f.getName() + "\n"
540 getdownTextString += line
543 into project.ext.getdownAppDir
547 if (JAVA_VERSION.equals("11")) {
548 def j11libFiles = fileTree(dir: "$jalviewDir/$j11libDir", include: ["*.jar"]).getFiles()
549 j11libFiles.sort().each{f ->
550 def line = "code = " + getdown_j11lib_dir + '/' + f.getName() + "\n"
551 getdownTextString += line
554 into project.ext.getdownJ11libDir
559 getdownTextString += "code = " + file(getdownLauncher).getName() + "\n"
560 getdownTextString += "class = " + mainClass + "\n"
562 def getdown_txt = file(project.ext.getdownWebsiteDir + "/getdown.txt")
563 getdown_txt.write(getdownTextString)
567 into project.ext.getdownFilesDir
572 into project.ext.getdownWebsiteDir
577 into project.ext.getdownFilesDir
582 into project.ext.getdownFilesDir
587 into project.ext.getdownWebsiteDir
591 from jalviewDir + '/' + project.getProperty('getdown_txt_ui.background_image')
592 from jalviewDir + '/' + project.getProperty('getdown_txt_ui.error_background')
593 from jalviewDir + '/' + project.getProperty('getdown_txt_ui.progress_image')
594 from jalviewDir + '/' + project.getProperty('getdown_txt_ui.icon')
595 from jalviewDir + '/' + project.getProperty('getdown_txt_ui.mac_dock_icon')
596 into project.ext.getdownFilesDir + '/' + getdown_resource_dir
600 inputs.dir(jalviewDir + '/' + packageDir)
601 outputs.dir(project.ext.getdownWebsiteDir)
602 outputs.dir(project.ext.getdownFilesDir)
605 task getdownDigest(type: JavaExec) {
606 dependsOn getdownWebsite
607 classpath = files(jalviewDir + '/' + getdown_core)
608 classpath file(jalviewDir + '/' + getdown_lib1)
609 main = "com.threerings.getdown.tools.Digester"
610 args project.ext.getdownWebsiteDir
611 outputs.file(project.ext.getdownWebsiteDir + '/' + "digest2.txt")
615 dependsOn getdownDigest
619 delete project.ext.getdownWebsiteDir
620 delete project.ext.getdownFilesDir
624 def install4jHomeDir = "/opt/install4j"
625 def hostname = "hostname".execute().text.trim()
626 if (hostname.equals("jv-bamboo")) {
627 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
628 } else if (OperatingSystem.current().isMacOsX()) {
629 install4jHomeDir = '/Applications/install4j.app/Contents/Resources/app'
630 if (! file(install4jHomeDir).exists()) {
631 install4jHomeDir = System.getProperty("user.home")+install4jHomeDir
633 } else if (OperatingSystem.current().isLinux()) {
634 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
636 installDir = file(install4jHomeDir)
637 mediaTypes = Arrays.asList(install4jMediaTypes.split(","))
643 task copyInstall4jTemplate(type: Copy) {
644 def install4jDir = "$jalviewDir/$install4jResourceDir"
645 def install4jConfFile = "jalview-installers-java"+JAVA_VERSION+".install4j"
646 macosJavaVMDir = System.env.HOME+"/buildtools/jre/openjdk-java_vm/macos-jre"+JAVA_VERSION+"/java_vm"
647 windowsJavaVMDir = System.env.HOME+"/buildtools/jre/openjdk-java_vm/windows-jre"+JAVA_VERSION+"/java_vm"
648 from (install4jDir) {
649 include install4jTemplate
650 rename (install4jTemplate, install4jConfFile)
651 filter(ReplaceTokens, beginToken: '', endToken: '', tokens: ['9999999999': JAVA_VERSION])
652 filter(ReplaceTokens, beginToken: '$$', endToken: '$$', tokens: ['VERSION': JALVIEW_VERSION, 'MACOS_JAVA_VM_DIR': macosJavaVMDir, 'WINDOWS_JAVA_VM_DIR': windowsJavaVMDir])
655 install4jConf = "$install4jDir/$install4jConfFile"
656 inputs.files("$install4jDir/$install4jTemplate")
657 outputs.files(install4jConf)
660 task installers(type: com.install4j.gradle.Install4jTask) {
662 dependsOn copyInstall4jTemplate
663 projectFile = file install4jConf
664 variables = [majorVersion: version.substring(2, 11), build: 001]
665 destination = "$jalviewDir/$install4jBuildDir"
667 inputs.dir(project.ext.getdownWebsiteDir)
668 inputs.file(install4jConf)
669 inputs.dir(macosJavaVMDir)
670 inputs.dir(windowsJavaVMDir)
671 outputs.dir("$jalviewDir/$install4jBuildDir")