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)
304 task copyResources(type: Copy) {
306 description = "Copy (and make text substitutions in) the resources dir to the build area"
308 def inputDir = resourceDir
309 def outputDir = resourcesBuildDir
315 filter(ReplaceTokens,
319 'Version-Rel': JALVIEW_VERSION,
320 'Year-Rel': getDate("yyyy")
333 outputs.dir(outputDir)
336 task copyChannelResources(type: Copy) {
337 dependsOn copyResources
339 description = "Copy the channel resources dir to the build resources area"
341 def inputDir = "${channelDir}/${resource_dir}"
342 def outputDir = resourcesBuildDir
347 outputs.dir(outputDir)
350 task createBuildProperties(type: Copy) {
351 // using the build_properties already included in the source tarball
352 def inputFile = "build_properties"
353 def outputFile = buildProperties
355 into file(outputFile).getParent()
356 rename(file(inputFile).getName(), file(outputFile).getName())
358 inputs.file(inputFile)
359 outputs.file(outputFile)
363 task buildIndices(type: JavaExec) {
365 classpath = sourceSets.main.compileClasspath
366 main = "com.sun.java.help.search.Indexer"
367 workingDir = "${helpBuildDir}/${help_dir}"
370 inputs.dir("${workingDir}/${argDir}")
372 outputs.dir("${classesDir}/doc")
373 outputs.dir("${classesDir}/help")
374 outputs.file("${workingDir}/JavaHelpSearch/DOCS")
375 outputs.file("${workingDir}/JavaHelpSearch/DOCS.TAB")
376 outputs.file("${workingDir}/JavaHelpSearch/OFFSETS")
377 outputs.file("${workingDir}/JavaHelpSearch/POSITIONS")
378 outputs.file("${workingDir}/JavaHelpSearch/SCHEMA")
379 outputs.file("${workingDir}/JavaHelpSearch/TMAP")
382 task buildResources {
383 dependsOn copyResources
384 dependsOn copyChannelResources
385 dependsOn createBuildProperties
389 dependsOn buildResources
392 dependsOn buildIndices
396 compileJava.dependsOn prepare
397 run.dependsOn compileJava
398 //run.dependsOn prepare
401 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
404 dependsOn compileJava //?
407 includeGroups testng_groups
408 excludeGroups testng_excluded_groups
410 useDefaultListeners=true
413 maxHeapSize = "1024m"
415 workingDir = jalviewDir
416 //systemProperties 'clover.jar' System.properties.clover.jar
417 def testLaf = project.findProperty("test_laf")
418 if (testLaf != null) {
419 println("Setting Test LaF to '${testLaf}'")
420 systemProperty "laf", testLaf
422 def testHiDPIScale = project.findProperty("test_HiDPIScale")
423 if (testHiDPIScale != null) {
424 println("Setting Test HiDPI Scale to '${testHiDPIScale}'")
425 systemProperty "sun.java2d.uiScale", testHiDPIScale
427 sourceCompatibility = compile_source_compatibility
428 targetCompatibility = compile_target_compatibility
429 jvmArgs += additional_compiler_args
436 task compileLinkCheck(type: JavaCompile) {
438 classpath = files("${jalviewDir}/${utils_dir}")
439 destinationDir = file("${jalviewDir}/${utils_dir}")
440 source = fileTree(dir: "${jalviewDir}/${utils_dir}", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
442 inputs.file("${jalviewDir}/${utils_dir}/HelpLinksChecker.java")
443 inputs.file("${jalviewDir}/${utils_dir}/HelpLinksChecker.java")
444 outputs.file("${jalviewDir}/${utils_dir}/HelpLinksChecker.class")
445 outputs.file("${jalviewDir}/${utils_dir}/BufferedLineReader.class")
449 task linkCheck(type: JavaExec) {
451 dependsOn compileLinkCheck
453 def helpLinksCheckerOutFile = file("${jalviewDir}/${utils_dir}/HelpLinksChecker.out")
454 classpath = files("${jalviewDir}/${utils_dir}")
455 main = "HelpLinksChecker"
456 workingDir = jalviewDir
457 args = [ "${helpBuildDir}/${help_dir}", "-nointernet" ]
459 def outFOS = new FileOutputStream(helpLinksCheckerOutFile, false) // false == don't append
460 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
463 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
467 inputs.dir(helpBuildDir)
468 outputs.file(helpLinksCheckerOutFile)
472 // import the pubhtmlhelp target
473 ant.properties.basedir = "${jalviewDir}"
474 ant.properties.helpBuildDir = "${helpBuildDir}/${help_dir}"
475 ant.importBuild "${utils_dir}/publishHelp.xml"
478 task cleanPackageDir(type: Delete) {
480 delete fileTree(dir: "${jalviewDir}/${package_dir}", include: "*.jar")
490 attributes "Main-Class": main_class,
491 "Permissions": "all-permissions",
492 "Application-Name": install4jApplicationName,
493 "Codebase": application_codebase,
494 "Implementation-Version": JALVIEW_VERSION
497 def outputDir = "${jalviewDir}/${package_dir}"
498 destinationDirectory = file(outputDir)
499 archiveFileName = rootProject.name+".jar"
507 inputs.dir(sourceSets.main.java.outputDir)
508 sourceSets.main.resources.srcDirs.each{ dir ->
512 outputs.file("${outputDir}/${archiveFileName}")