Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@
package com.google.devtools.ksp

import com.google.devtools.ksp.processing.impl.MessageCollectorBasedKSPLogger
import com.intellij.core.CoreApplicationEnvironment
import com.intellij.mock.MockProject
import com.intellij.psi.PsiTreeChangeAdapter
import com.intellij.psi.PsiTreeChangeListener
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot
import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption
import org.jetbrains.kotlin.compiler.plugin.CliOptionProcessingException
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.jetbrains.kotlin.config.CommonConfigurationKeys
import org.jetbrains.kotlin.config.CompilerConfiguration
Expand Down Expand Up @@ -63,8 +59,10 @@ class KotlinSymbolProcessingCommandLineProcessor : CommandLineProcessor {
// https://github.com/tschuchortdev/kotlin-compile-testing
@Suppress("DEPRECATION")
@ExperimentalCompilerApi
class KotlinSymbolProcessingComponentRegistrar : ComponentRegistrar {
override fun registerProjectComponents(project: MockProject, configuration: CompilerConfiguration) {
class KotlinSymbolProcessingComponentRegistrar : CompilerPluginRegistrar() {
override val pluginId: String = "com.google.devtools.ksp.symbol-processing"

override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) {
// KSP 1.x don't and will not support K2. Do not register if language version >= 2.
if (configuration.languageVersionSettings.languageVersion >= LanguageVersion.KOTLIN_2_0)
return
Expand All @@ -87,13 +85,8 @@ class KotlinSymbolProcessingComponentRegistrar : ComponentRegistrar {
throw IllegalStateException("ksp: `incremental` is incompatible with `withCompilation`.")
}
val kotlinSymbolProcessingHandlerExtension = KotlinSymbolProcessingExtension(options, logger)
AnalysisHandlerExtension.registerExtension(project, kotlinSymbolProcessingHandlerExtension)
AnalysisHandlerExtension.registerExtension(kotlinSymbolProcessingHandlerExtension)
configuration.put(CommonConfigurationKeys.LOOKUP_TRACKER, DualLookupTracker())

// Dummy extension point; Required by dropPsiCaches().
CoreApplicationEnvironment.registerExtensionPoint(
project.extensionArea, PsiTreeChangeListener.EP.name, PsiTreeChangeAdapter::class.java
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,16 @@ import org.junit.Assume
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.junit.runner.RunWith
import org.junit.runners.Parameterized

@RunWith(Parameterized::class)
class GradleCompilationTest(val useKSP2: Boolean) {

companion object {
@JvmStatic
@Parameterized.Parameters(name = "KSP2={0}")
fun params() = listOf(arrayOf(true), arrayOf(false))
}
class GradleCompilationTest() {

@Rule
@JvmField
val tmpDir = TemporaryFolder()

@Rule
@JvmField
val testRule = KspIntegrationTestRule(tmpDir, useKSP2)
val testRule = KspIntegrationTestRule(tmpDir)

@Test
fun errorMessageFailsCompilation() {
Expand Down Expand Up @@ -420,27 +411,11 @@ class GradleCompilationTest(val useKSP2: Boolean) {
assertThat(result.output).doesNotContain("app/build/generated/ksp/main/classes")
}

@Test
fun changingKsp2AtRuntime() {
Assume.assumeFalse(useKSP2)
testRule.setupAppAsJvmApp()
testRule.appModule.buildFileAdditions.add(
"""
@OptIn(com.google.devtools.ksp.KspExperimental::class)
ksp { useKsp2.set(true) }
""".trimIndent()
)

testRule.runner().withArguments().build()
}

/**
* Regression test for b/362279380
*/
@Test
fun androidGradlePluginBuiltInKotlin() {
// built in kotlin will only be supported with KSP2
Assume.assumeTrue(useKSP2)
testRule.setupAppAsAndroidApp(enableAgpBuiltInKotlinSupport = true)
testRule.appModule.dependencies.addAll(
listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,16 @@ import com.google.devtools.ksp.gradle.testing.KspIntegrationTestRule
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.junit.runner.RunWith
import org.junit.runners.Parameterized

@RunWith(Parameterized::class)
class ProcessorClasspathConfigurationsTest(val useKSP2: Boolean) {

companion object {
@JvmStatic
@Parameterized.Parameters(name = "KSP2={0}")
fun params() = listOf(arrayOf(true), arrayOf(false))
}
class ProcessorClasspathConfigurationsTest() {

@Rule
@JvmField
val tmpDir = TemporaryFolder()

@Rule
@JvmField
val testRule = KspIntegrationTestRule(tmpDir, useKSP2)
val testRule = KspIntegrationTestRule(tmpDir)

private val kspConfigs by lazy {
"""configurations.matching { it.name.startsWith("ksp") && !it.name.endsWith("ProcessorClasspath") }"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,20 @@ import com.google.devtools.ksp.processing.SymbolProcessor
import com.google.devtools.ksp.symbol.KSAnnotated
import com.google.devtools.ksp.symbol.KSClassDeclaration
import org.gradle.testkit.runner.TaskOutcome
import org.junit.Assume
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import java.io.File

@RunWith(Parameterized::class)
class SourceSetConfigurationsTest(val useKSP2: Boolean) {

companion object {
@JvmStatic
@Parameterized.Parameters(name = "KSP2={0}")
fun params() = listOf(arrayOf(true), arrayOf(false))
}
class SourceSetConfigurationsTest() {

@Rule
@JvmField
val tmpDir = TemporaryFolder()

@Rule
@JvmField
val testRule = KspIntegrationTestRule(tmpDir, useKSP2)
val testRule = KspIntegrationTestRule(tmpDir)

@Test
fun configurationsForJvmApp() {
Expand Down Expand Up @@ -167,7 +157,6 @@ class SourceSetConfigurationsTest(val useKSP2: Boolean) {

@Test
fun registerGeneratedSourcesToAndroid() {
Assume.assumeTrue(useKSP2)
testRule.setupAppAsAndroidApp()
testRule.appModule.dependencies.addAll(
listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import kotlin.reflect.KClass
*/
class KspIntegrationTestRule(
private val tmpFolder: TemporaryFolder,
private val useKSP2: Boolean
) : TestWatcher() {
/**
* Initialized when the test starts.
Expand Down Expand Up @@ -169,6 +168,6 @@ class KspIntegrationTestRule(

override fun starting(description: Description) {
super.starting(description)
testProject = TestProject(tmpFolder.newFolder(), testConfig, useKSP2)
testProject = TestProject(tmpFolder.newFolder(), testConfig)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import java.io.File
class TestProject(
val rootDir: File,
val testConfig: TestConfig,
val useKSP2: Boolean,
) {
val processorModule = TestModule(
rootDir.resolve("processor")
Expand Down Expand Up @@ -60,7 +59,6 @@ class TestProject(
val contents = """
kotlin.jvm.target.validation.mode=warning
ksp.useKSP2=$useKSP2
""".trimIndent()
rootDir.resolve("gradle.properties").appendText(contents)
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copied from kotlinc
org.gradle.jvmargs=-Duser.country=US -Dkotlin.daemon.jvm.options=-Xmx4096m -Dfile.encoding=UTF-8

kotlinBaseVersion=2.2.20
kotlinBaseVersion=2.3.0-Beta1
agpBaseVersion=8.13.0-rc01
intellijVersion=241.19416.19
junitVersion=4.13.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import java.io.File
class AGP810IT {
@Rule
@JvmField
val project: TemporaryTestProject = TemporaryTestProject("playground-android-multi", "playground", true)
val project: TemporaryTestProject = TemporaryTestProject("playground-android-multi", "playground")

@Test
fun testRunsKSP() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import java.io.File
class AGP812IT {
@Rule
@JvmField
val project: TemporaryTestProject = TemporaryTestProject("playground-android-multi", "playground", true)
val project: TemporaryTestProject = TemporaryTestProject("playground-android-multi", "playground")

@Test
fun testRunsKSP() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import java.io.File
class AGP890IT {
@Rule
@JvmField
val project: TemporaryTestProject = TemporaryTestProject("playground-android-multi", "playground", true)
val project: TemporaryTestProject = TemporaryTestProject("playground-android-multi", "playground")

@Test
fun testRunsKSP() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ import org.gradle.testkit.runner.TaskOutcome
import org.junit.Assert
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import java.io.File

@RunWith(Parameterized::class)
class AGP900IT(useKSP2: Boolean) {
class AGP900IT() {
@Rule
@JvmField
val project: TemporaryTestProject = TemporaryTestProject("playground-android-multi", "playground", useKSP2)
val project: TemporaryTestProject = TemporaryTestProject("playground-android-multi", "playground")

@Test
fun testRunsKSP() {
Expand All @@ -27,10 +24,4 @@ class AGP900IT(useKSP2: Boolean) {
Assert.assertEquals(TaskOutcome.SUCCESS, result.task(":workload:kspDebugKotlin")?.outcome)
}
}

companion object {
@JvmStatic
@Parameterized.Parameters(name = "KSP2={0}")
fun params() = listOf(arrayOf(true), arrayOf(false))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import java.io.File
class AndroidBuiltInKotlinIT {
@Rule
@JvmField
val project: TemporaryTestProject = TemporaryTestProject("playground-android-builtinkotlin", "playground", true)
val project: TemporaryTestProject = TemporaryTestProject("playground-android-builtinkotlin", "playground")

@Test
fun testPlaygroundAndroidWithBuiltInKotlin() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ import org.gradle.testkit.runner.GradleRunner
import org.junit.Assert
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized

@RunWith(Parameterized::class)
class AndroidDataBindingIT(useKSP2: Boolean) {
class AndroidDataBindingIT() {
@Rule
@JvmField
val project: TemporaryTestProject = TemporaryTestProject("android-data-binding", useKSP2 = useKSP2)
val project: TemporaryTestProject = TemporaryTestProject("android-data-binding")

@Test
fun testPlaygroundAndroid() {
Expand All @@ -33,10 +30,4 @@ class AndroidDataBindingIT(useKSP2: Boolean) {
Assert.assertTrue(kspTask.isNotEmpty())
}
}

companion object {
@JvmStatic
@Parameterized.Parameters(name = "KSP2={0}")
fun params() = listOf(arrayOf(true), arrayOf(false))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ import org.gradle.testkit.runner.TaskOutcome
import org.junit.Assert
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import java.io.File

@RunWith(Parameterized::class)
class AndroidIT(useKSP2: Boolean) {
class AndroidIT() {
@Rule
@JvmField
val project: TemporaryTestProject = TemporaryTestProject("playground-android", "playground", useKSP2)
val project: TemporaryTestProject = TemporaryTestProject("playground-android", "playground")

@Test
fun testPlaygroundAndroid() {
Expand All @@ -36,12 +33,6 @@ class AndroidIT(useKSP2: Boolean) {
assert("w: [ksp] [workload_release] Mangled name for internalFun: internalFun\$workload_release" in outputs)
}
}

companion object {
@JvmStatic
@Parameterized.Parameters(name = "KSP2={0}")
fun params() = listOf(arrayOf(true), arrayOf(false))
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ import org.gradle.testkit.runner.TaskOutcome
import org.junit.Assert
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import java.io.File

@RunWith(Parameterized::class)
class AndroidIncrementalIT(useKSP2: Boolean) {
class AndroidIncrementalIT() {
@Rule
@JvmField
val project: TemporaryTestProject = TemporaryTestProject("playground-android-multi", "playground", useKSP2)
val project: TemporaryTestProject = TemporaryTestProject("playground-android-multi", "playground")

private fun testWithExtraFlags(vararg extras: String) {
val gradleRunner = GradleRunner.create().withProjectDir(project.root)
Expand Down Expand Up @@ -68,10 +65,4 @@ class AndroidIncrementalIT(useKSP2: Boolean) {
fun testPlaygroundAndroid() {
testWithExtraFlags()
}

companion object {
@JvmStatic
@Parameterized.Parameters(name = "KSP2={0}")
fun params() = listOf(arrayOf(true), arrayOf(false))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ import org.gradle.testkit.runner.GradleRunner
import org.junit.Assert
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized

@RunWith(Parameterized::class)
class AndroidViewBindingIT(useKSP2: Boolean) {
class AndroidViewBindingIT() {
@Rule
@JvmField
val project: TemporaryTestProject = TemporaryTestProject("android-view-binding", useKSP2 = useKSP2)
val project: TemporaryTestProject = TemporaryTestProject("android-view-binding")

@Test
fun testPlaygroundAndroid() {
Expand All @@ -33,10 +30,4 @@ class AndroidViewBindingIT(useKSP2: Boolean) {
Assert.assertTrue(kspTask.isNotEmpty())
}
}

companion object {
@JvmStatic
@Parameterized.Parameters(name = "KSP2={0}")
fun params() = listOf(arrayOf(true), arrayOf(false))
}
}
Loading
Loading