Skip to content

Commit

Permalink
8297071: Provide gradle "TEST_ONLY" flag to completely suppress build…
Browse files Browse the repository at this point in the history
…ing the sdk and shims

Reviewed-by: kcr, aghaisas
  • Loading branch information
arapte committed May 8, 2023
1 parent c50ce60 commit 27ee7e3
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 16 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/submit.yml
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
56 changes: 49 additions & 7 deletions build.gradle
Expand Up @@ -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"]

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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-*.*"
}
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -4264,7 +4306,7 @@ task zips() {
}

task all() {
dependsOn(sdk,publicExports,apps,perf,zips)
dependsOn(sdk, shims, publicExports, apps, perf, zips)
}


Expand Down
11 changes: 5 additions & 6 deletions gradle.properties.template
Expand Up @@ -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.
Expand Down

1 comment on commit 27ee7e3

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.