1 import org.apache.tools.ant.filters.ReplaceTokens
2 import org.gradle.internal.os.OperatingSystem
7 classpath 'org.openclover:clover:4.3.1'
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"
42 srcDirs "$jalviewDir/$sourceDir"
43 outputDir = file("$classes")
47 srcDirs "$jalviewDir/$resourceDir"
48 srcDirs "$jalviewDir/$libDir"
51 jar.destinationDir = file("$jalviewDir/$packageDir")
53 compileClasspath = files(sourceSets.main.java.outputDir)
54 compileClasspath += fileTree(dir: "$jalviewDir/$libDir", include: ["*.jar"])
55 if (JAVA_VERSION.equals("1.8")) {
56 print("ADDING J11LIBS TO CLASSPATH\n")
57 compileClasspath += fileTree(dir: "$jalviewDir/$j11libDir", include: ["*.jar"])
60 runtimeClasspath = compileClasspath
64 compileClasspath = fileTree(dir: "$jalviewDir/$j11libDir", include: ["*.jar"])
66 runtimeClasspath = compileClasspath
71 srcDirs = [ cloverInstrDir ]
72 outputDir = file("${buildDir}/${cloverClassesDir}")
76 srcDirs = sourceSets.main.resources.srcDirs
78 compileClasspath = configurations.cloverRuntime + files( sourceSets.clover.java.outputDir )
79 compileClasspath += fileTree(dir: "$jalviewDir/$utilsDir", include: ["**/*.jar"])
80 compileClasspath += fileTree(dir: "$jalviewDir/$libDir", include: ["*.jar"])
81 if (JAVA_VERSION.equals("1.8")) {
82 print("ADDING J11LIBS TO CLASSPATH\n")
83 compileClasspath += fileTree(dir: "$jalviewDir/$j11libDir", include: ["*.jar"])
86 runtimeClasspath = compileClasspath
91 srcDirs "$jalviewDir/$testSourceDir"
92 outputDir = file("$jalviewDir/$testOutputDir")
96 srcDirs = sourceSets.main.resources.srcDirs
99 compileClasspath = files( sourceSets.test.java.outputDir )
101 compileClasspath += sourceSets.clover.compileClasspath
103 compileClasspath += sourceSets.main.compileClasspath
105 compileClasspath += files( sourceSets.main.resources.srcDirs)
106 compileClasspath += fileTree(dir: "$jalviewDir/$utilsDir", include: ["**/*.jar"])
107 compileClasspath += fileTree(dir: "$jalviewDir/$libDir", include: ["*.jar"])
108 if (JAVA_VERSION.equals("1.8")) {
109 print("ADDING J11LIBS TO CLASSPATH\n")
110 compileClasspath += fileTree(dir: "$jalviewDir/$j11libDir", include: ["*.jar"])
113 runtimeClasspath = compileClasspath
120 cloverCompile 'org.openclover:clover:4.3.1'
121 testCompile 'org.openclover:clover:4.3.1'
127 cloverRuntime.extendsFrom cloverCompile
131 // only instrument source, we build test classes as normal
132 inputs.files files (sourceSets.main.allJava) // , fileTree(dir:"$jalviewDir/$testSourceDir", include: ["**/*.java"]))
133 outputs.dir cloverInstrDir
136 delete cloverInstrDir
137 def argsList = ["--initstring", "${buildDir}/clover/clover.db",
138 "-d", "${buildDir}/${cloverSourcesInstrDir}"]
139 argsList.addAll(inputs.files.files.collect({ file ->
142 String[] args = argsList.toArray()
143 println("About to instrument "+args.length +" files")
144 com.atlassian.clover.CloverInstr.mainImpl(args)
150 inputs.dir "${buildDir}/clover"
151 outputs.dir "${reportsDir}/clover"
153 file("${buildDir}/clover/clover.db").exists()
156 def argsList = ["--initstring", "${buildDir}/clover/clover.db",
157 "-o", "${reportsDir}/clover"]
158 String[] args = argsList.toArray()
159 com.atlassian.clover.reporters.html.HtmlReporter.runReport(args)
161 // and generate ${reportsDir}/clover/clover.xml
162 args = ["--initstring", "${buildDir}/clover/clover.db",
163 "-o", "${reportsDir}/clover/clover.xml"].toArray()
164 com.atlassian.clover.reporters.xml.XMLReporter.runReport(args)
174 if (JAVA_VERSION.equals("1.8")) {
175 sourceCompatibility = 1.8
176 targetCompatibility = 1.8
177 } else if (JAVA_VERSION.equals("11")) {
178 sourceCompatibility = 11
179 targetCompatibility = 11
181 options.compilerArgs = [
182 '--module-path', sourceSets.modules.compileClasspath.asPath,
183 '--add-modules', j11modules
186 print ("Setting target compatibility to "+targetCompatibility+"\n")
193 dependsOn compileCloverJava
194 classpath += configurations.cloverRuntime
197 if (JAVA_VERSION.equals("1.8")) {
198 sourceCompatibility = 1.8
199 targetCompatibility = 1.8
200 } else if (JAVA_VERSION.equals("11")) {
201 sourceCompatibility = 11
202 targetCompatibility = 11
204 options.compilerArgs = [
205 '--module-path', sourceSets.modules.compileClasspath.asPath,
206 '--add-modules', j11modules
209 print ("Setting target compatibility to "+targetCompatibility+"\n")
217 if (JAVA_VERSION.equals("1.8")) {
218 sourceCompatibility = 1.8
219 targetCompatibility = 1.8
220 } else if (JAVA_VERSION.equals("11")) {
221 sourceCompatibility = 11
222 targetCompatibility = 11
224 options.compilerArgs += [
225 '--module-path', sourceSets.modules.compileClasspath.asPath,
226 '--add-modules', j11modules
229 print ("Setting target compatibility to "+targetCompatibility+"\n")
231 classpath += configurations.cloverRuntime
235 delete sourceSets.main.java.outputDir
239 delete sourceSets.test.java.outputDir
240 delete cloverInstrDir
243 def getDate(format) {
244 def date = new Date()
245 //return date.format("dd MMMM yyyy")
246 return date.format(format)
250 def stdout = new ByteArrayOutputStream()
252 commandLine "git", "rev-parse", "--short", "HEAD"
253 standardOutput = stdout
254 workingDir = jalviewDir
256 return stdout.toString().trim()
260 def stdout = new ByteArrayOutputStream()
262 commandLine "git", "rev-parse", "--abbrev-ref", "HEAD"
263 standardOutput = stdout
264 workingDir = jalviewDir
266 return stdout.toString().trim()
269 task createBuildProperties(type: WriteProperties) {
270 inputs.dir("$jalviewDir/$sourceDir")
271 inputs.dir("$jalviewDir/$resourceDir")
272 outputFile "$classes/$buildPropertiesFile"
273 /* taking time/date specific comment out to allow better incremental builds */
274 //comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd HH:mm:ss")
275 comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd")
276 property "BUILD_DATE", getDate("dd MMMM yyyy")
277 property "VERSION", JALVIEW_VERSION
278 property "INSTALLATION", INSTALLATION+" git-commit:"+getGitHash()+" ["+getGitBranch()+"]"
279 outputs.file(outputFile)
280 outputs.dir("$classes")
283 task syncDocs(type: Sync) {
284 def syncDir = "$classes/$docDir"
285 from fileTree("$jalviewDir/$docDir")
290 def helpFile = "$classes/$helpDir/help.jhm"
291 task syncHelp(type: Sync) {
292 inputs.files("$jalviewDir/$helpDir")
293 outputs.files(helpFile)
295 def syncDir = "$classes/$helpDir"
296 from fileTree("$jalviewDir/$helpDir")
300 task copyHelp(type: Copy) {
301 def inputDir = "$jalviewDir/$helpDir"
302 def outputDir = "$classes/$helpDir"
305 filter(ReplaceTokens, beginToken: '$$', endToken: '$$', tokens: ['Version-Rel': "USING_FILTER"])
307 outputs.files(helpFile)
308 outputs.dir(outputDir)
311 task syncLib(type: Sync) {
312 def syncDir = "$classes/$libDir"
313 from fileTree("$jalviewDir/$libDir")
317 task syncResources(type: Sync) {
318 from "$jalviewDir/$resourceDir"
328 dependsOn syncResources
334 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
338 dependsOn cloverInstr
340 print("Running tests " + (clover?"WITH":"WITHOUT") + " clover [clover="+clover+"]\n")
343 includeGroups testngGroups
345 useDefaultListeners=true
348 workingDir = jalviewDir
349 //systemProperties 'clover.jar' System.properties.clover.jar
350 if (JAVA_VERSION.equals("1.8")) {
351 sourceCompatibility = 1.8
352 targetCompatibility = 1.8
353 } else if (JAVA_VERSION.equals("11")) {
354 sourceCompatibility = 11
355 targetCompatibility = 11
359 sourceSets.modules.compileClasspath.asPath,
364 print ("Setting target compatibility to "+targetCompatibility+"\n")
367 task buildIndices(type: JavaExec) {
369 classpath = sourceSets.main.compileClasspath
370 main = "com.sun.java.help.search.Indexer"
371 workingDir = "$classes/$helpDir"
374 inputs.dir("$workingDir/$argDir")
376 outputs.dir("$classes/doc")
377 outputs.dir("$classes/help")
378 outputs.file("$workingDir/JavaHelpSearch/DOCS")
379 outputs.file("$workingDir/JavaHelpSearch/DOCS.TAB")
380 outputs.file("$workingDir/JavaHelpSearch/OFFSETS")
381 outputs.file("$workingDir/JavaHelpSearch/POSITIONS")
382 outputs.file("$workingDir/JavaHelpSearch/SCHEMA")
383 outputs.file("$workingDir/JavaHelpSearch/TMAP")
386 task compileLinkCheck(type: JavaCompile) {
388 classpath = files("$jalviewDir/$utilsDir")
389 destinationDir = file("$jalviewDir/$utilsDir")
390 source = fileTree(dir: "$jalviewDir/$utilsDir", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
392 outputs.file("$jalviewDir/$utilsDir/HelpLinksChecker.class")
393 outputs.file("$jalviewDir/$utilsDir/BufferedLineReader.class")
396 task linkCheck(type: JavaExec) {
397 dependsOn prepare, compileLinkCheck
398 classpath = files("$jalviewDir/$utilsDir")
399 main = "HelpLinksChecker"
400 workingDir = jalviewDir
401 def help = "$classes/$helpDir"
402 args = [ "$classes/$helpDir", "-nointernet" ]
403 //args = [ "$classesDir/$helpDir", "-nointernet" ]
406 standardOutput new FileOutputStream("$jalviewDir/$utilsDir/HelpLinksChecker.out")
409 outputs.file("$jalviewDir/$utilsDir/HelpLinksChecker.out")
412 task cleanPackageDir(type: Delete) {
413 delete fileTree("$jalviewDir/$packageDir").include("*.jar")
418 dependsOn buildIndices
419 dependsOn createBuildProperties
422 attributes "Main-Class": mainClass,
423 "Permissions": "all-permissions",
424 "Application-Name": "Jalview Desktop",
425 "Codebase": application_codebase
428 destinationDir = file("$jalviewDir/$packageDir")
429 archiveName = rootProject.name+".jar"
437 inputs.dir("$classes")
438 outputs.file("$jalviewDir/$packageDir/$archiveName")
441 task copyJars(type: Copy) {
442 from fileTree("$classes").include("**/*.jar").include("*.jar").files
443 into "$jalviewDir/$packageDir"
446 // doing a Sync instead of Copy as Copy doesn't deal with "outputs" very well
447 task syncJars(type: Sync) {
448 from fileTree("$jalviewDir/$libDir").include("**/*.jar").include("*.jar").files
449 into "$jalviewDir/$packageDir"
451 include jar.archiveName
456 // order of "cleanPackageDir", "copyJars", "jar" important!
457 jar.mustRunAfter cleanPackageDir
458 syncJars.mustRunAfter cleanPackageDir
459 dependsOn cleanPackageDir
462 outputs.dir("$jalviewDir/$packageDir")
466 dependsOn cleanPackageDir
473 if (JAVA_VERSION.equals("11")) {
474 from ("$jalviewDir/$j11libDir") {
478 mainClassName = shadowJarMainClass
485 getdownWebsiteDir = jalviewDir + '/' + getdown_website_dir
486 getdownAppDir = getdownWebsiteDir + '/' + getdown_app_dir
487 getdownJ11libDir = getdownWebsiteDir + '/' + getdown_j11lib_dir
488 getdownResourceDir = getdownWebsiteDir + '/' + getdown_resource_dir
489 getdownLauncher = jalviewDir + '/' + getdown_launcher
490 getdownFilesDir = jalviewDir + '/' + getdown_files_dir
493 task getdownWebsite() {
495 def getdownWebsiteResourceFilenames = []
496 def getdownTextString = ""
497 def getdownResourceDir = project.ext.getdownResourceDir
498 def getdownAppDir = project.ext.getdownAppDir
499 def getdownResourceFilenames = []
501 // go through properties looking for getdown_txt_...
502 def props = project.properties.sort { it.key }
503 if (JAVA_VERSION.equals("11")) {
504 props.put("getdown_txt_java_min_version", getdown_alt_java11_min_version)
506 props.put("getdown_txt_java_min_version", getdown_alt_java8_min_version)
508 props.each{ prop, val ->
509 if (prop.startsWith("getdown_txt_") && val != null) {
510 if (prop.startsWith("getdown_txt_multi_")) {
511 def key = prop.substring(18)
512 val.split(",").each{ v ->
513 def line = key + " = " + v + "\n"
514 getdownTextString += line
517 // file values rationalised
518 if (val.indexOf('/') > -1) {
520 if (val.indexOf('/') == 0) {
523 } else if (val.indexOf('/') > 0) {
524 // relative path (relative to jalviewDir)
525 r = file( jalviewDir + '/' + val )
528 val = getdown_resource_dir + '/' + r.getName()
529 getdownWebsiteResourceFilenames += val
530 getdownResourceFilenames += r.getPath()
533 def line = prop.substring(12) + " = " + val + "\n"
534 getdownTextString += line
539 getdownWebsiteResourceFilenames.each{ filename ->
540 getdownTextString += "resource = "+filename+"\n"
542 getdownResourceFilenames.each{ filename ->
545 into project.ext.getdownResourceDir
550 makeDist.outputs.files.each{ f ->
551 if (f.isDirectory()) {
552 def files = fileTree(dir: f, include: ["*"]).getFiles()
554 } else if (f.exists()) {
558 codeFiles.sort().each{f ->
559 def line = "code = " + getdown_app_dir + '/' + f.getName() + "\n"
560 getdownTextString += line
563 into project.ext.getdownAppDir
567 if (JAVA_VERSION.equals("11")) {
568 def j11libFiles = fileTree(dir: "$jalviewDir/$j11libDir", include: ["*.jar"]).getFiles()
569 j11libFiles.sort().each{f ->
570 def line = "code = " + getdown_j11lib_dir + '/' + f.getName() + "\n"
571 getdownTextString += line
574 into project.ext.getdownJ11libDir
579 getdownTextString += "code = " + file(getdownLauncher).getName() + "\n"
580 getdownTextString += "class = " + mainClass + "\n"
582 def getdown_txt = file(project.ext.getdownWebsiteDir + "/getdown.txt")
583 getdown_txt.write(getdownTextString)
587 into project.ext.getdownFilesDir
592 into project.ext.getdownWebsiteDir
597 into project.ext.getdownFilesDir
601 from jalviewDir + '/' + project.getProperty('getdown_txt_ui.background_image')
602 from jalviewDir + '/' + project.getProperty('getdown_txt_ui.error_background')
603 from jalviewDir + '/' + project.getProperty('getdown_txt_ui.progress_image')
604 from jalviewDir + '/' + project.getProperty('getdown_txt_ui.icon')
605 from jalviewDir + '/' + project.getProperty('getdown_txt_ui.mac_dock_icon')
606 into project.ext.getdownFilesDir + '/' + getdown_resource_dir
610 inputs.dir(jalviewDir + '/' + packageDir)
611 outputs.dir(project.ext.getdownWebsiteDir)
612 outputs.dir(project.ext.getdownFilesDir)
615 task getdownDigest(type: JavaExec) {
616 dependsOn getdownWebsite
617 classpath = files(jalviewDir + '/' + getdown_core)
618 main = "com.threerings.getdown.tools.Digester"
619 args project.ext.getdownWebsiteDir
620 outputs.file(project.ext.getdownWebsiteDir + '/' + "digest2.txt")
624 dependsOn getdownDigest
628 delete project.ext.getdownWebsiteDir
629 delete project.ext.getdownFilesDir
633 def install4jHomeDir = "/opt/install4j"
634 def hostname = "hostname".execute().text.trim()
635 if (hostname.equals("jv-bamboo")) {
636 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
637 } else if (OperatingSystem.current().isMacOsX()) {
638 install4jHomeDir = '/Applications/install4j.app/Contents/Resources/app'
639 if (! file(install4jHomeDir).exists()) {
640 install4jHomeDir = System.getProperty("user.home")+install4jHomeDir
642 } else if (OperatingSystem.current().isLinux()) {
643 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
645 installDir = file(install4jHomeDir)
648 task installers(type: com.install4j.gradle.Install4jTask) {
650 projectFile = "$jalviewDir/$install4jResourceDir/$install4jConf"
651 variables = [majorVersion: version.substring(2, 11), build: 001]
652 destination = "$jalviewDir/$install4jBuildDir"
654 inputs.dir(project.ext.getdownWebsiteDir)
655 outputs.dir("$jalviewDir/$install4jBuildDir")