Skip to content

Commit

Permalink
Reverse dependencies of test-utils
Browse files Browse the repository at this point in the history
by splitting and merging it into compiler-plugin and
kotlin-analysis-api.

(cherry picked from commit 9d33227)
  • Loading branch information
ting-yuan committed Jun 29, 2024
1 parent f34f279 commit e99509f
Show file tree
Hide file tree
Showing 23 changed files with 727 additions and 104 deletions.
65 changes: 65 additions & 0 deletions compiler-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ description = "Kotlin Symbol Processing"
val intellijVersion: String by project
val kotlinBaseVersion: String by project

val junitVersion: String by project
val junit5Version: String by project
val junitPlatformVersion: String by project
val libsForTesting by configurations.creating
val libsForTestingCommon by configurations.creating

tasks.withType<KotlinCompile> {
compilerOptions.freeCompilerArgs.add("-Xjvm-default=all-compatibility")
}
Expand Down Expand Up @@ -36,6 +42,8 @@ dependencies {
"com.jetbrains.intellij.platform:core",
"com.jetbrains.intellij.platform:core-impl",
"com.jetbrains.intellij.platform:extensions",
"com.jetbrains.intellij.java:java-frontback-psi",
"com.jetbrains.intellij.java:java-frontback-psi-impl",
"com.jetbrains.intellij.java:java-psi",
"com.jetbrains.intellij.java:java-psi-impl",
).forEach {
Expand All @@ -48,6 +56,20 @@ dependencies {

implementation(project(":api"))
implementation(project(":common-util"))

testImplementation("junit:junit:$junitVersion")
testImplementation("org.junit.jupiter:junit-jupiter-api:$junit5Version")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junit5Version")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-params:$junit5Version")
testRuntimeOnly("org.junit.platform:junit-platform-suite:$junitPlatformVersion")
testImplementation("org.jetbrains.kotlin:kotlin-compiler:$kotlinBaseVersion")
testImplementation("org.jetbrains.kotlin:kotlin-compiler-internal-test-framework:$kotlinBaseVersion")
testImplementation(project(":test-utils"))

libsForTesting(kotlin("stdlib", kotlinBaseVersion))
libsForTesting(kotlin("test", kotlinBaseVersion))
libsForTesting(kotlin("script-runtime", kotlinBaseVersion))
libsForTestingCommon(kotlin("stdlib-common", kotlinBaseVersion))
}

