1 import org.apache.tools.ant.filters.ReplaceTokens
2 import org.gradle.internal.os.OperatingSystem
7 //classpath files("$gradlePluginsDir/gradle-macappbundle-2.3.0-patched-2.3.0.jar")
14 id 'com.github.johnrengelman.shadow' version '4.0.3'
15 id 'com.install4j.gradle' version '7.0.9'
26 mainClassName = launcherClass
32 srcDirs "$jalviewDir/$sourceDir"
33 outputDir = file("$jalviewDir/$classesDir")
37 srcDirs "$jalviewDir/$resourceDir"
38 srcDirs "$jalviewDir/$libDir"
41 jar.destinationDir = file("$jalviewDir/$packageDir")
43 compileClasspath = files(sourceSets.main.java.outputDir)
44 compileClasspath += fileTree(dir: "$jalviewDir/$libDir", include: ["*.jar"])
45 if (JAVA_VERSION.equals("1.8")) {
46 print("ADDING J11LIBS TO CLASSPATH")
47 compileClasspath += fileTree(dir: "$jalviewDir/$j11libDir", include: ["*.jar"])
50 runtimeClasspath = compileClasspath
55 srcDirs "$jalviewDir/$testSourceDir"
56 outputDir = file("$jalviewDir/$testOutputDir")
60 srcDirs = sourceSets.main.resources.srcDirs
63 compileClasspath = sourceSets.main.compileClasspath
64 compileClasspath += files( sourceSets.test.java.outputDir )
65 compileClasspath += fileTree(dir: "$jalviewDir/$utilsDir", include: ["**/*.jar"])
67 runtimeClasspath = compileClasspath
71 compileClasspath = fileTree(dir: "$jalviewDir/$j11libDir", include: ["*.jar"])
73 runtimeClasspath = compileClasspath
81 if (JAVA_VERSION.equals("1.8")) {
82 sourceCompatibility = 1.8
83 targetCompatibility = 1.8
84 } else if (JAVA_VERSION.equals("11")) {
85 sourceCompatibility = 11
86 targetCompatibility = 11
88 options.compilerArgs = [
89 '--module-path', sourceSets.modules.compileClasspath.asPath,
90 '--add-modules', j11modules
93 print ("Setting target compatibility to "+targetCompatibility+"\n")
101 if (JAVA_VERSION.equals("1.8")) {
102 sourceCompatibility = 1.8
103 targetCompatibility = 1.8
104 } else if (JAVA_VERSION.equals("11")) {
105 sourceCompatibility = 11
106 targetCompatibility = 11
108 options.compilerArgs = [
109 '--module-path', sourceSets.modules.compileClasspath.asPath,
110 '--add-modules', j11modules
113 print ("Setting target compatibility to "+targetCompatibility+"\n")
119 delete sourceSets.main.java.outputDir
123 delete sourceSets.test.java.outputDir
126 def getDate(format) {
127 def date = new Date()
128 //return date.format("dd MMMM yyyy")
129 return date.format(format)
133 def stdout = new ByteArrayOutputStream()
135 commandLine "git", "rev-parse", "--short", "HEAD"
136 standardOutput = stdout
137 workingDir = jalviewDir
139 return stdout.toString().trim()
143 def stdout = new ByteArrayOutputStream()
145 commandLine "git", "rev-parse", "--abbrev-ref", "HEAD"
146 standardOutput = stdout
147 workingDir = jalviewDir
149 return stdout.toString().trim()
152 task createBuildProperties(type: WriteProperties) {
153 inputs.dir("$jalviewDir/$sourceDir")
154 inputs.dir("$jalviewDir/$resourceDir")
155 outputFile "$jalviewDir/$classesDir/$buildPropertiesFile"
156 /* taking time/date specific comment out to allow better incremental builds */
157 //comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd HH:mm:ss")
158 comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd")
159 property "BUILD_DATE", getDate("dd MMMM yyyy")
160 property "VERSION", JALVIEW_VERSION
161 property "INSTALLATION", INSTALLATION+" git-commit:"+getGitHash()+" ["+getGitBranch()+"]"
162 outputs.file(outputFile)
163 outputs.dir("$jalviewDir/$classesDir")
166 task syncDocs(type: Sync) {
167 def syncDir = "$jalviewDir/$classesDir/$docDir"
168 from fileTree("$jalviewDir/$docDir")
173 def helpFile = "$jalviewDir/$classesDir/$helpDir/help.jhm"
174 task syncHelp(type: Sync) {
175 inputs.files("$jalviewDir/$helpDir")
176 outputs.files(helpFile)
178 def syncDir = "$jalviewDir/$classesDir/$helpDir"
179 from fileTree("$jalviewDir/$helpDir")
183 task copyHelp(type: Copy) {
184 def inputDir = "$jalviewDir/$helpDir"
185 def outputDir = "$jalviewDir/$classesDir/$helpDir"
188 filter(ReplaceTokens, beginToken: '$$', endToken: '$$', tokens: ['Version-Rel': "USING_FILTER"])
190 outputs.files(helpFile)
191 outputs.dir(outputDir)
194 task syncLib(type: Sync) {
195 def syncDir = "$jalviewDir/$classesDir/$libDir"
196 from fileTree("$jalviewDir/$libDir")
200 task syncResources(type: Sync) {
201 from "$jalviewDir/$resourceDir"
204 into "$jalviewDir/$classesDir"
211 dependsOn syncResources
216 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
219 dependsOn compileJava
220 dependsOn compileTestJava
222 includeGroups testngGroups
226 workingDir = jalviewDir
227 //systemProperties 'clover.jar' System.properties.clover.jar
228 if (JAVA_VERSION.equals("1.8")) {
229 sourceCompatibility = 1.8
230 targetCompatibility = 1.8
231 } else if (JAVA_VERSION.equals("11")) {
232 sourceCompatibility = 11
233 targetCompatibility = 11
237 sourceSets.modules.compileClasspath.asPath,
242 print ("Setting target compatibility to "+targetCompatibility+"\n")
245 task buildIndices(type: JavaExec) {
247 classpath = sourceSets.main.compileClasspath
248 main = "com.sun.java.help.search.Indexer"
249 workingDir = "$jalviewDir/$classesDir/$helpDir"
252 inputs.dir("$workingDir/$argDir")
254 outputs.dir("$jalviewDir/$classesDir/doc")
255 outputs.dir("$jalviewDir/$classesDir/help")
256 outputs.file("$workingDir/JavaHelpSearch/DOCS")
257 outputs.file("$workingDir/JavaHelpSearch/DOCS.TAB")
258 outputs.file("$workingDir/JavaHelpSearch/OFFSETS")
259 outputs.file("$workingDir/JavaHelpSearch/POSITIONS")
260 outputs.file("$workingDir/JavaHelpSearch/SCHEMA")
261 outputs.file("$workingDir/JavaHelpSearch/TMAP")
264 task compileLinkCheck(type: JavaCompile) {
266 classpath = files("$jalviewDir/$utilsDir")
267 destinationDir = file("$jalviewDir/$utilsDir")
268 source = fileTree(dir: "$jalviewDir/$utilsDir", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
270 outputs.file("$jalviewDir/$utilsDir/HelpLinksChecker.class")
271 outputs.file("$jalviewDir/$utilsDir/BufferedLineReader.class")
274 task linkCheck(type: JavaExec) {
275 dependsOn prepare, compileLinkCheck
276 classpath = files("$jalviewDir/$utilsDir")
277 main = "HelpLinksChecker"
278 workingDir = "$jalviewDir"
279 args = [ "$classesDir/$helpDir", "-nointernet" ]
282 standardOutput new FileOutputStream("$jalviewDir/$utilsDir/HelpLinksChecker.out")
285 outputs.file("$jalviewDir/$utilsDir/HelpLinksChecker.out")
288 task cleanPackageDir(type: Delete) {
289 delete fileTree("$jalviewDir/$packageDir").include("*.jar")
294 dependsOn buildIndices
295 dependsOn createBuildProperties
298 attributes "Main-Class": mainClass,
299 "Permissions": "all-permissions",
300 "Application-Name": "Jalview Desktop",
301 "Codebase": application_codebase
304 destinationDir = file("$jalviewDir/$packageDir")
305 archiveName = rootProject.name+".jar"
313 inputs.dir("$jalviewDir/$classesDir")
314 outputs.file("$jalviewDir/$packageDir/$archiveName")
317 task copyJars(type: Copy) {
318 from fileTree("$jalviewDir/$classesDir").include("**/*.jar").include("*.jar").files
319 into "$jalviewDir/$packageDir"
322 // doing a Sync instead of Copy as Copy doesn't deal with "outputs" very well
323 task syncJars(type: Sync) {
324 from fileTree("$jalviewDir/$libDir").include("**/*.jar").include("*.jar").files
325 into "$jalviewDir/$packageDir"
327 include jar.archiveName
332 // order of "cleanPackageDir", "copyJars", "jar" important!
333 jar.mustRunAfter cleanPackageDir
334 syncJars.mustRunAfter cleanPackageDir
335 dependsOn cleanPackageDir
338 outputs.dir("$jalviewDir/$packageDir")
342 dependsOn cleanPackageDir
349 if (JAVA_VERSION.equals("11")) {
350 from ("$jalviewDir/$j11libDir") {
354 mainClassName = shadowJarMainClass
361 getdownWebsiteDir = jalviewDir + '/' + getdown_website_dir
362 getdownAppDir = getdownWebsiteDir + '/' + getdown_app_dir
363 getdownJ11libDir = getdownWebsiteDir + '/' + getdown_j11lib_dir
364 getdownResourceDir = getdownWebsiteDir + '/' + getdown_resource_dir
365 getdownLauncher = jalviewDir + '/' + getdown_launcher
366 getdownFilesDir = jalviewDir + '/' + getdown_files_dir
369 task getdownWebsite() {
371 def getdownWebsiteResourceFilenames = []
372 def getdownTextString = ""
373 def getdownResourceDir = project.ext.getdownResourceDir
374 def getdownAppDir = project.ext.getdownAppDir
375 def getdownResourceFilenames = []
377 // go through properties looking for getdown_txt_...
378 def props = project.properties.sort { it.key }
379 if (JAVA_VERSION.equals("11")) {
380 props.put("getdown_txt_java_min_version", getdown_alt_java11_min_version)
382 props.put("getdown_txt_java_min_version", getdown_alt_java8_min_version)
384 props.each{ prop, val ->
385 if (prop.startsWith("getdown_txt_") && val != null) {
386 if (prop.startsWith("getdown_txt_multi_")) {
387 def key = prop.substring(18)
388 val.split(",").each{ v ->
389 def line = key + " = " + v + "\n"
390 getdownTextString += line
393 // file values rationalised
394 if (val.indexOf('/') > -1) {
396 if (val.indexOf('/') == 0) {
399 } else if (val.indexOf('/') > 0) {
400 // relative path (relative to jalviewDir)
401 r = file( jalviewDir + '/' + val )
404 val = getdown_resource_dir + '/' + r.getName()
405 getdownWebsiteResourceFilenames += val
406 getdownResourceFilenames += r.getPath()
409 def line = prop.substring(12) + " = " + val + "\n"
410 getdownTextString += line
415 getdownWebsiteResourceFilenames.each{ filename ->
416 getdownTextString += "resource = "+filename+"\n"
418 getdownResourceFilenames.each{ filename ->
421 into project.ext.getdownResourceDir
426 makeDist.outputs.files.each{ f ->
427 if (f.isDirectory()) {
428 def files = fileTree(dir: f, include: ["*"]).getFiles()
430 } else if (f.exists()) {
434 codeFiles.sort().each{f ->
435 def line = "code = " + getdown_app_dir + '/' + f.getName() + "\n"
436 getdownTextString += line
439 into project.ext.getdownAppDir
443 if (JAVA_VERSION.equals("11")) {
444 def j11libFiles = fileTree(dir: "$jalviewDir/$j11libDir", include: ["*.jar"]).getFiles()
445 j11libFiles.sort().each{f ->
446 def line = "code = " + getdown_j11lib_dir + '/' + f.getName() + "\n"
447 getdownTextString += line
450 into project.ext.getdownJ11libDir
455 getdownTextString += "code = " + file(getdownLauncher).getName() + "\n"
456 getdownTextString += "class = " + mainClass + "\n"
458 def getdown_txt = file(project.ext.getdownWebsiteDir + "/getdown.txt")
459 getdown_txt.write(getdownTextString)
463 into project.ext.getdownFilesDir
468 into project.ext.getdownWebsiteDir
473 into project.ext.getdownFilesDir
477 from jalviewDir + '/' + project.getProperty('getdown_txt_ui.background_image')
478 from jalviewDir + '/' + project.getProperty('getdown_txt_ui.error_background')
479 from jalviewDir + '/' + project.getProperty('getdown_txt_ui.progress_image')
480 from jalviewDir + '/' + project.getProperty('getdown_txt_ui.icon')
481 from jalviewDir + '/' + project.getProperty('getdown_txt_ui.mac_dock_icon')
482 into project.ext.getdownFilesDir + '/' + getdown_resource_dir
486 inputs.dir(jalviewDir + '/' + packageDir)
487 outputs.dir(project.ext.getdownWebsiteDir)
488 outputs.dir(project.ext.getdownFilesDir)
491 task getdownDigest(type: JavaExec) {
492 dependsOn getdownWebsite
493 classpath = files(jalviewDir + '/' + getdown_core)
494 main = "com.threerings.getdown.tools.Digester"
495 args project.ext.getdownWebsiteDir
496 outputs.file(project.ext.getdownWebsiteDir + '/' + "digest2.txt")
500 dependsOn getdownDigest
504 delete project.ext.getdownWebsiteDir
505 delete project.ext.getdownFilesDir
509 def install4jHomeDir = "/opt/install4j"
510 def hostname = "hostname".execute().text.trim()
511 if (hostname.equals("jv-bamboo")) {
512 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
513 } else if (OperatingSystem.current().isMacOsX()) {
514 install4jHomeDir = '/Applications/install4j.app/Contents/Resources/app'
515 if (! file(install4jHomeDir).exists()) {
516 install4jHomeDir = System.getProperty("user.home")+install4jHomeDir
518 } else if (OperatingSystem.current().isLinux()) {
519 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
521 installDir = file(install4jHomeDir)
524 task installers(type: com.install4j.gradle.Install4jTask) {
526 projectFile = "$jalviewDir/$install4jResourceDir/$install4jConf"
527 variables = [majorVersion: version.substring(2, 11), build: 001]
528 destination = "$jalviewDir/$install4jBuildDir"
530 inputs.dir(project.ext.getdownWebsiteDir)
531 outputs.dir("$jalviewDir/$install4jBuildDir")