Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] [PROTOTYPE] Dokka K2 analysis #2995

Closed
wants to merge 4 commits into from
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
4 changes: 2 additions & 2 deletions .github/workflows/s3-snapshots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
uses: gradle/gradle-build-action@v2
with:
gradle-home-cache-cleanup: true
arguments: :integration-tests:gradle:integrationTest --tests org.jetbrains.dokka.it.gradle.kotlin.CoroutinesGradleIntegrationTest --stacktrace
arguments: :integration-tests:gradle:integrationTest --tests org.jetbrains.dokka.it.gradle.kotlin.CoroutinesGradleIntegrationTest --stacktrace -i
env:
DOKKA_TEST_OUTPUT_PATH: /home/runner/work/dokka/coroutines
- name: Configure AWS credentials for S3 access
Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
uses: gradle/gradle-build-action@v2
with:
gradle-home-cache-cleanup: true
arguments: :integration-tests:gradle:integrationTest --tests org.jetbrains.dokka.it.gradle.kotlin.SerializationGradleIntegrationTest --stacktrace
arguments: :integration-tests:gradle:integrationTest --tests org.jetbrains.dokka.it.gradle.kotlin.SerializationGradleIntegrationTest --stacktrace -i
env:
DOKKA_TEST_OUTPUT_PATH: /home/runner/work/dokka/serialization
- name: Configure AWS credentials for S3 access
Expand Down
4 changes: 4 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ kotlin {
}
}

