From 2436da9fb1d7980ee075099ad261299f4d3a8cd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonard=20Br=C3=BCnings?= Date: Fri, 20 Dec 2024 12:31:44 +0100 Subject: [PATCH 1/3] Isolate flaky timeout tests --- .../smoke/extension/GlobalTimeoutExtension.groovy | 5 +++-- .../spock/util/concurrent/BlockingVariableSpec.groovy | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/spock-specs/src/test/groovy/org/spockframework/smoke/extension/GlobalTimeoutExtension.groovy b/spock-specs/src/test/groovy/org/spockframework/smoke/extension/GlobalTimeoutExtension.groovy index cc39e73fd1..6dafd10baa 100644 --- a/spock-specs/src/test/groovy/org/spockframework/smoke/extension/GlobalTimeoutExtension.groovy +++ b/spock-specs/src/test/groovy/org/spockframework/smoke/extension/GlobalTimeoutExtension.groovy @@ -1,12 +1,13 @@ package org.spockframework.smoke.extension - +import spock.lang.Isolated import spock.timeout.BaseTimeoutExtensionSpecification import java.time.Duration import org.spockframework.runtime.SpockTimeoutError +@Isolated("The timings are quite tight and it can get flaky on weak machines if run in parallel.") class GlobalTimeoutExtension extends BaseTimeoutExtensionSpecification { def "applies timeout to features"() { given: @@ -151,7 +152,7 @@ class GlobalTimeoutExtension extends BaseTimeoutExtensionSpecification { def "can exclude fixture methods from global timeout"() { given: - enableGlobalTimeout(false, Duration.ofMillis(5)) + enableGlobalTimeout(false, Duration.ofMillis(20)) when: runner.runSpecBody(""" diff --git a/spock-specs/src/test/groovy/spock/util/concurrent/BlockingVariableSpec.groovy b/spock-specs/src/test/groovy/spock/util/concurrent/BlockingVariableSpec.groovy index e7df8a6817..78f0a54f3a 100644 --- a/spock-specs/src/test/groovy/spock/util/concurrent/BlockingVariableSpec.groovy +++ b/spock-specs/src/test/groovy/spock/util/concurrent/BlockingVariableSpec.groovy @@ -19,9 +19,10 @@ import spock.lang.* import java.util.concurrent.TimeUnit import org.spockframework.runtime.SpockTimeoutError +@Isolated("The test can get flaky on weak machines if run in parallel.") class BlockingVariableSpec extends Specification { def "variable is read after it is written"() { - def list = new BlockingVariable>() + def list = new BlockingVariable>() when: Thread.start { @@ -35,7 +36,7 @@ class BlockingVariableSpec extends Specification { } def "variable is read before it is written"() { - def list = new BlockingVariable>() + def list = new BlockingVariable>() when: Thread.start { @@ -49,7 +50,7 @@ class BlockingVariableSpec extends Specification { } def "read times out if no write occurs"() { - def list = new BlockingVariable() + def list = new BlockingVariable() when: list.get() From f516604473a611954f0eebada15afc455e31a282 Mon Sep 17 00:00:00 2001 From: Christoph Loy Date: Fri, 20 Dec 2024 13:35:47 +0100 Subject: [PATCH 2/3] Configure compiler options via build-logic (#2026) Moves some of the "uninteresting" options to build-logic to clean up `.gradle` files. The basic idea of this PR is that much of the tedious configuration shall happen in the spockframework.base plugin. All subprojects apply that plugin and profit from the abstraction. "Interesting stuff" like declaration of dependencies shall still happen in `.gradle` files. I'd like to expand this idea , but I want to keep the PRs small and start with the most simple stuff first. --- .../gradle/SpockBasePlugin.groovy | 32 +++++++++++++++++++ .../gradle/SpockBasePluginSpec.groovy | 32 +++++++++++++++++++ build.gradle | 13 +------- spock-core/core.gradle | 4 +-- spock-specs/specs.gradle | 4 --- spock-testkit/testkit.gradle | 4 --- 6 files changed, 67 insertions(+), 22 deletions(-) create mode 100644 build-logic/base/src/test/groovy/org/spockframework/gradle/SpockBasePluginSpec.groovy diff --git a/build-logic/base/src/main/groovy/org/spockframework/gradle/SpockBasePlugin.groovy b/build-logic/base/src/main/groovy/org/spockframework/gradle/SpockBasePlugin.groovy index 9de191e2d7..191d9e10fa 100644 --- a/build-logic/base/src/main/groovy/org/spockframework/gradle/SpockBasePlugin.groovy +++ b/build-logic/base/src/main/groovy/org/spockframework/gradle/SpockBasePlugin.groovy @@ -19,11 +19,43 @@ package org.spockframework.gradle import groovy.transform.CompileStatic import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.plugins.JavaPlugin +import org.gradle.api.tasks.compile.GroovyCompile +import org.gradle.api.tasks.compile.JavaCompile import org.gradle.api.tasks.testing.Test +import org.gradle.jvm.toolchain.JavaLanguageVersion +import org.gradle.jvm.toolchain.JavaToolchainService +import org.jetbrains.annotations.VisibleForTesting @CompileStatic class SpockBasePlugin implements Plugin { + + @VisibleForTesting + public static final JavaLanguageVersion COMPILER_VERSION = JavaLanguageVersion.of(8) + void apply(Project project) { + compileTasks(project) + testTasks(project) + } + + private static void compileTasks(Project project) { + project.with { + def javaToolchains = extensions.getByType(JavaToolchainService) + tasks.withType(JavaCompile).configureEach { comp -> + if (comp.name == JavaPlugin.COMPILE_JAVA_TASK_NAME) { + comp.javaCompiler.set(javaToolchains.compilerFor { + it.languageVersion.set(COMPILER_VERSION) + }) + } + comp.options.encoding = 'UTF-8' + } + tasks.withType(GroovyCompile).configureEach { + it.options.encoding = 'UTF-8' + } + } + } + + private static void testTasks(Project project) { project.tasks.withType(Test).configureEach { task -> def taskName = task.name.capitalize() File configFile = project.file("Spock${taskName}Config.groovy") diff --git a/build-logic/base/src/test/groovy/org/spockframework/gradle/SpockBasePluginSpec.groovy b/build-logic/base/src/test/groovy/org/spockframework/gradle/SpockBasePluginSpec.groovy new file mode 100644 index 0000000000..28f3d7e56d --- /dev/null +++ b/build-logic/base/src/test/groovy/org/spockframework/gradle/SpockBasePluginSpec.groovy @@ -0,0 +1,32 @@ +package org.spockframework.gradle + +import org.gradle.api.Project +import org.gradle.api.plugins.JavaPlugin +import org.gradle.api.tasks.compile.JavaCompile +import org.gradle.testfixtures.ProjectBuilder +import spock.lang.Specification + +class SpockBasePluginSpec extends Specification { + + def 'Compile settings are configured'() { + setup: + def project = createProject() + + when: + def compileJavaTasks = project.tasks.withType(JavaCompile) + def compileJava = project.tasks.getByName(JavaPlugin.COMPILE_JAVA_TASK_NAME) as JavaCompile + + then: + compileJavaTasks.every { it.options.encoding == "UTF-8" } + compileJava.javaCompiler.get().metadata.languageVersion == SpockBasePlugin.COMPILER_VERSION + } + + private static Project createProject() { + def result = ProjectBuilder.builder() + .build() + result.plugins.apply("java-library") + result.plugins.apply("groovy") + result.plugins.apply(SpockBasePlugin) + return result + } +} diff --git a/build.gradle b/build.gradle index 1582dfd9f5..dcb4219406 100644 --- a/build.gradle +++ b/build.gradle @@ -102,6 +102,7 @@ subprojects { apply plugin: "java-library" apply plugin: "groovy" apply plugin: "jacoco" + apply plugin: "org.spockframework.base" java { toolchain { @@ -109,18 +110,6 @@ subprojects { } } - tasks.withType(JavaCompile).configureEach { - if (it.name == 'compileJava') { - javaCompiler = javaToolchains.compilerFor { - languageVersion = JavaLanguageVersion.of(8) - } - } - options.encoding = 'UTF-8' - } - tasks.withType(GroovyCompile).configureEach { - options.encoding = 'UTF-8' - } - sourceSets.all { ss -> for (gv in variants.findAll { variant <= it }) { java { diff --git a/spock-core/core.gradle b/spock-core/core.gradle index 7db47aa758..0bc05f9684 100644 --- a/spock-core/core.gradle +++ b/spock-core/core.gradle @@ -96,7 +96,7 @@ tasks.named("processResources") { tasks.register("coreConsole", JavaExec) { description = 'Start a groovy Console with Spock Core Classpath, useful for AST-Inspection' mainClass = variant == 2.5 ? "groovy.ui.Console" : "groovy.console.ui.Console" - classpath(sourceSets.named("main").map {it.runtimeClasspath }, configurations.named("coreConsoleRuntime")) + classpath(sourceSets.named("main").map { it.runtimeClasspath }, configurations.named("coreConsoleRuntime")) workingDir = file('build/console') ignoreExitValue true args file('CoreConsole.groovy').absolutePath @@ -119,7 +119,7 @@ def osgiProperties = tasks.register('osgiProperties', WriteProperties) { // that its metadata is valid. If the metadata is invalid this task will // fail. def verifyOSGi = tasks.register('verifyOSGi', Resolve) { - getBndrun().fileProvider(osgiProperties.map { it.outputFile }) + getBndrun().set(osgiProperties.flatMap { it.destinationFile }) getOutputBndrun().set(layout.getBuildDirectory().file("resolvedOSGiProperties.bndrun")) reportOptional = false // By default bnd will use jars found in: diff --git a/spock-specs/specs.gradle b/spock-specs/specs.gradle index 0111b2fc31..c7c86fcd2e 100644 --- a/spock-specs/specs.gradle +++ b/spock-specs/specs.gradle @@ -1,9 +1,5 @@ import org.spockframework.gradle.JacocoJavaagentProvider -plugins { - id 'org.spockframework.base' -} - ext.displayName = "Spock Framework - Specs for Core Module" description = "Spock specifications for the Core Module. Yes, we eat our own dog food." diff --git a/spock-testkit/testkit.gradle b/spock-testkit/testkit.gradle index 20aaa7d3ae..3d4910d066 100644 --- a/spock-testkit/testkit.gradle +++ b/spock-testkit/testkit.gradle @@ -1,7 +1,3 @@ -plugins { - id 'org.spockframework.base' -} - ext.displayName = "Spock Framework - Temp Specs for Core Module" //configurations { From 78787ce0a0979bcd426ac35888ff9840c263c8bc Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 21 Dec 2024 09:58:35 +0100 Subject: [PATCH 3/3] Update dependency gradle to v8.12 (#2059) --- gradle/wrapper/gradle-wrapper.properties | 4 ++-- gradlew | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index eb1a55be0e..e1b837a19c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionSha256Sum=f397b287023acdba1e9f6fc5ea72d22dd63669d59ed4a289a29b1a76eee151c6 -distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip +distributionSha256Sum=7a00d51fb93147819aab76024feece20b6b84e420694101f276be952e08bef03 +distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index f5feea6d6b..f3b75f3b0d 100755 --- a/gradlew +++ b/gradlew @@ -86,8 +86,7 @@ done # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) -APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s -' "$PWD" ) || exit +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum