File tree Expand file tree Collapse file tree 11 files changed +181
-0
lines changed
resources/META-INF/services
test/kotlin/kotlinx/rpc/dokka
gradle-conventions/common/src/main/kotlin/util Expand file tree Collapse file tree 11 files changed +181
-0
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,10 @@ dokka {
7373 }
7474}
7575
76+ dependencies {
77+ dokkaPlugin(libs.dokka.rpc.plugin)
78+ }
79+
7680configureProjectReport()
7781configureNpm()
7882configureApiValidation()
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+ */
4+
5+ plugins {
6+ alias(libs.plugins.conventions.gradle.doctor)
7+ id(" build-util" )
8+ alias(libs.plugins.kotlin.jvm)
9+ }
10+
11+ val rpcVersion: String = libs.versions.kotlinx.rpc.get()
12+ val kotlinLangVersion = libs.versions.kotlin.lang.get()
13+
14+ group = " org.jetbrains.kotlinx"
15+ version = rpcVersion
16+
17+ println (" [Dokka Plugin] kotlinx.rpc project version: $version , Kotlin version: $kotlinLangVersion " )
18+
19+ kotlin {
20+ jvmToolchain(8 )
21+ }
22+
23+ dependencies {
24+ compileOnly(libs.dokka.core)
25+ compileOnly(libs.dokka.base)
26+
27+ testImplementation(kotlin(" test" ))
28+ testImplementation(libs.dokka.base)
29+ testImplementation(" org.jetbrains.dokka:dokka-test-api:${libs.versions.dokka.get()} " )
30+ testImplementation(" org.jetbrains.dokka:dokka-base-test-utils:${libs.versions.dokka.get()} " )
31+ testImplementation(" org.jetbrains.dokka:analysis-kotlin-symbols:${libs.versions.dokka.get()} " )
32+ }
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+ */
4+
5+ rootProject.name = " dokka-rpc-plugin"
6+
7+ enableFeaturePreview(" TYPESAFE_PROJECT_ACCESSORS" )
8+
9+ pluginManagement {
10+ includeBuild(" ../gradle-conventions" )
11+ includeBuild(" ../gradle-conventions-settings" )
12+ }
13+
14+ plugins {
15+ id(" conventions-repositories" )
16+ id(" conventions-version-resolution" )
17+ id(" conventions-develocity" )
18+ }
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+ */
4+
5+ package kotlinx.rpc.dokka
6+
7+ import org.jetbrains.dokka.pages.RootPageNode
8+ import org.jetbrains.dokka.plugability.DokkaContext
9+ import org.jetbrains.dokka.transformers.pages.PageTransformer
10+
11+ class AddDocsLinkPageTransformer (private val context : DokkaContext ) : PageTransformer {
12+ override fun invoke (input : RootPageNode ): RootPageNode = input
13+ }
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+ */
4+
5+ package kotlinx.rpc.dokka
6+
7+ import org.jetbrains.dokka.base.DokkaBaseConfiguration
8+ import org.jetbrains.dokka.base.transformers.documentables.SuppressedByConditionDocumentableFilterTransformer
9+ import org.jetbrains.dokka.model.Annotations
10+ import org.jetbrains.dokka.model.Documentable
11+ import org.jetbrains.dokka.model.properties.WithExtraProperties
12+ import org.jetbrains.dokka.plugability.DokkaContext
13+
14+ class HideInternalRpcApiTransformer (context : DokkaContext ) : SuppressedByConditionDocumentableFilterTransformer(context) {
15+ override fun shouldBeSuppressed (d : Documentable ): Boolean {
16+ DokkaBaseConfiguration
17+ val annotations: List <Annotations .Annotation > =
18+ (d as ? WithExtraProperties <* >)
19+ ?.extra
20+ ?.allOfType<Annotations >()
21+ ?.flatMap { it.directAnnotations.values.flatten() }
22+ ? : emptyList()
23+
24+ return annotations.any { isInternalRpcAnnotation(it) }
25+ }
26+
27+ private fun isInternalRpcAnnotation (annotation : Annotations .Annotation ): Boolean {
28+ return annotation.dri.packageName == " kotlinx.rpc.internal.utils"
29+ && annotation.dri.classNames == " InternalRpcApi"
30+ }
31+ }
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+ */
4+
5+ package kotlinx.rpc.dokka
6+
7+ import org.jetbrains.dokka.CoreExtensions
8+ import org.jetbrains.dokka.base.DokkaBase
9+ import org.jetbrains.dokka.plugability.DokkaPlugin
10+ import org.jetbrains.dokka.plugability.DokkaPluginApiPreview
11+ import org.jetbrains.dokka.plugability.PluginApiPreviewAcknowledgement
12+
13+ @Suppress(" unused" )
14+ class RpcDokkaPlugin : DokkaPlugin () {
15+ @OptIn(DokkaPluginApiPreview ::class )
16+ override fun pluginApiPreviewAcknowledgement () = PluginApiPreviewAcknowledgement
17+
18+ val rpcInternalApiTransformer by extending {
19+ plugin<DokkaBase >().preMergeDocumentableTransformer providing ::HideInternalRpcApiTransformer
20+ }
21+
22+ val pageTransformer by extending {
23+ CoreExtensions .pageTransformer providing ::AddDocsLinkPageTransformer
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ #
2+ # Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+ #
4+
5+ kotlinx.rpc.dokka.RpcDokkaPlugin
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+ */
4+
5+ package kotlinx.rpc.dokka
6+
7+ import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
8+ import kotlin.test.Test
9+ import kotlin.test.assertEquals
10+
11+ class HideInternalRpcApiPluginTest : BaseAbstractTest () {
12+ @Test
13+ fun `should hide annotated functions` () {
14+ val configuration = dokkaConfiguration {
15+ sourceSets {
16+ sourceSet {
17+ sourceRoots = listOf (" src/main/kotlin/basic/Test.kt" )
18+ }
19+ }
20+ }
21+
22+ testInline(
23+ """
24+ |/src/main/kotlin/basic/Test.kt
25+ |package kotlinx.rpc.internal.utils
26+ |
27+ |annotation class InternalRpcApi
28+ |
29+ |fun shouldBeVisible() {}
30+ |
31+ |@InternalRpcApi
32+ |fun shouldBeExcludedFromDocumentation() {}
33+ """ .trimMargin(),
34+ configuration = configuration,
35+ pluginOverrides = listOf (RpcDokkaPlugin ())
36+ ) {
37+ preMergeDocumentablesTransformationStage = { modules ->
38+ val testModule = modules.single { it.name == " root" }
39+ val testPackage = testModule.packages.single { it.name == " kotlinx.rpc.internal.utils" }
40+
41+ val packageFunctions = testPackage.functions
42+ assertEquals(1 , packageFunctions.size)
43+ assertEquals(" shouldBeVisible" , packageFunctions[0 ].name)
44+ }
45+ }
46+ }
47+ }
Original file line number Diff line number Diff line change @@ -51,6 +51,8 @@ fun Project.applyDokka() {
5151 }
5252 }
5353
54+ dependencies.add(" dokkaPlugin" , libs.dokka.rpc.plugin)
55+
5456 val thisProject = project
5557
5658 rootProject.configurations.matching { it.name == " dokka" }.all {
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ plugins {
3232
3333dependencyResolutionManagement {
3434 includeBuild(" compiler-plugin" )
35+ includeBuild(" dokka-plugin" )
3536}
3637
3738includePublic(" :bom" )
You can’t perform that action at this time.
0 commit comments