1 /* Convention for properties. Read from gradle.properties, use lower_case_underlines for property names.
2 * For properties set within build.gradle, use camelCaseNoSpace.
4 import org.apache.tools.ant.filters.ReplaceTokens
11 // in ext the values are cast to Object. Ensure string values are cast as String (and not GStringImpl) for later use
12 def string(Object o) {
13 return o == null ? "" : o.toString()
16 def overrideProperties(String propsFileName, boolean output = false) {
17 if (propsFileName == null) {
20 def propsFile = file(propsFileName)
21 if (propsFile != null && propsFile.exists()) {
22 println("Using properties from file '${propsFileName}'")
24 def p = new Properties()
25 def localPropsFIS = new FileInputStream(propsFile)
31 if (project.hasProperty(key)) {
32 oldval = project.findProperty(key)
33 project.setProperty(key, val)
35 println("Overriding property '${key}' ('${oldval}') with ${file(propsFile).getName()} value '${val}'")
38 ext.setProperty(key, val)
40 println("Setting ext property '${key}' with ${file(propsFile).getName()}s value '${val}'")
44 } catch (Exception e) {
45 println("Exception reading local.properties")
52 jalviewDirAbsolutePath = file(jalviewDir).getAbsolutePath()
53 jalviewDirRelativePath = jalviewDir
55 propertiesChannelName = "release"
56 channelDir = string("${jalviewDir}/${channel_properties_dir}/${propertiesChannelName}")
57 channelGradleProperties = string("${channelDir}/channel_gradle.properties")
58 overrideProperties(channelGradleProperties, false)
61 // Import releaseProps from the RELEASE file
62 // or a file specified via JALVIEW_RELEASE_FILE if defined
63 // Expect jalview.version and target release branch in jalview.release
64 def releaseProps = new Properties();
65 def releasePropFile = findProperty("JALVIEW_RELEASE_FILE");
66 def defaultReleasePropFile = "${jalviewDirAbsolutePath}/RELEASE";
68 (new File(releasePropFile!=null ? releasePropFile : defaultReleasePropFile)).withInputStream {
71 } catch (Exception fileLoadError) {
72 throw new Error("Couldn't load release properties file "+(releasePropFile==null ? defaultReleasePropFile : "from custom location: releasePropFile"),fileLoadError);
75 // Set JALVIEW_VERSION if it is not already set
76 if (findProperty("JALVIEW_VERSION")==null || "".equals(JALVIEW_VERSION)) {
77 JALVIEW_VERSION = releaseProps.get("jalview.version")
81 bareSourceDir = string(source_dir)
82 sourceDir = string("${jalviewDir}/${bareSourceDir}")
83 resourceDir = string("${jalviewDir}/${resource_dir}")
84 bareTestSourceDir = string(test_source_dir)
85 testDir = string("${jalviewDir}/${bareTestSourceDir}")
87 classesDir = string("${jalviewDir}/${classes_dir}")
91 resourceClassesDir = classesDir
93 testSourceDir = testDir
94 testClassesDir = "${jalviewDir}/${test_output_dir}"
96 buildProperties = string("${classesDir}/${build_properties_file}")
97 getdownSetAppBaseProperty = false // whether to pass the appbase and appdistdir to the application
99 install4jApplicationName = "${jalview_name}"
101 println("Using a ${CHANNEL} profile.")
103 additional_compiler_args = []
104 // configure classpath/args for j8/j11 compilation
105 if (JAVA_VERSION.equals("1.8")) {
106 JAVA_INTEGER_VERSION = string("8")
109 libDistDir = j8libDir
110 compile_source_compatibility = 1.8
111 compile_target_compatibility = 1.8
112 } else if (JAVA_VERSION.equals("11")) {
113 JAVA_INTEGER_VERSION = string("11")
115 libDistDir = j11libDir
116 compile_source_compatibility = 11
117 compile_target_compatibility = 11
119 throw new GradleException("JAVA_VERSION=${JAVA_VERSION} not currently supported by Jalview")
122 resourceBuildDir = string("${buildDir}/resources")
123 resourcesBuildDir = string("${resourceBuildDir}/resources_build")
124 helpBuildDir = string("${resourceBuildDir}/help_build")
125 docBuildDir = string("${resourceBuildDir}/doc_build")
127 if (buildProperties == null) {
128 buildProperties = string("${resourcesBuildDir}/${build_properties_file}")
130 buildingHTML = string("${jalviewDir}/${doc_dir}/building.html")
131 helpParentDir = string("${jalviewDir}/${help_parent_dir}")
132 helpSourceDir = string("${helpParentDir}/${help_dir}")
133 helpFile = string("${helpBuildDir}/${help_dir}/help.jhm")
143 outputDir = file(classesDir)
147 srcDirs = [ resourcesBuildDir, docBuildDir, helpBuildDir ]
150 compileClasspath = files(sourceSets.main.java.outputDir)
151 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
154 compileClasspath = files(sourceSets.main.java.outputDir)
155 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
157 runtimeClasspath = compileClasspath
158 runtimeClasspath += files(sourceSets.main.resources.srcDirs)
163 srcDirs testSourceDir
164 outputDir = file(testClassesDir)
168 srcDirs = useClover ? sourceSets.clover.resources.srcDirs : sourceSets.main.resources.srcDirs
171 compileClasspath = files( sourceSets.test.java.outputDir )
172 compileClasspath += useClover ? sourceSets.clover.compileClasspath : sourceSets.main.compileClasspath
173 compileClasspath += fileTree(dir: "${jalviewDir}/${utils_dir}/testnglibs", include: ["**/*.jar"])
175 runtimeClasspath = compileClasspath
176 runtimeClasspath += files(sourceSets.test.resources.srcDirs)
180 srcDirs testSourceDir
181 outputDir = file(testClassesDir)
185 srcDirs = sourceSets.main.resources.srcDirs
188 compileClasspath = files( sourceSets.test.java.outputDir )
189 compileClasspath += sourceSets.main.compileClasspath
190 compileClasspath += fileTree(dir: "${jalviewDir}/${utils_dir}/testnglibs", include: ["** REMOVE_THIS_GAP /*.jar"])
192 runtimeClasspath = compileClasspath
199 sourceCompatibility = compile_source_compatibility
200 targetCompatibility = compile_target_compatibility
201 options.compilerArgs = additional_compiler_args
203 print ("Setting target compatibility to "+compile_target_compatibility+"\n")
210 sourceCompatibility = compile_source_compatibility
211 targetCompatibility = compile_target_compatibility
212 options.compilerArgs = additional_compiler_args
213 print ("Setting target compatibility to "+targetCompatibility+"\n")
220 delete sourceSets.main.java.outputDir
227 delete sourceSets.test.java.outputDir
232 // format is a string like date.format("dd MMMM yyyy")
233 def getDate(format) {
234 def date = new Date()
235 return date.format(format)
239 task copyDocs(type: Copy) {
240 def inputDir = "${jalviewDir}/${doc_dir}"
241 def outputDir = "${docBuildDir}/${doc_dir}"
247 filter(ReplaceTokens,
251 'Version-Rel': JALVIEW_VERSION,
252 'Year-Rel': getDate("yyyy")
265 outputs.dir(outputDir)
269 task copyHelp(type: Copy) {
270 def inputDir = helpSourceDir
271 def outputDir = "${helpBuildDir}/${help_dir}"
279 filter(ReplaceTokens,
283 'Version-Rel': JALVIEW_VERSION,
284 'Year-Rel': getDate("yyyy")
299 outputs.files(helpFile)
300 outputs.dir(outputDir)
303 task releasesTemplates {
305 description "Recreate whatsNew.html and releases.html from markdown files and templates in help"
309 def releasesTemplateFile = file("${jalviewDir}/${releases_template}")
310 def whatsnewTemplateFile = file("${jalviewDir}/${whatsnew_template}")
311 def releasesHtmlFile = file("${helpBuildDir}/${help_dir}/${releases_html}")
312 def whatsnewHtmlFile = file("${helpBuildDir}/${help_dir}/${whatsnew_html}")
313 def releasesMdDir = "${jalviewDir}/${releases_dir}"
314 def whatsnewMdDir = "${jalviewDir}/${whatsnew_dir}"
317 def JALVIEW_VERSION_UNDERSCORES = JALVIEW_VERSION.replaceAll("\\.", "_")
318 def releaseMdFile = file("${releasesMdDir}/release-${JALVIEW_VERSION_UNDERSCORES}.md")
319 def whatsnewMdFile = file("${whatsnewMdDir}/whatsnew-${JALVIEW_VERSION_UNDERSCORES}.md")
321 if (CHANNEL == "RELEASE") {
322 if (!releaseMdFile.exists()) {
323 throw new GradleException("File ${releaseMdFile} must be created for RELEASE")
325 if (!whatsnewMdFile.exists()) {
326 throw new GradleException("File ${whatsnewMdFile} must be created for RELEASE")
330 def releaseFiles = fileTree(dir: releasesMdDir, include: "release-*.md")
331 def releaseFilesDates = releaseFiles.collectEntries {
334 releaseFiles = releaseFiles.sort { a,b -> releaseFilesDates[a].compareTo(releaseFilesDates[b]) }
336 def releasesTemplate = releasesTemplateFile.text
337 def m = releasesTemplate =~ /(?s)__VERSION_LOOP_START__(.*)__VERSION_LOOP_END__/
338 def versionTemplate = m[0][1]
340 def versionsHtml = ""
341 def linkedVersions = []
343 releasesTemplate = releasesTemplate.replaceAll("(?s)__VERSION_LOOP_START__.*__VERSION_LOOP_END__", versionsHtml)
344 releasesHtmlFile.text = releasesTemplate
346 whatsnewHtmlFile.text = "Debian build " + getDate("yyyy-MM-dd HH:mm:ss")
349 inputs.file(releasesTemplateFile)
350 inputs.file(whatsnewTemplateFile)
351 inputs.dir(releasesMdDir)
352 inputs.dir(whatsnewMdDir)
353 outputs.file(releasesHtmlFile)
354 outputs.file(whatsnewHtmlFile)
357 task copyResources(type: Copy) {
359 description = "Copy (and make text substitutions in) the resources dir to the build area"
361 def inputDir = resourceDir
362 def outputDir = resourcesBuildDir
368 filter(ReplaceTokens,
372 'Version-Rel': JALVIEW_VERSION,
373 'Year-Rel': getDate("yyyy")
386 outputs.dir(outputDir)
389 task copyChannelResources(type: Copy) {
390 dependsOn copyResources
392 description = "Copy the channel resources dir to the build resources area"
394 def inputDir = "${channelDir}/${resource_dir}"
395 def outputDir = resourcesBuildDir
400 outputs.dir(outputDir)
403 task createBuildProperties(type: Copy) {
404 // using the build_properties already included in the source tarball
405 def inputFile = "build_properties"
406 def outputFile = buildProperties
408 into file(outputFile).getParent()
409 rename(file(inputFile).getName(), file(outputFile).getName())
411 inputs.file(inputFile)
412 outputs.file(outputFile)
416 task buildIndices(type: JavaExec) {
418 classpath = sourceSets.main.compileClasspath
419 main = "com.sun.java.help.search.Indexer"
420 workingDir = "${helpBuildDir}/${help_dir}"
423 inputs.dir("${workingDir}/${argDir}")
425 outputs.dir("${classesDir}/doc")
426 outputs.dir("${classesDir}/help")
427 outputs.file("${workingDir}/JavaHelpSearch/DOCS")
428 outputs.file("${workingDir}/JavaHelpSearch/DOCS.TAB")
429 outputs.file("${workingDir}/JavaHelpSearch/OFFSETS")
430 outputs.file("${workingDir}/JavaHelpSearch/POSITIONS")
431 outputs.file("${workingDir}/JavaHelpSearch/SCHEMA")
432 outputs.file("${workingDir}/JavaHelpSearch/TMAP")
435 task buildResources {
436 dependsOn copyResources
437 dependsOn copyChannelResources
438 dependsOn createBuildProperties
442 dependsOn buildResources
445 dependsOn releasesTemplates
446 dependsOn buildIndices
450 compileJava.dependsOn prepare
451 run.dependsOn compileJava
452 //run.dependsOn prepare
455 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
458 dependsOn compileJava //?
461 includeGroups testng_groups
462 excludeGroups testng_excluded_groups
464 useDefaultListeners=true
467 maxHeapSize = "1024m"
469 workingDir = jalviewDir
470 //systemProperties 'clover.jar' System.properties.clover.jar
471 def testLaf = project.findProperty("test_laf")
472 if (testLaf != null) {
473 println("Setting Test LaF to '${testLaf}'")
474 systemProperty "laf", testLaf
476 def testHiDPIScale = project.findProperty("test_HiDPIScale")
477 if (testHiDPIScale != null) {
478 println("Setting Test HiDPI Scale to '${testHiDPIScale}'")
479 systemProperty "sun.java2d.uiScale", testHiDPIScale
481 sourceCompatibility = compile_source_compatibility
482 targetCompatibility = compile_target_compatibility
483 jvmArgs += additional_compiler_args
490 task compileLinkCheck(type: JavaCompile) {
492 classpath = files("${jalviewDir}/${utils_dir}")
493 destinationDir = file("${jalviewDir}/${utils_dir}")
494 source = fileTree(dir: "${jalviewDir}/${utils_dir}", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
496 inputs.file("${jalviewDir}/${utils_dir}/HelpLinksChecker.java")
497 inputs.file("${jalviewDir}/${utils_dir}/HelpLinksChecker.java")
498 outputs.file("${jalviewDir}/${utils_dir}/HelpLinksChecker.class")
499 outputs.file("${jalviewDir}/${utils_dir}/BufferedLineReader.class")
503 task linkCheck(type: JavaExec) {
505 dependsOn compileLinkCheck
507 def helpLinksCheckerOutFile = file("${jalviewDir}/${utils_dir}/HelpLinksChecker.out")
508 classpath = files("${jalviewDir}/${utils_dir}")
509 main = "HelpLinksChecker"
510 workingDir = "${helpBuildDir}"
511 args = [ "${helpBuildDir}/${help_dir}", "-nointernet" ]
513 def outFOS = new FileOutputStream(helpLinksCheckerOutFile, false) // false == don't append
514 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
517 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
521 inputs.dir(helpBuildDir)
522 outputs.file(helpLinksCheckerOutFile)
526 // import the pubhtmlhelp target
527 ant.properties.basedir = "${jalviewDir}"
528 ant.properties.helpBuildDir = "${helpBuildDir}/${help_dir}"
529 ant.importBuild "${utils_dir}/publishHelp.xml"
532 task cleanPackageDir(type: Delete) {
534 delete fileTree(dir: "${jalviewDir}/${package_dir}", include: "*.jar")
544 attributes "Main-Class": main_class,
545 "Permissions": "all-permissions",
546 "Application-Name": install4jApplicationName,
547 "Codebase": application_codebase,
548 "Implementation-Version": JALVIEW_VERSION
551 def outputDir = "${jalviewDir}/${package_dir}"
552 destinationDirectory = file(outputDir)
553 archiveFileName = rootProject.name+".jar"
561 inputs.dir(sourceSets.main.java.outputDir)
562 sourceSets.main.resources.srcDirs.each{ dir ->
566 outputs.file("${outputDir}/${archiveFileName}")