id 'eclipse'
id "com.diffplug.gradle.spotless" version "3.28.0"
id 'com.github.johnrengelman.shadow' version '4.0.3'
- id 'com.install4j.gradle' version '9.0.6'
+ id 'com.install4j.gradle' version '10.0.3'
id 'com.dorongold.task-tree' version '2.1.0' // only needed to display task dependency tree with gradle task1 [task2 ...] taskTree
id 'com.palantir.git-version' version '0.13.0' apply false
}
// for install4j
JAVA_MIN_VERSION = JAVA_VERSION
JAVA_MAX_VERSION = JAVA_VERSION
- def jreInstallsDir = string(jre_installs_dir)
+ jreInstallsDir = string(jre_installs_dir)
if (jreInstallsDir.startsWith("~/")) {
jreInstallsDir = System.getProperty("user.home") + jreInstallsDir.substring(1)
}
- macosJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-mac-x64/jre")
- windowsJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-windows-x64/jre")
- linuxJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-linux-x64/jre")
- macosJavaVMTgz = string("${jreInstallsDir}/tgz/jre_${JAVA_INTEGER_VERSION}_mac_x64.tar.gz")
- windowsJavaVMTgz = string("${jreInstallsDir}/tgz/jre_${JAVA_INTEGER_VERSION}_windows_x64.tar.gz")
- linuxJavaVMTgz = string("${jreInstallsDir}/tgz/jre_${JAVA_INTEGER_VERSION}_linux_x64.tar.gz")
install4jDir = string("${jalviewDir}/${install4j_utils_dir}")
install4jConfFileName = string("jalview-install4j-conf.install4j")
install4jConfFile = file("${install4jDir}/${install4jConfFileName}")
compileJava.dependsOn prepare
run.dependsOn compileJava
-//run.dependsOn prepare
+compileTestJava.dependsOn compileJava
-//testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
-test {
- dependsOn prepare
-
- if (useClover) {
- dependsOn cloverClasses
- } else { //?
- dependsOn compileJava //?
+ext.testsFailed = false
+/* testTask0 is the main test task */
+task testTask0(type: Test) {
+ useTestNG() {
+ includeGroups testng_groups.split(",")
+ excludeGroups testng_excluded_groups.split(",")
+ tasks.withType(Test).matching {it.name.startsWith("testTask") && it.name != name}.all {t -> excludeGroups t.name}
+ preserveOrder true
+ useDefaultListeners=true
}
+}
+/* separated tests */
+task testTask1(type: Test) {
useTestNG() {
- includeGroups testng_groups
- excludeGroups testng_excluded_groups
+ includeGroups name
+ excludeGroups testng_excluded_groups.split(",")
+ tasks.withType(Test).matching {it.name.startsWith("testTask") && it.name != name}.all {t -> excludeGroups t.name}
preserveOrder true
useDefaultListeners=true
}
+}
- maxHeapSize = "1024m"
+/*
+ * adapted from https://medium.com/@wasyl/pretty-tests-summary-in-gradle-744804dd676c
+ * to summarise test results from all Test tasks
+ */
+/* START of test tasks results summary */
+import groovy.time.TimeCategory
+import org.gradle.api.tasks.testing.logging.TestExceptionFormat
+import org.gradle.api.tasks.testing.logging.TestLogEvent
+
+rootProject.ext.testsResults = [] // Container for tests summaries
+
+allprojects { project ->
+ tasks.withType(Test).matching {t -> t.getName().startsWith("testTask")}.all { testTask ->
+
+ // run main tests first
+// if (!testTask.name.equals("testTask0"))
+// testTask.mustRunAfter testTask0
+
+ testTask.testLogging { logging ->
+ events TestLogEvent.FAILED,
+ TestLogEvent.SKIPPED,
+ TestLogEvent.STANDARD_OUT,
+ TestLogEvent.STANDARD_ERROR
+
+ exceptionFormat TestExceptionFormat.FULL
+ showExceptions true
+ showCauses true
+ showStackTraces true
+ }
- workingDir = jalviewDir
- def testLaf = project.findProperty("test_laf")
- if (testLaf != null) {
- println("Setting Test LaF to '${testLaf}'")
- systemProperty "laf", testLaf
- }
- def testHiDPIScale = project.findProperty("test_HiDPIScale")
- if (testHiDPIScale != null) {
- println("Setting Test HiDPI Scale to '${testHiDPIScale}'")
- systemProperty "sun.java2d.uiScale", testHiDPIScale
- }
- sourceCompatibility = compile_source_compatibility
- targetCompatibility = compile_target_compatibility
- jvmArgs += additional_compiler_args
+ ignoreFailures = true // Always try to run all tests for all modules
- doFirst {
+ afterSuite { desc, result ->
+
+ if (desc.parent) return // Only summarize results for whole modules
+
+ String summary = "${testTask.project.name}:${testTask.name} results: ${result.resultType} " +
+ "(" +
+ "${result.testCount} tests, " +
+ "${result.successfulTestCount} successes, " +
+ "${result.failedTestCount} failures, " +
+ "${result.skippedTestCount} skipped" +
+ ") " +
+ "in ${TimeCategory.minus(new Date(result.endTime), new Date(result.startTime))}" +
+ "\n" +
+ "Report file: ${testTask.reports.html.entryPoint}"
+
+ // Add reports in `testsResults`, keep failed suites at the end
+ if (result.resultType == TestResult.ResultType.SUCCESS) {
+ rootProject.ext.testsResults.add(0, summary)
+ } else {
+ rootProject.ext.testsResults += summary
+ }
+ if (result.resultType == TestResult.ResultType.FAILURE) {
+ testsFailed = true
+ }
+ }
+
+ // from original test task
if (useClover) {
- println("Running tests " + (useClover?"WITH":"WITHOUT") + " clover")
+ dependsOn cloverClasses
+ } else { //?
+ dependsOn compileJava //?
+ }
+ maxHeapSize = "1024m"
+
+ workingDir = jalviewDir
+ def testLaf = project.findProperty("test_laf")
+ if (testLaf != null) {
+ println("Setting Test LaF to '${testLaf}'")
+ systemProperty "laf", testLaf
}
+ def testHiDPIScale = project.findProperty("test_HiDPIScale")
+ if (testHiDPIScale != null) {
+ println("Setting Test HiDPI Scale to '${testHiDPIScale}'")
+ systemProperty "sun.java2d.uiScale", testHiDPIScale
+ }
+ sourceCompatibility = compile_source_compatibility
+ targetCompatibility = compile_target_compatibility
+ jvmArgs += additional_compiler_args
+
+ doFirst {
+ if (useClover) {
+ println("Running tests " + (useClover?"WITH":"WITHOUT") + " clover")
+ }
+ }
+
}
}
+gradle.buildFinished {
+ def allResults = rootProject.ext.testsResults
+
+ if (!allResults.isEmpty()) {
+ printResults allResults
+ }
+}
+
+private static void printResults(allResults) {
+ def maxLength = allResults*.readLines().flatten().collect { it.length() }.max()
+
+ println "┌${"${"─" * maxLength}"}┐"
+
+ println allResults.collect {
+ it.readLines().collect {
+ "│" + it + " " * (maxLength - it.length()) + "│"
+ }.join("\n")
+ }.join("\n├${"${"─" * maxLength}"}┤\n")
+
+ println "└${"${"─" * maxLength}"}┘"
+}
+/* END of test tasks results summary */
+
+task verifyTestStatus {
+ doLast {
+ if (testsFailed) {
+ throw new GradleException("There were failing tests!")
+ }
+ }
+}
+
+test {
+ dependsOn tasks.withType(Test).matching {t -> t.getName().startsWith("testTask")}
+ finalizedBy verifyTestStatus
+
+ // not running tests in this task
+ exclude "**/*"
+}
+
task compileLinkCheck(type: JavaCompile) {
options.fork = true
'JAVA_VERSION': JAVA_VERSION,
'JAVA_INTEGER_VERSION': JAVA_INTEGER_VERSION,
'VERSION': JALVIEW_VERSION,
- 'MACOS_JAVA_VM_DIR': macosJavaVMDir,
- 'WINDOWS_JAVA_VM_DIR': windowsJavaVMDir,
- 'LINUX_JAVA_VM_DIR': linuxJavaVMDir,
- 'MACOS_JAVA_VM_TGZ': macosJavaVMTgz,
- 'WINDOWS_JAVA_VM_TGZ': windowsJavaVMTgz,
- 'LINUX_JAVA_VM_TGZ': linuxJavaVMTgz,
'COPYRIGHT_MESSAGE': install4j_copyright_message,
'BUNDLE_ID': install4jBundleId,
'INTERNAL_ID': install4jInternalId,
'WINDOWS_ICONS_FILE': install4jWindowsIconsFile,
'PNG_ICON_FILE': install4jPngIconFile,
'BACKGROUND': install4jBackground,
+ ]
+ def varNameMap = [
+ 'mac': 'MACOS',
+ 'windows': 'WINDOWS',
+ 'linux': 'LINUX'
+ ]
+
+ // these are the bundled OS/architecture VMs needed by install4j
+ def osArch = [
+ [ "mac", "x64" ],
+ [ "mac", "aarch64" ],
+ [ "windows", "x64" ],
+ [ "linux", "x64" ],
+ [ "linux", "aarch64" ]
]
+ osArch.forEach { os, arch ->
+ variables[ sprintf("%s_%s_JAVA_VM_DIR", varNameMap[os], arch.toUpperCase(Locale.ROOT)) ] = sprintf("%s/jre-%s-%s-%s/jre", jreInstallsDir, JAVA_INTEGER_VERSION, os, arch)
+ // N.B. For some reason install4j requires the below filename to have underscores and not hyphens
+ // otherwise running `gradle installers` generates a non-useful error:
+ // `install4j: compilation failed. Reason: java.lang.NumberFormatException: For input string: "windows"`
+ variables[ sprintf("%s_%s_JAVA_VM_TGZ", varNameMap[os], arch.toUpperCase(Locale.ROOT)) ] = sprintf("%s/tgz/jre_%s_%s_%s.tar.gz", jreInstallsDir, JAVA_INTEGER_VERSION, os, arch)
+ }
//println("INSTALL4J VARIABLES:")
//variables.each{k,v->println("${k}=${v}")}
inputs.dir(getdownAppBaseDir)
inputs.file(install4jConfFile)
inputs.file("${install4jDir}/${install4j_info_plist_file_associations}")
- inputs.dir(macosJavaVMDir)
- inputs.dir(windowsJavaVMDir)
outputs.dir("${jalviewDir}/${install4j_build_dir}/${JAVA_VERSION}")
}
description "Build the site"
dependsOn jalviewjsBuildSite
}
+