From 5955883bf5fb7bb77f8a970725040a74e8b56205 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 24 Jan 2023 16:12:13 +0800 Subject: [PATCH 1/3] Defer more test configurations --- _ext/eclipse-wtp/build.gradle | 2 +- _ext/gradle/java-setup.gradle | 4 +++- gradle/special-tests.gradle | 2 +- lib-extra/build.gradle | 2 +- plugin-gradle/build.gradle | 2 +- testlib/build.gradle | 2 +- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/_ext/eclipse-wtp/build.gradle b/_ext/eclipse-wtp/build.gradle index 92a78578f6..feacfbf4c1 100644 --- a/_ext/eclipse-wtp/build.gradle +++ b/_ext/eclipse-wtp/build.gradle @@ -100,7 +100,7 @@ sourceSets { * All test classes need to run separately since they all instatiate different setups of the * Eclipse framework. */ -test { +tasks.withType(Test).configureEach { //Skip default tests, which would run every test case. exclude '**' } diff --git a/_ext/gradle/java-setup.gradle b/_ext/gradle/java-setup.gradle index 598077d73c..9572fc2955 100644 --- a/_ext/gradle/java-setup.gradle +++ b/_ext/gradle/java-setup.gradle @@ -22,4 +22,6 @@ dependencies { testImplementation project(':testlib') } -test { useJUnitPlatform() } +tasks.withType(Test).configureEach { + useJUnitPlatform() +} diff --git a/gradle/special-tests.gradle b/gradle/special-tests.gradle index c435bc7e81..fd5f602243 100644 --- a/gradle/special-tests.gradle +++ b/gradle/special-tests.gradle @@ -7,7 +7,7 @@ def special = [ ] boolean isCiServer = System.getenv().containsKey("CI") -tasks.named('test') { +tasks.withType(Test).configureEach { // See com.diffplug.spotless.tag package for available JUnit 5 @Tag annotations useJUnitPlatform { excludeTags special as String[] diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index 08bf286d8d..8381d14041 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -26,7 +26,7 @@ dependencies { spotbugs { reportLevel = 'low' } // low|medium|high (low = sensitive to even minor mistakes) apply from: rootProject.file('gradle/special-tests.gradle') -tasks.named('test') { +tasks.withType(Test).configureEach { if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_16)) { // needed for EclipseCdtFormatterStepTest jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED' diff --git a/plugin-gradle/build.gradle b/plugin-gradle/build.gradle index 11258db0e6..3e44335276 100644 --- a/plugin-gradle/build.gradle +++ b/plugin-gradle/build.gradle @@ -28,7 +28,7 @@ dependencies { } apply from: rootProject.file('gradle/special-tests.gradle') -tasks.named('test') { +tasks.withType(Test).configureEach { testLogging.showStandardStreams = true } diff --git a/testlib/build.gradle b/testlib/build.gradle index 64d4681805..639df8a2ab 100644 --- a/testlib/build.gradle +++ b/testlib/build.gradle @@ -22,7 +22,7 @@ dependencies { spotbugs { reportLevel = 'high' } // low|medium|high (low = sensitive to even minor mistakes) apply from: rootProject.file('gradle/special-tests.gradle') -tasks.named('test') { +tasks.withType(Test).configureEach { if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_16)) { // for Antlr4FormatterStepTest and KtLintStepTest def args = [ From c4df046be318e7a780a7e3b9ba100ceb62d1be3a Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 24 Jan 2023 16:43:18 +0800 Subject: [PATCH 2/3] Let check depend on version compatibility tasks https://github.com/davidburstrom/version-compatibility-gradle-plugin#lifecycle-tasks --- lib/build.gradle | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/build.gradle b/lib/build.gradle index 30c8fe8b15..0b42c7bcc1 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -42,6 +42,11 @@ versionCompatibility { } } +tasks.named("check").configure { + dependsOn(tasks.named("testCompatibilityAdapters")) + dependsOn(tasks.named("testCompatibility")) +} + dependencies { compileOnly 'org.slf4j:slf4j-api:2.0.0' // zero runtime reqs is a hard requirements for spotless-lib From 057f6c42a0dbbe61f7a77ec14828a7f233e6b250 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 24 Jan 2023 17:09:22 +0800 Subject: [PATCH 3/3] Make KtLintCompat0Dot48Dot0AdapterTest workable https://github.com/pinterest/ktlint/blob/2642124cfec306050dd0258870a16dc95aaa106c/build-logic/src/main/kotlin/ToolchainForTests.kt#L16-L35 --- lib/build.gradle | 17 +++++++++++++++++ .../KtLintCompat0Dot48Dot0AdapterTest.java | 7 +++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/build.gradle b/lib/build.gradle index 0b42c7bcc1..1a112c78cc 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -119,6 +119,23 @@ dependencies { spotbugs { reportLevel = 'low' } // low|medium|high (low = sensitive to even minor mistakes) apply from: rootProject.file('gradle/special-tests.gradle') +tasks.withType(Test).configureEach { + def jdkVersion = JavaVersion.current().majorVersion.toInteger() + def args = [] + if (jdkVersion >= 16) { + // https://docs.gradle.org/7.5/userguide/upgrading_version_7.html#removes_implicit_add_opens_for_test_workers + args += [ + "--add-opens=java.base/java.lang=ALL-UNNAMED", + "--add-opens=java.base/java.util=ALL-UNNAMED", + ] + } + if (jdkVersion >= 18) { + // https://openjdk.org/jeps/411 + args += "-Djava.security.manager=allow" + } + jvmArgs(args) +} + jar { for (glue in NEEDS_GLUE) { from sourceSets.getByName(glue).output.classesDirs diff --git a/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java index 6825b3d818..8804f86b08 100644 --- a/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java @@ -22,6 +22,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; @@ -33,12 +34,13 @@ public class KtLintCompat0Dot48Dot0AdapterTest { public void testDefaults(@TempDir Path path) throws IOException { KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); String text = loadAndWriteText(path, "empty_class_body.kt"); + final Path filePath = Paths.get(path.toString(), "empty_class_body.kt"); Map userData = new HashMap<>(); Map editorConfigOverrideMap = new HashMap<>(); - String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, path, false, false, null, userData, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap); assertEquals("class empty_class_body\n", formatted); } @@ -46,6 +48,7 @@ public void testDefaults(@TempDir Path path) throws IOException { public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); String text = loadAndWriteText(path, "fails_no_semicolons.kt"); + final Path filePath = Paths.get(path.toString(), "fails_no_semicolons.kt"); Map userData = new HashMap<>(); @@ -53,7 +56,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { editorConfigOverrideMap.put("indent_style", "tab"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); - String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, path, false, false, null, userData, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap); assertEquals("class fails_no_semicolons {\n\tval i = 0;\n}\n", formatted); }