Skip to content

Commit

Permalink
KAPT3: Use another class in com.sun.tools.javac.main
Browse files Browse the repository at this point in the history
Instead of CommandLine use Option, since CommandLine was moved or
removed from JDK 21.

 #KT-60507 Fixed
  • Loading branch information
ilmirus committed Nov 21, 2023
1 parent d4ce8c7 commit c66b789
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.jvm.toolchain.internal.NoToolchainAvailableException
import org.jetbrains.kotlin.pill.PillExtension
import java.nio.file.Paths

Expand Down Expand Up @@ -386,6 +387,12 @@ tasks.withType<Test> {
systemProperty("jdk11Home", jdk11Provider.get())
systemProperty("jdk16Home", jdk16Provider.get())
systemProperty("jdk17Home", jdk17Provider.get())
// jdk21Provider.isPresent throws NoToolchainAvailableException, so, we have to check for the exception
// Storing jdk21Provider in a field leads to "Configuration cache state could not be cached" error,
// since it tries to resolve the toolchain as well.
try {
systemProperty("jdk21Home", project.getToolchainJdkHomeFor(JdkMajorVersion.JDK_21_0).get())
} catch (_: NoToolchainAvailableException) {}
if (mavenLocalRepo != null) {
systemProperty("maven.repo.local", mavenLocalRepo)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,36 @@ open class Kapt3IT : Kapt3BaseIT() {
}
}

// TODO: Remove as JDK 21 is supported on Java Toolchains
@DisplayName("Kapt is working with JDK 21")
@GradleTest
@GradleTestVersions(minVersion = TestVersions.Gradle.G_7_3)
@EnableOnJdk21
fun doTestSimpleWithJdk21(
gradleVersion: GradleVersion
) {
project(
"simple".withPrefix,
gradleVersion
) {
//language=Groovy
buildGradle.appendText(
"""
|
|kotlin {
| jvmToolchain(21)
|}
""".trimMargin()
)

build("assemble") {
assertTasksExecuted(":kaptGenerateStubsKotlin", ":kaptKotlin")
// Check added because of https://youtrack.jetbrains.com/issue/KT-33056.
assertOutputDoesNotContain("javaslang.match.PatternsProcessor")
}
}
}

@DisplayName("KT-48402: Kapt worker classpath is using JRE classes from toolchain")
@JdkVersions(versions = [JavaVersion.VERSION_16])
@GradleWithJdkTest
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package org.jetbrains.kotlin.gradle.testbase

import org.junit.jupiter.api.extension.ConditionEvaluationResult
import org.junit.jupiter.api.extension.ExecutionCondition
import org.junit.jupiter.api.extension.ExtendWith
import org.junit.jupiter.api.extension.ExtensionContext

class EnableOnJdk21Condition : ExecutionCondition {
override fun evaluateExecutionCondition(context: ExtensionContext?): ConditionEvaluationResult =
if (System.getProperty("jdk21Home") == null) {
ConditionEvaluationResult.disabled("No JDK 21 Found")
} else {
ConditionEvaluationResult.enabled("JDK 21 Found")
}
}

@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
@ExtendWith(EnableOnJdk21Condition::class)
annotation class EnableOnJdk21
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ val REQUIRED_PACKAGES_TO_TEST_CLASSES = mapOf(
"com.sun.tools.javac.util" to "Context",
"com.sun.tools.javac.file" to "CacheFSInfo",
"com.sun.tools.javac.tree" to "TreeTranslator",
"com.sun.tools.javac.main" to "CommandLine",
"com.sun.tools.javac.main" to "Option",
"com.sun.tools.javac.jvm" to "ClassFile",
"com.sun.tools.javac.parser" to "Tokens\$TokenKind",
"com.sun.tools.javac.code" to "Source",
Expand Down

0 comments on commit c66b789

Please sign in to comment.