From 705c8047aec3298ecb803df6ba12da88509c7eeb Mon Sep 17 00:00:00 2001 From: Ilmir Usmanov Date: Thu, 26 Oct 2023 04:26:27 +0200 Subject: [PATCH] KAPT: Run tests on JDK 21 Previously, some tests have also been disabled on JDK 11+, since we did not filter out empty filesets, which led to failed assertion inside JDK. #KT-57389 --- .../org/jetbrains/kotlin/generators/tests/GenerateTests.kt | 2 +- .../org/jetbrains/kotlin/kapt3/base/annotationProcessing.kt | 2 +- plugins/kapt3/kapt3-compiler/build.gradle.kts | 1 + .../runners/AbstractClassFileToSourceStubConverterTest.kt | 5 +++++ .../kapt3/test/runners/AbstractKotlinKaptContextTest.kt | 5 +++++ .../kapt3/test/runners/IrKotlinKaptContextTestGenerated.java | 2 -- plugins/kapt4/build.gradle.kts | 1 + ...textTestBase.kt => AbstractKotlinKapt4ContextTestBase.kt} | 5 +++++ 8 files changed, 19 insertions(+), 4 deletions(-) rename plugins/kapt4/test/org/jetbrains/kotlin/kapt4/{AbstractKotlinKaptContextTestBase.kt => AbstractKotlinKapt4ContextTestBase.kt} (93%) diff --git a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index 7518704d87d0f..f898e1d38ef12 100644 --- a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -382,7 +382,7 @@ fun main(args: Array) { model("kotlinRunner") } - testClass(annotations = annotations) { + testClass { model("kotlinRunner") } diff --git a/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/annotationProcessing.kt b/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/annotationProcessing.kt index a569b31d9aba0..2b0de644fe21a 100644 --- a/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/annotationProcessing.kt +++ b/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/annotationProcessing.kt @@ -297,7 +297,7 @@ fun KaptContext.parseJavaFiles(javaSourceFiles: List): JavacList): JavacList { - if (isJava9OrLater()) { + if (files.isNotEmpty() && isJava9OrLater()) { val initModulesMethod = compiler.javaClass.getMethod("initModules", JavacList::class.java) @Suppress("UNCHECKED_CAST") diff --git a/plugins/kapt3/kapt3-compiler/build.gradle.kts b/plugins/kapt3/kapt3-compiler/build.gradle.kts index 5eba8729eb9cc..8cc075ce6fb62 100644 --- a/plugins/kapt3/kapt3-compiler/build.gradle.kts +++ b/plugins/kapt3/kapt3-compiler/build.gradle.kts @@ -62,6 +62,7 @@ testsJar {} kaptTestTask("test", JavaLanguageVersion.of(8)) kaptTestTask("testJdk11", JavaLanguageVersion.of(11)) kaptTestTask("testJdk17", JavaLanguageVersion.of(17)) +kaptTestTask("testJdk21", JavaLanguageVersion.of(21)) fun Project.kaptTestTask(name: String, javaLanguageVersion: JavaLanguageVersion) { val service = extensions.getByType() diff --git a/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/runners/AbstractClassFileToSourceStubConverterTest.kt b/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/runners/AbstractClassFileToSourceStubConverterTest.kt index 9540f1c15b95a..b129027438b73 100644 --- a/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/runners/AbstractClassFileToSourceStubConverterTest.kt +++ b/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/runners/AbstractClassFileToSourceStubConverterTest.kt @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.kapt3.test.KaptRegularExtensionForTestConfigurator import org.jetbrains.kotlin.kapt3.test.KaptTestDirectives.MAP_DIAGNOSTIC_LOCATIONS import org.jetbrains.kotlin.kapt3.test.KaptTestDirectives.USE_JVM_IR import org.jetbrains.kotlin.kapt3.test.handlers.ClassFileToSourceKaptStubHandler +import org.jetbrains.kotlin.kapt3.util.doOpenInternalPackagesIfRequired import org.jetbrains.kotlin.platform.jvm.JvmPlatforms import org.jetbrains.kotlin.test.TargetBackend import org.jetbrains.kotlin.test.backend.BlackBoxCodegenSuppressor @@ -26,6 +27,10 @@ import org.jetbrains.kotlin.test.services.configuration.JvmEnvironmentConfigurat abstract class AbstractClassFileToSourceStubConverterTestBase( targetBackend: TargetBackend ) : AbstractKotlinCompilerWithTargetBackendTest(targetBackend) { + init { + doOpenInternalPackagesIfRequired() + } + override fun TestConfigurationBuilder.configuration() { globalDefaults { frontend = FrontendKinds.ClassicFrontend diff --git a/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/runners/AbstractKotlinKaptContextTest.kt b/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/runners/AbstractKotlinKaptContextTest.kt index 9efef880d01b0..4ff44568e39d5 100644 --- a/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/runners/AbstractKotlinKaptContextTest.kt +++ b/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/runners/AbstractKotlinKaptContextTest.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.kapt3.test.runners +import org.jetbrains.kotlin.kapt3.util.doOpenInternalPackagesIfRequired import org.jetbrains.kotlin.kapt3.test.* import org.jetbrains.kotlin.kapt3.test.KaptTestDirectives.MAP_DIAGNOSTIC_LOCATIONS import org.jetbrains.kotlin.kapt3.test.handlers.KaptContextHandler @@ -20,6 +21,10 @@ import org.jetbrains.kotlin.test.services.configuration.JvmEnvironmentConfigurat abstract class AbstractKotlinKaptContextTestBase( targetBackend: TargetBackend ) : AbstractKotlinCompilerWithTargetBackendTest(targetBackend) { + init { + doOpenInternalPackagesIfRequired() + } + override fun TestConfigurationBuilder.configuration() { globalDefaults { frontend = FrontendKinds.ClassicFrontend diff --git a/plugins/kapt3/kapt3-compiler/tests-gen/org/jetbrains/kotlin/kapt3/test/runners/IrKotlinKaptContextTestGenerated.java b/plugins/kapt3/kapt3-compiler/tests-gen/org/jetbrains/kotlin/kapt3/test/runners/IrKotlinKaptContextTestGenerated.java index 649e0eb538ffe..c5dabde453334 100644 --- a/plugins/kapt3/kapt3-compiler/tests-gen/org/jetbrains/kotlin/kapt3/test/runners/IrKotlinKaptContextTestGenerated.java +++ b/plugins/kapt3/kapt3-compiler/tests-gen/org/jetbrains/kotlin/kapt3/test/runners/IrKotlinKaptContextTestGenerated.java @@ -7,7 +7,6 @@ import com.intellij.testFramework.TestDataPath; import org.jetbrains.kotlin.test.util.KtTestUtil; -import org.junit.jupiter.api.Tag; import org.jetbrains.kotlin.test.TargetBackend; import org.jetbrains.kotlin.test.TestMetadata; import org.junit.jupiter.api.Nested; @@ -20,7 +19,6 @@ @SuppressWarnings("all") @TestMetadata("plugins/kapt3/kapt3-compiler/testData/kotlinRunner") @TestDataPath("$PROJECT_ROOT") -@Tag("IgnoreJDK11") public class IrKotlinKaptContextTestGenerated extends AbstractIrKotlinKaptContextTest { @Test public void testAllFilesPresentInKotlinRunner() throws Exception { diff --git a/plugins/kapt4/build.gradle.kts b/plugins/kapt4/build.gradle.kts index f6ed61caa9093..9ba0b0d3f3200 100644 --- a/plugins/kapt4/build.gradle.kts +++ b/plugins/kapt4/build.gradle.kts @@ -57,6 +57,7 @@ testsJar {} kaptTestTask("test", JavaLanguageVersion.of(8)) kaptTestTask("testJdk11", JavaLanguageVersion.of(11)) kaptTestTask("testJdk17", JavaLanguageVersion.of(17)) +kaptTestTask("testJdk21", JavaLanguageVersion.of(21)) fun Project.kaptTestTask(name: String, javaLanguageVersion: JavaLanguageVersion) { val service = extensions.getByType() diff --git a/plugins/kapt4/test/org/jetbrains/kotlin/kapt4/AbstractKotlinKaptContextTestBase.kt b/plugins/kapt4/test/org/jetbrains/kotlin/kapt4/AbstractKotlinKapt4ContextTestBase.kt similarity index 93% rename from plugins/kapt4/test/org/jetbrains/kotlin/kapt4/AbstractKotlinKaptContextTestBase.kt rename to plugins/kapt4/test/org/jetbrains/kotlin/kapt4/AbstractKotlinKapt4ContextTestBase.kt index e14c8934b0669..c12cf3aa950b2 100644 --- a/plugins/kapt4/test/org/jetbrains/kotlin/kapt4/AbstractKotlinKaptContextTestBase.kt +++ b/plugins/kapt4/test/org/jetbrains/kotlin/kapt4/AbstractKotlinKapt4ContextTestBase.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.kapt4 +import org.jetbrains.kotlin.kapt3.util.doOpenInternalPackagesIfRequired import org.jetbrains.kotlin.kapt3.test.* import org.jetbrains.kotlin.kapt3.test.KaptTestDirectives.MAP_DIAGNOSTIC_LOCATIONS import org.jetbrains.kotlin.platform.jvm.JvmPlatforms @@ -22,6 +23,10 @@ open class AbstractKotlinKapt4ContextTest : AbstractKotlinKapt4ContextTestBase(T abstract class AbstractKotlinKapt4ContextTestBase( targetBackend: TargetBackend ) : AbstractKotlinCompilerWithTargetBackendTest(targetBackend) { + init { + doOpenInternalPackagesIfRequired() + } + override fun TestConfigurationBuilder.configuration() { globalDefaults { frontend = FrontendKinds.FIR