Merge changes from topic "ksp2-fix-tests-again" into androidx-main
* changes:
Remove kotlin-compiler-embeddable dependency from room-compiler
Use KSP1 for all tests in room-compiler and privacysandbox
Run failing tests in room-compiler-processing* with KSP1
Update KSP to 2.0.20-Beta2-1.0.23 in room-compiler-processing-testing
Update xprocessing-testing for K2
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index cc94802..ef118d2 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -225,6 +225,8 @@
kotlinXHtml = { module = "org.jetbrains.kotlinx:kotlinx-html-jvm", version = "0.7.3" }
ksp = { module = "com.google.devtools.ksp:symbol-processing", version.ref = "ksp" }
kspApi = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" }
+kspCommon = { module = "com.google.devtools.ksp:symbol-processing-common-deps", version.ref = "ksp" }
+kspEmbeddable = { module = "com.google.devtools.ksp:symbol-processing-aa-embeddable", version.ref = "ksp" }
kspGradlePluginz = { module = "com.google.devtools.ksp:symbol-processing-gradle-plugin", version.ref = "ksp" }
ktfmt = { module = "com.facebook:ktfmt", version.ref = "ktfmt" }
kxml2 = { module = "net.sf.kxml:kxml2", version = "2.3.0" }
diff --git a/privacysandbox/tools/tools-apicompiler/src/test/java/androidx/privacysandbox/tools/apicompiler/util/KspTestRunner.kt b/privacysandbox/tools/tools-apicompiler/src/test/java/androidx/privacysandbox/tools/apicompiler/util/KspTestRunner.kt
index 977f26e..101939d 100644
--- a/privacysandbox/tools/tools-apicompiler/src/test/java/androidx/privacysandbox/tools/apicompiler/util/KspTestRunner.kt
+++ b/privacysandbox/tools/tools-apicompiler/src/test/java/androidx/privacysandbox/tools/apicompiler/util/KspTestRunner.kt
@@ -20,6 +20,7 @@
import androidx.privacysandbox.tools.core.model.ParsedApi
import androidx.privacysandbox.tools.testing.CompilationResultSubject
import androidx.privacysandbox.tools.testing.CompilationTestHelper.assertThat
+import androidx.room.compiler.processing.util.KOTLINC_LANGUAGE_1_9_ARGS
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.compiler.TestCompilationArguments
import androidx.room.compiler.processing.util.compiler.compile
@@ -40,6 +41,7 @@
TestCompilationArguments(
sources = sources.toList(),
symbolProcessorProviders = listOf(provider),
+ kotlincArguments = KOTLINC_LANGUAGE_1_9_ARGS
)
)
)
@@ -55,8 +57,9 @@
Files.createTempDirectory("test").toFile(),
TestCompilationArguments(
sources = sources.asList(),
- symbolProcessorProviders = listOf(provider)
- )
+ symbolProcessorProviders = listOf(provider),
+ kotlincArguments = KOTLINC_LANGUAGE_1_9_ARGS
+ ),
)
return assertThat(result).also { it.fails() }
}
diff --git a/privacysandbox/tools/tools-testing/src/main/java/androidx/privacysandbox/tools/testing/CompilationTestHelper.kt b/privacysandbox/tools/tools-testing/src/main/java/androidx/privacysandbox/tools/testing/CompilationTestHelper.kt
index 51bcaed..7c68d5b 100644
--- a/privacysandbox/tools/tools-testing/src/main/java/androidx/privacysandbox/tools/testing/CompilationTestHelper.kt
+++ b/privacysandbox/tools/tools-testing/src/main/java/androidx/privacysandbox/tools/testing/CompilationTestHelper.kt
@@ -18,6 +18,7 @@
import androidx.room.compiler.processing.util.DiagnosticLocation
import androidx.room.compiler.processing.util.DiagnosticMessage
+import androidx.room.compiler.processing.util.KOTLINC_LANGUAGE_1_9_ARGS
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.compiler.TestCompilationArguments
import androidx.room.compiler.processing.util.compiler.TestCompilationResult
@@ -50,6 +51,7 @@
classpath = extraClasspath,
symbolProcessorProviders = symbolProcessorProviders,
processorOptions = processorOptions,
+ kotlincArguments = KOTLINC_LANGUAGE_1_9_ARGS
)
)
}
diff --git a/room/room-compiler-processing-testing/build.gradle b/room/room-compiler-processing-testing/build.gradle
index f3b5539..77d66f7 100644
--- a/room/room-compiler-processing-testing/build.gradle
+++ b/room/room-compiler-processing-testing/build.gradle
@@ -30,18 +30,26 @@
id("kotlin")
}
+ext {
+ kotlin = "2.0.20-Beta2"
+ ksp = "${kotlin}-1.0.23"
+}
+
dependencies {
api(project(":room:room-compiler-processing"))
- implementation(libs.kotlinStdlib)
- implementation(libs.kspApi)
- implementation(libs.kotlinStdlibJdk8) // KSP defines older version as dependency, force update.
- implementation(libs.ksp)
+ implementation(libs.kotlinStdlibJdk8)
+ // For Java source compilation
implementation(libs.googleCompileTesting)
- // specify these to match the kotlin compiler version in AndroidX rather than what KSP or KCT
- // uses
- implementation(libs.kotlinCompilerEmbeddable)
- implementation(libs.kotlinDaemonEmbeddable)
- implementation(libs.kotlinAnnotationProcessingEmbeddable)
+ // TODO(b/314151707): Use the versions in Androidx once Androidx moves to 2.x.
+ // For KSP processing
+ implementation("com.google.devtools.ksp:symbol-processing:${ksp}")
+ implementation("com.google.devtools.ksp:symbol-processing-api:${ksp}")
+ implementation("com.google.devtools.ksp:symbol-processing-common-deps:${ksp}")
+ implementation("com.google.devtools.ksp:symbol-processing-aa-embeddable:${ksp}")
+ // For Kotlin source compilation and KAPT
+ implementation("org.jetbrains.kotlin:kotlin-compiler-embeddable:${kotlin}")
+ implementation("org.jetbrains.kotlin:kotlin-daemon-embeddable:${kotlin}")
+ implementation("org.jetbrains.kotlin:kotlin-annotation-processing-embeddable:${kotlin}")
}
/**
diff --git a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/CompilationResultSubject.kt b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/CompilationResultSubject.kt
index 8a862b0..afbc127 100644
--- a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/CompilationResultSubject.kt
+++ b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/CompilationResultSubject.kt
@@ -68,7 +68,7 @@
override fun toString(): String {
return buildString {
appendLine("CompilationResult (with $testRunnerName)")
- Diagnostic.Kind.entries.forEach { kind ->
+ Diagnostic.Kind.values().forEach { kind ->
val messages = diagnosticsOfKind(kind)
appendLine("${kind.name}: ${messages.size}")
messages.forEach { appendLine(it) }
@@ -98,7 +98,10 @@
"Scripting plugin will not be loaded: not",
"Using JVM IR backend",
"Configuring the compilation environment",
- "Loading modules:"
+ "Loading modules:",
+ // TODO: Remove once we use a Kotlin 2.x version that has
+ // https://github.com/JetBrains/kotlin/commit/7e9d6e601d007bc1250e1b47c6b2e55e3399145b
+ "Kapt currently doesn't support language version"
)
}
}
@@ -474,7 +477,7 @@
@ExperimentalProcessingApi
internal class JavaCompileTestingCompilationResult(
testRunner: CompilationTestRunner,
- private val delegate: Compilation,
+ @Suppress("unused") private val delegate: Compilation,
processor: SyntheticJavacProcessor,
diagnostics: Map<Diagnostic.Kind, List<DiagnosticMessage>>,
override val generatedSources: List<Source>,
@@ -494,7 +497,8 @@
}
@ExperimentalProcessingApi
-internal class KotlinCompilationResult(
+internal class KotlinCompilationResult
+constructor(
testRunner: CompilationTestRunner,
processor: SyntheticProcessor,
private val delegate: TestCompilationResult
diff --git a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/ProcessorTestExt.kt b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/ProcessorTestExt.kt
index d0065be1..b932e31 100644
--- a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/ProcessorTestExt.kt
+++ b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/ProcessorTestExt.kt
@@ -549,3 +549,6 @@
tmpDir.deleteRecursively()
}
}
+
+/** Kotlin compiler arguments for K1 */
+val KOTLINC_LANGUAGE_1_9_ARGS = listOf("-language-version=1.9", "-api-version=1.9")
diff --git a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/DelegatingTestRegistrar.kt b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/DelegatingTestRegistrar.kt
index bea0abc..e62003f 100644
--- a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/DelegatingTestRegistrar.kt
+++ b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/DelegatingTestRegistrar.kt
@@ -16,98 +16,151 @@
package androidx.room.compiler.processing.util.compiler
-import androidx.room.compiler.processing.util.compiler.DelegatingTestRegistrar.Companion.runCompilation
+import androidx.room.compiler.processing.util.compiler.DelegatingTestRegistrar.runCompilation
import java.net.URI
-import java.nio.file.Paths
+import kotlin.io.path.absolute
+import kotlin.io.path.toPath
import org.jetbrains.kotlin.cli.common.ExitCode
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
import org.jetbrains.kotlin.com.intellij.mock.MockProject
+import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.Services
import org.jetbrains.kotlin.util.ServiceLoaderLite
/**
- * A component registrar for Kotlin Compiler that delegates to a list of thread local delegates.
+ * A utility object for setting up Kotlin Compiler plugins that delegate to a list of thread local
+ * plugins.
*
* see [runCompilation] for usages.
*/
-@Suppress("DEPRECATION") // TODO: Migrate ComponentRegistrar to CompilerPluginRegistrar
@OptIn(ExperimentalCompilerApi::class)
-internal class DelegatingTestRegistrar :
- @Suppress("DEPRECATION") org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar {
- override fun registerProjectComponents(
- project: MockProject,
- configuration: CompilerConfiguration
- ) {
- delegates.get()?.let { it.forEach { it.registerProjectComponents(project, configuration) } }
+object DelegatingTestRegistrar {
+
+ @Suppress("DEPRECATION")
+ private val k1Delegates =
+ ThreadLocal<List<org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar>>()
+
+ private val k2Delegates = ThreadLocal<List<CompilerPluginRegistrar>>()
+
+ class K1Registrar :
+ @Suppress("DEPRECATION") org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar {
+ override fun registerProjectComponents(
+ project: MockProject,
+ configuration: CompilerConfiguration
+ ) {
+ k1Delegates.get()?.forEach { it.registerProjectComponents(project, configuration) }
+ }
+
+ // FirKotlinToJvmBytecodeCompiler throws an error when it sees an incompatible plugin.
+ override val supportsK2: Boolean
+ get() = true
}
- companion object {
- private const val REGISTRAR_CLASSPATH =
- "META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar"
+ class K2Registrar : CompilerPluginRegistrar() {
+ override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) {
+ k2Delegates.get()?.forEach { with(it) { registerExtensions(configuration) } }
+ }
- private val resourcePathForSelfClassLoader by lazy {
+ override val supportsK2: Boolean
+ get() = true
+ }
+
+ private const val K1_SERVICES_REGISTRAR_PATH =
+ "META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar"
+
+ private const val K2_SERVICES_REGISTRAR_PATH =
+ "META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar"
+
+ private val k1ResourcePathForSelfClassLoader by lazy {
+ getResourcePathForClassLoader(K1_SERVICES_REGISTRAR_PATH)
+ }
+
+ private val k2ResourcePathForSelfClassLoader by lazy {
+ getResourcePathForClassLoader(K2_SERVICES_REGISTRAR_PATH)
+ }
+
+ private fun getResourcePathForClassLoader(servicesRegistrarPath: String): String {
+ val registrarClassToLoad =
+ when (servicesRegistrarPath) {
+ K1_SERVICES_REGISTRAR_PATH ->
+ @Suppress("DEPRECATION")
+ org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar::class
+ K2_SERVICES_REGISTRAR_PATH -> CompilerPluginRegistrar::class
+ else -> error("Unknown services registrar path: $servicesRegistrarPath")
+ }
+ val expectedRegistrarClass =
+ when (servicesRegistrarPath) {
+ K1_SERVICES_REGISTRAR_PATH -> K1Registrar::class
+ K2_SERVICES_REGISTRAR_PATH -> K2Registrar::class
+ else -> error("Unknown services registrar path: $servicesRegistrarPath")
+ }
+ val classpath =
this::class
.java
.classLoader
- .getResources(REGISTRAR_CLASSPATH)
+ .getResources(servicesRegistrarPath)
.asSequence()
.mapNotNull { url ->
- val uri = URI.create(url.toString().removeSuffix("/$REGISTRAR_CLASSPATH"))
+ val uri = URI.create(url.toString().removeSuffix("/$servicesRegistrarPath"))
when (uri.scheme) {
- "jar" -> Paths.get(URI.create(uri.schemeSpecificPart.removeSuffix("!")))
- "file" -> Paths.get(uri)
+ "jar" -> URI.create(uri.schemeSpecificPart.removeSuffix("!")).toPath()
+ "file" -> uri.toPath()
else -> return@mapNotNull null
- }.toAbsolutePath()
+ }.absolute()
}
.find { resourcesPath ->
ServiceLoaderLite.findImplementations(
- @Suppress("DEPRECATION")
- org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar::class.java,
+ registrarClassToLoad.java,
listOf(resourcesPath.toFile())
)
.any { implementation ->
- implementation == DelegatingTestRegistrar::class.java.name
+ implementation == expectedRegistrarClass.java.name
}
}
- ?.toString()
- ?: throw AssertionError(
- """
- Could not find the ComponentRegistrar class loader that should load
- ${DelegatingTestRegistrar::class.qualifiedName}
- """
- .trimIndent()
- )
+ if (classpath == null) {
+ throw AssertionError(
+ """
+ Could not find the $registrarClassToLoad class loader that should load
+ $expectedRegistrarClass
+ """
+ .trimIndent()
+ )
}
- @Suppress("DEPRECATION")
- private val delegates =
- ThreadLocal<List<org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar>>()
+ return classpath.toString()
+ }
- fun runCompilation(
- compiler: K2JVMCompiler,
- messageCollector: MessageCollector,
- arguments: K2JVMCompilerArguments,
- @Suppress("DEPRECATION")
- pluginRegistrars: List<org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar>
- ): ExitCode {
- try {
- arguments.addDelegatingTestRegistrar()
- delegates.set(pluginRegistrars)
- return compiler.exec(
- messageCollector = messageCollector,
- services = Services.EMPTY,
- arguments = arguments
- )
- } finally {
- delegates.remove()
- }
+ internal fun runCompilation(
+ compiler: K2JVMCompiler,
+ messageCollector: MessageCollector,
+ arguments: K2JVMCompilerArguments,
+ registrars: PluginRegistrarArguments
+ ): ExitCode {
+ try {
+ k1Delegates.set(registrars.k1Registrars)
+ k2Delegates.set(registrars.k2Registrars)
+ arguments.addDelegatingTestRegistrars()
+ return compiler.exec(
+ messageCollector = messageCollector,
+ services = Services.EMPTY,
+ arguments = arguments
+ )
+ } finally {
+ k1Delegates.remove()
+ k2Delegates.remove()
}
+ }
- private fun K2JVMCompilerArguments.addDelegatingTestRegistrar() {
- pluginClasspaths = (pluginClasspaths ?: arrayOf()) + resourcePathForSelfClassLoader
- }
+ private fun K2JVMCompilerArguments.addDelegatingTestRegistrars() {
+ pluginClasspaths =
+ buildList {
+ pluginClasspaths?.let { addAll(it) }
+ add(k1ResourcePathForSelfClassLoader)
+ add(k2ResourcePathForSelfClassLoader)
+ }
+ .toTypedArray()
}
}
diff --git a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/KotlinCliRunner.kt b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/KotlinCliRunner.kt
index 7515bac..5335ea3 100644
--- a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/KotlinCliRunner.kt
+++ b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/KotlinCliRunner.kt
@@ -18,66 +18,35 @@
import androidx.room.compiler.processing.util.compiler.steps.CompilationStepArguments
import androidx.room.compiler.processing.util.compiler.steps.RawDiagnosticMessage
-import androidx.room.compiler.processing.util.getSystemClasspaths
import java.io.File
-import java.net.URLClassLoader
import org.jetbrains.kotlin.cli.common.ExitCode
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
-import org.jetbrains.kotlin.config.JvmDefaultMode
-import org.jetbrains.kotlin.config.JvmTarget
+import org.jetbrains.kotlin.compiler.plugin.parseLegacyPluginOption
+import org.jetbrains.kotlin.config.LanguageVersion
/** Utility object to run kotlin compiler via its CLI API. */
internal object KotlinCliRunner {
private val compiler = K2JVMCompiler()
- private fun List<SourceSet>.existingRootPaths() =
- this.asSequence().map { it.root }.filter { it.exists() }.map { it.canonicalPath }.distinct()
-
- private fun CompilationStepArguments.copyToCliArguments(cliArguments: K2JVMCompilerArguments) {
- // stdlib is in the classpath so no need to specify it here.
- cliArguments.noStdlib = true
- cliArguments.noReflect = true
- cliArguments.jvmTarget = JvmTarget.JVM_1_8.description
- cliArguments.noOptimize = true
- // useJavac & compileJava are experimental so lets not use it for now.
- cliArguments.useJavac = false
- cliArguments.compileJava = false
- cliArguments.jvmDefault = JvmDefaultMode.ALL_COMPATIBILITY.description
- cliArguments.allowNoSourceFiles = true
- cliArguments.javacArguments = javacArguments.toTypedArray()
- val inherited =
- if (inheritClasspaths) {
- inheritedClasspath
- } else {
- emptyList()
- }
- cliArguments.classpath =
- (additionalClasspaths + inherited)
- .filter { it.exists() }
- .distinct()
- .joinToString(separator = File.pathSeparator) { it.canonicalPath }
- cliArguments.javaSourceRoots =
- this.sourceSets.filter { it.hasJavaSource }.existingRootPaths().toList().toTypedArray()
- cliArguments.freeArgs += this.sourceSets.filter { it.hasKotlinSource }.existingRootPaths()
- }
-
- /** Runs the kotlin cli API with the given arguments. */
- @OptIn(ExperimentalCompilerApi::class)
+ /** Runs the Kotlin CLI API with the given arguments. */
fun runKotlinCli(
/** Compilation arguments (sources, classpaths etc) */
arguments: CompilationStepArguments,
/** Destination directory where generated class files will be written to */
destinationDir: File,
- /** List of component registrars for the compilation. */
- @Suppress("DEPRECATION")
- pluginRegistrars: List<org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar>
+ /** List of plugin registrars for the compilation. */
+ @OptIn(ExperimentalCompilerApi::class)
+ pluginRegistrars: PluginRegistrarArguments =
+ PluginRegistrarArguments(emptyList(), emptyList())
): KotlinCliResult {
- val cliArguments = compiler.createArguments()
destinationDir.mkdirs()
- cliArguments.destination = destinationDir.absolutePath
- arguments.copyToCliArguments(cliArguments)
+ val cliArguments =
+ compiler.createArguments().apply {
+ destination = destinationDir.absolutePath
+ arguments.copyToCliArguments(this)
+ }
compiler.parseArguments(arguments.kotlincArguments.toTypedArray(), cliArguments)
val diagnosticsMessageCollector = DiagnosticsMessageCollector("kotlinc")
@@ -86,7 +55,7 @@
compiler = compiler,
messageCollector = diagnosticsMessageCollector,
arguments = cliArguments,
- pluginRegistrars = pluginRegistrars
+ registrars = pluginRegistrars
)
return KotlinCliResult(
@@ -97,6 +66,53 @@
)
}
+ /** Get the language version specified with `-language-version=xxx`. */
+ fun getLanguageVersion(kotlincArguments: List<String>): LanguageVersion {
+ val cliArguments = compiler.createArguments()
+ compiler.parseArguments(kotlincArguments.toTypedArray(), cliArguments)
+ return cliArguments.languageVersion?.let { LanguageVersion.fromVersionString(it) }
+ ?: TestDefaultOptions.kotlinLanguageVersion
+ }
+
+ private fun CompilationStepArguments.copyToCliArguments(cliArguments: K2JVMCompilerArguments) {
+ // stdlib is in the classpath so no need to specify it here.
+ cliArguments.noStdlib = true
+ cliArguments.noReflect = true
+ cliArguments.noOptimize = true
+
+ // We want allow no sources to run test handlers
+ cliArguments.allowNoSourceFiles = true
+
+ cliArguments.languageVersion = TestDefaultOptions.kotlinLanguageVersion.versionString
+ cliArguments.apiVersion = TestDefaultOptions.kotlinApiVersion.versionString
+ cliArguments.jvmTarget = TestDefaultOptions.jvmTarget.description
+ cliArguments.jvmDefault = TestDefaultOptions.jvmDefaultMode.description
+
+ // useJavac & compileJava are experimental so lets not use it for now.
+ cliArguments.useJavac = false
+ cliArguments.compileJava = false
+
+ cliArguments.javacArguments = javacArguments.toTypedArray()
+
+ val inherited =
+ if (inheritClasspaths) {
+ TestClasspath.inheritedClasspath
+ } else {
+ emptyList()
+ }
+ cliArguments.classpath =
+ (additionalClasspaths + inherited)
+ .filter { it.exists() }
+ .distinct()
+ .joinToString(separator = File.pathSeparator) { it.canonicalPath }
+
+ cliArguments.javaSourceRoots =
+ this.sourceSets.filter { it.hasJavaSource }.existingRootPaths().toList().toTypedArray()
+
+ // Sources to compile are passed as args
+ cliArguments.freeArgs += this.sourceSets.filter { it.hasKotlinSource }.existingRootPaths()
+ }
+
/** Result of a kotlin compilation request */
internal class KotlinCliResult(
/** The exit code reported by the compiler */
@@ -109,47 +125,18 @@
val kotlinCliArguments: K2JVMCompilerArguments
)
- private val inheritedClasspath by
- lazy(LazyThreadSafetyMode.NONE) {
- getClasspathFromClassloader(KotlinCliRunner::class.java.classLoader)
- }
-
- // ported from https://github.com/google/compile-testing/blob/master/src/main/java/com
- // /google/testing/compile/Compiler.java#L231
- private fun getClasspathFromClassloader(referenceClassLoader: ClassLoader): List<File> {
- val platformClassLoader: ClassLoader = ClassLoader.getPlatformClassLoader()
- var currentClassloader = referenceClassLoader
- val systemClassLoader = ClassLoader.getSystemClassLoader()
-
- // Concatenate search paths from all classloaders in the hierarchy
- // 'till the system classloader.
- val classpaths: MutableSet<String> = LinkedHashSet()
- while (true) {
- if (currentClassloader === systemClassLoader) {
- classpaths.addAll(getSystemClasspaths())
- break
- }
- if (currentClassloader === platformClassLoader) {
- break
- }
- check(currentClassloader is URLClassLoader) {
- """Classpath for compilation could not be extracted
- since $currentClassloader is not an instance of URLClassloader
- """
- .trimIndent()
- }
- // We only know how to extract classpaths from URLClassloaders.
- currentClassloader.urLs.forEach { url ->
- check(url.protocol == "file") {
- """Given classloader consists of classpaths which are unsupported for
- compilation.
- """
- .trimIndent()
- }
- classpaths.add(url.path)
- }
- currentClassloader = currentClassloader.parent
- }
- return classpaths.map { File(it) }.filter { it.exists() }
+ internal fun getPluginOptions(
+ pluginId: String,
+ kotlincArguments: List<String>
+ ): Map<String, String> {
+ val options =
+ kotlincArguments
+ .dropLast(1)
+ .zip(kotlincArguments.drop(1))
+ .filter { it.first == "-P" }
+ .mapNotNull { parseLegacyPluginOption(it.second) }
+ return options
+ .filter { it.pluginId == pluginId }
+ .associateBy({ it.optionName }, { it.value })
}
}
diff --git a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/Ksp1Compilation.kt b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/Ksp1Compilation.kt
new file mode 100644
index 0000000..92cdd9d
--- /dev/null
+++ b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/Ksp1Compilation.kt
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package androidx.room.compiler.processing.util.compiler
+
+import androidx.room.compiler.processing.util.FileResource
+import androidx.room.compiler.processing.util.compiler.steps.CompilationStepArguments
+import androidx.room.compiler.processing.util.compiler.steps.CompilationStepResult
+import androidx.room.compiler.processing.util.compiler.steps.resolveDiagnostics
+import com.google.devtools.ksp.KspOptions
+import com.google.devtools.ksp.processing.SymbolProcessorProvider
+import java.io.File
+import org.jetbrains.kotlin.cli.common.ExitCode
+import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
+
+internal class Ksp1Compilation(
+ private val name: String,
+ private val symbolProcessorProviders: List<SymbolProcessorProvider>,
+ private val processorOptions: Map<String, String>
+) {
+ private fun createKspOptions(workingDir: File): KspOptions.Builder {
+ return KspOptions.Builder().apply {
+ this.javaOutputDir = workingDir.resolve(JAVA_OUT_DIR)
+ this.kotlinOutputDir = workingDir.resolve(KOTLIN_OUT_DIR)
+ this.processingOptions.putAll(processorOptions)
+ }
+ }
+
+ @OptIn(ExperimentalCompilerApi::class)
+ fun execute(workingDir: File, arguments: CompilationStepArguments): CompilationStepResult {
+ if (symbolProcessorProviders.isEmpty()) {
+ return CompilationStepResult.skip(arguments)
+ }
+ val kspMessages = DiagnosticsMessageCollector(name)
+ val result =
+ KotlinCliRunner.runKotlinCli(
+ arguments = arguments,
+ destinationDir = workingDir.resolve(CLASS_OUT_FOLDER_NAME),
+ pluginRegistrars =
+ PluginRegistrarArguments(
+ listOf(
+ TestKspRegistrar(
+ kspWorkingDir = workingDir.resolve("ksp-compiler"),
+ baseOptions = createKspOptions(workingDir),
+ processorProviders = symbolProcessorProviders,
+ messageCollector = kspMessages
+ )
+ ),
+ emptyList()
+ ),
+ )
+ // workaround for https://github.com/google/ksp/issues/623
+ val failureDueToWarnings =
+ result.kotlinCliArguments.allWarningsAsErrors && kspMessages.hasWarnings()
+
+ val generatedSources =
+ listOfNotNull(
+ workingDir.resolve(KOTLIN_OUT_DIR).toSourceSet(),
+ workingDir.resolve(JAVA_OUT_DIR).toSourceSet(),
+ )
+ val diagnostics =
+ resolveDiagnostics(
+ diagnostics = result.diagnostics + kspMessages.getDiagnostics(),
+ sourceSets = arguments.sourceSets + generatedSources
+ )
+ val outputResources = workingDir.resolve(RESOURCES_OUT_FOLDER_NAME)
+ val outputClasspath = listOf(result.compiledClasspath) + outputResources
+ val generatedResources =
+ outputResources
+ .walkTopDown()
+ .filter { it.isFile }
+ .map { FileResource(it.relativeTo(outputResources).path, it) }
+ .toList()
+ return CompilationStepResult(
+ success = result.exitCode == ExitCode.OK && !failureDueToWarnings,
+ generatedSourceRoots = generatedSources,
+ diagnostics = diagnostics,
+ nextCompilerArguments =
+ arguments.copy(sourceSets = arguments.sourceSets + generatedSources),
+ outputClasspath = outputClasspath,
+ generatedResources = generatedResources
+ )
+ }
+
+ companion object {
+ private const val JAVA_OUT_DIR = "generatedJava"
+ private const val KOTLIN_OUT_DIR = "generatedKotlin"
+ private const val CLASS_OUT_FOLDER_NAME = "class-out"
+ private const val RESOURCES_OUT_FOLDER_NAME = "ksp-compiler/resourceOutputDir"
+ }
+}
diff --git a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/Ksp2Compilation.kt b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/Ksp2Compilation.kt
new file mode 100644
index 0000000..6f1b94b
--- /dev/null
+++ b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/Ksp2Compilation.kt
@@ -0,0 +1,171 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package androidx.room.compiler.processing.util.compiler
+
+import androidx.room.compiler.processing.util.FileResource
+import androidx.room.compiler.processing.util.compiler.steps.CompilationStepArguments
+import androidx.room.compiler.processing.util.compiler.steps.CompilationStepResult
+import androidx.room.compiler.processing.util.compiler.steps.RawDiagnosticMessage
+import androidx.room.compiler.processing.util.compiler.steps.resolveDiagnostics
+import com.google.devtools.ksp.impl.KotlinSymbolProcessing
+import com.google.devtools.ksp.processing.KSPJvmConfig
+import com.google.devtools.ksp.processing.KSPLogger
+import com.google.devtools.ksp.processing.SymbolProcessorProvider
+import com.google.devtools.ksp.symbol.FileLocation
+import com.google.devtools.ksp.symbol.KSNode
+import com.google.devtools.ksp.symbol.NonExistLocation
+import java.io.File
+import java.io.PrintWriter
+import java.io.StringWriter
+import javax.tools.Diagnostic
+
+internal class Ksp2Compilation(
+ private val name: String,
+ private val symbolProcessorProviders: List<SymbolProcessorProvider>,
+ private val processorOptions: Map<String, String>
+) {
+ fun execute(workingDir: File, arguments: CompilationStepArguments): CompilationStepResult {
+ if (symbolProcessorProviders.isEmpty()) {
+ return CompilationStepResult.skip(arguments)
+ }
+
+ val kspConfig = createKspConfig(workingDir, arguments)
+ val kspDiagnostics = DiagnosticsCollectorKspLogger()
+ val exitCode =
+ KotlinSymbolProcessing(
+ kspConfig = kspConfig,
+ symbolProcessorProviders = symbolProcessorProviders,
+ logger = kspDiagnostics
+ )
+ .execute()
+ val generatedSources =
+ listOfNotNull(
+ workingDir.resolve(JAVA_SRC_OUT_FOLDER_NAME).toSourceSet(),
+ workingDir.resolve(KOTLIN_SRC_OUT_FOLDER_NAME).toSourceSet(),
+ )
+ val diagnostics =
+ resolveDiagnostics(
+ diagnostics = kspDiagnostics.messages,
+ sourceSets = arguments.sourceSets + generatedSources
+ )
+ val outputResources = workingDir.resolve(RESOURCES_OUT_FOLDER_NAME)
+ val outputClasspath = listOf(workingDir.resolve(CLASS_OUT_FOLDER_NAME))
+ val generatedResources =
+ outputResources
+ .walkTopDown()
+ .filter { it.isFile }
+ .map { FileResource(it.relativeTo(outputResources).path, it) }
+ .toList()
+ return CompilationStepResult(
+ success = exitCode == KotlinSymbolProcessing.ExitCode.OK,
+ generatedSourceRoots = generatedSources,
+ diagnostics = diagnostics,
+ nextCompilerArguments =
+ arguments.copy(sourceSets = arguments.sourceSets + generatedSources),
+ outputClasspath = outputClasspath,
+ generatedResources = generatedResources
+ )
+ }
+
+ private fun createKspConfig(workingDir: File, arguments: CompilationStepArguments) =
+ KSPJvmConfig.Builder()
+ .apply {
+ projectBaseDir = workingDir
+
+ sourceRoots =
+ arguments.sourceSets.filter { it.hasKotlinSource }.existingRoots().toList()
+ javaSourceRoots =
+ arguments.sourceSets.filter { it.hasJavaSource }.existingRoots().toList()
+
+ libraries = buildList {
+ if (arguments.inheritClasspaths) {
+ addAll(TestClasspath.inheritedClasspath)
+ }
+ addAll(arguments.additionalClasspaths)
+ }
+ jdkHome = File(System.getProperty("java.home"))
+
+ outputBaseDir = workingDir
+ javaOutputDir = workingDir.resolve(JAVA_SRC_OUT_FOLDER_NAME)
+ kotlinOutputDir = workingDir.resolve(KOTLIN_SRC_OUT_FOLDER_NAME)
+ resourceOutputDir = workingDir.resolve(RESOURCE_OUT_FOLDER_NAME)
+ classOutputDir = workingDir.resolve(CLASS_OUT_FOLDER_NAME)
+
+ cachesDir = workingDir.resolve(CACHE_FOLDER_NAME)
+
+ moduleName = ""
+
+ languageVersion = TestDefaultOptions.kotlinLanguageVersion.versionString
+ apiVersion = TestDefaultOptions.kotlinApiVersion.versionString
+ jvmTarget = TestDefaultOptions.jvmTarget.description
+ jvmDefaultMode = TestDefaultOptions.jvmDefaultMode.description
+
+ processorOptions = [email protected]
+ }
+ .build()
+
+ // We purposely avoid using MessageCollectorBasedKSPLogger to reduce our dependency on impls.
+ private class DiagnosticsCollectorKspLogger : KSPLogger {
+
+ val messages = mutableListOf<RawDiagnosticMessage>()
+
+ override fun error(message: String, symbol: KSNode?) {
+ messages.add(RawDiagnosticMessage(Diagnostic.Kind.ERROR, message, symbol.toLocation()))
+ }
+
+ override fun exception(e: Throwable) {
+ val writer = StringWriter()
+ e.printStackTrace(PrintWriter(writer))
+ messages.add(RawDiagnosticMessage(Diagnostic.Kind.ERROR, writer.toString(), null))
+ }
+
+ override fun info(message: String, symbol: KSNode?) {
+ messages.add(RawDiagnosticMessage(Diagnostic.Kind.NOTE, message, symbol.toLocation()))
+ }
+
+ override fun logging(message: String, symbol: KSNode?) {
+ messages.add(RawDiagnosticMessage(Diagnostic.Kind.NOTE, message, symbol.toLocation()))
+ }
+
+ override fun warn(message: String, symbol: KSNode?) {
+ messages.add(
+ RawDiagnosticMessage(Diagnostic.Kind.WARNING, message, symbol.toLocation())
+ )
+ }
+
+ private fun KSNode?.toLocation(): RawDiagnosticMessage.Location? {
+ val location = this?.location ?: return null
+ return when (location) {
+ is FileLocation ->
+ RawDiagnosticMessage.Location(
+ path = location.filePath,
+ line = location.lineNumber
+ )
+ NonExistLocation -> null
+ }
+ }
+ }
+
+ companion object {
+ private const val JAVA_SRC_OUT_FOLDER_NAME = "ksp-java-src-out"
+ private const val KOTLIN_SRC_OUT_FOLDER_NAME = "ksp-kotlin-src-out"
+ private const val RESOURCE_OUT_FOLDER_NAME = "ksp-resource-out"
+ private const val CACHE_FOLDER_NAME = "ksp-cache"
+ private const val CLASS_OUT_FOLDER_NAME = "class-out"
+ private const val RESOURCES_OUT_FOLDER_NAME = "ksp-compiler/resourceOutputDir"
+ }
+}
diff --git a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/SourceSet.kt b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/SourceSet.kt
index e1bf9a1..cc02a4f 100644
--- a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/SourceSet.kt
+++ b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/SourceSet.kt
@@ -105,3 +105,9 @@
} else {
null
}
+
+internal fun List<SourceSet>.existingRoots() =
+ this.asSequence().map { it.root }.filter { it.exists() }.distinct()
+
+internal fun List<SourceSet>.existingRootPaths() =
+ this.asSequence().map { it.root }.filter { it.exists() }.map { it.canonicalPath }.distinct()
diff --git a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/TestClasspath.kt b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/TestClasspath.kt
new file mode 100644
index 0000000..4bbe437
--- /dev/null
+++ b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/TestClasspath.kt
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package androidx.room.compiler.processing.util.compiler
+
+import androidx.room.compiler.processing.util.getSystemClasspaths
+import java.io.File
+import java.net.URLClassLoader
+
+/** Test runtime classpath helper. */
+internal object TestClasspath {
+ internal val inheritedClasspath by
+ lazy(LazyThreadSafetyMode.NONE) {
+ getClasspathFromClassloader(KotlinCliRunner::class.java.classLoader)
+ }
+
+ // Ported from
+ // https://github.com/google/compile-testing/blob/master/src/main/java/com/google/testing/compile/Compiler.java#L231
+ private fun getClasspathFromClassloader(referenceClassLoader: ClassLoader): List<File> {
+ val platformClassLoader: ClassLoader = ClassLoader.getPlatformClassLoader()
+ var currentClassloader = referenceClassLoader
+ val systemClassLoader = ClassLoader.getSystemClassLoader()
+
+ // Concatenate search paths from all classloaders in the hierarchy
+ // 'till the system classloader.
+ val classpaths: MutableSet<String> = LinkedHashSet()
+ while (true) {
+ if (currentClassloader === systemClassLoader) {
+ classpaths.addAll(getSystemClasspaths())
+ break
+ }
+ if (currentClassloader === platformClassLoader) {
+ break
+ }
+ check(currentClassloader is URLClassLoader) {
+ "Classpath for compilation could not be extracted since $currentClassloader " +
+ "is not an instance of URLClassloader"
+ }
+
+ // We only know how to extract classpaths from URLClassloaders.
+ currentClassloader.urLs.forEach { url ->
+ check(url.protocol == "file") {
+ "Given classloader consists of classpaths which are unsupported for " +
+ "compilation."
+ }
+ classpaths.add(url.path)
+ }
+ currentClassloader = currentClassloader.parent
+ }
+ return classpaths.map { File(it) }.filter { it.exists() }
+ }
+}
diff --git a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/TestDefaultOptions.kt b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/TestDefaultOptions.kt
new file mode 100644
index 0000000..48ea099
--- /dev/null
+++ b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/TestDefaultOptions.kt
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package androidx.room.compiler.processing.util.compiler
+
+import org.jetbrains.kotlin.config.ApiVersion
+import org.jetbrains.kotlin.config.JvmDefaultMode
+import org.jetbrains.kotlin.config.JvmTarget
+import org.jetbrains.kotlin.config.LanguageVersion
+
+/** Default argument / options across the steps and test compiler infra. */
+internal object TestDefaultOptions {
+ // TODO(kuanyingchou): Change it back to follow AndroidX once it's updated to K2.
+ internal val kotlinLanguageVersion = LanguageVersion.KOTLIN_2_0
+ internal val kotlinApiVersion = ApiVersion.createByLanguageVersion(kotlinLanguageVersion)
+ internal val jvmTarget = JvmTarget.JVM_1_8
+ internal val jvmDefaultMode = JvmDefaultMode.ALL_COMPATIBILITY
+}
diff --git a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/TestKapt3Registrar.kt b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/TestKapt3Registrar.kt
deleted file mode 100644
index 18d556d..0000000
--- a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/TestKapt3Registrar.kt
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * Copyright 2010-2016 JetBrains s.r.o.
- * Copyright 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package androidx.room.compiler.processing.util.compiler
-
-import java.io.File
-import javax.annotation.processing.Processor
-import org.jetbrains.kotlin.base.kapt3.KaptFlag
-import org.jetbrains.kotlin.base.kapt3.KaptOptions
-import org.jetbrains.kotlin.base.kapt3.logString
-import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
-import org.jetbrains.kotlin.cli.common.messages.MessageCollector
-import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot
-import org.jetbrains.kotlin.cli.jvm.config.JvmClasspathRoot
-import org.jetbrains.kotlin.com.intellij.mock.MockProject
-import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
-import org.jetbrains.kotlin.config.CompilerConfiguration
-import org.jetbrains.kotlin.config.JVMConfigurationKeys
-import org.jetbrains.kotlin.container.StorageComponentContainer
-import org.jetbrains.kotlin.container.useInstance
-import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithVisibility
-import org.jetbrains.kotlin.descriptors.ModuleDescriptor
-import org.jetbrains.kotlin.extensions.StorageComponentContainerContributor
-import org.jetbrains.kotlin.kapt3.AbstractKapt3Extension
-import org.jetbrains.kotlin.kapt3.base.LoadedProcessors
-import org.jetbrains.kotlin.kapt3.base.incremental.DeclaredProcType
-import org.jetbrains.kotlin.kapt3.base.incremental.IncrementalProcessor
-import org.jetbrains.kotlin.kapt3.util.MessageCollectorBackedKaptLogger
-import org.jetbrains.kotlin.kapt3.util.doOpenInternalPackagesIfRequired
-import org.jetbrains.kotlin.platform.TargetPlatform
-import org.jetbrains.kotlin.platform.jvm.isJvm
-import org.jetbrains.kotlin.resolve.jvm.ReplaceWithSupertypeAnonymousTypeTransformer
-import org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisHandlerExtension
-import org.jetbrains.kotlin.resolve.jvm.extensions.PartialAnalysisHandlerExtension
-import org.jetbrains.kotlin.types.KotlinType
-
-/**
- * Registers the KAPT component for the kotlin compilation.
- *
- * mostly taken from
- * https://github.com/JetBrains/kotlin/blob/master/plugins/kapt3/kapt3-compiler/src/
- * org/jetbrains/kotlin/kapt3/Kapt3Plugin.kt
- */
-@Suppress("DEPRECATION") // TODO: Migrate ComponentRegistrar to CompilerPluginRegistrar
-@OptIn(ExperimentalCompilerApi::class)
-internal class TestKapt3Registrar(
- val processors: List<Processor>,
- val baseOptions: KaptOptions.Builder,
- val messageCollector: MessageCollector
-) : @Suppress("DEPRECATION") org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar {
- override fun registerProjectComponents(
- project: MockProject,
- configuration: CompilerConfiguration
- ) {
- doOpenInternalPackagesIfRequired()
- val contentRoots = configuration[CLIConfigurationKeys.CONTENT_ROOTS] ?: emptyList()
-
- val optionsBuilder =
- baseOptions.apply {
- projectBaseDir = project.basePath?.let(::File)
- compileClasspath.addAll(
- contentRoots.filterIsInstance<JvmClasspathRoot>().map { it.file }
- )
- javaSourceRoots.addAll(
- contentRoots.filterIsInstance<JavaSourceRoot>().map { it.file }
- )
- classesOutputDir =
- classesOutputDir ?: configuration.get(JVMConfigurationKeys.OUTPUT_DIRECTORY)
- }
-
- val logger =
- MessageCollectorBackedKaptLogger(
- isVerbose = optionsBuilder.flags.contains(KaptFlag.VERBOSE),
- isInfoAsWarnings = optionsBuilder.flags.contains(KaptFlag.INFO_AS_WARNINGS),
- messageCollector = messageCollector
- )
-
- val options = optionsBuilder.build()
-
- options.sourcesOutputDir.mkdirs()
-
- if (options[KaptFlag.VERBOSE]) {
- logger.info(options.logString())
- }
-
- val kapt3AnalysisCompletedHandlerExtension =
- object :
- AbstractKapt3Extension(
- options = options,
- logger = logger,
- compilerConfiguration = configuration
- ) {
- override fun loadProcessors(): LoadedProcessors {
- return LoadedProcessors(
- processors =
- processors.map {
- IncrementalProcessor(
- processor = it,
- kind = DeclaredProcType.NON_INCREMENTAL,
- logger = logger
- )
- },
- classLoader = TestKapt3Registrar::class.java.classLoader
- )
- }
- }
-
- AnalysisHandlerExtension.registerExtension(project, kapt3AnalysisCompletedHandlerExtension)
- StorageComponentContainerContributor.registerExtension(
- project,
- KaptComponentContributor(kapt3AnalysisCompletedHandlerExtension)
- )
- }
-
- class KaptComponentContributor(private val analysisExtension: PartialAnalysisHandlerExtension) :
- StorageComponentContainerContributor {
- override fun registerModuleComponents(
- container: StorageComponentContainer,
- platform: TargetPlatform,
- moduleDescriptor: ModuleDescriptor
- ) {
- if (!platform.isJvm()) return
- container.useInstance(
- object : ReplaceWithSupertypeAnonymousTypeTransformer() {
- override fun transformAnonymousType(
- descriptor: DeclarationDescriptorWithVisibility,
- type: KotlinType
- ): KotlinType? {
- if (!analysisExtension.analyzePartially) return null
- return super.transformAnonymousType(descriptor, type)
- }
- }
- )
- }
- }
-}
diff --git a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/TestKotlinCompiler.kt b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/TestKotlinCompiler.kt
index 8913ac9..2849e59 100644
--- a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/TestKotlinCompiler.kt
+++ b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/TestKotlinCompiler.kt
@@ -29,6 +29,8 @@
import java.io.File
import javax.annotation.processing.Processor
import javax.tools.Diagnostic
+import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
+import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
/** Compilation runner for kotlin using kotlin CLI tool */
data class TestCompilationArguments(
@@ -70,6 +72,13 @@
val generatedResources: List<Resource>,
)
+@OptIn(ExperimentalCompilerApi::class)
+internal class PluginRegistrarArguments(
+ @Suppress("DEPRECATION")
+ val k1Registrars: List<org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar>,
+ val k2Registrars: List<CompilerPluginRegistrar>
+)
+
/** Ensures the list of sources has at least 1 kotlin file, if not, adds one. */
internal fun TestCompilationArguments.withAtLeastOneKotlinSource(): TestCompilationArguments {
val hasKotlinSource = sources.any { it is Source.KotlinSource }
diff --git a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/TestKspRegistrar.kt b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/TestKspRegistrar.kt
index 074079e..0deef7a 100644
--- a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/TestKspRegistrar.kt
+++ b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/TestKspRegistrar.kt
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package androidx.room.compiler.processing.util.compiler
import com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension
@@ -64,15 +63,12 @@
?: kspWorkingDir.resolve(KspCliOption.RESOURCE_OUTPUT_DIR_OPTION.optionName)
cachesDir =
cachesDir ?: kspWorkingDir.resolve(KspCliOption.CACHES_DIR_OPTION.optionName)
-
kspOutputDir =
kspOutputDir ?: kspWorkingDir.resolve(KspCliOption.KSP_OUTPUT_DIR_OPTION.optionName)
val contentRoots = configuration[CLIConfigurationKeys.CONTENT_ROOTS] ?: emptyList()
-
compileClasspath.addAll(
contentRoots.filterIsInstance<JvmClasspathRoot>().map { it.file }
)
-
javaSourceRoots.addAll(contentRoots.filterIsInstance<JavaSourceRoot>().map { it.file })
}
val logger =
diff --git a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/steps/JavaSourceCompilationStep.kt b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/steps/JavaSourceCompilationStep.kt
index bf807f6..9551279 100644
--- a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/steps/JavaSourceCompilationStep.kt
+++ b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/steps/JavaSourceCompilationStep.kt
@@ -25,9 +25,11 @@
import javax.tools.JavaFileObject
/**
- * Compiles java sources. Note that this does not run java annotation processors. They are run in
- * the KAPT step for consistency. When a test is run with purely java sources, it uses the google
- * compile testing library directly instead of the kotlin compilation pipeline.
+ * Compiles Java sources.
+ *
+ * Note that this does not run Java annotation processors. They are run in the KAPT step for
+ * consistency. When a test is run with purely Java sources, it uses google-compile-testing library
+ * directly instead of the Kotlin compilation pipeline.
*/
internal object JavaSourceCompilationStep : KotlinCompilationStep {
override val name = "javaSourceCompilation"
diff --git a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/steps/KaptCompilationStep.kt b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/steps/KaptCompilationStep.kt
index ae6d781..dc620b9 100644
--- a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/steps/KaptCompilationStep.kt
+++ b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/steps/KaptCompilationStep.kt
@@ -17,61 +17,33 @@
package androidx.room.compiler.processing.util.compiler.steps
import androidx.room.compiler.processing.util.FileResource
-import androidx.room.compiler.processing.util.compiler.DiagnosticsMessageCollector
import androidx.room.compiler.processing.util.compiler.KotlinCliRunner
-import androidx.room.compiler.processing.util.compiler.TestKapt3Registrar
import androidx.room.compiler.processing.util.compiler.toSourceSet
+import java.io.ByteArrayOutputStream
import java.io.File
+import java.io.ObjectOutputStream
+import java.util.Base64
import javax.annotation.processing.Processor
-import org.jetbrains.kotlin.base.kapt3.AptMode
-import org.jetbrains.kotlin.base.kapt3.KaptFlag
-import org.jetbrains.kotlin.base.kapt3.KaptOptions
import org.jetbrains.kotlin.cli.common.ExitCode
-import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
-import org.jetbrains.kotlin.compiler.plugin.parseLegacyPluginOption
+import org.jetbrains.kotlin.com.intellij.util.PathUtil
+import org.jetbrains.kotlin.kapt.cli.CliToolOption
+import org.jetbrains.kotlin.kapt.cli.KaptCliOption
+import org.jetbrains.kotlin.kapt3.base.AptMode
-/** Runs KAPT to run annotation processors. */
+/** Runs KAPT to run Java annotation processors. */
internal class KaptCompilationStep(
private val annotationProcessors: List<Processor>,
private val processorOptions: Map<String, String>,
) : KotlinCompilationStep {
override val name = "kapt"
- private fun createKaptArgs(
- workingDir: File,
- javacArguments: List<String>,
- kotlincArguments: List<String>
- ): KaptOptions.Builder {
- return KaptOptions.Builder().also {
- it.stubsOutputDir = workingDir.resolve("kapt-stubs") // IGNORED
- it.sourcesOutputDir = workingDir.resolve(JAVA_SRC_OUT_FOLDER_NAME)
- // Compiled classes don't end up here but generated resources do.
- it.classesOutputDir = workingDir.resolve(RESOURCES_OUT_FOLDER_NAME)
- it.projectBaseDir = workingDir
- it.processingOptions["kapt.kotlin.generated"] =
- workingDir.resolve(KOTLIN_SRC_OUT_FOLDER_NAME).also { it.mkdirs() }.canonicalPath
- it.processingOptions.putAll(processorOptions)
- it.mode = AptMode.STUBS_AND_APT
- it.processors.addAll(annotationProcessors.map { it::class.java.name })
- // NOTE: this does not work very well until the following bug is fixed
- // https://youtrack.jetbrains.com/issue/KT-47934
- it.flags.add(KaptFlag.MAP_DIAGNOSTIC_LOCATIONS)
-
- if (
- getPluginOptions(KAPT_PLUGIN_ID, kotlincArguments)
- .getOrDefault("correctErrorTypes", "false") == "true"
- ) {
- it.flags.add(KaptFlag.CORRECT_ERROR_TYPES)
- }
-
- javacArguments.forEach { javacArg ->
- it.javacOptions[javacArg.substringBefore("=")] =
- javacArg.substringAfter("=", missingDelimiterValue = "")
- }
+ init {
+ check(annotationProcessors.size <= 10) {
+ "Only 10 annotation processor can be loaded for test compilation for now, but " +
+ "requested ${annotationProcessors.size}. Tell Dany to support more!"
}
}
- @OptIn(ExperimentalCompilerApi::class)
override fun execute(
workingDir: File,
arguments: CompilationStepArguments
@@ -79,34 +51,38 @@
if (annotationProcessors.isEmpty()) {
return CompilationStepResult.skip(arguments)
}
- val kaptMessages = DiagnosticsMessageCollector(name)
+
+ val kaptArgs = buildList {
+ // Both 'kotlin-annotation-processing.jar' and
+ // 'kotlin-annotation-processing-embeddable.jar' contain the KAPT plugin that must
+ // specified so we use the `CliToolOption` class just as `KaptCli` does.
+ val pathToAnnotationJar = PathUtil.getJarPathForClass(CliToolOption::class.java)
+ add("-Xplugin=$pathToAnnotationJar")
+ createKaptCliOptions(workingDir, arguments).forEach { (option, value) ->
+ add("-P")
+ add("plugin:$KAPT_PLUGIN_ID:${option.optionName}=$value")
+ }
+ }
+ val argumentsWithKapt =
+ arguments.copy(kotlincArguments = arguments.kotlincArguments + kaptArgs)
val result =
- KotlinCliRunner.runKotlinCli(
- arguments = arguments, // output is ignored,
- destinationDir = workingDir.resolve(CLASS_OUT_FOLDER_NAME),
- pluginRegistrars =
- listOf(
- TestKapt3Registrar(
- processors = annotationProcessors,
- baseOptions =
- createKaptArgs(
- workingDir,
- arguments.javacArguments,
- arguments.kotlincArguments
- ),
- messageCollector = kaptMessages
- )
- )
- )
+ try {
+ delegateProcessors.set(annotationProcessors)
+ KotlinCliRunner.runKotlinCli(
+ arguments = argumentsWithKapt,
+ destinationDir = workingDir.resolve(CLASS_OUT_FOLDER_NAME)
+ )
+ } finally {
+ delegateProcessors.remove()
+ }
val generatedSources =
listOfNotNull(
workingDir.resolve(JAVA_SRC_OUT_FOLDER_NAME).toSourceSet(),
workingDir.resolve(KOTLIN_SRC_OUT_FOLDER_NAME).toSourceSet()
)
-
val diagnostics =
resolveDiagnostics(
- diagnostics = result.diagnostics + kaptMessages.getDiagnostics(),
+ diagnostics = result.diagnostics,
sourceSets = arguments.sourceSets + generatedSources
)
val outputResources = workingDir.resolve(RESOURCES_OUT_FOLDER_NAME)
@@ -128,28 +104,121 @@
)
}
+ private fun createKaptCliOptions(
+ workingDir: File,
+ arguments: CompilationStepArguments
+ ): List<Pair<KaptCliOption, String>> = buildList {
+ add(KaptCliOption.APT_MODE_OPTION to AptMode.STUBS_AND_APT.stringValue)
+ add(
+ KaptCliOption.SOURCE_OUTPUT_DIR_OPTION to
+ workingDir.resolve(JAVA_SRC_OUT_FOLDER_NAME).absolutePath
+ )
+ // Compiled classes don't end up here but generated resources do.
+ add(
+ KaptCliOption.CLASS_OUTPUT_DIR_OPTION to
+ workingDir.resolve(RESOURCES_OUT_FOLDER_NAME).absolutePath
+ )
+ add(
+ KaptCliOption.STUBS_OUTPUT_DIR_OPTION to
+ workingDir.resolve(STUBS_OUT_FOLDER_NAME).absolutePath
+ )
+
+ // 'apclasspath' is not used since FQN are specified in 'processors', but if left unset
+ // KAPT does not try to load processors at all.
+ add(KaptCliOption.ANNOTATION_PROCESSOR_CLASSPATH_OPTION to "empty")
+ List(annotationProcessors.size) { index ->
+ add(
+ KaptCliOption.ANNOTATION_PROCESSORS_OPTION to
+ TestDelegateProcessor.KaptTestDelegateAP0::class.java.name.dropLast(1) + index
+ )
+ }
+
+ val apOptionsMap = buildMap {
+ // Kotlin generated source output location is specified through this special
+ // annotation processor option.
+ put(
+ "kapt.kotlin.generated",
+ workingDir.resolve(KOTLIN_SRC_OUT_FOLDER_NAME).also { it.mkdirs() }.canonicalPath
+ )
+ putAll(processorOptions)
+ }
+ // We *need* to use the deprecated 'apoptions' since it supports multiple values as
+ // opposed to 'apOption' that only accepts one value and also is
+ // allowMultipleOccurrences = false
+ @Suppress("DEPRECATION")
+ add(KaptCliOption.APT_OPTIONS_OPTION to apOptionsMap.base64Encoded())
+
+ val javacOptionsMap =
+ arguments.javacArguments.associate { rawArg ->
+ val keyValuePair = rawArg.split('=', limit = 2).takeIf { it.size == 2 }
+ if (keyValuePair != null) {
+ keyValuePair[0] to keyValuePair[1]
+ } else {
+ rawArg to ""
+ }
+ }
+ // We *need* to use the deprecated 'javacArguments' since it supports multiple values as
+ // opposed to 'javacOption' that only accepts one value and also is
+ // allowMultipleOccurrences = false
+ @Suppress("DEPRECATION")
+ add(KaptCliOption.JAVAC_CLI_OPTIONS_OPTION to javacOptionsMap.base64Encoded())
+
+ // NOTE: This does not work very well until the following bug is fixed
+ // https://youtrack.jetbrains.com/issue/KT-47934
+ add(KaptCliOption.MAP_DIAGNOSTIC_LOCATIONS_OPTION to "true")
+ }
+
+ // As suggested by https://kotlinlang.org/docs/kapt.html#ap-javac-options-encoding
+ private fun Map<String, String>.base64Encoded(): String {
+ val os = ByteArrayOutputStream()
+ val oos = ObjectOutputStream(os)
+ oos.writeInt(size)
+ for ((key, value) in entries) {
+ oos.writeUTF(key)
+ oos.writeUTF(value)
+ }
+ oos.flush()
+ return Base64.getEncoder().encodeToString(os.toByteArray())
+ }
+
companion object {
private const val JAVA_SRC_OUT_FOLDER_NAME = "kapt-java-src-out"
private const val KOTLIN_SRC_OUT_FOLDER_NAME = "kapt-kotlin-src-out"
+ private const val STUBS_OUT_FOLDER_NAME = "kapt-stubs-out"
private const val RESOURCES_OUT_FOLDER_NAME = "kapt-classes-out"
private const val CLASS_OUT_FOLDER_NAME = "class-out"
private const val KAPT_PLUGIN_ID = "org.jetbrains.kotlin.kapt3"
-
- internal fun getPluginOptions(
- pluginId: String,
- kotlincArguments: List<String>
- ): Map<String, String> {
- val options =
- kotlincArguments
- .dropLast(1)
- .zip(kotlincArguments.drop(1))
- .filter { it.first == "-P" }
- .mapNotNull { parseLegacyPluginOption(it.second) }
- val filteredOptionsMap =
- options
- .filter { it.pluginId == pluginId }
- .associateBy({ it.optionName }, { it.value })
- return filteredOptionsMap
- }
}
}
+
+/** The list of processors to delegate to during the test compilation. */
+private val delegateProcessors = ThreadLocal<List<Processor>>()
+
+/**
+ * These delegate classes may seem unused but will be instantiated by KAPT via reflection and
+ * through their no-arg constructor, and we use them to delegate to actual processors provided for
+ * the test compilation. Note that the processor to delegate to is index based and obtained from the
+ * thread local [delegateProcessors] that is set before compiler invocation.
+ */
+@Suppress("UNUSED")
+sealed class TestDelegateProcessor(val delegate: Processor) : Processor by delegate {
+ class KaptTestDelegateAP0 : TestDelegateProcessor(checkNotNull(delegateProcessors.get())[0])
+
+ class KaptTestDelegateAP1 : TestDelegateProcessor(checkNotNull(delegateProcessors.get())[1])
+
+ class KaptTestDelegateAP2 : TestDelegateProcessor(checkNotNull(delegateProcessors.get())[2])
+
+ class KaptTestDelegateAP3 : TestDelegateProcessor(checkNotNull(delegateProcessors.get())[3])
+
+ class KaptTestDelegateAP4 : TestDelegateProcessor(checkNotNull(delegateProcessors.get())[4])
+
+ class KaptTestDelegateAP5 : TestDelegateProcessor(checkNotNull(delegateProcessors.get())[5])
+
+ class KaptTestDelegateAP6 : TestDelegateProcessor(checkNotNull(delegateProcessors.get())[6])
+
+ class KaptTestDelegateAP7 : TestDelegateProcessor(checkNotNull(delegateProcessors.get())[7])
+
+ class KaptTestDelegateAP8 : TestDelegateProcessor(checkNotNull(delegateProcessors.get())[8])
+
+ class KaptTestDelegateAP9 : TestDelegateProcessor(checkNotNull(delegateProcessors.get())[9])
+}
diff --git a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/steps/KotlinCompilationStep.kt b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/steps/KotlinCompilationStep.kt
index 1017983..558afec 100644
--- a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/steps/KotlinCompilationStep.kt
+++ b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/steps/KotlinCompilationStep.kt
@@ -25,8 +25,11 @@
import javax.tools.Diagnostic
/**
- * Kotlin compilation is run in multiple steps: process KSP process KAPT compile kotlin sources
- * compile java sources
+ * Kotlin compilation is run in multiple steps:
+ * * process KSP
+ * * process KAPT
+ * * compile kotlin sources
+ * * compile java sources
*
* Each step implements the [KotlinCompilationStep] interfaces and provides the arguments for the
* following step.
diff --git a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/steps/KotlinSourceCompilationStep.kt b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/steps/KotlinSourceCompilationStep.kt
index 779070e..17b431c 100644
--- a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/steps/KotlinSourceCompilationStep.kt
+++ b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/steps/KotlinSourceCompilationStep.kt
@@ -19,17 +19,15 @@
import androidx.room.compiler.processing.util.compiler.KotlinCliRunner
import java.io.File
import org.jetbrains.kotlin.cli.common.ExitCode
-import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
/**
- * Compiles kotlin sources.
+ * Compiles Kotlin sources.
*
- * Note that annotation/symbol processors are not run by this step.
+ * Note that annotation / symbol processors are not run by this step.
*/
internal object KotlinSourceCompilationStep : KotlinCompilationStep {
override val name = "kotlinSourceCompilation"
- @OptIn(ExperimentalCompilerApi::class)
override fun execute(
workingDir: File,
arguments: CompilationStepArguments
@@ -41,7 +39,6 @@
KotlinCliRunner.runKotlinCli(
arguments = arguments,
destinationDir = workingDir.resolve(CLASS_OUT_FOLDER_NAME),
- pluginRegistrars = emptyList()
)
val diagnostics =
resolveDiagnostics(diagnostics = result.diagnostics, sourceSets = arguments.sourceSets)
@@ -55,7 +52,8 @@
listOf(workingDir.resolve(CLASS_OUT_FOLDER_NAME)) +
arguments.additionalClasspaths,
// NOTE: ideally, we should remove kotlin sources but we know that there are no
- // more kotlin steps so we skip unnecessary work
+ // more
+ // kotlin steps so we skip unnecessary work
sourceSets = arguments.sourceSets
),
outputClasspath = listOf(result.compiledClasspath),
diff --git a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/steps/KspCompilationStep.kt b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/steps/KspCompilationStep.kt
index 1f77c72..fdda61e 100644
--- a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/steps/KspCompilationStep.kt
+++ b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/steps/KspCompilationStep.kt
@@ -16,92 +16,31 @@
package androidx.room.compiler.processing.util.compiler.steps
-import androidx.room.compiler.processing.util.FileResource
-import androidx.room.compiler.processing.util.compiler.DiagnosticsMessageCollector
import androidx.room.compiler.processing.util.compiler.KotlinCliRunner
-import androidx.room.compiler.processing.util.compiler.TestKspRegistrar
-import androidx.room.compiler.processing.util.compiler.toSourceSet
-import com.google.devtools.ksp.KspOptions
+import androidx.room.compiler.processing.util.compiler.Ksp1Compilation
+import androidx.room.compiler.processing.util.compiler.Ksp2Compilation
import com.google.devtools.ksp.processing.SymbolProcessorProvider
import java.io.File
-import org.jetbrains.kotlin.cli.common.ExitCode
-import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
+import org.jetbrains.kotlin.config.LanguageVersion
-/** Runs the Symbol Processors */
+/** Runs KSP to run the Symbol Processors */
internal class KspCompilationStep(
private val symbolProcessorProviders: List<SymbolProcessorProvider>,
private val processorOptions: Map<String, String>
) : KotlinCompilationStep {
override val name: String = "ksp"
- private fun createKspOptions(workingDir: File): KspOptions.Builder {
- return KspOptions.Builder().apply {
- this.javaOutputDir = workingDir.resolve(JAVA_OUT_DIR)
- this.kotlinOutputDir = workingDir.resolve(KOTLIN_OUT_DIR)
- this.processingOptions.putAll(processorOptions)
- }
- }
-
- @OptIn(ExperimentalCompilerApi::class)
override fun execute(
workingDir: File,
arguments: CompilationStepArguments
): CompilationStepResult {
- if (symbolProcessorProviders.isEmpty()) {
- return CompilationStepResult.skip(arguments)
+ val languageVersion = KotlinCliRunner.getLanguageVersion(arguments.kotlincArguments)
+ return if (languageVersion < LanguageVersion.KOTLIN_2_0) {
+ Ksp1Compilation(name, symbolProcessorProviders, processorOptions)
+ .execute(workingDir, arguments)
+ } else {
+ Ksp2Compilation(name, symbolProcessorProviders, processorOptions)
+ .execute(workingDir, arguments)
}
- val kspMessages = DiagnosticsMessageCollector(name)
- val result =
- KotlinCliRunner.runKotlinCli(
- arguments = arguments,
- destinationDir = workingDir.resolve(CLASS_OUT_FOLDER_NAME),
- pluginRegistrars =
- listOf(
- TestKspRegistrar(
- kspWorkingDir = workingDir.resolve("ksp-compiler"),
- baseOptions = createKspOptions(workingDir),
- processorProviders = symbolProcessorProviders,
- messageCollector = kspMessages
- )
- ),
- )
- // workaround for https://github.com/google/ksp/issues/623
- val failureDueToWarnings =
- result.kotlinCliArguments.allWarningsAsErrors && kspMessages.hasWarnings()
-
- val generatedSources =
- listOfNotNull(
- workingDir.resolve(KOTLIN_OUT_DIR).toSourceSet(),
- workingDir.resolve(JAVA_OUT_DIR).toSourceSet(),
- )
- val diagnostics =
- resolveDiagnostics(
- diagnostics = result.diagnostics + kspMessages.getDiagnostics(),
- sourceSets = arguments.sourceSets + generatedSources
- )
- val outputResources = workingDir.resolve(RESOURCES_OUT_FOLDER_NAME)
- val outputClasspath = listOf(result.compiledClasspath) + outputResources
- val generatedResources =
- outputResources
- .walkTopDown()
- .filter { it.isFile }
- .map { FileResource(it.relativeTo(outputResources).path, it) }
- .toList()
- return CompilationStepResult(
- success = result.exitCode == ExitCode.OK && !failureDueToWarnings,
- generatedSourceRoots = generatedSources,
- diagnostics = diagnostics,
- nextCompilerArguments =
- arguments.copy(sourceSets = arguments.sourceSets + generatedSources),
- outputClasspath = outputClasspath,
- generatedResources = generatedResources
- )
- }
-
- companion object {
- private const val JAVA_OUT_DIR = "generatedJava"
- private const val KOTLIN_OUT_DIR = "generatedKotlin"
- private const val CLASS_OUT_FOLDER_NAME = "class-out"
- private const val RESOURCES_OUT_FOLDER_NAME = "ksp-compiler/resourceOutputDir"
}
}
diff --git a/room/room-compiler-processing-testing/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar b/room/room-compiler-processing-testing/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
new file mode 100644
index 0000000..57a62dc
--- /dev/null
+++ b/room/room-compiler-processing-testing/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
@@ -0,0 +1,17 @@
+#
+# Copyright 2021 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+androidx.room.compiler.processing.util.compiler.DelegatingTestRegistrar$K2Registrar
\ No newline at end of file
diff --git a/room/room-compiler-processing-testing/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar b/room/room-compiler-processing-testing/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
index ffaca31..67086aa 100644
--- a/room/room-compiler-processing-testing/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
+++ b/room/room-compiler-processing-testing/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
@@ -14,4 +14,4 @@
# limitations under the License.
#
-androidx.room.compiler.processing.util.compiler.DelegatingTestRegistrar
\ No newline at end of file
+androidx.room.compiler.processing.util.compiler.DelegatingTestRegistrar$K1Registrar
\ No newline at end of file
diff --git a/room/room-compiler-processing-testing/src/test/java/androidx/room/compiler/processing/util/TestRunnerTest.kt b/room/room-compiler-processing-testing/src/test/java/androidx/room/compiler/processing/util/TestRunnerTest.kt
index 600845d..321cc80 100644
--- a/room/room-compiler-processing-testing/src/test/java/androidx/room/compiler/processing/util/TestRunnerTest.kt
+++ b/room/room-compiler-processing-testing/src/test/java/androidx/room/compiler/processing/util/TestRunnerTest.kt
@@ -25,9 +25,9 @@
import androidx.room.compiler.processing.XProcessingStep
import androidx.room.compiler.processing.javac.JavacBasicAnnotationProcessor
import androidx.room.compiler.processing.ksp.KspBasicAnnotationProcessor
+import androidx.room.compiler.processing.util.compiler.KotlinCliRunner
import androidx.room.compiler.processing.util.compiler.TestCompilationArguments
import androidx.room.compiler.processing.util.compiler.compile
-import androidx.room.compiler.processing.util.compiler.steps.KaptCompilationStep
import com.google.common.truth.Truth.assertThat
import com.google.devtools.ksp.processing.SymbolProcessor
import com.google.devtools.ksp.processing.SymbolProcessorEnvironment
@@ -318,7 +318,10 @@
)
runProcessorTest(
sources = listOf(src),
- kotlincArguments = listOf("-Werror"),
+ // TODO(kuanyingchou): Remove the "1.9" args when we move to KAPT4. Our processor
+ // doesn't get to run with KAPT3 and K2 as we pass "-Werror" and we got warning:
+ // "Kapt currently doesn't support language version 2.0+. Falling back to 1.9."
+ kotlincArguments = listOf("-Werror", "-language-version=1.9", "-api-version=1.9"),
javacArguments = listOf("-Werror") // needed for kapt as it uses javac,
) { invocation ->
invocation.processingEnv.messager.printMessage(Diagnostic.Kind.WARNING, "some warning")
@@ -364,47 +367,46 @@
@Test
fun testPluginOptions() {
- KaptCompilationStep.getPluginOptions(
+ KotlinCliRunner.getPluginOptions(
"org.jetbrains.kotlin.kapt3",
listOf("-P", "plugin:org.jetbrains.kotlin.kapt3:correctErrorTypes=true")
)
.let { options -> assertThat(options).containsExactly("correctErrorTypes", "true") }
// zero args
- KaptCompilationStep.getPluginOptions("org.jetbrains.kotlin.kapt3", emptyList()).let {
- options ->
+ KotlinCliRunner.getPluginOptions("org.jetbrains.kotlin.kapt3", emptyList()).let { options ->
assertThat(options).isEmpty()
}
// odd number of args
- KaptCompilationStep.getPluginOptions(
+ KotlinCliRunner.getPluginOptions(
"org.jetbrains.kotlin.kapt3",
listOf("-P", "plugin:org.jetbrains.kotlin.kapt3:correctErrorTypes=true", "-verbose")
)
.let { options -> assertThat(options).containsExactly("correctErrorTypes", "true") }
// illegal format (missing "=")
- KaptCompilationStep.getPluginOptions(
+ KotlinCliRunner.getPluginOptions(
"org.jetbrains.kotlin.kapt3",
listOf("-P", "plugin:org.jetbrains.kotlin.kapt3:correctErrorTypestrue")
)
.let { options -> assertThat(options).isEmpty() }
// illegal format (missing "-P")
- KaptCompilationStep.getPluginOptions(
+ KotlinCliRunner.getPluginOptions(
"org.jetbrains.kotlin.kapt3",
listOf("plugin:org.jetbrains.kotlin.kapt3:correctErrorTypestrue")
)
.let { options -> assertThat(options).isEmpty() }
// illegal format (wrong plugin id)
- KaptCompilationStep.getPluginOptions(
+ KotlinCliRunner.getPluginOptions(
"org.jetbrains.kotlin.kapt3",
listOf("-P", "plugin:abc:correctErrorTypes=true")
)
.let { options -> assertThat(options).isEmpty() }
- KaptCompilationStep.getPluginOptions(
+ KotlinCliRunner.getPluginOptions(
"org.jetbrains.kotlin.kapt3",
listOf(
"-P",
diff --git a/room/room-compiler-processing/build.gradle b/room/room-compiler-processing/build.gradle
index 2d110d8..1890458 100644
--- a/room/room-compiler-processing/build.gradle
+++ b/room/room-compiler-processing/build.gradle
@@ -71,7 +71,7 @@
}
dependencies {
- api(libs.kotlinStdlib)
+ api(libs.kotlinStdlibJdk8)
api(libs.javapoet)
api(libs.kotlinPoet)
api(libs.kotlinPoetJavaPoet)
@@ -82,14 +82,12 @@
exclude group: "org.jetbrains.kotlin", module: "kotlin-stdlib"
}
implementation(libs.kspApi)
- implementation(libs.kotlinStdlibJdk8) // KSP defines older version as dependency, force update.
testImplementation("androidx.annotation:annotation:1.8.1")
testImplementation(libs.googleCompileTesting)
testImplementation(libs.junit)
testImplementation(libs.jsr250)
- testImplementation(libs.ksp)
- testImplementation(libs.kotlinMetadataJvm)
+ testImplementation(libs.kotlinMetadataJvm) // Due to being shadowed in main dependency
testImplementation(libs.testParameterInjector)
testImplementation(project(":room:room-compiler-processing-testing"))
testImplementation(project(":internal-testutils-common"))
@@ -109,6 +107,9 @@
tasks.withType(Test).configureEach { test ->
test.maxParallelForks(2)
test.systemProperty("androidx.room.compiler.processing.strict", "true")
+ // With the move to K2 and KSP2 the memory usage has increased so we enlarge the heap
+ // to prevent OOM while running all the tests in one go.
+ test.maxHeapSize("8g")
}
androidx {
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/FallbackLocationInformationTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/FallbackLocationInformationTest.kt
index 5326743..3e57c9c 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/FallbackLocationInformationTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/FallbackLocationInformationTest.kt
@@ -17,6 +17,7 @@
package androidx.room.compiler.processing
import androidx.kruth.assertThat
+import androidx.room.compiler.processing.util.KOTLINC_LANGUAGE_1_9_ARGS
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.compileFiles
import androidx.room.compiler.processing.util.getField
@@ -64,7 +65,11 @@
// sources and javac fails to resolve metadata
val placeholder = Source.kotlin("MyPlaceholder.kt", "")
val dependency = compileFiles(listOf(kotlinSource, javaSource))
- runProcessorTest(sources = listOf(placeholder), classpath = dependency) { invocation ->
+ runProcessorTest(
+ sources = listOf(placeholder),
+ classpath = dependency,
+ kotlincArguments = KOTLINC_LANGUAGE_1_9_ARGS
+ ) { invocation ->
val kotlinSubject = invocation.processingEnv.requireTypeElement("foo.bar.KotlinSubject")
assertThat(kotlinSubject.getField("prop").fallbackLocationText)
.isEqualTo("prop in foo.bar.KotlinSubject")
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/InternalModifierTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/InternalModifierTest.kt
index fe3f93a..0b80372 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/InternalModifierTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/InternalModifierTest.kt
@@ -18,6 +18,7 @@
import androidx.kruth.assertThat
import androidx.room.compiler.processing.util.CompilationTestCapabilities
+import androidx.room.compiler.processing.util.KOTLINC_LANGUAGE_1_9_ARGS
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.compileFiles
import androidx.room.compiler.processing.util.runKaptTest
@@ -141,6 +142,7 @@
runKspTest(
sources = listOf(source),
classpath = classpath,
+ kotlincArguments = KOTLINC_LANGUAGE_1_9_ARGS,
config = config,
) { invocation ->
kspResult = traverse(invocation.processingEnv)
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/MethodSpecHelperTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/MethodSpecHelperTest.kt
index 4949386..6cb5d28 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/MethodSpecHelperTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/MethodSpecHelperTest.kt
@@ -19,6 +19,7 @@
import androidx.kruth.assertThat
import androidx.room.compiler.processing.javac.JavacMethodElement
import androidx.room.compiler.processing.javac.JavacTypeElement
+import androidx.room.compiler.processing.util.KOTLINC_LANGUAGE_1_9_ARGS
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
import androidx.room.compiler.processing.util.compileFiles
@@ -171,7 +172,7 @@
"""
.trimIndent()
)
- overridesCheck(source)
+ overridesCheck(source, kotlincArgs = KOTLINC_LANGUAGE_1_9_ARGS)
}
@Test
@@ -467,7 +468,11 @@
}
@Suppress("NAME_SHADOWING") // intentional
- private fun overridesCheck(vararg sources: Source, ignoreInheritedMethods: Boolean = false) {
+ private fun overridesCheck(
+ vararg sources: Source,
+ ignoreInheritedMethods: Boolean = false,
+ kotlincArgs: List<String> = emptyList()
+ ) {
val (sources: List<Source>, classpath: List<File>) =
if (preCompiledCode) {
emptyList<Source>() to compileFiles(sources.toList())
@@ -483,7 +488,8 @@
)
runProcessorTest(
sources = sources + Source.kotlin("Placeholder.kt", ""),
- classpath = classpath
+ classpath = classpath,
+ kotlincArguments = kotlincArgs
) { invocation ->
val (target, methods) = invocation.getOverrideTestTargets(ignoreInheritedMethods)
methods.forEachIndexed { index, method ->
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationBoxTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationBoxTest.kt
index 663815d..6b27602 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationBoxTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationBoxTest.kt
@@ -31,6 +31,7 @@
import androidx.room.compiler.processing.testcode.OtherAnnotation
import androidx.room.compiler.processing.testcode.RepeatableJavaAnnotation
import androidx.room.compiler.processing.testcode.TestSuppressWarnings
+import androidx.room.compiler.processing.util.KOTLINC_LANGUAGE_1_9_ARGS
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
import androidx.room.compiler.processing.util.compileFiles
@@ -47,7 +48,11 @@
@RunWith(Parameterized::class)
class XAnnotationBoxTest(private val preCompiled: Boolean) {
- private fun runTest(sources: List<Source>, handler: (XTestInvocation) -> Unit) {
+ private fun runTest(
+ sources: List<Source>,
+ kotlincArgs: List<String> = emptyList(),
+ handler: (XTestInvocation) -> Unit
+ ) {
if (preCompiled) {
val compiled = compileFiles(sources)
val hasKotlinSources = sources.any { it is Source.KotlinSource }
@@ -60,9 +65,14 @@
val newSources =
kotlinSources +
Source.java("PlaceholderJava", "public class " + "PlaceholderJava {}")
- runProcessorTest(sources = newSources, handler = handler, classpath = compiled)
+ runProcessorTest(
+ sources = newSources,
+ handler = handler,
+ classpath = compiled,
+ kotlincArguments = kotlincArgs
+ )
} else {
- runProcessorTest(sources = sources, handler = handler)
+ runProcessorTest(sources = sources, handler = handler, kotlincArguments = kotlincArgs)
}
}
@@ -212,7 +222,7 @@
"""
.trimIndent()
)
- runTest(listOf(mySource)) { invocation ->
+ runTest(listOf(mySource), kotlincArgs = KOTLINC_LANGUAGE_1_9_ARGS) { invocation ->
val element = invocation.processingEnv.requireTypeElement("Subject")
element.getAnnotation(MainAnnotation::class)!!.let { annotation ->
assertThat(annotation.getAsTypeList("typeList").map { it.asTypeName() })
@@ -420,7 +430,8 @@
"""
.trimIndent()
)
- runTest(sources = listOf(kotlinSrc, javaSrc)) { invocation ->
+ runTest(sources = listOf(kotlinSrc, javaSrc), kotlincArgs = KOTLINC_LANGUAGE_1_9_ARGS) {
+ invocation ->
listOf("KotlinClass", "JavaClass")
.map { invocation.processingEnv.requireTypeElement(it) }
.forEach { typeElement ->
@@ -631,7 +642,8 @@
"""
.trimIndent()
)
- runTest(sources = listOf(javaSrc, kotlinSrc)) { invocation ->
+ runTest(sources = listOf(javaSrc, kotlinSrc), kotlincArgs = KOTLINC_LANGUAGE_1_9_ARGS) {
+ invocation ->
listOf("JavaSubject", "KotlinSubject")
.map(invocation.processingEnv::requireTypeElement)
.forEach { subject ->
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationTest.kt
index e8f2e14..27be10a 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationTest.kt
@@ -32,6 +32,7 @@
import androidx.room.compiler.processing.testcode.RepeatableJavaAnnotation
import androidx.room.compiler.processing.testcode.RepeatableKotlinAnnotation
import androidx.room.compiler.processing.testcode.TestSuppressWarnings
+import androidx.room.compiler.processing.util.KOTLINC_LANGUAGE_1_9_ARGS
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
import androidx.room.compiler.processing.util.asJTypeName
@@ -55,7 +56,11 @@
@RunWith(Parameterized::class)
class XAnnotationTest(private val preCompiled: Boolean) {
- private fun runTest(sources: List<Source>, handler: (XTestInvocation) -> Unit) {
+ private fun runTest(
+ sources: List<Source>,
+ kotlincArgs: List<String> = emptyList(),
+ handler: (XTestInvocation) -> Unit
+ ) {
if (preCompiled) {
val compiled = compileFiles(sources)
val hasKotlinSources = sources.any { it is Source.KotlinSource }
@@ -68,9 +73,14 @@
val newSources =
kotlinSources +
Source.java("PlaceholderJava", "public class " + "PlaceholderJava {}")
- runProcessorTest(sources = newSources, handler = handler, classpath = compiled)
+ runProcessorTest(
+ sources = newSources,
+ handler = handler,
+ classpath = compiled,
+ kotlincArguments = kotlincArgs
+ )
} else {
- runProcessorTest(sources = sources, handler = handler)
+ runProcessorTest(sources = sources, handler = handler, kotlincArguments = kotlincArgs)
}
}
@@ -158,7 +168,8 @@
"""
.trimIndent()
)
- runTest(sources = listOf(javaSrc, kotlinSrc)) { invocation ->
+ runTest(sources = listOf(javaSrc, kotlinSrc), kotlincArgs = KOTLINC_LANGUAGE_1_9_ARGS) {
+ invocation ->
val typeElement = invocation.processingEnv.requireTypeElement("Foo")
val annotation =
typeElement.getAllAnnotations().single { it.qualifiedName == "MyAnnotation" }
@@ -464,7 +475,7 @@
"""
.trimIndent()
)
- runTest(listOf(mySource)) { invocation ->
+ runTest(listOf(mySource), kotlincArgs = KOTLINC_LANGUAGE_1_9_ARGS) { invocation ->
val element = invocation.processingEnv.requireTypeElement("Subject")
val annotation = element.requireAnnotation<MainAnnotation>()
@@ -936,7 +947,8 @@
"""
.trimIndent()
)
- runTest(sources = listOf(javaSrc, kotlinSrc)) { invocation ->
+ runTest(sources = listOf(javaSrc, kotlinSrc), kotlincArgs = KOTLINC_LANGUAGE_1_9_ARGS) {
+ invocation ->
listOf("JavaSubject", "KotlinSubject")
.map(invocation.processingEnv::requireTypeElement)
.forEach { subject ->
@@ -1192,6 +1204,7 @@
.trimIndent()
)
),
+ kotlincArgs = KOTLINC_LANGUAGE_1_9_ARGS
) { invocation ->
val subject = invocation.processingEnv.requireTypeElement("test.Subject")
val myAnnotation = invocation.processingEnv.requireTypeElement("test.MyAnnotation")
@@ -1324,7 +1337,8 @@
)
listOf(javaSource, kotlinSource).forEach { source ->
- runTest(sources = listOf(source)) { invocation ->
+ runTest(sources = listOf(source), kotlincArgs = KOTLINC_LANGUAGE_1_9_ARGS) { invocation
+ ->
fun XAnnotated.getAllAnnotationTypeElements(): List<XTypeElement> {
return getAllAnnotations()
.filter {
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationValueTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationValueTest.kt
index bc1a9a0..fc1bb0a 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationValueTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationValueTest.kt
@@ -18,6 +18,7 @@
import androidx.kruth.assertThat
import androidx.room.compiler.codegen.JArrayTypeName
+import androidx.room.compiler.processing.util.KOTLINC_LANGUAGE_1_9_ARGS
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
import androidx.room.compiler.processing.util.asJClassName
@@ -62,6 +63,7 @@
private fun runTest(
javaSource: Source.JavaSource,
kotlinSource: Source.KotlinSource,
+ kotlincArgs: List<String> = emptyList(),
handler: (XTestInvocation) -> Unit
) {
val sources =
@@ -81,9 +83,14 @@
val newSources =
kotlinSources +
Source.java("PlaceholderJava", "public class " + "PlaceholderJava {}")
- runProcessorTest(sources = newSources, handler = handler, classpath = compiled)
+ runProcessorTest(
+ sources = newSources,
+ handler = handler,
+ classpath = compiled,
+ kotlincArguments = kotlincArgs
+ )
} else {
- runProcessorTest(sources = sources, handler = handler)
+ runProcessorTest(sources = sources, handler = handler, kotlincArguments = kotlincArgs)
}
}
@@ -1330,7 +1337,8 @@
MyInterface
"""
.trimIndent()
- ) as Source.KotlinSource
+ ) as Source.KotlinSource,
+ kotlincArgs = KOTLINC_LANGUAGE_1_9_ARGS
) { invocation ->
val classJTypeName =
JParameterizedTypeName.get(
@@ -1451,20 +1459,33 @@
@MyAnnotation(stringParam = "2") MyInterface
"""
.trimIndent()
- ) as Source.KotlinSource
+ ) as Source.KotlinSource,
+ kotlincArgs = KOTLINC_LANGUAGE_1_9_ARGS
) { invocation ->
val annotation = getAnnotation(invocation)
// Compare the AnnotationSpec string ignoring whitespace
assertThat(annotation.toAnnotationSpec().toString().removeWhiteSpace())
.isEqualTo(
- """
+ // TODO(b/314151707): List values are missing in type annotations with K2. File
+ // a bug!
+ if (sourceKind == SourceKind.KOTLIN && isTypeAnnotation && isPreCompiled) {
+ """
+ @test.MyAnnotation(
+ stringParam="2",
+ stringParam2="1"
+ )
+ """
+ .removeWhiteSpace()
+ } else {
+ """
@test.MyAnnotation(
stringParam="2",
stringParam2="1",
stringArrayParam={"3","5","7"}
)
"""
- .removeWhiteSpace()
+ .removeWhiteSpace()
+ }
)
assertThat(
@@ -1488,7 +1509,15 @@
.firstOrNull()
?.value
)
- .isEqualTo("3")
+ .isEqualTo(
+ // TODO(b/314151707): List values are missing in type annotations with K2. File
+ // a bug!
+ if (sourceKind == SourceKind.KOTLIN && isTypeAnnotation && isPreCompiled) {
+ null
+ } else {
+ "3"
+ }
+ )
}
}
@@ -1554,7 +1583,8 @@
MyInterface
"""
.trimIndent()
- ) as Source.KotlinSource
+ ) as Source.KotlinSource,
+ kotlincArgs = KOTLINC_LANGUAGE_1_9_ARGS
) { invocation ->
val aJTypeName = JClassName.get("test", "A")
val aKTypeName = KClassName("test", "A")
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XElementTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XElementTest.kt
index b736a07..15781b1 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XElementTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XElementTest.kt
@@ -26,6 +26,7 @@
import androidx.room.compiler.processing.ksp.KspFileMemberContainer
import androidx.room.compiler.processing.ksp.synthetic.KspSyntheticFileMemberContainer
import androidx.room.compiler.processing.testcode.OtherAnnotation
+import androidx.room.compiler.processing.util.KOTLINC_LANGUAGE_1_9_ARGS
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
import androidx.room.compiler.processing.util.asJClassName
@@ -866,7 +867,8 @@
"""
.trimIndent()
)
- )
+ ),
+ kotlincArgs = KOTLINC_LANGUAGE_1_9_ARGS
) { invocation, precompiled ->
val enclosingElement =
invocation.processingEnv.requireTypeElement("foo.bar.KotlinClass")
@@ -1367,9 +1369,12 @@
private fun runProcessorTestHelper(
sources: List<Source>,
+ kotlincArgs: List<String> = emptyList(),
handler: (XTestInvocation, Boolean) -> Unit
) {
- runProcessorTest(sources = sources) { handler(it, false) }
- runProcessorTest(classpath = compileFiles(sources)) { handler(it, true) }
+ runProcessorTest(sources = sources, kotlincArguments = kotlincArgs) { handler(it, false) }
+ runProcessorTest(classpath = compileFiles(sources), kotlincArguments = kotlincArgs) {
+ handler(it, true)
+ }
}
}
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XExecutableElementTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XExecutableElementTest.kt
index 1312ac5..3166c55 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XExecutableElementTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XExecutableElementTest.kt
@@ -21,6 +21,7 @@
import androidx.room.compiler.codegen.XTypeName
import androidx.room.compiler.codegen.asClassName
import androidx.room.compiler.processing.util.CONTINUATION_JCLASS_NAME
+import androidx.room.compiler.processing.util.KOTLINC_LANGUAGE_1_9_ARGS
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.UNIT_JCLASS_NAME
import androidx.room.compiler.processing.util.className
@@ -505,7 +506,8 @@
"""
.trimIndent()
)
- runProcessorTest(sources = listOf(src)) { invocation ->
+ runProcessorTest(sources = listOf(src), kotlincArguments = KOTLINC_LANGUAGE_1_9_ARGS) {
+ invocation ->
val klass = invocation.processingEnv.requireTypeElement("MyDataClass")
val methodNames = klass.getAllMethods().map { it.jvmName }.toList()
assertThat(methodNames)
@@ -1346,7 +1348,11 @@
val sources = buildSources("app")
val classpath = compileFiles(buildSources("lib"))
- runProcessorTest(sources = sources, classpath = classpath) { invocation ->
+ runProcessorTest(
+ sources = sources,
+ classpath = classpath,
+ kotlincArguments = KOTLINC_LANGUAGE_1_9_ARGS
+ ) { invocation ->
// we use this to remove the hash added by the compiler for function names that don't
// have valid JVM names
// regex: match 7 characters after -
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XExecutableTypeTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XExecutableTypeTest.kt
index be06f3c..eef3af7 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XExecutableTypeTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XExecutableTypeTest.kt
@@ -21,6 +21,7 @@
import androidx.room.compiler.codegen.asMutableClassName
import androidx.room.compiler.processing.ksp.KspProcessingEnv
import androidx.room.compiler.processing.util.CONTINUATION_JCLASS_NAME
+import androidx.room.compiler.processing.util.KOTLINC_LANGUAGE_1_9_ARGS
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.UNIT_JCLASS_NAME
import androidx.room.compiler.processing.util.XTestInvocation
@@ -61,7 +62,8 @@
"""
.trimIndent()
)
- )
+ ),
+ kotlincArguments = KOTLINC_LANGUAGE_1_9_ARGS
) { invocation ->
fun checkConstructor(className: String) {
val typeElement = invocation.processingEnv.requireTypeElement(className)
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XMessagerTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XMessagerTest.kt
index 6e65c40..113d34ab 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XMessagerTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XMessagerTest.kt
@@ -17,6 +17,7 @@
package androidx.room.compiler.processing
import androidx.kruth.assertThat
+import androidx.room.compiler.processing.util.KOTLINC_LANGUAGE_1_9_ARGS
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.runProcessorTest
import javax.tools.Diagnostic
@@ -193,7 +194,8 @@
"""
.trimIndent()
)
- )
+ ),
+ kotlincArguments = KOTLINC_LANGUAGE_1_9_ARGS
) {
val fooElement = it.processingEnv.requireTypeElement("test.Foo")
val fooAnnotations =
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XTypeElementTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XTypeElementTest.kt
index ce9c840..8544d232 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XTypeElementTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XTypeElementTest.kt
@@ -23,6 +23,7 @@
import androidx.room.compiler.codegen.asClassName
import androidx.room.compiler.processing.javac.JavacType
import androidx.room.compiler.processing.ksp.KspProcessingEnv
+import androidx.room.compiler.processing.util.KOTLINC_LANGUAGE_1_9_ARGS
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
import androidx.room.compiler.processing.util.asKClassName
@@ -53,7 +54,11 @@
class XTypeElementTest(
private val isPreCompiled: Boolean,
) {
- private fun runTest(sources: List<Source>, handler: (XTestInvocation) -> Unit) {
+ private fun runTest(
+ sources: List<Source>,
+ kotlincArgs: List<String> = emptyList(),
+ handler: (XTestInvocation) -> Unit
+ ) {
if (isPreCompiled) {
val compiled = compileFiles(sources)
val hasKotlinSources = sources.any { it is Source.KotlinSource }
@@ -66,9 +71,14 @@
val newSources =
kotlinSources +
Source.java("PlaceholderJava", "public class " + "PlaceholderJava {}")
- runProcessorTest(sources = newSources, handler = handler, classpath = compiled)
+ runProcessorTest(
+ sources = newSources,
+ handler = handler,
+ classpath = compiled,
+ kotlincArguments = kotlincArgs
+ )
} else {
- runProcessorTest(sources = sources, handler = handler)
+ runProcessorTest(sources = sources, handler = handler, kotlincArguments = kotlincArgs)
}
}
@@ -1348,6 +1358,7 @@
.trimIndent()
)
),
+ kotlincArgs = KOTLINC_LANGUAGE_1_9_ARGS
) { invocation ->
val appSubject = invocation.processingEnv.requireTypeElement("test.Subject")
val methodNames = appSubject.getAllMethods().map { it.name }.toList()
@@ -1614,7 +1625,7 @@
"""
.trimIndent()
)
- runTest(sources = listOf(src)) { invocation ->
+ runTest(sources = listOf(src), kotlincArgs = KOTLINC_LANGUAGE_1_9_ARGS) { invocation ->
val defaultArgsConstructors =
invocation.processingEnv
.requireTypeElement("DefaultArgs")
@@ -1648,24 +1659,45 @@
)
.inOrder()
} else {
- assertThat(defaultArgsConstructors)
- .containsExactly(
- "DefaultArgs(int,double,long)",
- "DefaultArgs(double)",
- "DefaultArgs(int,double)"
- )
- .inOrder()
+ if (invocation.isKsp) {
+ assertThat(defaultArgsConstructors)
+ .containsExactly(
+ "DefaultArgs(int,double,long)",
+ "DefaultArgs(double)",
+ "DefaultArgs(int,double)",
+ )
+ .inOrder()
+ } else {
+ assertThat(defaultArgsConstructors)
+ .containsExactly(
+ "DefaultArgs(double)",
+ "DefaultArgs(int,double)",
+ "DefaultArgs(int,double,long)",
+ )
+ .inOrder()
+ }
assertThat(noDefaultArgsConstructors)
.containsExactly("NoDefaultArgs(int,double,long)")
.inOrder()
- assertThat(allDefaultArgsConstructors)
- .containsExactly(
- "AllDefaultArgs(int,double,long)",
- "AllDefaultArgs()",
- "AllDefaultArgs(int)",
- "AllDefaultArgs(int,double)"
- )
- .inOrder()
+ if (invocation.isKsp) {
+ assertThat(allDefaultArgsConstructors)
+ .containsExactly(
+ "AllDefaultArgs(int,double,long)",
+ "AllDefaultArgs()",
+ "AllDefaultArgs(int)",
+ "AllDefaultArgs(int,double)",
+ )
+ .inOrder()
+ } else {
+ assertThat(allDefaultArgsConstructors)
+ .containsExactly(
+ "AllDefaultArgs()",
+ "AllDefaultArgs(int)",
+ "AllDefaultArgs(int,double)",
+ "AllDefaultArgs(int,double,long)",
+ )
+ .inOrder()
+ }
}
val subjects = listOf("DefaultArgs", "NoDefaultArgs", "AllDefaultArgs")
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XTypeTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XTypeTest.kt
index c3172f6..840c0e7 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XTypeTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XTypeTest.kt
@@ -27,6 +27,7 @@
import androidx.room.compiler.processing.ksp.ERROR_JTYPE_NAME
import androidx.room.compiler.processing.ksp.ERROR_KTYPE_NAME
import androidx.room.compiler.processing.ksp.KspTypeArgumentType
+import androidx.room.compiler.processing.util.KOTLINC_LANGUAGE_1_9_ARGS
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
import androidx.room.compiler.processing.util.asJClassName
@@ -1084,7 +1085,10 @@
"""
.trimIndent()
)
- runProcessorTest(sources = listOf(src, javaSource)) { invocation ->
+ runProcessorTest(
+ sources = listOf(src, javaSource),
+ kotlincArguments = KOTLINC_LANGUAGE_1_9_ARGS
+ ) { invocation ->
val styleApplier = invocation.processingEnv.requireType("StyleApplier")
val styleBuilder = invocation.processingEnv.requireType("StyleBuilder")
assertThat(styleApplier.typeName.dumpToString(5))
@@ -1618,7 +1622,8 @@
.trimIndent()
)
),
- createProcessingSteps = { listOf(WildcardProcessingStep()) }
+ createProcessingSteps = { listOf(WildcardProcessingStep()) },
+ kotlincArguments = KOTLINC_LANGUAGE_1_9_ARGS
) { result ->
result.hasError()
result.hasErrorCount(1)
@@ -2326,7 +2331,8 @@
compileFiles(listOf(kotlinSrc, javaSrc))
} else {
emptyList()
- }
+ },
+ kotlincArguments = KOTLINC_LANGUAGE_1_9_ARGS
) { invocation ->
val kotlinElm = invocation.processingEnv.requireTypeElement("KotlinClass")
kotlinElm.getMethodByJvmName("kotlinValueClassDirectUsage").apply {
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/compat/XConvertersTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/compat/XConvertersTest.kt
index db986f6..11f0abf 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/compat/XConvertersTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/compat/XConvertersTest.kt
@@ -26,6 +26,7 @@
import androidx.room.compiler.processing.ksp.KspProcessingEnv
import androidx.room.compiler.processing.ksp.synthetic.KspSyntheticPropertyMethodElement
import androidx.room.compiler.processing.testcode.TestSuppressWarnings
+import androidx.room.compiler.processing.util.KOTLINC_LANGUAGE_1_9_ARGS
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
import androidx.room.compiler.processing.util.getDeclaredField
@@ -34,7 +35,6 @@
import androidx.room.compiler.processing.util.runProcessorTest
import com.google.auto.common.MoreElements
import com.google.auto.common.MoreTypes
-import com.google.devtools.ksp.common.impl.KSNameImpl
import com.google.devtools.ksp.getDeclaredFunctions
import com.squareup.javapoet.ClassName
import com.squareup.javapoet.JavaFile
@@ -562,7 +562,10 @@
@Test
fun annotationValues() {
- runProcessorTest(sources = listOf(kotlinSrc, javaSrc)) { invocation ->
+ runProcessorTest(
+ sources = listOf(kotlinSrc, javaSrc),
+ kotlincArguments = KOTLINC_LANGUAGE_1_9_ARGS
+ ) { invocation ->
val kotlinClass = invocation.processingEnv.requireTypeElement("KotlinClass")
val javaClass = invocation.processingEnv.requireTypeElement("JavaClass")
@@ -858,7 +861,7 @@
(this.processingEnv as JavacProcessingEnv).delegate.elementUtils.getTypeElement(fqn)
private fun XTestInvocation.getKspTypeElement(fqn: String) =
- (this.processingEnv as KspProcessingEnv)
- .resolver
- .getClassDeclarationByName(KSNameImpl.getCached(fqn))!!
+ (this.processingEnv as KspProcessingEnv).resolver.let { resolver ->
+ resolver.getClassDeclarationByName(resolver.getKSNameFromString(fqn))
+ }!!
}
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/javac/kotlin/KotlinMetadataElementTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/javac/kotlin/KotlinMetadataElementTest.kt
index 8aa8de5..f176019 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/javac/kotlin/KotlinMetadataElementTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/javac/kotlin/KotlinMetadataElementTest.kt
@@ -20,6 +20,7 @@
import androidx.kruth.assertWithMessage
import androidx.room.compiler.processing.XNullability
import androidx.room.compiler.processing.javac.JavacProcessingEnv
+import androidx.room.compiler.processing.util.KOTLINC_LANGUAGE_1_9_ARGS
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
import androidx.room.compiler.processing.util.compileFiles
@@ -818,11 +819,15 @@
"""
.trimIndent()
)
- simpleRun(sources = listOf(src)) { env ->
+ simpleRun(sources = listOf(src), kotlincArgs = KOTLINC_LANGUAGE_1_9_ARGS) { env ->
val subject = env.requireTypeElement("Subject")
subject.getDeclaredFields().forEach { assertThat(it.getter).isNotNull() }
subject.getDeclaredMethods().forEach {
- assertThat(it.isKotlinPropertyMethod()).isTrue()
+ // A private static function was generated for the lambda passed to lazy() with K2
+ // so we filter these out.
+ if (!it.jvmName.contains("$")) {
+ assertThat(it.isKotlinPropertyMethod()).isTrue()
+ }
}
}
}
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/KspJvmDescriptorUtilsTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/KspJvmDescriptorUtilsTest.kt
index 6efe0df..d6ea9e1 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/KspJvmDescriptorUtilsTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/KspJvmDescriptorUtilsTest.kt
@@ -23,6 +23,7 @@
import androidx.room.compiler.processing.isField
import androidx.room.compiler.processing.isMethod
import androidx.room.compiler.processing.isTypeElement
+import androidx.room.compiler.processing.util.KOTLINC_LANGUAGE_1_9_ARGS
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
import androidx.room.compiler.processing.util.compileFiles
@@ -51,7 +52,7 @@
@Test
fun descriptor_method_simple() {
fun checkSources(vararg sources: Source) {
- runTest(sources = sources) { invocation ->
+ runTest(sources = sources, kotlincArgs = KOTLINC_LANGUAGE_1_9_ARGS) { invocation ->
assertThat(invocation.annotatedElements().map(this::descriptor))
.containsExactly("emptyMethod()V")
}
@@ -82,8 +83,8 @@
@Test
fun descriptor_field() {
- fun checkSources(vararg sources: Source) {
- runTest(sources = sources) { invocation ->
+ fun checkSources(vararg sources: Source, kotlincArgs: List<String> = emptyList()) {
+ runTest(sources = sources, kotlincArgs = kotlincArgs) { invocation ->
assertThat(invocation.annotatedElements().map(this::descriptor))
.containsExactly(
"field1:I",
@@ -108,7 +109,8 @@
@Describe List<String> field4;
}
"""
- )
+ ),
+ kotlincArgs = KOTLINC_LANGUAGE_1_9_ARGS
)
checkSources(
Source.kotlin(
@@ -129,7 +131,7 @@
@Test
fun descriptor_method_erasured() {
fun checkSources(vararg sources: Source) {
- runTest(sources = sources) { invocation ->
+ runTest(sources = sources, KOTLINC_LANGUAGE_1_9_ARGS) { invocation ->
assertThat(invocation.annotatedElements().map(this::descriptor))
.containsAtLeast(
"method1(Landroidx/room/test/Foo;)V",
@@ -204,7 +206,7 @@
@Test
fun descriptor_class_erasured() {
fun checkSources(vararg sources: Source) {
- runTest(sources = sources) { invocation ->
+ runTest(sources = sources, kotlincArgs = KOTLINC_LANGUAGE_1_9_ARGS) { invocation ->
assertThat(invocation.annotatedElements().map(this::descriptor))
.containsExactly(
"method1(Ljava/lang/Object;)Ljava/lang/Object;",
@@ -277,7 +279,7 @@
@Test
fun descriptor_method_primitiveParams() {
fun checkSources(vararg sources: Source) {
- runTest(sources = sources) { invocation ->
+ runTest(sources = sources, kotlincArgs = KOTLINC_LANGUAGE_1_9_ARGS) { invocation ->
assertThat(invocation.annotatedElements().map(this::descriptor))
.containsExactly("method1(ZI)V", "method2(C)B", "method3(DF)V", "method4(JS)V")
}
@@ -315,7 +317,7 @@
@Test
fun descriptor_method_classParam_javaTypes() {
fun checkSources(vararg sources: Source) {
- runTest(sources = sources) { invocation ->
+ runTest(sources = sources, KOTLINC_LANGUAGE_1_9_ARGS) { invocation ->
assertThat(invocation.annotatedElements().map(this::descriptor))
.containsExactly(
"method1(Ljava/lang/Object;)V",
@@ -363,7 +365,7 @@
@Test
fun descriptor_method_classParam_testClass() {
fun checkSources(vararg sources: Source) {
- runTest(sources = sources) { invocation ->
+ runTest(sources = sources, KOTLINC_LANGUAGE_1_9_ARGS) { invocation ->
assertThat(invocation.annotatedElements().map(this::descriptor))
.containsExactly(
"method1(Landroidx/room/test/DataClass;)V",
@@ -408,7 +410,7 @@
@Test
fun descriptor_method_classParam_innerTestClass() {
fun checkSources(vararg sources: Source) {
- runTest(sources = sources) { invocation ->
+ runTest(sources = sources, KOTLINC_LANGUAGE_1_9_ARGS) { invocation ->
assertThat(invocation.annotatedElements().map(this::descriptor))
.containsExactly(
"method1(Landroidx/room/test/DataClass\$MemberInnerData;)V",
@@ -467,7 +469,7 @@
@Test
fun descriptor_method_arrayParams() {
fun checkSources(vararg sources: Source) {
- runTest(sources = sources) { invocation ->
+ runTest(sources = sources, kotlincArgs = KOTLINC_LANGUAGE_1_9_ARGS) { invocation ->
assertThat(invocation.annotatedElements().map(this::descriptor))
.containsExactly(
"method1([Landroidx/room/test/DataClass;)V",
@@ -515,7 +517,11 @@
)
}
- private fun runTest(vararg sources: Source, handler: (XTestInvocation) -> Unit) {
+ private fun runTest(
+ vararg sources: Source,
+ kotlincArgs: List<String> = emptyList(),
+ handler: (XTestInvocation) -> Unit
+ ) {
if (isPreCompiled) {
val compiled = compileFiles(listOf(*sources) + describeAnnotation)
val hasKotlinSources = sources.any { it is Source.KotlinSource }
@@ -528,9 +534,18 @@
val newSources =
kotlinSources +
Source.java("PlaceholderJava", "public class " + "PlaceholderJava {}")
- runProcessorTest(sources = newSources, handler = handler, classpath = compiled)
+ runProcessorTest(
+ sources = newSources,
+ handler = handler,
+ classpath = compiled,
+ kotlincArguments = kotlincArgs
+ )
} else {
- runProcessorTest(sources = listOf(*sources) + describeAnnotation, handler = handler)
+ runProcessorTest(
+ sources = listOf(*sources) + describeAnnotation,
+ handler = handler,
+ kotlincArguments = kotlincArgs
+ )
}
}
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/KspTypeNamesGoldenTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/KspTypeNamesGoldenTest.kt
index 3b8cc6f..98645e6 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/KspTypeNamesGoldenTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/KspTypeNamesGoldenTest.kt
@@ -21,6 +21,7 @@
import androidx.room.compiler.processing.XExecutableElement
import androidx.room.compiler.processing.XMethodElement
import androidx.room.compiler.processing.util.CompilationTestCapabilities
+import androidx.room.compiler.processing.util.KOTLINC_LANGUAGE_1_9_ARGS
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
import androidx.room.compiler.processing.util.compileFiles
@@ -103,7 +104,11 @@
collectSignaturesInto(invocation, golden)
}
val ksp = mutableMapOf<String, List<TypeName>>()
- runKspTest(sources = sources, classpath = classpath) { invocation ->
+ runKspTest(
+ sources = sources,
+ classpath = classpath,
+ kotlincArguments = KOTLINC_LANGUAGE_1_9_ARGS
+ ) { invocation ->
collectSignaturesInto(invocation, ksp)
}
diff --git a/room/room-compiler/build.gradle b/room/room-compiler/build.gradle
index 136bd39..ff0e1d5 100644
--- a/room/room-compiler/build.gradle
+++ b/room/room-compiler/build.gradle
@@ -87,7 +87,6 @@
testImplementation(libs.jsr250)
testImplementation(libs.mockitoCore4)
testImplementation(libs.antlr4)
- testImplementation(libs.kotlinCompilerEmbeddable)
testImplementation(SdkHelperKt.getSdkDependency(project))
testImplementationAarAsJar(project(":room:room-runtime"))
testImplementationAarAsJar(project(":sqlite:sqlite"))
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/ProcessorTestWrapper.kt b/room/room-compiler/src/test/kotlin/androidx/room/ProcessorTestWrapper.kt
new file mode 100644
index 0000000..ecb2da5
--- /dev/null
+++ b/room/room-compiler/src/test/kotlin/androidx/room/ProcessorTestWrapper.kt
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package androidx.room
+
+import androidx.room.compiler.processing.XProcessingEnvConfig
+import androidx.room.compiler.processing.XProcessingStep
+import androidx.room.compiler.processing.util.CompilationResultSubject
+import androidx.room.compiler.processing.util.Source
+import androidx.room.compiler.processing.util.XTestInvocation
+import androidx.room.compiler.processing.util.runKspTest
+import androidx.room.compiler.processing.util.runProcessorTest
+import com.google.devtools.ksp.processing.SymbolProcessorProvider
+import java.io.File
+import javax.annotation.processing.Processor
+
+fun runProcessorTestWithK1(
+ sources: List<Source> = emptyList(),
+ classpath: List<File> = emptyList(),
+ options: Map<String, String> = emptyMap(),
+ javacArguments: List<String> = emptyList(),
+ kotlincArguments: List<String> = emptyList(),
+ handler: (XTestInvocation) -> Unit
+) {
+ androidx.room.compiler.processing.util.runProcessorTest(
+ sources = sources,
+ classpath = classpath,
+ options = options,
+ javacArguments = javacArguments,
+ kotlincArguments = listOf("-language-version=1.9", "-api-version=1.9") + kotlincArguments,
+ handler = handler
+ )
+}
+
+fun runProcessorTestWithK1(
+ sources: List<Source> = emptyList(),
+ classpath: List<File> = emptyList(),
+ options: Map<String, String> = emptyMap(),
+ javacArguments: List<String> = emptyList(),
+ kotlincArguments: List<String> = emptyList(),
+ createProcessingSteps: () -> Iterable<XProcessingStep>,
+ onCompilationResult: (CompilationResultSubject) -> Unit
+) {
+ androidx.room.compiler.processing.util.runProcessorTest(
+ sources = sources,
+ classpath = classpath,
+ options = options,
+ javacArguments = javacArguments,
+ kotlincArguments = listOf("-language-version=1.9", "-api-version=1.9") + kotlincArguments,
+ createProcessingSteps = createProcessingSteps,
+ onCompilationResult = onCompilationResult
+ )
+}
+
+fun runProcessorTestWithK1(
+ sources: List<Source> = emptyList(),
+ classpath: List<File> = emptyList(),
+ options: Map<String, String> = emptyMap(),
+ javacArguments: List<String> = emptyList(),
+ kotlincArguments: List<String> = emptyList(),
+ javacProcessors: List<Processor>,
+ symbolProcessorProviders: List<SymbolProcessorProvider>,
+ onCompilationResult: (CompilationResultSubject) -> Unit
+) {
+ runProcessorTest(
+ sources = sources,
+ classpath = classpath,
+ options = options,
+ javacArguments = javacArguments,
+ kotlincArguments = listOf("-language-version=1.9", "-api-version=1.9") + kotlincArguments,
+ javacProcessors = javacProcessors,
+ symbolProcessorProviders = symbolProcessorProviders,
+ onCompilationResult = onCompilationResult
+ )
+}
+
+fun runKspTestWithK1(
+ sources: List<Source>,
+ classpath: List<File> = emptyList(),
+ options: Map<String, String> = emptyMap(),
+ javacArguments: List<String> = emptyList(),
+ kotlincArguments: List<String> = emptyList(),
+ config: XProcessingEnvConfig? = null,
+ handler: (XTestInvocation) -> Unit
+) {
+ if (config != null) {
+ runKspTest(
+ sources = sources,
+ classpath = classpath,
+ options = options,
+ javacArguments = javacArguments,
+ kotlincArguments =
+ listOf("-language-version=1.9", "-api-version=1.9") + kotlincArguments,
+ config = config,
+ handler = handler
+ )
+ } else {
+ runKspTest(
+ sources = sources,
+ classpath = classpath,
+ options = options,
+ javacArguments = javacArguments,
+ kotlincArguments =
+ listOf("-language-version=1.9", "-api-version=1.9") + kotlincArguments,
+ handler = handler
+ )
+ }
+}
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/ext/ElementExtTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/ext/ElementExtTest.kt
index f1d3a45..1e314bf 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/ext/ElementExtTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/ext/ElementExtTest.kt
@@ -24,8 +24,8 @@
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
import androidx.room.compiler.processing.util.compileFiles
-import androidx.room.compiler.processing.util.runKspTest
-import androidx.room.compiler.processing.util.runProcessorTest
+import androidx.room.runKspTestWithK1
+import androidx.room.runProcessorTestWithK1
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
@@ -232,7 +232,7 @@
"""
.trimIndent()
)
- runKspTest(
+ runKspTestWithK1(
sources = listOf(src),
config =
XProcessingEnvConfig.DEFAULT.copy(excludeMethodsWithInvalidJvmSourceNames = false)
@@ -255,7 +255,7 @@
} else {
sources to emptyList()
}
- runProcessorTest(sources = sources, classpath = classpath, handler = handler)
+ runProcessorTestWithK1(sources = sources, classpath = classpath, handler = handler)
}
private fun XTestInvocation.objectMethodNames(): List<String> {
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/parser/SQLTypeAffinityTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/parser/SQLTypeAffinityTest.kt
index 9927769..cc19974 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/parser/SQLTypeAffinityTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/parser/SQLTypeAffinityTest.kt
@@ -20,7 +20,7 @@
import androidx.room.compiler.codegen.CodeLanguage
import androidx.room.compiler.processing.XNullability
import androidx.room.compiler.processing.XType
-import androidx.room.compiler.processing.util.runProcessorTest
+import androidx.room.runProcessorTestWithK1
import org.junit.Test
class SQLTypeAffinityTest {
@@ -33,7 +33,7 @@
*/
@Test
fun affinityTypes() {
- runProcessorTest(sources = emptyList()) { invocation ->
+ runProcessorTestWithK1(sources = emptyList()) { invocation ->
fun XNullability.toSignature() =
if (invocation.isKsp) {
when (this) {
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/AutoMigrationProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/AutoMigrationProcessorTest.kt
index c567a4d..5c21636 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/AutoMigrationProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/AutoMigrationProcessorTest.kt
@@ -17,7 +17,6 @@
package androidx.room.processor
import androidx.room.compiler.processing.util.Source
-import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.migration.bundle.DatabaseBundle
import androidx.room.migration.bundle.EntityBundle
import androidx.room.migration.bundle.FieldBundle
@@ -25,6 +24,7 @@
import androidx.room.migration.bundle.SchemaBundle
import androidx.room.processor.ProcessorErrors.AUTOMIGRATION_SPEC_MISSING_NOARG_CONSTRUCTOR
import androidx.room.processor.ProcessorErrors.INNER_CLASS_AUTOMIGRATION_SPEC_MUST_BE_STATIC
+import androidx.room.runProcessorTestWithK1
import androidx.room.testing.context
import org.junit.Test
@@ -44,7 +44,7 @@
.trimIndent()
)
- runProcessorTest(listOf(source)) { invocation ->
+ runProcessorTestWithK1(listOf(source)) { invocation ->
AutoMigrationProcessor(
context = invocation.context,
spec = invocation.processingEnv.requireType("foo.bar.MyAutoMigration"),
@@ -71,7 +71,7 @@
.trimIndent()
)
- runProcessorTest(listOf(source)) { invocation ->
+ runProcessorTestWithK1(listOf(source)) { invocation ->
AutoMigrationProcessor(
context = invocation.context,
spec = invocation.processingEnv.requireType("foo.bar.MyAutoMigration"),
@@ -100,7 +100,7 @@
.trimIndent()
)
- runProcessorTest(listOf(source)) { invocation ->
+ runProcessorTestWithK1(listOf(source)) { invocation ->
AutoMigrationProcessor(
context = invocation.context,
spec =
@@ -132,7 +132,7 @@
.trimIndent()
)
- runProcessorTest(listOf(source)) { invocation ->
+ runProcessorTestWithK1(listOf(source)) { invocation ->
AutoMigrationProcessor(
context = invocation.context,
spec = invocation.processingEnv.requireType("foo.bar.MyAutoMigration"),
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/BaseDaoTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/BaseDaoTest.kt
index 0d0484c..95779d9 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/BaseDaoTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/BaseDaoTest.kt
@@ -4,7 +4,7 @@
import androidx.room.compiler.codegen.CodeLanguage
import androidx.room.compiler.processing.XProcessingEnv
import androidx.room.compiler.processing.util.Source
-import androidx.room.compiler.processing.util.runProcessorTest
+import androidx.room.runProcessorTestWithK1
import androidx.room.testing.context
import androidx.room.vo.Dao
import androidx.room.writer.DaoWriter
@@ -209,7 +209,7 @@
"""
.trimIndent()
)
- runProcessorTest(sources = listOf(source)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(source)) { invocation ->
val dbElm = invocation.context.processingEnv.requireTypeElement("MyDb")
val dbType = dbElm.type
// if we could create valid code, it is good, no need for assertions.
@@ -268,8 +268,8 @@
}
"""
)
- runProcessorTest(sources = listOf(baseClass, extension, COMMON.USER, fakeDb)) { invocation
- ->
+ runProcessorTestWithK1(sources = listOf(baseClass, extension, COMMON.USER, fakeDb)) {
+ invocation ->
val daoElm = invocation.processingEnv.requireTypeElement("foo.bar.MyDao")
val dbElm = invocation.context.processingEnv.requireTypeElement("foo.bar.MyDb")
val dbType = dbElm.type
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/BaseEntityParserTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/BaseEntityParserTest.kt
index 657c1f7..d70520f 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/BaseEntityParserTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/BaseEntityParserTest.kt
@@ -19,7 +19,7 @@
import androidx.room.compiler.processing.XTypeElement
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
-import androidx.room.compiler.processing.util.runProcessorTest
+import androidx.room.runProcessorTestWithK1
import androidx.room.testing.context
import androidx.room.vo.Entity
import java.io.File
@@ -61,7 +61,7 @@
} else {
baseClassReplacement = " extends $baseClass"
}
- runProcessorTest(
+ runProcessorTestWithK1(
sources =
sources +
Source.java(
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/BaseFtsEntityParserTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/BaseFtsEntityParserTest.kt
index 5d44695..9ac795b 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/BaseFtsEntityParserTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/BaseFtsEntityParserTest.kt
@@ -18,7 +18,7 @@
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
-import androidx.room.compiler.processing.util.runProcessorTest
+import androidx.room.runProcessorTestWithK1
import androidx.room.testing.context
import androidx.room.vo.FtsEntity
import java.io.File
@@ -76,7 +76,8 @@
baseClassReplacement
) + input + ENTITY_SUFFIX
)
- runProcessorTest(sources = sources + entitySource, classpath = classpath) { invocation ->
+ runProcessorTestWithK1(sources = sources + entitySource, classpath = classpath) { invocation
+ ->
val entity = invocation.processingEnv.requireTypeElement("foo.bar.MyEntity")
val processor = FtsTableEntityProcessor(invocation.context, entity)
val processedEntity = processor.process()
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/CustomConverterProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/CustomConverterProcessorTest.kt
index ea33b1c..e48920a 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/CustomConverterProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/CustomConverterProcessorTest.kt
@@ -28,7 +28,6 @@
import androidx.room.compiler.codegen.XTypeSpec.Builder.Companion.apply
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
-import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.ext.CommonTypeNames
import androidx.room.ext.CommonTypeNames.MUTABLE_LIST
import androidx.room.ext.CommonTypeNames.STRING
@@ -37,6 +36,7 @@
import androidx.room.processor.ProcessorErrors.TYPE_CONVERTER_MISSING_NOARG_CONSTRUCTOR
import androidx.room.processor.ProcessorErrors.TYPE_CONVERTER_MUST_BE_PUBLIC
import androidx.room.processor.ProcessorErrors.TYPE_CONVERTER_UNBOUND_GENERIC
+import androidx.room.runProcessorTestWithK1
import androidx.room.testing.context
import androidx.room.vo.CustomTypeConverter
import com.squareup.javapoet.TypeVariableName
@@ -256,7 +256,7 @@
.build()
.toString()
)
- runProcessorTest(sources = listOf(baseConverter, extendingClass)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(baseConverter, extendingClass)) { invocation ->
val element =
invocation.processingEnv.requireTypeElement(extendingClassName.canonicalName)
val converter =
@@ -339,7 +339,7 @@
public class Container {}
"""
)
- runProcessorTest(listOf(source)) { invocation ->
+ runProcessorTestWithK1(listOf(source)) { invocation ->
val result =
CustomConverterProcessor.findConverters(
invocation.context,
@@ -405,7 +405,7 @@
vararg sources: Source,
handler: (CustomTypeConverter?, XTestInvocation) -> Unit
) {
- runProcessorTest(sources = sources.toList() + CONTAINER) { invocation ->
+ runProcessorTestWithK1(sources = sources.toList() + CONTAINER) { invocation ->
val processed =
CustomConverterProcessor.findConverters(
invocation.context,
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/DaoProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/DaoProcessorTest.kt
index 4306440..8956655 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/DaoProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/DaoProcessorTest.kt
@@ -22,11 +22,11 @@
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
import androidx.room.compiler.processing.util.compileFiles
-import androidx.room.compiler.processing.util.runKspTest
-import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.ext.RoomTypeNames.ROOM_DB
import androidx.room.processor.ProcessorErrors.nullableCollectionOrArrayReturnTypeInDaoMethod
import androidx.room.processor.ProcessorErrors.nullableComponentInDaoMethodReturnType
+import androidx.room.runKspTestWithK1
+import androidx.room.runProcessorTestWithK1
import androidx.room.testing.context
import androidx.room.vo.Dao
import androidx.room.vo.ReadQueryMethod
@@ -263,7 +263,7 @@
"""
.trimIndent()
)
- runProcessorTest(sources = listOf(daoSrc) + COMMON.USER) { invocation ->
+ runProcessorTestWithK1(sources = listOf(daoSrc) + COMMON.USER) { invocation ->
val dao =
invocation.roundEnv
.getElementsAnnotatedWith(androidx.room.Dao::class.qualifiedName!!)
@@ -452,7 +452,7 @@
"""
.trimIndent()
)
- runProcessorTest(sources = listOf(source)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(source)) { invocation ->
val dao = invocation.processingEnv.requireTypeElement("MyDao")
val dbType = invocation.context.processingEnv.requireType(ROOM_DB)
DaoProcessor(
@@ -490,7 +490,7 @@
"""
.trimIndent()
)
- runKspTest(
+ runKspTestWithK1(
sources = listOf(src),
options = mapOf(Context.BooleanProcessorOptions.GENERATE_KOTLIN.argName to "true"),
) { invocation ->
@@ -528,7 +528,7 @@
"""
.trimIndent()
)
- runKspTest(
+ runKspTestWithK1(
sources = listOf(src),
options = mapOf(Context.BooleanProcessorOptions.GENERATE_KOTLIN.argName to "true"),
) { invocation ->
@@ -569,7 +569,7 @@
"""
.trimIndent()
)
- runKspTest(
+ runKspTestWithK1(
sources = listOf(src),
options = mapOf(Context.BooleanProcessorOptions.GENERATE_KOTLIN.argName to "true"),
) { invocation ->
@@ -641,7 +641,7 @@
"""
.trimIndent()
)
- runKspTest(
+ runKspTestWithK1(
sources = listOf(src),
options = mapOf(Context.BooleanProcessorOptions.GENERATE_KOTLIN.argName to "true"),
) { invocation ->
@@ -767,7 +767,7 @@
"""
.trimIndent()
)
- runKspTest(
+ runKspTestWithK1(
sources = listOf(src),
options = mapOf(Context.BooleanProcessorOptions.GENERATE_KOTLIN.argName to "true"),
) { invocation ->
@@ -838,7 +838,7 @@
classpathFiles: List<File> = emptyList(),
handler: (Dao, XTestInvocation) -> Unit
) {
- runProcessorTest(
+ runProcessorTestWithK1(
sources =
listOf(
Source.java("foo.bar.MyDao", DAO_PREFIX + inputs.joinToString("\n")),
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/DatabaseConstructorProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/DatabaseConstructorProcessorTest.kt
index 44ec92f..d66a941 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/DatabaseConstructorProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/DatabaseConstructorProcessorTest.kt
@@ -19,7 +19,7 @@
import androidx.room.compiler.processing.XTypeElement
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
-import androidx.room.compiler.processing.util.runKspTest
+import androidx.room.runKspTestWithK1
import androidx.room.testing.context
import org.junit.Test
@@ -136,7 +136,7 @@
}
private fun runTest(constructorSource: Source, handler: (XTestInvocation) -> Unit = { _ -> }) {
- runKspTest(sources = listOf(databaseSource, constructorSource)) { invocation ->
+ runKspTestWithK1(sources = listOf(databaseSource, constructorSource)) { invocation ->
val entity =
invocation.roundEnv
.getElementsAnnotatedWith(androidx.room.Database::class.qualifiedName!!)
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/DatabaseProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/DatabaseProcessorTest.kt
index 5885790..885b353 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/DatabaseProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/DatabaseProcessorTest.kt
@@ -29,12 +29,12 @@
import androidx.room.compiler.processing.util.XTestInvocation
import androidx.room.compiler.processing.util.compileFiles
import androidx.room.compiler.processing.util.compileFilesIntoJar
-import androidx.room.compiler.processing.util.runKspTest
-import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.parser.ParsedQuery
import androidx.room.parser.QueryType
import androidx.room.parser.Table
import androidx.room.processor.ProcessorErrors.invalidAutoMigrationSchema
+import androidx.room.runKspTestWithK1
+import androidx.room.runProcessorTestWithK1
import androidx.room.solver.query.result.EntityRowAdapter
import androidx.room.solver.query.result.PojoRowAdapter
import androidx.room.testing.context
@@ -508,7 +508,7 @@
}
"""
)
- runProcessorTest(
+ runProcessorTestWithK1(
sources = listOf(BOOK, BOOK_DAO, DB1, DB2, db1_2),
options = mapOf(Context.BooleanProcessorOptions.GENERATE_KOTLIN.argName to "false"),
createProcessingSteps = { listOf(DatabaseProcessingStep()) }
@@ -1257,7 +1257,7 @@
}
"""
)
- runProcessorTest(sources = listOf(badDaoType)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(badDaoType)) { invocation ->
val element = invocation.processingEnv.requireTypeElement("foo.bar.MyDb")
val result =
DatabaseProcessor(baseContext = invocation.context, element = element).process()
@@ -1281,7 +1281,7 @@
}
"""
)
- runProcessorTest(listOf(badDaoType)) { invocation ->
+ runProcessorTestWithK1(listOf(badDaoType)) { invocation ->
val element = invocation.processingEnv.requireTypeElement("foo.bar.MyDb")
val result =
DatabaseProcessor(baseContext = invocation.context, element = element).process()
@@ -1503,7 +1503,7 @@
"""
.trimIndent()
)
- runProcessorTest(
+ runProcessorTestWithK1(
sources = listOf(dbSource, USER),
options = mapOf("room.schemaLocation" to "schemas/", "room.generateKotlin" to "false")
) { invocation ->
@@ -1561,7 +1561,7 @@
.trimIndent()
)
}
- runProcessorTest(
+ runProcessorTestWithK1(
sources = listOf(dbSource, USER),
javacProcessors = listOf(RoomProcessor()),
symbolProcessorProviders = listOf(RoomKspProcessor.Provider()),
@@ -1591,7 +1591,7 @@
}
"""
)
- runProcessorTest(
+ runProcessorTestWithK1(
sources = listOf(jvmNameInDaoGetter),
options = mapOf(Context.BooleanProcessorOptions.GENERATE_KOTLIN.argName to "false"),
) { invocation ->
@@ -1630,7 +1630,7 @@
"""
.trimIndent()
)
- runKspTest(
+ runKspTestWithK1(
sources = listOf(src),
options = mapOf(Context.BooleanProcessorOptions.GENERATE_KOTLIN.argName to "true"),
) { invocation ->
@@ -1663,7 +1663,7 @@
views: Map<String, Set<String>>,
body: (List<DatabaseView>, XTestInvocation) -> Unit
) {
- runProcessorTest(
+ runProcessorTestWithK1(
sources = listOf(DB3, BOOK),
options = mapOf(Context.BooleanProcessorOptions.GENERATE_KOTLIN.argName to "false"),
) { invocation ->
@@ -1716,7 +1716,7 @@
}
"""
)
- runProcessorTest(
+ runProcessorTestWithK1(
sources = listOf(BOOK, bookDao) + dbs,
options = mapOf(Context.BooleanProcessorOptions.GENERATE_KOTLIN.argName to "false"),
createProcessingSteps = { listOf(DatabaseProcessingStep()) },
@@ -1731,7 +1731,7 @@
classpath: List<File> = emptyList(),
handler: (Database, XTestInvocation) -> Unit
) {
- runProcessorTest(
+ runProcessorTestWithK1(
sources = otherFiles.toList() + Source.java("foo.bar.MyDb", DATABASE_PREFIX + input),
classpath = classpath,
options =
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/DatabaseViewProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/DatabaseViewProcessorTest.kt
index d9d5117..a00de28 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/DatabaseViewProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/DatabaseViewProcessorTest.kt
@@ -19,9 +19,9 @@
import androidx.kruth.assertThat
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
-import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.parser.ParserErrors
import androidx.room.parser.SQLTypeAffinity
+import androidx.room.runProcessorTestWithK1
import androidx.room.testing.context
import androidx.room.verifier.ColumnInfo
import androidx.room.vo.DatabaseView
@@ -235,7 +235,7 @@
verify: Boolean = true,
handler: (view: DatabaseView, invocation: XTestInvocation) -> Unit
) {
- runProcessorTest(sources = sources + Source.java(name, DATABASE_PREFIX + input)) {
+ runProcessorTestWithK1(sources = sources + Source.java(name, DATABASE_PREFIX + input)) {
invocation ->
val view = invocation.processingEnv.requireTypeElement(name)
val verifier =
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/DeleteOrUpdateShortcutMethodProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/DeleteOrUpdateShortcutMethodProcessorTest.kt
index 4c5d5a1..18f90c1 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/DeleteOrUpdateShortcutMethodProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/DeleteOrUpdateShortcutMethodProcessorTest.kt
@@ -28,7 +28,6 @@
import androidx.room.compiler.processing.XTypeElement
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
-import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.ext.CommonTypeNames
import androidx.room.ext.GuavaUtilConcurrentTypeNames
import androidx.room.ext.KotlinTypeNames
@@ -36,6 +35,7 @@
import androidx.room.ext.ReactiveStreamsTypeNames
import androidx.room.ext.RxJava2TypeNames
import androidx.room.ext.RxJava3TypeNames
+import androidx.room.runProcessorTestWithK1
import androidx.room.testing.context
import androidx.room.vo.DeleteOrUpdateShortcutMethod
import kotlin.reflect.KClass
@@ -770,7 +770,7 @@
COMMON.LISTENABLE_FUTURE,
COMMON.GUAVA_ROOM
)
- runProcessorTest(
+ runProcessorTestWithK1(
sources = commonSources + additionalSources + inputSource,
options = mapOf(Context.BooleanProcessorOptions.GENERATE_KOTLIN.argName to "false"),
) { invocation ->
@@ -826,7 +826,7 @@
COMMON.GUAVA_ROOM
)
- runProcessorTest(
+ runProcessorTestWithK1(
sources = commonSources + additionalSources + inputSource,
options = mapOf(Context.BooleanProcessorOptions.GENERATE_KOTLIN.argName to "false"),
) { invocation ->
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/FieldProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/FieldProcessorTest.kt
index 0cfc88a4..01ebd89 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/FieldProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/FieldProcessorTest.kt
@@ -26,6 +26,7 @@
import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.parser.Collate
import androidx.room.parser.SQLTypeAffinity
+import androidx.room.runProcessorTestWithK1
import androidx.room.solver.types.ColumnTypeAdapter
import androidx.room.testing.context
import androidx.room.vo.Field
@@ -702,7 +703,7 @@
),
ARRAY_CONVERTER
)
- runProcessorTest(sources = sources) { invocation ->
+ runProcessorTestWithK1(sources = sources) { invocation ->
val (owner, fieldElement) =
invocation.roundEnv
.getElementsAnnotatedWith(Entity::class.qualifiedName!!)
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/Fts4TableEntityProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/Fts4TableEntityProcessorTest.kt
index b8ed3770..9d32327 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/Fts4TableEntityProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/Fts4TableEntityProcessorTest.kt
@@ -20,9 +20,9 @@
import androidx.room.compiler.codegen.CodeLanguage
import androidx.room.compiler.codegen.XTypeName
import androidx.room.compiler.processing.util.Source
-import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.parser.FtsVersion
import androidx.room.parser.SQLTypeAffinity
+import androidx.room.runProcessorTestWithK1
import androidx.room.testing.context
import androidx.room.vo.CallType
import androidx.room.vo.Field
@@ -86,7 +86,7 @@
@Test
fun missingEntityAnnotation() {
- runProcessorTest(
+ runProcessorTestWithK1(
sources =
listOf(
Source.java(
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/GeneratedCustomConverterTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/GeneratedCustomConverterTest.kt
index 6051837..d63633f 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/GeneratedCustomConverterTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/GeneratedCustomConverterTest.kt
@@ -26,7 +26,7 @@
import androidx.room.compiler.processing.javac.JavacBasicAnnotationProcessor
import androidx.room.compiler.processing.ksp.KspBasicAnnotationProcessor
import androidx.room.compiler.processing.util.Source
-import androidx.room.compiler.processing.util.runProcessorTest
+import androidx.room.runProcessorTestWithK1
import com.google.devtools.ksp.processing.SymbolProcessorEnvironment
import com.google.devtools.ksp.processing.SymbolProcessorProvider
import com.squareup.javapoet.ClassName
@@ -75,7 +75,7 @@
"""
.trimIndent()
)
- runProcessorTest(
+ runProcessorTestWithK1(
sources = listOf(src),
javacProcessors = listOf(RoomProcessor(), JavacCustomConverter()),
symbolProcessorProviders =
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/InsertOrUpsertShortcutMethodProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/InsertOrUpsertShortcutMethodProcessorTest.kt
index 857704e..f0ddca5 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/InsertOrUpsertShortcutMethodProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/InsertOrUpsertShortcutMethodProcessorTest.kt
@@ -28,7 +28,6 @@
import androidx.room.compiler.processing.XTypeElement
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
-import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.ext.CommonTypeNames
import androidx.room.ext.GuavaUtilConcurrentTypeNames
import androidx.room.ext.KotlinTypeNames
@@ -36,6 +35,7 @@
import androidx.room.ext.ReactiveStreamsTypeNames
import androidx.room.ext.RxJava2TypeNames
import androidx.room.ext.RxJava3TypeNames
+import androidx.room.runProcessorTestWithK1
import androidx.room.solver.shortcut.result.InsertOrUpsertMethodAdapter
import androidx.room.testing.context
import androidx.room.vo.InsertOrUpsertShortcutMethod
@@ -1139,7 +1139,7 @@
COMMON.RX3_SINGLE
)
- runProcessorTest(
+ runProcessorTestWithK1(
sources = commonSources + additionalSources + inputSource,
options = mapOf(Context.BooleanProcessorOptions.GENERATE_KOTLIN.argName to "false"),
) { invocation ->
@@ -1194,7 +1194,7 @@
COMMON.GUAVA_ROOM
)
- runProcessorTest(
+ runProcessorTestWithK1(
sources = commonSources + additionalSources + inputSource,
options = mapOf(Context.BooleanProcessorOptions.GENERATE_KOTLIN.argName to "false"),
) { invocation ->
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/PojoProcessorTargetMethodTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/PojoProcessorTargetMethodTest.kt
index 75abd32..8de7576 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/PojoProcessorTargetMethodTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/PojoProcessorTargetMethodTest.kt
@@ -19,7 +19,7 @@
import androidx.room.compiler.codegen.XClassName
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
-import androidx.room.compiler.processing.util.runProcessorTest
+import androidx.room.runProcessorTestWithK1
import androidx.room.testing.context
import org.junit.Test
import org.junit.runner.RunWith
@@ -461,7 +461,7 @@
}
private fun singleRun(vararg sources: Source, handler: ((XTestInvocation) -> Unit)? = null) {
- runProcessorTest(sources = sources.toList()) { invocation ->
+ runProcessorTestWithK1(sources = sources.toList()) { invocation ->
PojoProcessor.createFor(
context = invocation.context,
element = invocation.processingEnv.requireTypeElement(MY_POJO),
@@ -506,7 +506,7 @@
val pojoSource = Source.java(MY_POJO.canonicalName, pojoCode)
val autoValuePojoSource = Source.java(AUTOVALUE_MY_POJO.canonicalName, autoValuePojoCode)
val all = sources.toList() + pojoSource + autoValuePojoSource
- return runProcessorTest(sources = all) { invocation ->
+ return runProcessorTestWithK1(sources = all) { invocation ->
PojoProcessor.createFor(
context = invocation.context,
element = invocation.processingEnv.requireTypeElement(MY_POJO),
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/PojoProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/PojoProcessorTest.kt
index 9a2fa5d..f42c7c9 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/PojoProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/PojoProcessorTest.kt
@@ -23,7 +23,6 @@
import androidx.room.compiler.processing.XFieldElement
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
-import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.parser.SQLTypeAffinity
import androidx.room.processor.ProcessorErrors.CANNOT_FIND_GETTER_FOR_FIELD
import androidx.room.processor.ProcessorErrors.MISSING_POJO_CONSTRUCTOR
@@ -33,6 +32,7 @@
import androidx.room.processor.ProcessorErrors.relationCannotFindJunctionEntityField
import androidx.room.processor.ProcessorErrors.relationCannotFindJunctionParentField
import androidx.room.processor.ProcessorErrors.relationCannotFindParentEntityField
+import androidx.room.runProcessorTestWithK1
import androidx.room.testing.context
import androidx.room.vo.CallType
import androidx.room.vo.Constructor
@@ -84,7 +84,7 @@
public void setBaseField(String baseField){ }
}
"""
- runProcessorTest(
+ runProcessorTestWithK1(
sources =
listOf(
Source.java(
@@ -1054,7 +1054,7 @@
$FOOTER
"""
)
- runProcessorTest(sources = listOf(pojo)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(pojo)) { invocation ->
val element = invocation.processingEnv.requireTypeElement(MY_POJO)
val pojo1 =
PojoProcessor.createFor(
@@ -1706,7 +1706,7 @@
"foo.bar.TestData.WithJvmOverloads"
)
.forEach {
- runProcessorTest(sources = listOf(TEST_DATA)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(TEST_DATA)) { invocation ->
PojoProcessor.createFor(
context = invocation.context,
element = invocation.processingEnv.requireTypeElement(it),
@@ -1721,7 +1721,7 @@
@Test
fun dataClass_withJvmOverloads_primaryConstructor() {
- runProcessorTest(sources = listOf(TEST_DATA)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(TEST_DATA)) { invocation ->
PojoProcessor.createFor(
context = invocation.context,
element =
@@ -1751,7 +1751,7 @@
}
"""
)
- runProcessorTest(sources = listOf(source)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(source)) { invocation ->
val pojo =
PojoProcessor.createFor(
context = invocation.context,
@@ -1767,7 +1767,7 @@
@Test
fun ignoredColumns_noConstructor() {
- runProcessorTest(
+ runProcessorTestWithK1(
listOf(
Source.java(
MY_POJO.canonicalName,
@@ -1806,7 +1806,7 @@
@Test
fun ignoredColumns_noSetterGetter() {
- runProcessorTest(
+ runProcessorTestWithK1(
listOf(
Source.java(
MY_POJO.canonicalName,
@@ -1843,7 +1843,7 @@
@Test
fun ignoredColumns_columnInfo() {
- runProcessorTest(
+ runProcessorTestWithK1(
listOf(
Source.java(
MY_POJO.canonicalName,
@@ -1875,7 +1875,7 @@
@Test
fun ignoredColumns_missing() {
- runProcessorTest(
+ runProcessorTestWithK1(
listOf(
Source.java(
MY_POJO.canonicalName,
@@ -1909,7 +1909,7 @@
@Test
fun noSetter_scopeBindStmt() {
- runProcessorTest(
+ runProcessorTestWithK1(
listOf(
Source.java(
MY_POJO.canonicalName,
@@ -1938,7 +1938,7 @@
@Test
fun noSetter_scopeTwoWay() {
- runProcessorTest(
+ runProcessorTestWithK1(
listOf(
Source.java(
MY_POJO.canonicalName,
@@ -1970,7 +1970,7 @@
@Test
fun noSetter_scopeReadFromCursor() {
- runProcessorTest(
+ runProcessorTestWithK1(
listOf(
Source.java(
MY_POJO.canonicalName,
@@ -2002,7 +2002,7 @@
@Test
fun noGetter_scopeBindStmt() {
- runProcessorTest(
+ runProcessorTestWithK1(
listOf(
Source.java(
MY_POJO.canonicalName,
@@ -2034,7 +2034,7 @@
@Test
fun noGetter_scopeTwoWay() {
- runProcessorTest(
+ runProcessorTestWithK1(
listOf(
Source.java(
MY_POJO.canonicalName,
@@ -2066,7 +2066,7 @@
@Test
fun noGetter_scopeReadCursor() {
- runProcessorTest(
+ runProcessorTestWithK1(
listOf(
Source.java(
MY_POJO.canonicalName,
@@ -2095,7 +2095,7 @@
@Test
fun setterStartsWithIs() {
- runProcessorTest(
+ runProcessorTestWithK1(
listOf(
Source.kotlin(
"Book.kt",
@@ -2163,7 +2163,7 @@
@Test
fun embedded_nullability() {
listOf("foo.bar.TestData.SomeEmbeddedVals").forEach {
- runProcessorTest(sources = listOf(TEST_DATA)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(TEST_DATA)) { invocation ->
val result =
PojoProcessor.createFor(
context = invocation.context,
@@ -2211,7 +2211,7 @@
) {
val pojoSource = Source.java(MY_POJO.canonicalName, code)
val all = sources.toList() + pojoSource
- runProcessorTest(sources = all, classpath = classpath) { invocation ->
+ runProcessorTestWithK1(sources = all, classpath = classpath) { invocation ->
handler.invoke(
PojoProcessor.createFor(
context = invocation.context,
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/ProjectionExpanderTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/ProjectionExpanderTest.kt
index f4bf2e8..124fccd 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/ProjectionExpanderTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/ProjectionExpanderTest.kt
@@ -20,9 +20,9 @@
import androidx.room.compiler.processing.isTypeElement
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
-import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.parser.SqlParser
import androidx.room.parser.expansion.ProjectionExpander
+import androidx.room.runProcessorTestWithK1
import androidx.room.testing.context
import createVerifierFromEntitiesAndViews
import org.hamcrest.CoreMatchers.equalTo
@@ -521,7 +521,7 @@
@Test
fun joinAndAbandonEntity() {
- runProcessorTest(sources = ENTITIES) { invocation ->
+ runProcessorTestWithK1(sources = ENTITIES) { invocation ->
val entities =
invocation.roundEnv
.getElementsAnnotatedWith(androidx.room.Entity::class.qualifiedName!!)
@@ -613,7 +613,7 @@
val extraSource =
input?.let { listOf(Source.java(name, DATABASE_PREFIX + input)) } ?: emptyList()
val all = ENTITIES + extraSource
- return runProcessorTest(sources = all) { invocation ->
+ return runProcessorTestWithK1(sources = all) { invocation ->
val entities =
invocation.roundEnv
.getElementsAnnotatedWith(androidx.room.Entity::class.qualifiedName!!)
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/QueryMethodProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/QueryMethodProcessorTest.kt
index 1c92cc9..6ab007f 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/QueryMethodProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/QueryMethodProcessorTest.kt
@@ -27,7 +27,6 @@
import androidx.room.compiler.processing.XTypeElement
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
-import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.ext.CommonTypeNames
import androidx.room.ext.CommonTypeNames.LIST
import androidx.room.ext.CommonTypeNames.MUTABLE_LIST
@@ -46,6 +45,7 @@
import androidx.room.processor.ProcessorErrors.MAP_INFO_MUST_HAVE_AT_LEAST_ONE_COLUMN_PROVIDED
import androidx.room.processor.ProcessorErrors.cannotFindQueryResultAdapter
import androidx.room.processor.ProcessorErrors.mayNeedMapColumn
+import androidx.room.runProcessorTestWithK1
import androidx.room.solver.query.result.DataSourceFactoryQueryResultBinder
import androidx.room.solver.query.result.ListQueryResultAdapter
import androidx.room.solver.query.result.LiveDataQueryResultBinder
@@ -1239,7 +1239,7 @@
)
val allOptions =
mapOf(Context.BooleanProcessorOptions.GENERATE_KOTLIN.argName to "false") + options
- runProcessorTest(
+ runProcessorTestWithK1(
sources = additionalSources + commonSources + inputSource,
options = allOptions
) { invocation ->
@@ -1309,7 +1309,7 @@
COMMON.RX2_EMPTY_RESULT_SET_EXCEPTION
)
- runProcessorTest(
+ runProcessorTestWithK1(
sources = additionalSources + commonSources + inputSource,
options = options
) { invocation ->
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/RawQueryMethodProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/RawQueryMethodProcessorTest.kt
index 173a78a..d9cc959 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/RawQueryMethodProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/RawQueryMethodProcessorTest.kt
@@ -35,6 +35,7 @@
import androidx.room.ext.RxJava3TypeNames
import androidx.room.ext.SupportDbTypeNames
import androidx.room.processor.ProcessorErrors.RAW_QUERY_STRING_PARAMETER_REMOVED
+import androidx.room.runProcessorTestWithK1
import androidx.room.testing.context
import androidx.room.vo.RawQueryMethod
import androidx.sqlite.db.SupportSQLiteQuery
@@ -644,7 +645,7 @@
COMMON.IMAGE_FORMAT,
COMMON.CONVERTER
)
- runProcessorTest(
+ runProcessorTestWithK1(
sources = commonSources + inputSource,
options = mapOf(Context.BooleanProcessorOptions.GENERATE_KOTLIN.argName to "false"),
) { invocation ->
@@ -698,7 +699,7 @@
COMMON.FLOW,
COMMON.GUAVA_ROOM
)
- runProcessorTest(sources = commonSources + inputSource) { invocation ->
+ runProcessorTestWithK1(sources = commonSources + inputSource) { invocation ->
val (owner, methods) =
invocation.roundEnv
.getElementsAnnotatedWith(Dao::class.qualifiedName!!)
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/RemoveUnusedColumnsTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/RemoveUnusedColumnsTest.kt
index 4ffa12b..447dca2 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/RemoveUnusedColumnsTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/RemoveUnusedColumnsTest.kt
@@ -21,7 +21,7 @@
import androidx.room.RewriteQueriesToDropUnusedColumns
import androidx.room.compiler.processing.util.CompilationResultSubject
import androidx.room.compiler.processing.util.Source
-import androidx.room.compiler.processing.util.runProcessorTest
+import androidx.room.runProcessorTestWithK1
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
@@ -90,7 +90,7 @@
annotateMethod = annotateMethod
) + COMMON.USER
- runProcessorTest(
+ runProcessorTestWithK1(
sources = sources,
createProcessingSteps = { listOf(DatabaseProcessingStep()) },
options =
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/TableEntityProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/TableEntityProcessorTest.kt
index 109db0a..7d3459a 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/TableEntityProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/TableEntityProcessorTest.kt
@@ -23,9 +23,9 @@
import androidx.room.compiler.codegen.XTypeName.Companion.PRIMITIVE_LONG
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.compileFiles
-import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.parser.SQLTypeAffinity
import androidx.room.processor.ProcessorErrors.RELATION_IN_ENTITY
+import androidx.room.runProcessorTestWithK1
import androidx.room.testing.context
import androidx.room.vo.CallType
import androidx.room.vo.Field
@@ -2093,16 +2093,9 @@
sources = listOf(COMMON.USER)
) { _, invocation ->
invocation.assertCompilationResult {
- // TODO: https://github.com/google/ksp/issues/603
- // KSP validator does not validate annotation types so we will get another error
- // down the line.
- if (invocation.isKsp) {
- hasErrorContaining(ProcessorErrors.foreignKeyNotAnEntity("<Error>")).onLine(11)
- } else {
- hasErrorContaining(
- "Element 'foo.bar.MyEntity' references a type that is not present"
- )
- }
+ hasErrorContaining(
+ "Element 'foo.bar.MyEntity' references a type that is not present"
+ )
}
}
}
@@ -2637,7 +2630,7 @@
"""
.trimIndent()
)
- runProcessorTest(sources = listOf(src)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(src)) { invocation ->
val parser =
TableEntityProcessor(
invocation.context,
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/TransactionMethodProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/TransactionMethodProcessorTest.kt
index cc9d309..9354625 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/TransactionMethodProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/TransactionMethodProcessorTest.kt
@@ -23,7 +23,6 @@
import androidx.room.compiler.processing.XTypeElement
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
-import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.ext.GuavaUtilConcurrentTypeNames.LISTENABLE_FUTURE
import androidx.room.ext.KotlinTypeNames.FLOW
import androidx.room.ext.LifecyclesTypeNames.COMPUTABLE_LIVE_DATA
@@ -31,6 +30,7 @@
import androidx.room.ext.ReactiveStreamsTypeNames.PUBLISHER
import androidx.room.ext.RxJava2TypeNames
import androidx.room.ext.RxJava3TypeNames
+import androidx.room.runProcessorTestWithK1
import androidx.room.testing.context
import androidx.room.vo.TransactionMethod
import org.hamcrest.CoreMatchers.`is`
@@ -342,7 +342,7 @@
COMMON.LISTENABLE_FUTURE,
COMMON.FLOW
)
- runProcessorTest(
+ runProcessorTestWithK1(
sources = inputSource + otherSources,
options = mapOf(Context.BooleanProcessorOptions.GENERATE_KOTLIN.argName to "false")
) { invocation ->
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/autovalue/AutoValuePojoProcessorDelegateTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/autovalue/AutoValuePojoProcessorDelegateTest.kt
index 9c942db..c36fc4b 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/autovalue/AutoValuePojoProcessorDelegateTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/autovalue/AutoValuePojoProcessorDelegateTest.kt
@@ -20,10 +20,10 @@
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
import androidx.room.compiler.processing.util.compileFiles
-import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.processor.FieldProcessor
import androidx.room.processor.PojoProcessor
import androidx.room.processor.ProcessorErrors
+import androidx.room.runProcessorTestWithK1
import androidx.room.testing.context
import androidx.room.vo.Pojo
import com.google.auto.value.processor.AutoValueProcessor
@@ -112,7 +112,7 @@
// between javac (argN) and kotlinc (pN).
javacArguments = listOf("-parameters")
)
- runProcessorTest(
+ runProcessorTestWithK1(
sources = emptyList(),
classpath = libraryClasspath,
) { invocation: XTestInvocation ->
@@ -281,7 +281,7 @@
val pojoSource = Source.java(MY_POJO.canonicalName, pojoCode)
val autoValuePojoSource = Source.java(AUTOVALUE_MY_POJO.canonicalName, autoValuePojoCode)
val all: List<Source> = sources.toList() + pojoSource + autoValuePojoSource
- runProcessorTest(sources = all, classpath = classpathFiles) { invocation ->
+ runProcessorTestWithK1(sources = all, classpath = classpathFiles) { invocation ->
handler.invoke(
PojoProcessor.createFor(
context = invocation.context,
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/solver/BuiltInConverterFlagsTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/solver/BuiltInConverterFlagsTest.kt
index a53c6e7..6ced559 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/solver/BuiltInConverterFlagsTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/solver/BuiltInConverterFlagsTest.kt
@@ -23,10 +23,10 @@
import androidx.room.DatabaseProcessingStep
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
-import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.processor.Context
import androidx.room.processor.ProcessorErrors.CANNOT_FIND_COLUMN_TYPE_ADAPTER
import androidx.room.processor.ProcessorErrors.CANNOT_FIND_CURSOR_READER
+import androidx.room.runProcessorTestWithK1
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
@@ -138,7 +138,7 @@
daoAnnotation = daoAnnotation,
dbAnnotation = dbAnnotation
)
- runProcessorTest(
+ runProcessorTestWithK1(
sources = listOf(source),
options = mapOf(Context.BooleanProcessorOptions.GENERATE_KOTLIN.argName to "false"),
) { invocation ->
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/solver/CustomTypeConverterResolutionTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/solver/CustomTypeConverterResolutionTest.kt
index 3528c71..3bfb880 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/solver/CustomTypeConverterResolutionTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/solver/CustomTypeConverterResolutionTest.kt
@@ -31,11 +31,11 @@
import androidx.room.compiler.codegen.XTypeSpec
import androidx.room.compiler.processing.util.CompilationResultSubject
import androidx.room.compiler.processing.util.Source
-import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.ext.CommonTypeNames
import androidx.room.ext.RoomAnnotationTypeNames
import androidx.room.ext.RoomTypeNames.ROOM_DB
import androidx.room.processor.ProcessorErrors.CANNOT_BIND_QUERY_PARAMETER_INTO_STMT
+import androidx.room.runProcessorTestWithK1
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
@@ -212,7 +212,7 @@
sources: List<Source>,
onCompilationResult: (CompilationResultSubject) -> Unit = { it.hasErrorCount(0) }
) {
- runProcessorTest(
+ runProcessorTestWithK1(
sources =
sources +
CUSTOM_TYPE_JFO +
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/solver/NullabilityAwareTypeConverterStoreTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/solver/NullabilityAwareTypeConverterStoreTest.kt
index 9842dd3..9ed50f1 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/solver/NullabilityAwareTypeConverterStoreTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/solver/NullabilityAwareTypeConverterStoreTest.kt
@@ -25,11 +25,12 @@
import androidx.room.compiler.processing.util.XTestInvocation
import androidx.room.compiler.processing.util.compiler.TestCompilationArguments
import androidx.room.compiler.processing.util.compiler.compile
-import androidx.room.compiler.processing.util.runKspTest
import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.processor.Context.BooleanProcessorOptions.USE_NULL_AWARE_CONVERTER
import androidx.room.processor.CustomConverterProcessor
import androidx.room.processor.DaoProcessor
+import androidx.room.runKspTestWithK1
+import androidx.room.runProcessorTestWithK1
import androidx.room.solver.types.CustomTypeConverterWrapper
import androidx.room.solver.types.TypeConverter
import androidx.room.testing.context
@@ -405,7 +406,7 @@
"""
.trimIndent()
)
- runProcessorTest(
+ runProcessorTestWithK1(
sources = listOf(user, day, converters, dao),
options = mapOf(USE_NULL_AWARE_CONVERTER.argName to "true")
) { invocation ->
@@ -604,7 +605,7 @@
"""
.trimIndent()
)
- runProcessorTest(
+ runProcessorTestWithK1(
sources = listOf(source),
options = mapOf(USE_NULL_AWARE_CONVERTER.argName to "true")
) { invocation ->
@@ -680,7 +681,7 @@
"""
.trimIndent()
)
- runKspTest(
+ runKspTestWithK1(
sources = listOf(converters),
options = mapOf(USE_NULL_AWARE_CONVERTER.argName to "true")
) { invocation ->
@@ -738,7 +739,7 @@
"""
.trimIndent()
)
- runKspTest(sources = listOf(source)) { invocation ->
+ runKspTestWithK1(sources = listOf(source)) { invocation ->
val store = invocation.createStore("TimeConverter", "AwesomenessConverter")
val instantType = invocation.processingEnv.requireType("java.time.Instant")
val stringType = invocation.processingEnv.requireType("java.lang.String")
@@ -752,7 +753,7 @@
/** Collect results for conversion from String to our type */
private fun collectStringConversionResults(vararg selectedConverters: String): String {
val result = StringBuilder()
- runProcessorTest(
+ runProcessorTestWithK1(
sources = listOf(source),
options = mapOf(USE_NULL_AWARE_CONVERTER.argName to "true")
) { invocation ->
@@ -800,7 +801,7 @@
/** Collect results for conversion from an unknown cursor type to our type */
private fun collectCursorResults(vararg selectedConverters: String): String {
val result = StringBuilder()
- runProcessorTest(
+ runProcessorTestWithK1(
sources = listOf(source),
options = mapOf(USE_NULL_AWARE_CONVERTER.argName to "true")
) { invocation ->
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/solver/TypeAdapterStoreTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/solver/TypeAdapterStoreTest.kt
index 8aa2f41..e402617dd 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/solver/TypeAdapterStoreTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/solver/TypeAdapterStoreTest.kt
@@ -47,6 +47,7 @@
import androidx.room.processor.DaoProcessor
import androidx.room.processor.DaoProcessorTest
import androidx.room.processor.ProcessorErrors
+import androidx.room.runProcessorTestWithK1
import androidx.room.solver.binderprovider.DataSourceFactoryQueryResultBinderProvider
import androidx.room.solver.binderprovider.DataSourceQueryResultBinderProvider
import androidx.room.solver.binderprovider.ListenableFuturePagingSourceQueryResultBinderProvider
@@ -138,7 +139,7 @@
"""
.trimIndent()
)
- runProcessorTest(sources = listOf(entity, converter)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(entity, converter)) { invocation ->
val typeElement =
invocation.processingEnv.requireTypeElement("foo.bar.EntityWithOneWayEnum")
val context = Context(invocation.processingEnv)
@@ -202,7 +203,7 @@
"""
.trimMargin()
)
- runProcessorTest(sources = listOf(enumSrc)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(enumSrc)) { invocation ->
val store =
TypeAdapterStore.create(
Context(invocation.processingEnv),
@@ -235,7 +236,7 @@
)
var results: Map<String, String?> = mutableMapOf()
- runProcessorTest(sources = listOf(source)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(source)) { invocation ->
val typeAdapterStore =
TypeAdapterStore.create(
context = invocation.context,
@@ -291,7 +292,7 @@
.trimIndent()
)
- runProcessorTest(sources = listOf(source)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(source)) { invocation ->
TypeAdapterStore.create(
context = invocation.context,
builtInConverterFlags = BuiltInConverterFlags.DEFAULT
@@ -408,7 +409,7 @@
}
"""
)
- runProcessorTest(sources = listOf(point)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(point)) { invocation ->
val context = Context(invocation.processingEnv)
val converters =
CustomConverterProcessor(
@@ -569,7 +570,8 @@
@Test
fun testMissingRx2Room() {
- runProcessorTest(sources = listOf(COMMON.PUBLISHER, COMMON.RX2_FLOWABLE)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(COMMON.PUBLISHER, COMMON.RX2_FLOWABLE)) { invocation
+ ->
val publisherElement =
invocation.processingEnv.requireTypeElement(ReactiveStreamsTypeNames.PUBLISHER)
assertThat(publisherElement, notNullValue())
@@ -587,7 +589,8 @@
@Test
fun testMissingRx3Room() {
- runProcessorTest(sources = listOf(COMMON.PUBLISHER, COMMON.RX3_FLOWABLE)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(COMMON.PUBLISHER, COMMON.RX3_FLOWABLE)) { invocation
+ ->
val publisherElement =
invocation.processingEnv.requireTypeElement(ReactiveStreamsTypeNames.PUBLISHER)
assertThat(publisherElement, notNullValue())
@@ -626,7 +629,8 @@
@Test
fun testMissingRoomPagingGuava() {
- runProcessorTest(sources = listOf(COMMON.LISTENABLE_FUTURE_PAGING_SOURCE)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(COMMON.LISTENABLE_FUTURE_PAGING_SOURCE)) {
+ invocation ->
val listenableFuturePagingSourceElement =
invocation.processingEnv.requireTypeElement(
PagingTypeNames.LISTENABLE_FUTURE_PAGING_SOURCE
@@ -653,7 +657,7 @@
@Test
fun testMissingRoomPagingRx2() {
- runProcessorTest(sources = listOf(COMMON.RX2_PAGING_SOURCE)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(COMMON.RX2_PAGING_SOURCE)) { invocation ->
val rx2PagingSourceElement =
invocation.processingEnv.requireTypeElement(PagingTypeNames.RX2_PAGING_SOURCE)
val intType = invocation.processingEnv.requireType(Integer::class)
@@ -674,7 +678,7 @@
@Test
fun testMissingRoomPagingRx3() {
- runProcessorTest(sources = listOf(COMMON.RX3_PAGING_SOURCE)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(COMMON.RX3_PAGING_SOURCE)) { invocation ->
val rx3PagingSourceElement =
invocation.processingEnv.requireTypeElement(PagingTypeNames.RX3_PAGING_SOURCE)
val intType = invocation.processingEnv.requireType(Integer::class)
@@ -697,7 +701,7 @@
fun testFindPublisher() {
listOf(COMMON.RX2_FLOWABLE to COMMON.RX2_ROOM, COMMON.RX3_FLOWABLE to COMMON.RX3_ROOM)
.forEach { (rxTypeSrc, rxRoomSrc) ->
- runProcessorTest(
+ runProcessorTestWithK1(
sources = listOf(rxTypeSrc, rxRoomSrc),
classpath =
compileFiles(
@@ -736,7 +740,7 @@
Triple(COMMON.RX3_FLOWABLE, COMMON.RX3_ROOM, RxJava3TypeNames.FLOWABLE)
)
.forEach { (rxTypeSrc, rxRoomSrc, rxTypeClassName) ->
- runProcessorTest(
+ runProcessorTestWithK1(
sources = listOf(rxTypeSrc, rxRoomSrc),
classpath =
compileFiles(
@@ -771,7 +775,7 @@
Triple(COMMON.RX3_OBSERVABLE, COMMON.RX3_ROOM, RxJava3TypeNames.OBSERVABLE)
)
.forEach { (rxTypeSrc, rxRoomSrc, rxTypeClassName) ->
- runProcessorTest(
+ runProcessorTestWithK1(
sources = listOf(rxTypeSrc, rxRoomSrc),
classpath =
compileFiles(
@@ -809,7 +813,7 @@
Triple(COMMON.RX3_SINGLE, COMMON.RX3_ROOM, RxJava3TypeNames.SINGLE)
)
.forEach { (rxTypeSrc, _, rxTypeClassName) ->
- runProcessorTest(sources = listOf(rxTypeSrc)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(rxTypeSrc)) { invocation ->
val single = invocation.processingEnv.requireTypeElement(rxTypeClassName)
assertThat(single, notNullValue())
assertThat(
@@ -828,7 +832,7 @@
Triple(COMMON.RX3_MAYBE, COMMON.RX3_ROOM, RxJava3TypeNames.MAYBE)
)
.forEach { (rxTypeSrc, _, rxTypeClassName) ->
- runProcessorTest(sources = listOf(rxTypeSrc)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(rxTypeSrc)) { invocation ->
val maybe = invocation.processingEnv.requireTypeElement(rxTypeClassName)
assertThat(
RxCallableInsertOrUpsertMethodBinderProvider.getAll(invocation.context)
@@ -846,7 +850,7 @@
Triple(COMMON.RX3_COMPLETABLE, COMMON.RX3_ROOM, RxJava3TypeNames.COMPLETABLE)
)
.forEach { (rxTypeSrc, _, rxTypeClassName) ->
- runProcessorTest(sources = listOf(rxTypeSrc)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(rxTypeSrc)) { invocation ->
val completable = invocation.processingEnv.requireTypeElement(rxTypeClassName)
assertThat(
RxCallableInsertOrUpsertMethodBinderProvider.getAll(invocation.context)
@@ -859,7 +863,7 @@
@Test
fun testFindInsertListenableFuture() {
- runProcessorTest(sources = listOf(COMMON.LISTENABLE_FUTURE)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(COMMON.LISTENABLE_FUTURE)) { invocation ->
val future =
invocation.processingEnv.requireTypeElement(
GuavaUtilConcurrentTypeNames.LISTENABLE_FUTURE
@@ -874,7 +878,7 @@
@Test
fun testFindDeleteOrUpdateSingle() {
- runProcessorTest(sources = listOf(COMMON.RX2_SINGLE)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(COMMON.RX2_SINGLE)) { invocation ->
val single = invocation.processingEnv.requireTypeElement(RxJava2TypeNames.SINGLE)
assertThat(single, notNullValue())
assertThat(
@@ -888,7 +892,7 @@
@Test
fun testFindDeleteOrUpdateMaybe() {
- runProcessorTest(sources = listOf(COMMON.RX2_MAYBE)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(COMMON.RX2_MAYBE)) { invocation ->
val maybe = invocation.processingEnv.requireTypeElement(RxJava2TypeNames.MAYBE)
assertThat(maybe, notNullValue())
assertThat(
@@ -902,7 +906,7 @@
@Test
fun testFindDeleteOrUpdateCompletable() {
- runProcessorTest(sources = listOf(COMMON.RX2_COMPLETABLE)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(COMMON.RX2_COMPLETABLE)) { invocation ->
val completable =
invocation.processingEnv.requireTypeElement(RxJava2TypeNames.COMPLETABLE)
assertThat(completable, notNullValue())
@@ -917,7 +921,7 @@
@Test
fun testFindDeleteOrUpdateListenableFuture() {
- runProcessorTest(sources = listOf(COMMON.LISTENABLE_FUTURE)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(COMMON.LISTENABLE_FUTURE)) { invocation ->
val future =
invocation.processingEnv.requireTypeElement(
GuavaUtilConcurrentTypeNames.LISTENABLE_FUTURE
@@ -938,7 +942,7 @@
Triple(COMMON.RX3_SINGLE, COMMON.RX3_ROOM, RxJava3TypeNames.SINGLE)
)
.forEach { (rxTypeSrc, _, rxTypeClassName) ->
- runProcessorTest(sources = listOf(rxTypeSrc)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(rxTypeSrc)) { invocation ->
val single = invocation.processingEnv.requireTypeElement(rxTypeClassName)
assertThat(single).isNotNull()
assertThat(
@@ -957,7 +961,7 @@
Triple(COMMON.RX3_MAYBE, COMMON.RX3_ROOM, RxJava3TypeNames.MAYBE)
)
.forEach { (rxTypeSrc, _, rxTypeClassName) ->
- runProcessorTest(sources = listOf(rxTypeSrc)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(rxTypeSrc)) { invocation ->
val maybe = invocation.processingEnv.requireTypeElement(rxTypeClassName)
assertThat(
RxCallableInsertOrUpsertMethodBinderProvider.getAll(invocation.context)
@@ -975,7 +979,7 @@
Triple(COMMON.RX3_COMPLETABLE, COMMON.RX3_ROOM, RxJava3TypeNames.COMPLETABLE)
)
.forEach { (rxTypeSrc, _, rxTypeClassName) ->
- runProcessorTest(sources = listOf(rxTypeSrc)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(rxTypeSrc)) { invocation ->
val completable = invocation.processingEnv.requireTypeElement(rxTypeClassName)
assertThat(
RxCallableInsertOrUpsertMethodBinderProvider.getAll(invocation.context)
@@ -988,7 +992,7 @@
@Test
fun testFindUpsertListenableFuture() {
- runProcessorTest(sources = listOf(COMMON.LISTENABLE_FUTURE)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(COMMON.LISTENABLE_FUTURE)) { invocation ->
val future =
invocation.processingEnv.requireTypeElement(
GuavaUtilConcurrentTypeNames.LISTENABLE_FUTURE
@@ -1003,7 +1007,7 @@
@Test
fun testFindLiveData() {
- runProcessorTest(sources = listOf(COMMON.COMPUTABLE_LIVE_DATA, COMMON.LIVE_DATA)) {
+ runProcessorTestWithK1(sources = listOf(COMMON.COMPUTABLE_LIVE_DATA, COMMON.LIVE_DATA)) {
invocation ->
val liveData =
invocation.processingEnv.requireTypeElement(LifecyclesTypeNames.LIVE_DATA)
@@ -1017,7 +1021,7 @@
@Test
fun findPagingSourceIntKey() {
- runProcessorTest(
+ runProcessorTestWithK1(
sources = listOf(COMMON.LIMIT_OFFSET_PAGING_SOURCE),
) { invocation ->
val pagingSourceElement =
@@ -1161,7 +1165,8 @@
@Test
fun findListenableFuturePagingSourceJavaCollectionValue() {
- runProcessorTest(sources = listOf(COMMON.LISTENABLE_FUTURE_PAGING_SOURCE)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(COMMON.LISTENABLE_FUTURE_PAGING_SOURCE)) {
+ invocation ->
val listenableFuturePagingSourceElement =
invocation.processingEnv.requireTypeElement(
PagingTypeNames.LISTENABLE_FUTURE_PAGING_SOURCE
@@ -1189,7 +1194,8 @@
@Test
fun findListenableFutureKotlinCollectionValue() {
- runProcessorTest(sources = listOf(COMMON.LISTENABLE_FUTURE_PAGING_SOURCE)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(COMMON.LISTENABLE_FUTURE_PAGING_SOURCE)) {
+ invocation ->
val listenableFuturePagingSourceElement =
invocation.processingEnv.requireTypeElement(
PagingTypeNames.LISTENABLE_FUTURE_PAGING_SOURCE
@@ -1217,7 +1223,7 @@
@Test
fun findRx2PagingSourceJavaCollectionValue() {
- runProcessorTest(sources = listOf(COMMON.RX2_PAGING_SOURCE)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(COMMON.RX2_PAGING_SOURCE)) { invocation ->
val rx2PagingSourceElement =
invocation.processingEnv.requireTypeElement(PagingTypeNames.RX2_PAGING_SOURCE)
val intType = invocation.processingEnv.requireType(Integer::class)
@@ -1243,7 +1249,7 @@
@Test
fun findRx2PagingSourceKotlinCollectionValue() {
- runProcessorTest(sources = listOf(COMMON.RX2_PAGING_SOURCE)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(COMMON.RX2_PAGING_SOURCE)) { invocation ->
val rx2PagingSourceElement =
invocation.processingEnv.requireTypeElement(PagingTypeNames.RX2_PAGING_SOURCE)
val intType = invocation.processingEnv.requireType(Integer::class)
@@ -1269,7 +1275,7 @@
@Test
fun findRx3PagingSourceJavaCollectionValue() {
- runProcessorTest(sources = listOf(COMMON.RX3_PAGING_SOURCE)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(COMMON.RX3_PAGING_SOURCE)) { invocation ->
val rx3PagingSourceElement =
invocation.processingEnv.requireTypeElement(PagingTypeNames.RX3_PAGING_SOURCE)
val intType = invocation.processingEnv.requireType(Integer::class)
@@ -1295,7 +1301,7 @@
@Test
fun findRx3PagingSourceKotlinCollectionValue() {
- runProcessorTest(sources = listOf(COMMON.RX3_PAGING_SOURCE)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(COMMON.RX3_PAGING_SOURCE)) { invocation ->
val rx3PagingSourceElement =
invocation.processingEnv.requireTypeElement(PagingTypeNames.RX3_PAGING_SOURCE)
val intType = invocation.processingEnv.requireType(Integer::class)
@@ -1335,7 +1341,7 @@
"""
.trimIndent()
)
- runProcessorTest(
+ runProcessorTestWithK1(
sources =
listOf(
inputSource,
@@ -1399,7 +1405,7 @@
"""
.trimIndent()
)
- runProcessorTest(
+ runProcessorTestWithK1(
sources =
listOf(
inputSource,
@@ -1459,7 +1465,7 @@
"""
.trimIndent()
)
- runProcessorTest(
+ runProcessorTestWithK1(
sources =
listOf(
inputSource,
@@ -1515,7 +1521,7 @@
"""
.trimIndent()
)
- runProcessorTest(
+ runProcessorTestWithK1(
sources =
listOf(
inputSource,
@@ -1588,7 +1594,7 @@
@Test
fun findDataSourceFactory() {
- runProcessorTest(sources = listOf(COMMON.DATA_SOURCE_FACTORY)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(COMMON.DATA_SOURCE_FACTORY)) { invocation ->
val pagedListProvider =
invocation.processingEnv.requireTypeElement(PagingTypeNames.DATA_SOURCE_FACTORY)
assertThat(pagedListProvider, notNullValue())
@@ -1671,7 +1677,7 @@
"""
.trimIndent()
)
- runProcessorTest(sources = listOf(source)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(source)) { invocation ->
val converters =
CustomConverterProcessor(
context = invocation.context,
@@ -1807,7 +1813,7 @@
"""
.trimIndent()
)
- runProcessorTest(
+ runProcessorTestWithK1(
sources =
listOf(
classExtendsClassWithEqualsAndHashcodeFunctions,
@@ -1850,7 +1856,7 @@
"""
.trimIndent()
)
- runProcessorTest(
+ runProcessorTestWithK1(
sources =
listOf(
inputSource,
@@ -1882,7 +1888,7 @@
"""
.trimIndent()
)
- runProcessorTest(sources = listOf(source)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(source)) { invocation ->
val subjectTypeElement = invocation.processingEnv.requireTypeElement("Subject")
subjectTypeElement.getDeclaredFields().forEach {
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/solver/TypeAssignmentTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/solver/TypeAssignmentTest.kt
index c02a5de..d67ad7d 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/solver/TypeAssignmentTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/solver/TypeAssignmentTest.kt
@@ -20,7 +20,7 @@
import androidx.room.compiler.processing.XVariableElement
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
-import androidx.room.compiler.processing.util.runProcessorTest
+import androidx.room.runProcessorTestWithK1
import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Test
@@ -101,6 +101,6 @@
}
private fun runTest(handler: XTestInvocation.() -> Unit) {
- runProcessorTest(sources = listOf(TEST_OBJECT)) { it.apply { handler() } }
+ runProcessorTestWithK1(sources = listOf(TEST_OBJECT)) { it.apply { handler() } }
}
}
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/solver/TypeConverterStoreTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/solver/TypeConverterStoreTest.kt
index 10e445c..12ca821 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/solver/TypeConverterStoreTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/solver/TypeConverterStoreTest.kt
@@ -19,8 +19,8 @@
import androidx.kruth.assertThat
import androidx.room.compiler.codegen.CodeLanguage
import androidx.room.compiler.processing.util.Source
-import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.processor.CustomConverterProcessor
+import androidx.room.runProcessorTestWithK1
import androidx.room.solver.types.CompositeTypeConverter
import androidx.room.solver.types.CustomTypeConverterWrapper
import androidx.room.solver.types.TypeConverter
@@ -65,7 +65,7 @@
"""
.trimIndent()
)
- runProcessorTest(sources = listOf(source)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(source)) { invocation ->
val convertersElm = invocation.processingEnv.requireTypeElement("MyConverters")
val converters = CustomConverterProcessor(invocation.context, convertersElm).process()
val store =
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/solver/query/QueryWriterTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/solver/query/QueryWriterTest.kt
index ba3efa3..6da36ab 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/solver/query/QueryWriterTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/solver/query/QueryWriterTest.kt
@@ -22,10 +22,10 @@
import androidx.room.compiler.codegen.CodeLanguage
import androidx.room.compiler.processing.XTypeElement
import androidx.room.compiler.processing.util.Source
-import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.ext.RoomTypeNames.ROOM_SQL_QUERY
import androidx.room.ext.RoomTypeNames.STRING_UTIL
import androidx.room.processor.QueryMethodProcessor
+import androidx.room.runProcessorTestWithK1
import androidx.room.testing.context
import androidx.room.writer.QueryWriter
import org.junit.Test
@@ -361,7 +361,7 @@
fun singleQueryMethod(vararg input: String, handler: (Boolean, QueryWriter) -> Unit) {
val source =
Source.java("foo.bar.MyClass", DAO_PREFIX + input.joinToString("\n") + DAO_SUFFIX)
- runProcessorTest(sources = listOf(source)) { invocation ->
+ runProcessorTestWithK1(sources = listOf(source)) { invocation ->
val (owner, methods) =
invocation.roundEnv
.getElementsAnnotatedWith(Dao::class.qualifiedName!!)
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/testing/InProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/testing/InProcessorTest.kt
index 521e634..cdb11ac 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/testing/InProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/testing/InProcessorTest.kt
@@ -19,7 +19,7 @@
import androidx.kruth.assertThat
import androidx.room.compiler.processing.util.CompilationTestCapabilities
import androidx.room.compiler.processing.util.Source
-import androidx.room.compiler.processing.util.runProcessorTest
+import androidx.room.runProcessorTestWithK1
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
@@ -58,7 +58,7 @@
}
var runCount = 0
- runProcessorTest(sources = listOf(source)) {
+ runProcessorTestWithK1(sources = listOf(source)) {
assertThat(it.processingEnv.findTypeElement("foo.bar.MyClass")).isNotNull()
runCount++
}
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/writer/AutoMigrationWriterTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/writer/AutoMigrationWriterTest.kt
index 34b127f..b42941f 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/writer/AutoMigrationWriterTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/writer/AutoMigrationWriterTest.kt
@@ -21,9 +21,9 @@
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
import androidx.room.compiler.processing.util.runJavaProcessorTest
-import androidx.room.compiler.processing.util.runKspTest
import androidx.room.migration.bundle.FieldBundle
import androidx.room.processor.Context
+import androidx.room.runKspTestWithK1
import androidx.room.util.SchemaDiffResult
import androidx.room.vo.AutoMigration
import loadTestSource
@@ -88,7 +88,7 @@
)
}
- runProcessorTest(listOf(specSource)) { invocation ->
+ runProcessorTestWithK1(listOf(specSource)) { invocation ->
val autoMigrationResultWithNewAddedColumn =
AutoMigration(
from = 1,
@@ -172,7 +172,7 @@
)
}
- runProcessorTest(listOf(specSource)) { invocation ->
+ runProcessorTestWithK1(listOf(specSource)) { invocation ->
val autoMigrationResultWithNewAddedColumn =
AutoMigration(
from = 1,
@@ -264,7 +264,7 @@
)
}
- runProcessorTest(listOf(specSource)) { invocation ->
+ runProcessorTestWithK1(listOf(specSource)) { invocation ->
val autoMigrationResultWithNewAddedColumn =
AutoMigration(
from = 1,
@@ -320,7 +320,7 @@
}
}
- private fun runProcessorTest(sources: List<Source>, handler: (XTestInvocation) -> Unit) {
+ private fun runProcessorTestWithK1(sources: List<Source>, handler: (XTestInvocation) -> Unit) {
when (codeLanguage) {
CodeLanguage.JAVA ->
runJavaProcessorTest(
@@ -330,7 +330,7 @@
handler = handler
)
CodeLanguage.KOTLIN ->
- runKspTest(
+ runKspTestWithK1(
sources = sources + kotlinDatabaseSource,
options =
mapOf(Context.BooleanProcessorOptions.GENERATE_KOTLIN.argName to "true"),
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/writer/BaseDaoKotlinCodeGenTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/writer/BaseDaoKotlinCodeGenTest.kt
index 8385ac1..d30d126 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/writer/BaseDaoKotlinCodeGenTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/writer/BaseDaoKotlinCodeGenTest.kt
@@ -19,11 +19,10 @@
import androidx.room.DatabaseProcessingStep
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
-import androidx.room.compiler.processing.util.runKspTest
import androidx.room.processor.Context
+import androidx.room.runKspTestWithK1
import java.io.File
import loadTestSource
-import org.jetbrains.kotlin.config.JvmDefaultMode
import writeTestSource
abstract class BaseDaoKotlinCodeGenTest {
@@ -35,14 +34,14 @@
sources: List<Source>,
expectedFilePath: String,
compiledFiles: List<File> = emptyList(),
- jvmDefaultMode: JvmDefaultMode = JvmDefaultMode.DEFAULT,
+ jvmDefaultMode: String = "disable",
handler: (XTestInvocation) -> Unit = {}
) {
- runKspTest(
+ runKspTestWithK1(
sources = sources,
classpath = compiledFiles,
options = mapOf(Context.BooleanProcessorOptions.GENERATE_KOTLIN.argName to "true"),
- kotlincArguments = listOf("-Xjvm-default=${jvmDefaultMode.description}")
+ kotlincArguments = listOf("-Xjvm-default=${jvmDefaultMode}")
) {
val databaseFqn = "androidx.room.Database"
DatabaseProcessingStep()
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/writer/DaoKotlinCodeGenTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/writer/DaoKotlinCodeGenTest.kt
index b6130b5..a4afa61 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/writer/DaoKotlinCodeGenTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/writer/DaoKotlinCodeGenTest.kt
@@ -21,7 +21,6 @@
import androidx.room.compiler.processing.util.compileFiles
import com.google.testing.junit.testparameterinjector.TestParameter
import com.google.testing.junit.testparameterinjector.TestParameterInjector
-import org.jetbrains.kotlin.config.JvmDefaultMode
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
@@ -1033,8 +1032,7 @@
@Test
fun delegatingFunctions_defaultImplBridge(
- @TestParameter("DISABLE", "ALL_COMPATIBILITY", "ALL_INCOMPATIBLE")
- jvmDefaultMode: JvmDefaultMode
+ @TestParameter("disable", "all-compatibility", "all") jvmDefaultMode: String
) {
// For parametrized tests, use method name from reflection
val testName = object {}.javaClass.enclosingMethod!!.name
@@ -1110,8 +1108,7 @@
@Test
fun transactionMethodAdapter_interface(
- @TestParameter("DISABLE", "ALL_COMPATIBILITY", "ALL_INCOMPATIBLE")
- jvmDefaultMode: JvmDefaultMode
+ @TestParameter("disable", "all-compatibility", "all") jvmDefaultMode: String
) {
// For parametrized tests, use method name from reflection
val testName = object {}.javaClass.enclosingMethod!!.name
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/writer/DaoWriterTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/writer/DaoWriterTest.kt
index 9679f86..3f13507 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/writer/DaoWriterTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/writer/DaoWriterTest.kt
@@ -23,9 +23,9 @@
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
import androidx.room.compiler.processing.util.compileFiles
-import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.ext.RoomTypeNames.ROOM_DB
import androidx.room.processor.DaoProcessor
+import androidx.room.runProcessorTestWithK1
import androidx.room.testing.context
import com.google.testing.junit.testparameterinjector.TestParameter
import com.google.testing.junit.testparameterinjector.TestParameterInjector
@@ -148,10 +148,10 @@
COMMON.PUBLISHER
)
)
- runProcessorTest(sources = sources, classpath = libs) { invocation ->
+ runProcessorTestWithK1(sources = sources, classpath = libs) { invocation ->
if (invocation.isKsp && !javaLambdaSyntaxAvailable) {
// Skip KSP backend without lambda syntax, it is a nonsensical combination.
- return@runProcessorTest
+ return@runProcessorTestWithK1
}
val dao =
invocation.roundEnv
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/writer/DatabaseKotlinCodeGenTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/writer/DatabaseKotlinCodeGenTest.kt
index b13bd03..b3bc884 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/writer/DatabaseKotlinCodeGenTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/writer/DatabaseKotlinCodeGenTest.kt
@@ -19,8 +19,8 @@
import androidx.room.DatabaseProcessingStep
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
-import androidx.room.compiler.processing.util.runKspTest
import androidx.room.processor.Context
+import androidx.room.runKspTestWithK1
import loadTestSource
import org.junit.Rule
import org.junit.Test
@@ -245,7 +245,7 @@
expectedFilePath: String,
handler: (XTestInvocation) -> Unit = {}
) {
- runKspTest(
+ runKspTestWithK1(
sources = sources,
options = mapOf(Context.BooleanProcessorOptions.GENERATE_KOTLIN.argName to "true"),
) {
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/writer/DatabaseObjectConstructorWriterKotlinCodeGenTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/writer/DatabaseObjectConstructorWriterKotlinCodeGenTest.kt
index c912440..5eaf944 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/writer/DatabaseObjectConstructorWriterKotlinCodeGenTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/writer/DatabaseObjectConstructorWriterKotlinCodeGenTest.kt
@@ -19,8 +19,8 @@
import androidx.room.DatabaseProcessingStep
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
-import androidx.room.compiler.processing.util.runKspTest
import androidx.room.processor.Context
+import androidx.room.runKspTestWithK1
import loadTestSource
import org.junit.Rule
import org.junit.Test
@@ -72,7 +72,7 @@
expectedFilePath: String,
handler: (XTestInvocation) -> Unit = {}
) {
- runKspTest(
+ runKspTestWithK1(
sources = sources,
options = mapOf(Context.BooleanProcessorOptions.GENERATE_KOTLIN.argName to "true"),
) {
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/writer/DatabaseWriterTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/writer/DatabaseWriterTest.kt
index eb077c0..2632fe5 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/writer/DatabaseWriterTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/writer/DatabaseWriterTest.kt
@@ -22,8 +22,8 @@
import androidx.room.compiler.processing.util.CompilationResultSubject
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.compileFiles
-import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.processor.Context
+import androidx.room.runProcessorTestWithK1
import androidx.testutils.generateAllEnumerations
import loadTestSource
import org.junit.Test
@@ -159,7 +159,7 @@
COMMON.LISTENABLE_FUTURE
)
)
- runProcessorTest(
+ runProcessorTestWithK1(
sources = sources,
classpath = libs,
options = mapOf(Context.BooleanProcessorOptions.GENERATE_KOTLIN.argName to "false"),
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/writer/DefaultsInDaoTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/writer/DefaultsInDaoTest.kt
index 68ca39f..b237147 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/writer/DefaultsInDaoTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/writer/DefaultsInDaoTest.kt
@@ -21,13 +21,12 @@
import androidx.room.compiler.processing.XProcessingEnv
import androidx.room.compiler.processing.XTypeElement
import androidx.room.compiler.processing.util.Source
-import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.ext.RoomTypeNames.ROOM_DB
import androidx.room.processor.DaoProcessor
+import androidx.room.runProcessorTestWithK1
import androidx.room.testing.context
import com.google.common.truth.StringSubject
import createVerifierFromEntitiesAndViews
-import org.jetbrains.kotlin.config.JvmDefaultMode
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
@@ -42,11 +41,11 @@
* For Java default method tests, we have DefaultDaoMethodsTest in TestApp.
*/
@RunWith(Parameterized::class)
-class DefaultsInDaoTest(private val jvmDefaultMode: JvmDefaultMode) {
+class DefaultsInDaoTest(private val jvmDefaultMode: String) {
@Test
fun abstractDao() {
val defaultWithCompatibilityAnnotation =
- if (jvmDefaultMode == JvmDefaultMode.ALL_COMPATIBILITY) {
+ if (jvmDefaultMode == "all-compatibility") {
"@JvmDefaultWithoutCompatibility"
} else {
""
@@ -101,7 +100,7 @@
)
compileInEachDefaultsMode(source) { generated ->
generated.contains("public void upsert(final User obj)")
- if (jvmDefaultMode == JvmDefaultMode.DISABLE) {
+ if (jvmDefaultMode == "disable") {
generated.contains("SubjectDao.DefaultImpls.upsert(SubjectDao_Impl.this")
} else {
generated.contains("SubjectDao.super.upsert(")
@@ -137,7 +136,7 @@
"public Object upsert(final User obj, " +
"final Continuation<? super Unit> \$completion)"
)
- if (jvmDefaultMode == JvmDefaultMode.DISABLE) {
+ if (jvmDefaultMode == "disable") {
generated.contains("SubjectDao.DefaultImpls.upsert(SubjectDao_Impl.this")
} else {
generated.contains("SubjectDao.super.upsert(")
@@ -179,11 +178,10 @@
jvmTarget: String = "1.8",
handler: (StringSubject) -> Unit
) {
- runProcessorTest(
+ runProcessorTestWithK1(
sources = listOf(source, COMMON.COROUTINES_ROOM, COMMON.ROOM_DATABASE_KTX),
javacArguments = listOf("-source", jvmTarget),
- kotlincArguments =
- listOf("-jvm-target=$jvmTarget", "-Xjvm-default=${jvmDefaultMode.description}")
+ kotlincArguments = listOf("-jvm-target=$jvmTarget", "-Xjvm-default=${jvmDefaultMode}")
) { invocation ->
invocation.roundEnv
.getElementsAnnotatedWith(androidx.room.Dao::class.qualifiedName!!)
@@ -223,9 +221,9 @@
@Parameters(name = "jvmDefaultMode={0}")
fun modes() =
listOf(
- JvmDefaultMode.ALL_COMPATIBILITY,
- JvmDefaultMode.ALL_INCOMPATIBLE,
- JvmDefaultMode.DISABLE,
+ "all-compatibility",
+ "all",
+ "disable",
)
}
}
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/writer/OpenDelegateWriterTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/writer/OpenDelegateWriterTest.kt
index 5e9aa20..26f7d0b 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/writer/OpenDelegateWriterTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/writer/OpenDelegateWriterTest.kt
@@ -19,8 +19,8 @@
import androidx.room.compiler.processing.XTypeElement
import androidx.room.compiler.processing.util.Source
import androidx.room.compiler.processing.util.XTestInvocation
-import androidx.room.compiler.processing.util.runProcessorTest
import androidx.room.processor.DatabaseProcessor
+import androidx.room.runProcessorTestWithK1
import androidx.room.testing.context
import androidx.room.vo.Database
import org.hamcrest.CoreMatchers.`is`
@@ -219,7 +219,7 @@
}
"""
)
- runProcessorTest(sources = sources + databaseCode) { invocation ->
+ runProcessorTestWithK1(sources = sources + databaseCode) { invocation ->
val db =
invocation.roundEnv
.getElementsAnnotatedWith(androidx.room.Database::class.qualifiedName!!)