[KAPT] Setup KaptJavaLog writers during initialization.
Migrate KaptJavaLog to not used deprecated constructor in newer JDKs and instead set up the writers during initialization. This enables us to get rid of KaptJavaLog17. Fixes KT-54030
This commit is contained in:
committed by
Alexander Udalov
parent
f4845b8dd9
commit
189be2b117
@@ -56,6 +56,7 @@ testsJar {}
|
||||
|
||||
kaptTestTask("test", JavaLanguageVersion.of(8))
|
||||
kaptTestTask("testJdk11", JavaLanguageVersion.of(11))
|
||||
kaptTestTask("testJdk17", JavaLanguageVersion.of(17))
|
||||
|
||||
fun Project.kaptTestTask(name: String, javaLanguageVersion: JavaLanguageVersion) {
|
||||
val service = extensions.getByType<JavaToolchainService>()
|
||||
|
||||
+39
-11
@@ -5,6 +5,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.kapt3.test.integration
|
||||
|
||||
import org.jetbrains.kotlin.analyzer.CompilationErrorException
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.kapt3.javac.KaptJavaFileObject
|
||||
import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertEquals
|
||||
import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertTrue
|
||||
@@ -33,6 +35,7 @@ abstract class AbstractKotlinKapt3IntegrationTestBase(private val testInfo: Test
|
||||
name: String,
|
||||
vararg supportedAnnotations: String,
|
||||
options: Map<String, String> = emptyMap(),
|
||||
expectFailure: Boolean = false,
|
||||
process: (Set<TypeElement>, RoundEnvironment, ProcessingEnvironment, Kapt3ExtensionForTests) -> Unit
|
||||
) {
|
||||
val file = File(TEST_DATA_DIR, "$name.kt")
|
||||
@@ -43,7 +46,12 @@ abstract class AbstractKotlinKapt3IntegrationTestBase(private val testInfo: Test
|
||||
process
|
||||
).apply {
|
||||
initTestInfo(testInfo)
|
||||
runTest(file.absolutePath)
|
||||
try {
|
||||
runTest(file.absolutePath)
|
||||
if (expectFailure) throw AssertionError("Expected compilation to fail, but it didn't.")
|
||||
} catch (ex: CompilationErrorException) {
|
||||
if (!expectFailure) throw ex
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,19 +139,21 @@ abstract class AbstractKotlinKapt3IntegrationTestBase(private val testInfo: Test
|
||||
}
|
||||
|
||||
private fun List<LoggingMessageCollector.Message>.assertContainsDiagnostic(
|
||||
message: String
|
||||
message: String,
|
||||
severity: CompilerMessageSeverity? = null
|
||||
) {
|
||||
assertTrue(
|
||||
any {
|
||||
it.message.contains(message)
|
||||
any { msg ->
|
||||
(severity?.let { it == msg.severity } ?: true) && msg.message.contains(message)
|
||||
}
|
||||
) {
|
||||
"""
|
||||
Didn't find expected diagnostic message.
|
||||
Expected: $message
|
||||
Diagnostics:
|
||||
${this.joinToString("\n") { "${it.severity}: ${it.message}" }}
|
||||
""".trimIndent()
|
||||
|Didn't find expected diagnostic message.
|
||||
|Expected: $message
|
||||
|Severity: ${severity ?: "ANY"}
|
||||
|Diagnostics:
|
||||
|${this.joinToString("\n") { "${it.severity}: ${it.message}" }}
|
||||
""".trimMargin()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,12 +161,14 @@ abstract class AbstractKotlinKapt3IntegrationTestBase(private val testInfo: Test
|
||||
private fun diagnosticsTest(
|
||||
name: String,
|
||||
vararg supportedAnnotations: String,
|
||||
expectFailure: Boolean = false,
|
||||
process: (Set<TypeElement>, RoundEnvironment, ProcessingEnvironment) -> Unit
|
||||
): List<LoggingMessageCollector.Message> {
|
||||
lateinit var messageCollector: LoggingMessageCollector
|
||||
test(
|
||||
name = name,
|
||||
supportedAnnotations = supportedAnnotations
|
||||
supportedAnnotations = supportedAnnotations,
|
||||
expectFailure = expectFailure,
|
||||
) { typeElements, roundEnv, processingEnv, kaptExtension ->
|
||||
messageCollector = kaptExtension.messageCollector
|
||||
process(typeElements, roundEnv, processingEnv)
|
||||
@@ -211,4 +223,20 @@ abstract class AbstractKotlinKapt3IntegrationTestBase(private val testInfo: Test
|
||||
assertEquals("someLong", constructors[1].parameters[1].simpleName.toString())
|
||||
assertEquals("someString", constructors[1].parameters[2].simpleName.toString())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLog() {
|
||||
val diagnostics = diagnosticsTest(
|
||||
name = "Log",
|
||||
supportedAnnotations = arrayOf("*"),
|
||||
expectFailure = true
|
||||
) { _, _, env ->
|
||||
env.messager.printMessage(Diagnostic.Kind.ERROR, "a error from processor")
|
||||
env.messager.printMessage(Diagnostic.Kind.WARNING, "a warning from processor")
|
||||
env.messager.printMessage(Diagnostic.Kind.NOTE, "a note from processor")
|
||||
}
|
||||
diagnostics.assertContainsDiagnostic("error: a error from processor", CompilerMessageSeverity.ERROR)
|
||||
diagnostics.assertContainsDiagnostic("warning: a warning from processor", CompilerMessageSeverity.STRONG_WARNING)
|
||||
diagnostics.assertContainsDiagnostic("Note: a note from processor", CompilerMessageSeverity.INFO)
|
||||
}
|
||||
}
|
||||
+6
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.kapt3.test.JvmCompilerWithKaptFacade
|
||||
import org.jetbrains.kotlin.kapt3.test.KaptContextBinaryArtifact
|
||||
import org.jetbrains.kotlin.kapt3.test.KaptEnvironmentConfigurator
|
||||
import org.jetbrains.kotlin.kapt3.test.KaptTestDirectives
|
||||
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.bind
|
||||
@@ -28,6 +29,11 @@ class AbstractKotlinKapt3IntegrationTestRunner(
|
||||
private val supportedAnnotations: List<String>,
|
||||
private val process: (Set<TypeElement>, RoundEnvironment, ProcessingEnvironment, Kapt3ExtensionForTests) -> Unit
|
||||
) : AbstractKotlinCompilerWithTargetBackendTest(targetBackend) {
|
||||
|
||||
init {
|
||||
doOpenInternalPackagesIfRequired()
|
||||
}
|
||||
|
||||
override fun TestConfigurationBuilder.configuration() {
|
||||
globalDefaults {
|
||||
frontend = FrontendKinds.ClassicFrontend
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import java.lang.System;
|
||||
|
||||
@kotlin.Metadata()
|
||||
public final class Dummy {
|
||||
|
||||
public Dummy() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////
|
||||
|
||||
package error;
|
||||
|
||||
public final class NonExistentClass {
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
class Dummy
|
||||
+6
@@ -39,6 +39,12 @@ public class IrKotlinKaptContextTestGenerated extends AbstractIrKotlinKaptContex
|
||||
runTest("plugins/kapt3/kapt3-compiler/testData/kotlinRunner/ErrorLocationMapping.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("Log.kt")
|
||||
public void testLog() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-compiler/testData/kotlinRunner/Log.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("NestedClasses.kt")
|
||||
public void testNestedClasses() throws Exception {
|
||||
|
||||
+6
@@ -39,6 +39,12 @@ public class KotlinKaptContextTestGenerated extends AbstractKotlinKaptContextTes
|
||||
runTest("plugins/kapt3/kapt3-compiler/testData/kotlinRunner/ErrorLocationMapping.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("Log.kt")
|
||||
public void testLog() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-compiler/testData/kotlinRunner/Log.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("NestedClasses.kt")
|
||||
public void testNestedClasses() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user