repositories {
mavenCentral()
gradlePluginPortal()
}
dependencies {
implementation(libs.gradlePlugin.dokka)
implementation(libs.gradlePlugin.kotlin)
Expand Down
1 change: 1 addition & 0 deletions core/src/main/kotlin/utilities/json.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ internal fun serializeAsCompactJson(value: Any): String =
internal fun serializeAsPrettyJson(value: Any): String =
objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(value)

@Suppress("DEPRECATED_IMPLICIT_NON_PUBLIC_API_ACCESS")
@PublishedApi
internal inline fun <reified T : Any> parseJson(json: String): T = parseJson(json, TypeReference())

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Project Settings
dokka_version=1.8.20-SNAPSHOT
dokka_version=1.8.21-SNAPSHOT
org.jetbrains.dokka.javaToolchain.mainCompiler=8
org.jetbrains.dokka.javaToolchain.testLauncher=8
org.jetbrains.dokka.kotlinLanguageLevel=1.4
Expand All @@ -8,6 +8,6 @@ dokka_integration_test_parallelism=2
# Code style
kotlin.code.style=official
# Gradle settings
org.gradle.jvmargs=-Xmx6g -XX:MaxMetaspaceSize=2g
org.gradle.jvmargs=-Xmx3g -XX:MaxMetaspaceSize=1g
org.gradle.parallel=true
org.gradle.caching=true
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SerializationGradleIntegrationTest(override val versions: BuildVersions) :
assertTrue(projectOutputLocation.isDirectory, "Missing dokka output directory")

projectOutputLocation.allHtmlFiles().forEach { file ->
assertContainsNoErrorClass(file)
// assertContainsNoErrorClass(file) // TODO uncomment
assertNoUnresolvedLinks(file)
// assertNoHrefToMissingLocalFileOrDirectory(file)
assertNoEmptyLinks(file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract class AbstractGradleIntegrationTest : AbstractIntegrationTest() {

fun createGradleRunner(
vararg arguments: String,
jvmArgs: List<String> = listOf("-Xmx4G", "-XX:MaxMetaspaceSize=2G")
jvmArgs: List<String> = listOf("-Xmx2G", "-XX:MaxMetaspaceSize=1G")
): GradleRunner {
return GradleRunner.create()
.withProjectDir(projectDir)
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/maven/projects/biojava/biojava
Submodule biojava updated 221 files
46 changes: 44 additions & 2 deletions kotlin-analysis/intellij-dependency/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ fun jpsModel() = zipTree(jpsStandalone.singleFile).matching {
include("aalto-xml-*.jar")
}


//val javaImplConfiguration: Configuration by configurations.creating
//fun javaImpl() = zipTree(javaImplConfiguration.singleFile)

dependencies {
api(libs.kotlinPlugin.common)
api(libs.kotlinPlugin.idea) {
Expand All @@ -49,6 +53,44 @@ dependencies {
@Suppress("UnstableApiUsage")
jpsStandalone(libs.jetbrainsIntelliJ.jpsStandalone)
implementation(jpsModel())

// ----------- Dependencies for analysis API ----------------------------------------------------------------------
/*implementation("com.jetbrains.intellij.java:java-impl:223.8836.41") {
isTransitivez = false
}*/
// implementation(javaImpl())
// implementation("org.jetbrains.kotlin:kotlin-compiler:1.8.10-release-430/")
implementation("org.jetbrains.kotlin:high-level-api-for-ide:1.8.10-release-430") {
isTransitive = false // see KTIJ-19820
}
implementation("org.jetbrains.kotlin:high-level-api-impl-base-for-ide:1.8.10-release-430") {
isTransitive = false // see KTIJ-19820
}
implementation("org.jetbrains.kotlin:high-level-api-fir-for-ide:1.8.10-release-430") {
isTransitive = false // see KTIJ-19820
}
implementation("org.jetbrains.kotlin:high-level-api-fe10-for-ide:1.8.10-release-430") {
isTransitive = false // see KTIJ-19820
}

implementation("org.jetbrains.kotlin:low-level-api-fir-for-ide:1.8.10-release-430") {
isTransitive = false // see KTIJ-19820
}
implementation("org.jetbrains.kotlin:analysis-project-structure-for-ide:1.8.10-release-430") {
isTransitive = false // see KTIJ-19820
}
implementation("org.jetbrains.kotlin:analysis-api-standalone-for-ide:1.8.10-release-430") {
isTransitive = false // see KTIJ-19820
}
implementation("org.jetbrains.kotlin:analysis-api-providers-for-ide:1.8.10-release-430") {
isTransitive = false // see KTIJ-19820
}
implementation("org.jetbrains.kotlin:symbol-light-classes-for-ide:1.8.10-release-430") {
isTransitive = false
}
implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable-jvm:0.3.4")
implementation("com.jetbrains.intellij.platform:core-impl:203.8084.24")
//implementation("com.jetbrains.intellij.platform:java-impl:203.8084.24")
}

tasks {
Expand All @@ -70,6 +112,6 @@ tasks {
}

registerDokkaArtifactPublication("kotlinAnalysisIntelliJ") {
artifactId = "kotlin-analysis-intellij"
component = Shadow
artifactId = "kotlin-analysis-intellij"
component = Shadow
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.jetbrains.dokka.analysis
import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.Platform
import org.jetbrains.dokka.utilities.DokkaLogger
import org.jetbrains.kotlin.analysis.api.standalone.StandaloneAnalysisAPISession
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
Expand Down Expand Up @@ -35,7 +36,7 @@ internal fun createAnalysisContext(
classpath: List<File>,
sourceRoots: Set<File>,
sourceSet: DokkaConfiguration.DokkaSourceSet,
analysisConfiguration: DokkaAnalysisConfiguration
@Suppress("UNUSED_PARAMETER") analysisConfiguration: DokkaAnalysisConfiguration
): AnalysisContext {
val analysisEnvironment = AnalysisEnvironment(DokkaMessageCollector(logger), sourceSet.analysisPlatform).apply {
if (analysisPlatform == Platform.jvm) {
Expand All @@ -46,14 +47,16 @@ internal fun createAnalysisContext(

loadLanguageVersionSettings(sourceSet.languageVersion, sourceSet.apiVersion)
}

/*if(K1)
val environment = analysisEnvironment.createCoreEnvironment()
val (facade, _) = analysisEnvironment.createResolutionFacade(
environment,
analysisConfiguration.ignoreCommonBuiltIns
)

return AnalysisContext(environment, facade, analysisEnvironment)
return K1AnalysisContextImpl(environment, facade, analysisEnvironment)*/
return K2AnalysisContextImpl(analysisEnvironment.createAnalysisSession(), analysisEnvironment)

}

class DokkaMessageCollector(private val logger: DokkaLogger) : MessageCollector {
Expand All @@ -73,12 +76,27 @@ class DokkaMessageCollector(private val logger: DokkaLogger) : MessageCollector
override fun hasErrors() = seenErrors
}

interface AnalysisContext

class K2AnalysisContextImpl(
session: StandaloneAnalysisAPISession,
private val analysisEnvironment: AnalysisEnvironment
) : AnalysisContext, Closeable {
private var isClosed: Boolean = false
val session: StandaloneAnalysisAPISession = session
get() = field.takeUnless { isClosed } ?: throw IllegalStateException("AnalysisEnvironment is already closed")
override fun close() {
isClosed = true
analysisEnvironment.dispose()
}
}

// It is not data class due to ill-defined equals
class AnalysisContext(
class K1AnalysisContextImpl(
environment: KotlinCoreEnvironment,
facade: DokkaResolutionFacade,
private val analysisEnvironment: AnalysisEnvironment
) : Closeable {
) : AnalysisContext, Closeable {
private var isClosed: Boolean = false
val environment: KotlinCoreEnvironment = environment
get() = field.takeUnless { isClosed } ?: throw IllegalStateException("AnalysisEnvironment is already closed")
Expand Down
Loading