From 27ee7e34df7847e90f2aa4e326fd60715d74b7ac Mon Sep 17 00:00:00 2001 From: Ambarish Rapte Date: Mon, 8 May 2023 09:23:45 +0000 Subject: [PATCH] 8297071: Provide gradle "TEST_ONLY" flag to completely suppress building the sdk and shims Reviewed-by: kcr, aghaisas --- .github/workflows/submit.yml | 6 ++-- build.gradle | 56 +++++++++++++++++++++++++++++++----- gradle.properties.template | 11 ++++--- 3 files changed, 57 insertions(+), 16 deletions(-) diff --git a/.github/workflows/submit.yml b/.github/workflows/submit.yml index c47bdbb4512..e87ab4be9ef 100644 --- a/.github/workflows/submit.yml +++ b/.github/workflows/submit.yml @@ -139,7 +139,7 @@ jobs: run: | set -x export PATH="$JAVA_HOME/bin:$ANT_HOME/bin:$PATH" - bash gradlew --info --continue -PBUILD_SDK_FOR_TEST=false test -x :web:test + bash gradlew --info --continue -PTEST_ONLY=true test -x :web:test macos_x64_build: @@ -225,7 +225,7 @@ jobs: set -x #export PATH="$JAVA_HOME/bin:$ANT_HOME/bin:$PATH" export PATH="$JAVA_HOME/bin:$PATH" - bash gradlew --info --continue -PBUILD_SDK_FOR_TEST=false test -x :web:test + bash gradlew --info --continue -PTEST_ONLY=true test -x :web:test windows_x64_build: @@ -337,4 +337,4 @@ jobs: echo "ANT_HOME=$env:ANT_HOME" $env:Path = "$env:THE_PATH" ; echo "Path=$env:Path" - .\gradlew.bat --info --continue -PBUILD_SDK_FOR_TEST=false test -x :web:test + .\gradlew.bat --info --continue -PTEST_ONLY=true test -x :web:test diff --git a/build.gradle b/build.gradle index 6baaeca4499..b5edd25301b 100644 --- a/build.gradle +++ b/build.gradle @@ -50,6 +50,12 @@ * - ServiceWithSecurityManagerTest fails to complete when run from gradle. * - Integrate Parfait reports for C code * - FXML Project tests are not running + * + * Adding a new project or task: + * - Fix for JDK-8297071, introduces a restriction on assigning name for a project or task. + * - If the name of project or task contains word test/Test then it is considered as test task. + * - If the name of a task contains word shim/Shim then it is considered as shims task. + * - See TEST_ONLY flag, isTestTask() method, the tasks: shims and sdk for more clarity. */ defaultTasks = ["sdk"] @@ -605,9 +611,15 @@ if (hasProperty("CROSS_TOOLS_DIR")) { } ext.CROSS_TOOLS_DIR = file(crossToolsDir) -// Specifies whether to run tests with the existing javafx.* modules instead of compiling a new one +// For backward compatibility, -PBUILD_SDK_FOR_TEST=false will set TEST_ONLY to true defineProperty("BUILD_SDK_FOR_TEST", "true") -ext.DO_BUILD_SDK_FOR_TEST = Boolean.parseBoolean(BUILD_SDK_FOR_TEST) +def buildSdkForTest = Boolean.parseBoolean(BUILD_SDK_FOR_TEST) + +// Specifies whether to run only test tasks using the already built javafx.* modules +// and shim classes, instead of rebuilding them. +// If true, then all non test tasks, except verifyJava are disabled. see task sdk and isTestTask method. +defineProperty("TEST_ONLY", "false") +ext.IS_TEST_ONLY = Boolean.parseBoolean(TEST_ONLY) || !buildSdkForTest // Make sure JDK_HOME/bin/java exists if (!file(JAVA).exists()) throw new Exception("Missing or incorrect path to 'java': '$JAVA'. Perhaps bad JDK_HOME? $JDK_HOME") @@ -1806,6 +1818,14 @@ int compareJdkVersion(String a, String b) { return 0; } +/** + * Returns true if the name of task or name of task's project contains word test/Test. + */ +boolean isTestTask(Task task) { + return (task.project.name.contains("test") || task.project.name.contains("Test") + || task.name.contains("test") || task.name.contains("Test")) +} + // Task to verify the minimum level of Java needed to build JavaFX task verifyJava() { doLast { @@ -3472,7 +3492,7 @@ project(":web") { compileJava.dependsOn updateCacheIfNeeded - task webArchiveJar(type: Jar) { + task testWebArchiveJar(type: Jar) { from (project.file("$projectDir/src/test/resources/test/html")) { include "**/archive-*.*" } @@ -3526,7 +3546,7 @@ project(":web") { systemProperty 'glass.platform', 'Monocle' systemProperty 'monocle.platform', 'Headless' systemProperty 'prism.order', 'sw' - dependsOn webArchiveJar + dependsOn testWebArchiveJar def testResourceDir = file("$buildDir/testing/resources") jvmArgs "-DWEB_ARCHIVE_JAR_TEST_DIR=$testResourceDir" systemProperty 'java.security.manager', 'allow' @@ -4193,14 +4213,36 @@ task javadoc(type: Javadoc, dependsOn: createMSPfile) { dependsOn(projectsToDocument.collect { project -> project.getTasksByName("classes", true)}); } +task shims() { + gradle.allprojects { project -> + if (project.hasProperty("sourceSets") && project.sourceSets.hasProperty('shims')) { + project.tasks.each { task -> + if (task.name.contains("shim") || task.name.contains("Shim")) { + dependsOn(task) + } + } + } + } +} + task sdk() { - if (DO_BUILD_SDK_FOR_TEST) { + if (!IS_TEST_ONLY) { rootProject.getTasksByName("test", true).each { t -> - if (t.enabled) t.dependsOn(sdk) + if (t.enabled) t.dependsOn(shims) + } + } else { + gradle.taskGraph.whenReady { taskGraph -> + taskGraph.allTasks.each { task -> + if (!isTestTask(task) && !task.name.equals("verifyJava")) { + task.enabled = false + } + } } } } +shims.dependsOn(sdk) + task jmods() { dependsOn(sdk) // real work items added later. @@ -4264,7 +4306,7 @@ task zips() { } task all() { - dependsOn(sdk,publicExports,apps,perf,zips) + dependsOn(sdk, shims, publicExports, apps, perf, zips) } diff --git a/gradle.properties.template b/gradle.properties.template index b6f969fef10..a463d61eb7e 100644 --- a/gradle.properties.template +++ b/gradle.properties.template @@ -69,13 +69,12 @@ #INCLUDE_ES2 = true -# Specifies whether to build SDK for running unit tests -# By default, it is set to true and the tests are running of the -# fresh-built SDK. If set to false, this flag removes main sources -# compilation tasks and building the whole SDK. The existing SDK is used -# instead, and must have been previously built +# Specifies whether to build SDK for running the provided test task. +# By default, it is set to false and the tests are running of the +# fresh-built SDK. If set to true, this flag disables all non test tasks, +# and it is expected that sdk and shims tasks have been previously built. -#BUILD_SDK_FOR_TEST = false +#TEST_ONLY = true # Specifies whether to do a full test run or a "smoke test" run. By default we # do a smoke test run which excludes all tests that show a window or play media.