val dokkaJavadocJar by tasks.register<Jar>("dokkaJavadocJar") {
Expand All @@ -57,3 +79,46 @@ val dokkaJavadocJar by tasks.register<Jar>("dokkaJavadocJar") {
from(project(":common-util").tasks.dokkaJavadoc.flatMap { it.outputDirectory })
archiveClassifier.set("javadoc")
}

tasks.register<Copy>("CopyLibsForTesting") {
from(configurations.get("libsForTesting"))
into("dist/kotlinc/lib")
val escaped = Regex.escape(kotlinBaseVersion)
rename("(.+)-$escaped\\.jar", "$1.jar")
}

tasks.register<Copy>("CopyLibsForTestingCommon") {
from(configurations.get("libsForTestingCommon"))
into("dist/common")
val escaped = Regex.escape(kotlinBaseVersion)
rename("(.+)-$escaped\\.jar", "$1.jar")
}

tasks.test {
dependsOn("CopyLibsForTesting")
dependsOn("CopyLibsForTestingCommon")
maxHeapSize = "2g"

useJUnitPlatform()

systemProperty("idea.is.unit.test", "true")
systemProperty("java.awt.headless", "true")
environment("NO_FS_ROOTS_ACCESS_CHECK", "true")

testLogging {
events("passed", "skipped", "failed")
}

lateinit var tempTestDir: File
doFirst {
val ideaHomeDir = buildDir.resolve("tmp/ideaHome").takeIf { it.exists() || it.mkdirs() }!!
jvmArgumentProviders.add(com.google.devtools.ksp.RelativizingPathProvider("idea.home.path", ideaHomeDir))

tempTestDir = createTempDir()
jvmArgumentProviders.add(com.google.devtools.ksp.RelativizingPathProvider("java.io.tmpdir", tempTestDir))
}

doLast {
delete(tempTestDir)
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package com.google.devtools.ksp.processor

import com.google.devtools.ksp.impl.ResolverAAImpl
import com.google.devtools.ksp.processing.Resolver
import com.google.devtools.ksp.processing.impl.ResolverImpl
import com.google.devtools.ksp.symbol.*
Expand Down Expand Up @@ -56,7 +55,6 @@ class RecordJavaAsMemberOfProcessor : AbstractTestProcessor() {

val m = when (resolver) {
is ResolverImpl -> resolver.incrementalContext.dumpLookupRecords().toSortedMap()
is ResolverAAImpl -> resolver.incrementalContext.dumpLookupRecords().toSortedMap()
else -> throw IllegalStateException("Unknown Resolver: $resolver")
}
m.forEach { symbol, files ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package com.google.devtools.ksp.processor

import com.google.devtools.ksp.impl.ResolverAAImpl
import com.google.devtools.ksp.processing.Resolver
import com.google.devtools.ksp.processing.impl.ResolverImpl
import com.google.devtools.ksp.symbol.*
Expand All @@ -44,7 +43,6 @@ class RecordJavaGetAllMembersProcessor : AbstractTestProcessor() {

val m = when (resolver) {
is ResolverImpl -> resolver.incrementalContext.dumpLookupRecords().toSortedMap()
is ResolverAAImpl -> resolver.incrementalContext.dumpLookupRecords().toSortedMap()
else -> throw IllegalStateException("Unknown Resolver: $resolver")
}
m.forEach { symbol, files ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package com.google.devtools.ksp.processor

import com.google.devtools.ksp.impl.ResolverAAImpl
import com.google.devtools.ksp.processing.Resolver
import com.google.devtools.ksp.processing.impl.ResolverImpl
import com.google.devtools.ksp.symbol.*
Expand Down Expand Up @@ -61,7 +60,6 @@ class RecordJavaOverridesProcessor : AbstractTestProcessor() {

val m = when (resolver) {
is ResolverImpl -> resolver.incrementalContext.dumpLookupRecords().toSortedMap()
is ResolverAAImpl -> resolver.incrementalContext.dumpLookupRecords().toSortedMap()
else -> throw IllegalStateException("Unknown Resolver: $resolver")
}
m.forEach { symbol, files ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package com.google.devtools.ksp.processor

import com.google.devtools.ksp.impl.ResolverAAImpl
import com.google.devtools.ksp.processing.Resolver
import com.google.devtools.ksp.processing.impl.ResolverImpl
import com.google.devtools.ksp.symbol.*
Expand All @@ -40,7 +39,6 @@ class RecordJavaProcessor : AbstractTestProcessor() {
}
val m = when (resolver) {
is ResolverImpl -> resolver.incrementalContext.dumpLookupRecords().toSortedMap()
is ResolverAAImpl -> resolver.incrementalContext.dumpLookupRecords().toSortedMap()
else -> throw IllegalStateException("Unknown Resolver: $resolver")
}
m.forEach { symbol, files ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package com.google.devtools.ksp.processor

import com.google.devtools.ksp.impl.ResolverAAImpl
import com.google.devtools.ksp.processing.Resolver
import com.google.devtools.ksp.processing.impl.ResolverImpl
import com.google.devtools.ksp.symbol.*
Expand All @@ -41,7 +40,6 @@ class RecordJavaSupertypesProcessor : AbstractTestProcessor() {
}
val m = when (resolver) {
is ResolverImpl -> resolver.incrementalContext.dumpLookupRecords().toSortedMap()
is ResolverAAImpl -> resolver.incrementalContext.dumpLookupRecords().toSortedMap()
else -> throw IllegalStateException("Unknown Resolver: $resolver")
}
m.forEach { symbol, files ->
Expand Down
66 changes: 66 additions & 0 deletions kotlin-analysis-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ val signingPassword: String? by project

val kotlinBaseVersion: String by project

val junitVersion: String by project
val junit5Version: String by project
val junitPlatformVersion: String by project
val libsForTesting by configurations.creating
val libsForTestingCommon by configurations.creating

val aaKotlinBaseVersion: String by project
val aaIntellijVersion: String by project
val aaGuavaVersion: String by project
Expand All @@ -27,6 +33,7 @@ plugins {

val depSourceJars by configurations.creating
val depJarsForCheck by configurations.creating
val compilerJar by configurations.creating

dependencies {
listOf(
Expand Down Expand Up @@ -99,10 +106,26 @@ dependencies {
implementation(project(":common-util"))

testImplementation(kotlin("stdlib", aaKotlinBaseVersion))
testImplementation("junit:junit:$junitVersion")
testImplementation("org.junit.jupiter:junit-jupiter-api:$junit5Version")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junit5Version")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-params:$junit5Version")
testRuntimeOnly("org.junit.platform:junit-platform-suite:$junitPlatformVersion")
testImplementation("org.jetbrains.kotlin:kotlin-compiler:$aaKotlinBaseVersion")
testImplementation("org.jetbrains.kotlin:kotlin-compiler-internal-test-framework:$aaKotlinBaseVersion")
testImplementation(project(":common-deps"))
testImplementation(project(":test-utils"))

libsForTesting(kotlin("stdlib", aaKotlinBaseVersion))
libsForTesting(kotlin("test", aaKotlinBaseVersion))
libsForTesting(kotlin("script-runtime", aaKotlinBaseVersion))
libsForTestingCommon(kotlin("stdlib-common", aaKotlinBaseVersion))

depJarsForCheck("org.jetbrains.kotlin", "kotlin-stdlib", kotlinBaseVersion)
depJarsForCheck(project(":api"))
depJarsForCheck(project(":common-deps"))

compilerJar("org.jetbrains.kotlin:kotlin-compiler-common-for-ide:$aaKotlinBaseVersion")
}

sourceSets.main {
Expand Down Expand Up @@ -229,3 +252,46 @@ kotlin {
freeCompilerArgs.add("-Xcontext-receivers")
}
}

tasks.register<Copy>("CopyLibsForTesting") {
from(configurations.get("libsForTesting"))
into("dist/kotlinc/lib")
val escaped = Regex.escape(aaKotlinBaseVersion)
rename("(.+)-$escaped\\.jar", "$1.jar")
}

tasks.register<Copy>("CopyLibsForTestingCommon") {
from(configurations.get("libsForTestingCommon"))
into("dist/common")
val escaped = Regex.escape(aaKotlinBaseVersion)
rename("(.+)-$escaped\\.jar", "$1.jar")
}

tasks.test {
dependsOn("CopyLibsForTesting")
dependsOn("CopyLibsForTestingCommon")
maxHeapSize = "2g"

useJUnitPlatform()

systemProperty("idea.is.unit.test", "true")
systemProperty("java.awt.headless", "true")
environment("NO_FS_ROOTS_ACCESS_CHECK", "true")

testLogging {
events("passed", "skipped", "failed")
}

lateinit var tempTestDir: File
doFirst {
val ideaHomeDir = buildDir.resolve("tmp/ideaHome").takeIf { it.exists() || it.mkdirs() }!!
jvmArgumentProviders.add(com.google.devtools.ksp.RelativizingPathProvider("idea.home.path", ideaHomeDir))

tempTestDir = createTempDir()
jvmArgumentProviders.add(com.google.devtools.ksp.RelativizingPathProvider("java.io.tmpdir", tempTestDir))
}

doLast {
delete(tempTestDir)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<idea-plugin>
<id>org.jetbrains.kotlin</id>

<extensionPoints>
<extensionPoint qualifiedName="org.jetbrains.kotlin.analyzeCompleteHandlerExtension"
interface="org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisHandlerExtension"
area="IDEA_PROJECT"/>
<extensionPoint qualifiedName="org.jetbrains.kotlin.extensions.internal.callResolutionInterceptorExtension"
interface="org.jetbrains.kotlin.extensions.internal.CallResolutionInterceptorExtension"
area="IDEA_PROJECT"/>
<extensionPoint qualifiedName="org.jetbrains.kotlin.extensions.internal.typeResolutionInterceptorExtension"
interface="org.jetbrains.kotlin.extensions.internal.TypeResolutionInterceptorExtension"
area="IDEA_PROJECT"/>
<extensionPoint qualifiedName="org.jetbrains.kotlin.extensions.typeAttributeTranslatorExtension"
interface="org.jetbrains.kotlin.extensions.TypeAttributeTranslatorExtension"
area="IDEA_PROJECT"/>
<extensionPoint qualifiedName="org.jetbrains.kotlin.diagnosticSuppressor"
interface="org.jetbrains.kotlin.resolve.diagnostics.DiagnosticSuppressor"
area="IDEA_PROJECT" dynamic="true"/>
<extensionPoint qualifiedName="org.jetbrains.kotlin.expressionCodegenExtension"
interface="org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension"
area="IDEA_PROJECT" dynamic="true"/>
<extensionPoint qualifiedName="org.jetbrains.kotlin.syntheticResolveExtension"
interface="org.jetbrains.kotlin.resolve.extensions.SyntheticResolveExtension"
area="IDEA_PROJECT" dynamic="true"/>
<extensionPoint qualifiedName="org.jetbrains.kotlin.assignResolutionAltererExtension"
interface="org.jetbrains.kotlin.resolve.extensions.AssignResolutionAltererExtension"
area="IDEA_PROJECT" dynamic="true"/>
<extensionPoint qualifiedName="org.jetbrains.kotlin.jsSyntheticTranslateExtension"
interface="org.jetbrains.kotlin.js.translate.extensions.JsSyntheticTranslateExtension"
area="IDEA_PROJECT" dynamic="true"/>
<extensionPoint qualifiedName="org.jetbrains.kotlin.irGenerationExtension"
interface="org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension"
area="IDEA_PROJECT" dynamic="true"/>
<extensionPoint qualifiedName="org.jetbrains.kotlin.simpleNameReferenceExtension"
interface="org.jetbrains.kotlin.plugin.references.SimpleNameReferenceExtension"
area="IDEA_PROJECT" dynamic="true"/>
<extensionPoint qualifiedName="org.jetbrains.kotlin.classBuilderFactoryInterceptorExtension"
interface="org.jetbrains.kotlin.codegen.extensions.ClassBuilderInterceptorExtension"
area="IDEA_PROJECT" dynamic="true"/>
<extensionPoint qualifiedName="org.jetbrains.kotlin.classGeneratorExtension"
interface="org.jetbrains.kotlin.backend.jvm.extensions.ClassGeneratorExtension"
area="IDEA_PROJECT" dynamic="true"/>
<extensionPoint qualifiedName="org.jetbrains.kotlin.packageFragmentProviderExtension"
interface="org.jetbrains.kotlin.resolve.jvm.extensions.PackageFragmentProviderExtension"
area="IDEA_PROJECT" dynamic="true"/>
<extensionPoint qualifiedName="org.jetbrains.kotlin.storageComponentContainerContributor"
interface="org.jetbrains.kotlin.extensions.StorageComponentContainerContributor"
area="IDEA_PROJECT" dynamic="true"/>
<extensionPoint qualifiedName="org.jetbrains.kotlin.extraImportsProviderExtension"
interface="org.jetbrains.kotlin.resolve.extensions.ExtraImportsProviderExtension"
area="IDEA_PROJECT" dynamic="true"/>
<extensionPoint qualifiedName="org.jetbrains.kotlin.fir.extensions.firExtensionRegistrar"
interface="org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrarAdapter"
area="IDEA_PROJECT"/>
<extensionPoint qualifiedName="org.jetbrains.kotlin.DescriptorSerializerPlugin"
interface="org.jetbrains.kotlin.serialization.DescriptorSerializerPlugin"
area="IDEA_PROJECT"/>
<extensionPoint qualifiedName="org.jetbrains.kotlin.defaultErrorMessages"
interface="org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages.Extension"/>
</extensionPoints>
</idea-plugin>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2020 Google LLC
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
*
* 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 com.google.devtools.ksp.processor

import com.google.devtools.ksp.impl.ResolverAAImpl
import com.google.devtools.ksp.processing.Resolver
import com.google.devtools.ksp.symbol.*

class RecordJavaAsMemberOfProcessor : AbstractTestProcessor() {
val results = mutableListOf<String>()

override fun toResult(): List<String> {
val finalResult = mutableListOf(results[0])
finalResult.addAll(results.subList(1, results.size).sorted())
return finalResult
}

override fun process(resolver: Resolver): List<KSAnnotated> {
var function: KSFunctionDeclaration? = null
var type: KSType? = null
resolver.getAllFiles().forEach {
if (it.fileName == "C.kt") {
type = (
it.declarations.single {
it is KSPropertyDeclaration && it.simpleName.asString() == "a"
} as KSPropertyDeclaration
).type.resolve()
} else if (it.fileName == "B.java") {
function = (
it.declarations.single {
it is KSClassDeclaration && it.simpleName.asString() == "B"
} as KSClassDeclaration
).declarations.single {
it is KSFunctionDeclaration && it.simpleName.asString() == "f"
} as KSFunctionDeclaration
}
}

function!!.asMemberOf(type!!)

val m = when (resolver) {
is ResolverAAImpl -> resolver.incrementalContext.dumpLookupRecords().toSortedMap()
else -> throw IllegalStateException("Unknown Resolver: $resolver")
}
m.forEach { symbol, files ->
files.filter { it.endsWith(".java") }.sorted().forEach {
val fn = it.substringAfterLast("java-sources/")
results.add("$symbol: $fn")
}
}
return emptyList()
}
}
Loading

0 comments on commit e99509f

Please sign in to comment.