aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorPaweł Marks <pmarks@virtuslab.com>2020-09-16 16:36:54 +0200
committerBłażej Kardyś <bkardys@virtuslab.com>2020-11-27 03:15:02 +0100
commitc8a83153a88fe6f5b50b6f459295421f90a21583 (patch)
tree4ce52c287dde3a8303549287ce67e58174d9f9fc /plugins
parent585178984228a9c2e5bd2af9b675094ac6e3fa46 (diff)
downloaddokka-c8a83153a88fe6f5b50b6f459295421f90a21583.tar.gz
dokka-c8a83153a88fe6f5b50b6f459295421f90a21583.tar.bz2
dokka-c8a83153a88fe6f5b50b6f459295421f90a21583.zip
Extracting dokka generation to the dedicated extension point
Diffstat (limited to 'plugins')
-rw-r--r--plugins/all-module-page/build.gradle.kts9
-rw-r--r--plugins/all-module-page/src/main/kotlin/AllModulesPageGeneration.kt31
-rw-r--r--plugins/all-module-page/src/main/kotlin/AllModulesPagePlugin.kt25
-rw-r--r--plugins/all-module-page/src/main/kotlin/MultimoduleLocationProvider.kt41
-rw-r--r--plugins/all-module-page/src/main/kotlin/MultimodulePageCreator.kt (renamed from plugins/base/src/main/kotlin/allModulePage/MultimodulePageCreator.kt)2
-rw-r--r--plugins/all-module-page/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin1
-rw-r--r--plugins/base/src/main/kotlin/DokkaBase.kt7
-rw-r--r--plugins/base/src/main/kotlin/parsers/moduleAndPackage/ModuleAndPackageDocumentation.kt2
-rw-r--r--plugins/base/src/main/kotlin/parsers/moduleAndPackage/ModuleAndPackageDocumentationFragment.kt2
-rw-r--r--plugins/base/src/main/kotlin/parsers/moduleAndPackage/ModuleAndPackageDocumentationParsingContext.kt4
-rw-r--r--plugins/base/src/main/kotlin/parsers/moduleAndPackage/ModuleAndPackageDocumentationSource.kt2
-rw-r--r--plugins/base/src/main/kotlin/parsers/moduleAndPackage/parseModuleAndPackageDocumentation.kt2
-rw-r--r--plugins/base/src/main/kotlin/parsers/moduleAndPackage/parseModuleAndPackageDocumentationFragments.kt4
-rw-r--r--plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt4
14 files changed, 118 insertions, 18 deletions
diff --git a/plugins/all-module-page/build.gradle.kts b/plugins/all-module-page/build.gradle.kts
new file mode 100644
index 00000000..dc5e0a6a
--- /dev/null
+++ b/plugins/all-module-page/build.gradle.kts
@@ -0,0 +1,9 @@
+import org.jetbrains.registerDokkaArtifactPublication
+
+registerDokkaArtifactPublication("dokkaAllModulesPage") {
+ artifactId = "all-modules-page-plugin"
+}
+
+dependencies {
+ implementation(project(":plugins:base"))
+} \ No newline at end of file
diff --git a/plugins/all-module-page/src/main/kotlin/AllModulesPageGeneration.kt b/plugins/all-module-page/src/main/kotlin/AllModulesPageGeneration.kt
new file mode 100644
index 00000000..815cf160
--- /dev/null
+++ b/plugins/all-module-page/src/main/kotlin/AllModulesPageGeneration.kt
@@ -0,0 +1,31 @@
+package org.jetbrains.dokka.allModulesPage
+
+import org.jetbrains.dokka.CoreExtensions
+import org.jetbrains.dokka.Timer
+import org.jetbrains.dokka.generation.Generation
+import org.jetbrains.dokka.pages.RootPageNode
+import org.jetbrains.dokka.plugability.DokkaContext
+
+class AllModulesPageGeneration(private val context: DokkaContext) : Generation {
+ override fun Timer.generate() {
+ report("Creating all modules page")
+ val pages = createAllModulePage()
+
+ report("Transforming pages")
+ val transformedPages = transformAllModulesPage(pages)
+
+ report("Rendering")
+ render(transformedPages)
+ }
+
+ override val generationName = "index page for project"
+
+ fun createAllModulePage() = context.single(CoreExtensions.allModulePageCreator).invoke()
+
+ fun transformAllModulesPage(pages: RootPageNode) =
+ context[CoreExtensions.allModulePageTransformer].fold(pages) { acc, t -> t(acc) }
+
+ fun render(transformedPages: RootPageNode) {
+ context.single(CoreExtensions.renderer).render(transformedPages)
+ }
+} \ No newline at end of file
diff --git a/plugins/all-module-page/src/main/kotlin/AllModulesPagePlugin.kt b/plugins/all-module-page/src/main/kotlin/AllModulesPagePlugin.kt
new file mode 100644
index 00000000..163f13ab
--- /dev/null
+++ b/plugins/all-module-page/src/main/kotlin/AllModulesPagePlugin.kt
@@ -0,0 +1,25 @@
+package org.jetbrains.dokka.allModulesPage
+
+import org.jetbrains.dokka.CoreExtensions
+import org.jetbrains.dokka.base.DokkaBase
+import org.jetbrains.dokka.plugability.DokkaPlugin
+
+class AllModulesPagePlugin : DokkaPlugin() {
+ val allModulePageCreators by extending {
+ (CoreExtensions.allModulePageCreator
+ providing ::MultimodulePageCreator)
+ }
+
+ val multimoduleLocationProvider by extending {
+ (plugin<DokkaBase>().locationProviderFactory
+ providing MultimoduleLocationProvider::Factory
+ override plugin<DokkaBase>().locationProvider
+ applyIf { modules.size > 1 })
+ }
+
+ val allModulesPageGeneration by extending {
+ (CoreExtensions.generation
+ providing ::AllModulesPageGeneration
+ override CoreExtensions.singleGeneration)
+ }
+} \ No newline at end of file
diff --git a/plugins/all-module-page/src/main/kotlin/MultimoduleLocationProvider.kt b/plugins/all-module-page/src/main/kotlin/MultimoduleLocationProvider.kt
new file mode 100644
index 00000000..29107136
--- /dev/null
+++ b/plugins/all-module-page/src/main/kotlin/MultimoduleLocationProvider.kt
@@ -0,0 +1,41 @@
+package org.jetbrains.dokka.allModulesPage
+
+import org.jetbrains.dokka.base.resolvers.local.DokkaLocationProvider
+import org.jetbrains.dokka.base.resolvers.local.DokkaLocationProvider.Companion.identifierToFilename
+import org.jetbrains.dokka.base.resolvers.local.LocationProvider
+import org.jetbrains.dokka.base.resolvers.local.LocationProviderFactory
+import org.jetbrains.dokka.links.DRI
+import org.jetbrains.dokka.model.DisplaySourceSet
+import org.jetbrains.dokka.pages.PageNode
+import org.jetbrains.dokka.pages.RootPageNode
+import org.jetbrains.dokka.plugability.DokkaContext
+
+class MultimoduleLocationProvider(private val root: RootPageNode, context: DokkaContext) : LocationProvider {
+
+ private val defaultLocationProvider = DokkaLocationProvider(root, context)
+
+ val paths = context.configuration.modules.map {
+ it.name to it.relativePathToOutputDirectory
+ }.toMap()
+
+ override fun resolve(dri: DRI, sourceSets: Set<DisplaySourceSet>, context: PageNode?) =
+ dri.takeIf { it.packageName == MULTIMODULE_PACKAGE_PLACEHOLDER }?.classNames?.let { paths[it] }?.let {
+ "$it/${identifierToFilename(dri.classNames.orEmpty())}/index.html"
+ } ?: defaultLocationProvider.resolve(dri, sourceSets, context)
+
+ override fun resolve(node: PageNode, context: PageNode?, skipExtension: Boolean) =
+ defaultLocationProvider.resolve(node, context, skipExtension)
+
+ override fun pathToRoot(from: PageNode): String = defaultLocationProvider.pathToRoot(from)
+
+ override fun ancestors(node: PageNode): List<PageNode> = listOf(root)
+
+ companion object {
+ const val MULTIMODULE_PACKAGE_PLACEHOLDER = ".ext"
+ }
+
+ class Factory(private val context: DokkaContext): LocationProviderFactory {
+ override fun getLocationProvider(pageNode: RootPageNode) =
+ MultimoduleLocationProvider(pageNode, context)
+ }
+} \ No newline at end of file
diff --git a/plugins/base/src/main/kotlin/allModulePage/MultimodulePageCreator.kt b/plugins/all-module-page/src/main/kotlin/MultimodulePageCreator.kt
index 3c4f1dea..3ad3e0ce 100644
--- a/plugins/base/src/main/kotlin/allModulePage/MultimodulePageCreator.kt
+++ b/plugins/all-module-page/src/main/kotlin/MultimodulePageCreator.kt
@@ -1,4 +1,4 @@
-package org.jetbrains.dokka.base.allModulePage
+package org.jetbrains.dokka.allModulesPage
import org.jetbrains.dokka.DokkaConfiguration.DokkaModuleDescription
import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet
diff --git a/plugins/all-module-page/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin b/plugins/all-module-page/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin
new file mode 100644
index 00000000..3ac59dc6
--- /dev/null
+++ b/plugins/all-module-page/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin
@@ -0,0 +1 @@
+org.jetbrains.dokka.allModulesPage.AllModulesPagePlugin
diff --git a/plugins/base/src/main/kotlin/DokkaBase.kt b/plugins/base/src/main/kotlin/DokkaBase.kt
index e92759ff..de7e1e5e 100644
--- a/plugins/base/src/main/kotlin/DokkaBase.kt
+++ b/plugins/base/src/main/kotlin/DokkaBase.kt
@@ -4,7 +4,6 @@ package org.jetbrains.dokka.base
import org.jetbrains.dokka.CoreExtensions
import org.jetbrains.dokka.analysis.KotlinAnalysis
-import org.jetbrains.dokka.base.allModulePage.MultimodulePageCreator
import org.jetbrains.dokka.base.renderers.*
import org.jetbrains.dokka.base.renderers.html.*
import org.jetbrains.dokka.base.resolvers.external.ExternalLocationProviderFactory
@@ -205,12 +204,6 @@ class DokkaBase : DokkaPlugin() {
htmlPreprocessors providing ::SourcesetDependencyAppender order { after(rootCreator) }
}
- val allModulePageCreators by extending {
- CoreExtensions.allModulePageCreator providing {
- MultimodulePageCreator(it)
- }
- }
-
val baseSearchbarDataInstaller by extending {
htmlPreprocessors providing ::SearchbarDataInstaller order { after(sourceLinksTransformer) }
}
diff --git a/plugins/base/src/main/kotlin/parsers/moduleAndPackage/ModuleAndPackageDocumentation.kt b/plugins/base/src/main/kotlin/parsers/moduleAndPackage/ModuleAndPackageDocumentation.kt
index 5139c872..ee67fad1 100644
--- a/plugins/base/src/main/kotlin/parsers/moduleAndPackage/ModuleAndPackageDocumentation.kt
+++ b/plugins/base/src/main/kotlin/parsers/moduleAndPackage/ModuleAndPackageDocumentation.kt
@@ -2,7 +2,7 @@ package org.jetbrains.dokka.base.parsers.moduleAndPackage
import org.jetbrains.dokka.model.doc.DocumentationNode
-internal data class ModuleAndPackageDocumentation(
+data class ModuleAndPackageDocumentation(
val name: String,
val classifier: Classifier,
val documentation: DocumentationNode
diff --git a/plugins/base/src/main/kotlin/parsers/moduleAndPackage/ModuleAndPackageDocumentationFragment.kt b/plugins/base/src/main/kotlin/parsers/moduleAndPackage/ModuleAndPackageDocumentationFragment.kt
index fa99a8e2..06fef72c 100644
--- a/plugins/base/src/main/kotlin/parsers/moduleAndPackage/ModuleAndPackageDocumentationFragment.kt
+++ b/plugins/base/src/main/kotlin/parsers/moduleAndPackage/ModuleAndPackageDocumentationFragment.kt
@@ -2,7 +2,7 @@ package org.jetbrains.dokka.base.parsers.moduleAndPackage
import org.jetbrains.dokka.base.parsers.moduleAndPackage.ModuleAndPackageDocumentation.*
-internal data class ModuleAndPackageDocumentationFragment(
+data class ModuleAndPackageDocumentationFragment(
val name: String,
val classifier: Classifier,
val documentation: String,
diff --git a/plugins/base/src/main/kotlin/parsers/moduleAndPackage/ModuleAndPackageDocumentationParsingContext.kt b/plugins/base/src/main/kotlin/parsers/moduleAndPackage/ModuleAndPackageDocumentationParsingContext.kt
index 64441447..afdcc43f 100644
--- a/plugins/base/src/main/kotlin/parsers/moduleAndPackage/ModuleAndPackageDocumentationParsingContext.kt
+++ b/plugins/base/src/main/kotlin/parsers/moduleAndPackage/ModuleAndPackageDocumentationParsingContext.kt
@@ -17,7 +17,7 @@ import org.jetbrains.kotlin.idea.kdoc.resolveKDocLink
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
-internal fun interface ModuleAndPackageDocumentationParsingContext {
+fun interface ModuleAndPackageDocumentationParsingContext {
fun markdownParserFor(fragment: ModuleAndPackageDocumentationFragment): MarkdownParser
}
@@ -27,7 +27,7 @@ internal fun ModuleAndPackageDocumentationParsingContext.parse(
return markdownParserFor(fragment).parse(fragment.documentation)
}
-internal fun ModuleAndPackageDocumentationParsingContext(
+fun ModuleAndPackageDocumentationParsingContext(
logger: DokkaLogger,
facade: DokkaResolutionFacade? = null
) = ModuleAndPackageDocumentationParsingContext { fragment ->
diff --git a/plugins/base/src/main/kotlin/parsers/moduleAndPackage/ModuleAndPackageDocumentationSource.kt b/plugins/base/src/main/kotlin/parsers/moduleAndPackage/ModuleAndPackageDocumentationSource.kt
index 90dc9ca8..9514adb4 100644
--- a/plugins/base/src/main/kotlin/parsers/moduleAndPackage/ModuleAndPackageDocumentationSource.kt
+++ b/plugins/base/src/main/kotlin/parsers/moduleAndPackage/ModuleAndPackageDocumentationSource.kt
@@ -2,7 +2,7 @@ package org.jetbrains.dokka.base.parsers.moduleAndPackage
import java.io.File
-internal abstract class ModuleAndPackageDocumentationSource {
+abstract class ModuleAndPackageDocumentationSource {
abstract val sourceDescription: String
abstract val documentation: String
override fun toString(): String = sourceDescription
diff --git a/plugins/base/src/main/kotlin/parsers/moduleAndPackage/parseModuleAndPackageDocumentation.kt b/plugins/base/src/main/kotlin/parsers/moduleAndPackage/parseModuleAndPackageDocumentation.kt
index a2876308..5ef9d7ef 100644
--- a/plugins/base/src/main/kotlin/parsers/moduleAndPackage/parseModuleAndPackageDocumentation.kt
+++ b/plugins/base/src/main/kotlin/parsers/moduleAndPackage/parseModuleAndPackageDocumentation.kt
@@ -2,7 +2,7 @@
package org.jetbrains.dokka.base.parsers.moduleAndPackage
-internal fun parseModuleAndPackageDocumentation(
+fun parseModuleAndPackageDocumentation(
context: ModuleAndPackageDocumentationParsingContext,
fragment: ModuleAndPackageDocumentationFragment
): ModuleAndPackageDocumentation {
diff --git a/plugins/base/src/main/kotlin/parsers/moduleAndPackage/parseModuleAndPackageDocumentationFragments.kt b/plugins/base/src/main/kotlin/parsers/moduleAndPackage/parseModuleAndPackageDocumentationFragments.kt
index 7dcaccfa..d193ec0a 100644
--- a/plugins/base/src/main/kotlin/parsers/moduleAndPackage/parseModuleAndPackageDocumentationFragments.kt
+++ b/plugins/base/src/main/kotlin/parsers/moduleAndPackage/parseModuleAndPackageDocumentationFragments.kt
@@ -4,11 +4,11 @@ import org.jetbrains.dokka.base.parsers.moduleAndPackage.ModuleAndPackageDocumen
import java.io.File
-internal fun parseModuleAndPackageDocumentationFragments(source: File): List<ModuleAndPackageDocumentationFragment> {
+fun parseModuleAndPackageDocumentationFragments(source: File): List<ModuleAndPackageDocumentationFragment> {
return parseModuleAndPackageDocumentationFragments(ModuleAndPackageDocumentationFile(source))
}
-internal fun parseModuleAndPackageDocumentationFragments(
+fun parseModuleAndPackageDocumentationFragments(
source: ModuleAndPackageDocumentationSource
): List<ModuleAndPackageDocumentationFragment> {
val fragmentStrings = source.documentation.split(Regex("(|^)#\\s*(?=(Module|Package))"))
diff --git a/plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt
index 3ef8bcce..030197a5 100644
--- a/plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt
+++ b/plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt
@@ -129,12 +129,12 @@ open class DokkaLocationProvider(
protected data class PageWithKind(val page: ContentPage, val kind: Kind)
companion object {
- internal val reservedFilenames = setOf("index", "con", "aux", "lst", "prn", "nul", "eof", "inp", "out")
+ val reservedFilenames = setOf("index", "con", "aux", "lst", "prn", "nul", "eof", "inp", "out")
//Taken from: https://stackoverflow.com/questions/1976007/what-characters-are-forbidden-in-windows-and-linux-directory-names
internal val reservedCharacters = setOf('|', '>', '<', '*', ':', '"', '?', '%')
- internal fun identifierToFilename(name: String): String {
+ fun identifierToFilename(name: String): String {
if (name.isEmpty()) return "--root--"
return sanitizeFileName(name, reservedFilenames, reservedCharacters)
}