Skip to content

Commit

Permalink
Dokka plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
wkornewald committed Aug 31, 2024
1 parent 9b86ddf commit a04d53d
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 29 deletions.
70 changes: 41 additions & 29 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform

buildscript {
ext.kotlin_version = '2.0.0'
ext.kotlinVersion = '2.0.20'
ext.composeCompilerVersion = '1.6.10'
ext.dokkaVersion = '1.9.20'
}

plugins {
id 'com.android.application' version '8.4.0' apply false
id 'org.jetbrains.kotlin.android' version "$kotlin_version" apply false
id 'org.jetbrains.kotlin.android' version "$kotlinVersion" apply false
id "org.jetbrains.compose" version "$composeCompilerVersion" apply false
id "org.jetbrains.kotlin.plugin.compose" version "$kotlin_version" apply false
id "org.jetbrains.dokka" version "1.9.20"
id "org.jetbrains.kotlin.plugin.compose" version "$kotlinVersion" apply false
id "org.jetbrains.dokka" version "$dokkaVersion"
id 'pl.allegro.tech.build.axion-release' version '1.17.2'
id 'com.github.ben-manes.versions' version '0.51.0'
id "io.github.gradle-nexus.publish-plugin" version "2.0.0"
Expand Down Expand Up @@ -53,7 +54,7 @@ subprojects {
}

apply from: "$rootDir/dependencies.gradle"
if (!isPlatformProject) {
if (!isPlatformProject && (isMultiplatform || isAndroidProject)) {
task testAll(group: "verification")

if (isAndroidProject) {
Expand Down Expand Up @@ -167,7 +168,8 @@ subprojects {
base()
}

apply from: "$rootDir/gradle/common/dokka.gradle"
if (project.name == "reactivestate-core")
apply from: "$rootDir/gradle/common/dokka.gradle"

// TODO: Switch to Kover
// if (!publishing) {
Expand All @@ -176,30 +178,40 @@ subprojects {
// }
}

apply from: "$rootDir/gradle/common/publish.gradle"
publish(
url: "https://s01.oss.sonatype.org/service/local/",
username: publicationUsername,
password: publicationPassword,
repoUrl: "https://github.com/ensody/ReactiveState-Kotlin",
pomAction: {
description = "Easy reactive state management for Kotlin Multiplatform. No boilerplate. Compatible with Android."
url = "https://ensody.github.io/ReactiveState-Kotlin/"
licenses {
license(LICENSE.APACHE2)
}
developers {
developer {
id = "wkornewald"
name = "Waldemar Kornewald"
organization = "Ensody GmbH"
organizationUrl = "https://www.ensody.com"
if (isPlatformProject || isMultiplatform || isAndroidProject) {
apply from: "$rootDir/gradle/common/publish.gradle"
publish(
url: "https://s01.oss.sonatype.org/service/local/",
username: publicationUsername,
password: publicationPassword,
repoUrl: "https://github.com/ensody/ReactiveState-Kotlin",
pomAction: {
description = "Easy reactive state management for Kotlin Multiplatform. No boilerplate. Compatible with Android."
url = "https://ensody.github.io/ReactiveState-Kotlin/"
licenses {
license(LICENSE.APACHE2)
}
}
},
isPlatformProject: isPlatformProject,
sign: isOnCI,
)
developers {
developer {
id = "wkornewald"
name = "Waldemar Kornewald"
organization = "Ensody GmbH"
organizationUrl = "https://www.ensody.com"
}
}
},
isPlatformProject: isPlatformProject,
sign: isOnCI,
)
}
}

allprojects {
dependencies {
if (plugins.hasPlugin("org.jetbrains.dokka")) {
dokkaPlugin(project(":dokka-site"))
}
}
}

tasks.named("dokkaGfmMultiModule").configure {
Expand Down
13 changes: 13 additions & 0 deletions dokka-site/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
plugins {
kotlin("jvm")
}

val dokkaVersion: String by rootProject.ext

dependencies {
compileOnly("org.jetbrains.dokka:dokka-core:$dokkaVersion")
compileOnly("org.jetbrains.dokka:dokka-base:$dokkaVersion")
compileOnly("org.jetbrains.dokka:analysis-markdown:$dokkaVersion")
api("org.jetbrains.dokka:all-modules-page-plugin:$dokkaVersion")
api("org.jetbrains.dokka:templating-plugin:$dokkaVersion")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package com.ensody.dokka.site

import org.jetbrains.dokka.CoreExtensions
import org.jetbrains.dokka.Timer
import org.jetbrains.dokka.allModulesPage.AllModulesPageGeneration
import org.jetbrains.dokka.allModulesPage.AllModulesPagePlugin
import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.base.renderers.html.HtmlRenderer
import org.jetbrains.dokka.base.translators.documentables.DefaultDocumentableToPageTranslator
import org.jetbrains.dokka.generation.Generation
import org.jetbrains.dokka.model.DModule
import org.jetbrains.dokka.pages.PageNode
import org.jetbrains.dokka.pages.RootPageNode
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.plugability.DokkaPlugin
import org.jetbrains.dokka.plugability.DokkaPluginApiPreview
import org.jetbrains.dokka.plugability.Extension
import org.jetbrains.dokka.plugability.PluginApiPreviewAcknowledgement
import org.jetbrains.dokka.transformers.documentation.DocumentableToPageTranslator
import org.jetbrains.dokka.transformers.pages.PageTransformer

public class DokkaSitePlugin : DokkaPlugin() {

private val dokkaBase by lazy { plugin<DokkaBase>() }
private val allModulePagesPlugin by lazy { plugin<AllModulesPagePlugin>() }

public val allModulesPageTransformer: Extension<PageTransformer, *, *> by extending {
allModulePagesPlugin.allModulesPageTransformer providing ::ExtraPageTransformer
}

public val ourPageTranslator: Extension<DocumentableToPageTranslator, *, *> by extending {
(CoreExtensions.documentableToPageTranslator
providing ::SiteDocumentableToPageTranslator
override dokkaBase.documentableToPageTranslator)
}

public val allModulesPageGeneration: Extension<Generation, *, *> by extending {
(CoreExtensions.generation
providing ::SiteModulesPageGeneration
override allModulePagesPlugin.allModulesPageGeneration)
}

@OptIn(DokkaPluginApiPreview::class)
override fun pluginApiPreviewAcknowledgement(): PluginApiPreviewAcknowledgement =
PluginApiPreviewAcknowledgement
}

public class SiteDocumentableToPageTranslator(private val context: DokkaContext) : DocumentableToPageTranslator {
init {
println("INIT!!!!!!!!")
}

val delegate = DefaultDocumentableToPageTranslator(context)

override fun invoke(module: DModule): RootPageNode {
println("TRANSLATE $module")
return delegate(module)
}
}

public class SiteModulesPageGeneration(private val context: DokkaContext) : Generation {
override val generationName: String = "Site"

val delegate = AllModulesPageGeneration(context)

override fun Timer.generate() {
delegate.apply {
report("Processing submodules")
val generationContext = processSubmodules()

report("Creating all modules page")
val pages = createAllModulesPage(generationContext)

report("Transforming pages")
val transformedPages = transformAllModulesPage(pages)

report("Rendering")
val renderer = MyRenderer(context)
renderer.render(transformedPages)

report("Processing multimodule")
processMultiModule(transformedPages)

report("Finish submodule processing")
finishProcessingSubmodules()

report("Running post-actions")
runPostActions()
}
}
}

public class MyRenderer(context: DokkaContext) : HtmlRenderer(context) {
override suspend fun renderPage(page: PageNode) {
println("PAGE $page")
super.renderPage(page)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
@file:OptIn(InternalDokkaApi::class)

package com.ensody.dokka.site

import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet
import org.jetbrains.dokka.InternalDokkaApi
import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.pages.ContentGroup
import org.jetbrains.dokka.pages.ContentKind
import org.jetbrains.dokka.pages.MultimoduleRootPageNode
import org.jetbrains.dokka.pages.RootPageNode
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.plugability.plugin
import org.jetbrains.dokka.plugability.querySingle
import org.jetbrains.dokka.transformers.pages.PageTransformer

public class ExtraPageTransformer(
private val context: DokkaContext,
) : PageTransformer {
private val commentsConverter by lazy { context.plugin<DokkaBase>().querySingle { commentsToContentConverter } }
private val signatureProvider by lazy { context.plugin<DokkaBase>().querySingle { signatureProvider } }

override fun invoke(input: RootPageNode): RootPageNode {
input as MultimoduleRootPageNode
val sourceSetData = emptySet<DokkaSourceSet>()
val builder = PageContentBuilder(commentsConverter, signatureProvider, context.logger)
val contentNode: ContentGroup = builder.contentFor(
dri = DRI(extra = ".foo"),
kind = ContentKind.Cover,
sourceSets = sourceSetData
) {
text("Hello")
+input.content
}
return input.modified(
content = contentNode
) as RootPageNode
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.ensody.dokka.site.DokkaSitePlugin
10 changes: 10 additions & 0 deletions gradle/common/dokka.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
apply plugin: 'org.jetbrains.dokka'

tasks.named("dokkaHtmlPartial").configure {
dokkaSourceSets {
configureEach {
noAndroidSdkLink.set(false)
includes.from(*["README.md"].findAll { project.file(it).exists() })
offlineMode.set(true)
}
}
}

tasks.named("dokkaGfmPartial").configure {
dokkaSourceSets {
configureEach {
Expand Down
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ include ':reactivestate-compose'
include ':reactivestate-core'
include ':reactivestate-core-test'
include ':reactivestate-test'

include ':dokka-site'

0 comments on commit a04d53d

Please sign in to comment.