Skip to content

Commit

Permalink
dump
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcinAman committed Jul 14, 2021
1 parent 18eefff commit dac2f88
Show file tree
Hide file tree
Showing 32 changed files with 192 additions and 90 deletions.
1 change: 0 additions & 1 deletion core/src/main/kotlin/configuration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import java.net.URL
object DokkaDefaults {
val moduleName: String = "root"
val outputDir = File("./dokka")
const val format: String = "html"
val cacheRoot: File? = null
const val offlineMode: Boolean = false
const val failOnWarning: Boolean = false
Expand Down
9 changes: 4 additions & 5 deletions core/src/main/kotlin/pages/PageNodes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,15 @@ class MemberPageNode(
class MultimoduleRootPageNode(
override val dri: Set<DRI>,
override val content: ContentNode,
override val embeddedResources: List<String> = emptyList()
override val embeddedResources: List<String> = emptyList(),
override val children: List<PageNode> = emptyList()
) : RootPageNode(forceTopLevelName = true), MultimoduleRootPage {
override val name = "All modules"

override val children: List<PageNode> = emptyList()

override val documentable: Documentable? = null

override fun modified(name: String, children: List<PageNode>): RootPageNode =
MultimoduleRootPageNode(dri, content, embeddedResources)
MultimoduleRootPageNode(dri, content, embeddedResources, children)

override fun modified(
name: String,
Expand All @@ -178,7 +177,7 @@ class MultimoduleRootPageNode(
children: List<PageNode>
) =
if (name == this.name && content === this.content && embeddedResources === this.embeddedResources && children shallowEq this.children) this
else MultimoduleRootPageNode(dri, content, embeddedResources)
else MultimoduleRootPageNode(dri, content, embeddedResources, children)
}

inline fun <reified T : PageNode> PageNode.children() = children.filterIsInstance<T>()
Expand Down
1 change: 1 addition & 0 deletions core/src/main/kotlin/pages/RendererSpecificPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.jetbrains.dokka.model.DisplaySourceSet
import org.jetbrains.dokka.renderers.Renderer
import kotlin.reflect.KClass

typealias OutputExtension = String
fun interface DriResolver: (DRI, Set<DisplaySourceSet>) -> String?
fun interface PageResolver: (PageNode, PageNode?) -> String?

Expand Down
4 changes: 4 additions & 0 deletions core/src/main/kotlin/renderers/Renderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ package org.jetbrains.dokka.renderers
import org.jetbrains.dokka.pages.RootPageNode

interface Renderer {
/**
* Extension of the output format without dot at the beginning
*/
val outputExtension: String
fun render(root: RootPageNode)
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class TestDokkaConfigurationBuilder {
var suppressObviousFunctions: Boolean = DokkaDefaults.suppressObviousFunctions
var includes: List<File> = emptyList()
var suppressInheritedMembers: Boolean = DokkaDefaults.suppressInheritedMembers
var delayTemplateSubstitution: Boolean = false
private val lazySourceSets = mutableListOf<Lazy<DokkaSourceSetImpl>>()

fun build() = DokkaConfigurationImpl(
Expand All @@ -53,6 +54,7 @@ class TestDokkaConfigurationBuilder {
suppressObviousFunctions = suppressObviousFunctions,
includes = includes.toSet(),
suppressInheritedMembers = suppressInheritedMembers,
delayTemplateSubstitution = delayTemplateSubstitution
)

fun sourceSets(block: SourceSetsBuilder.() -> Unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ plugins {
kotlin("jvm")
id("org.jetbrains.dokka")
}

dependencies {
dokkaPlugin("org.jetbrains.dokka:sitemap-plugin:${System.getenv("DOKKA_VERSION")}")
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {

dependencies {
implementation(kotlin("stdlib"))
dokkaPlugin("org.jetbrains.dokka:sitemap-plugin:${System.getenv("DOKKA_VERSION")}")
}

tasks.withType<DokkaTask>().configureEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {

dependencies {
implementation(kotlin("stdlib"))
dokkaPlugin("org.jetbrains.dokka:sitemap-plugin:${System.getenv("DOKKA_VERSION")}")
}

tasks.withType<DokkaTask>().configureEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ plugins {

dependencies {
implementation(kotlin("stdlib"))
dokkaPlugin("org.jetbrains.dokka:sitemap-plugin:${System.getenv("DOKKA_VERSION")}")
}
8 changes: 0 additions & 8 deletions integration-tests/gradle/projects/template.root.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
allprojects {
repositories {
maven("https://cache-redirector.jetbrains.com/jcenter.bintray.com")
mavenLocal()
mavenCentral()
google()
maven("https://cache-redirector.jetbrains.com/dl.bintray.com/kotlin/kotlin-eap")
maven("https://cache-redirector.jetbrains.com/dl.bintray.com/kotlin/kotlin-dev")
maven("https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven") {
content {
includeGroup("org.jetbrains.kotlinx")
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ class MultiModule0IntegrationTest(override val versions: BuildVersions) : Abstra
"Expected moduleC being mentioned in -modules.html"
)

val sitemap = File(outputDir, "sitemap.txt")
assertTrue(sitemap.isFile, "Missing sitemap file")
val allHtmlFiles = outputDir.allHtmlFiles().toList()
val sitemapContent = sitemap.readLines()
assertTrue(sitemapContent.isNotEmpty())
assertEquals(allHtmlFiles.map { it.absolutePath.removePrefix(outputDir.absolutePath) }.sorted(), sitemapContent.sorted())

val gfmOutputDir = File(projectDir, "moduleA/build/dokka/gfmMultiModule")
assertTrue(gfmOutputDir.isDirectory, "Missing dokka GFM output directory")

Expand Down
12 changes: 7 additions & 5 deletions plugins/all-modules-page/src/main/kotlin/AllModulesPagePlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,26 @@ class AllModulesPagePlugin : DokkaPlugin() {
val multimoduleLocationProvider by extending {
(dokkaBase.locationProviderFactory
providing MultimoduleLocationProvider::Factory
override plugin<DokkaBase>().locationProvider)
override plugin<DokkaBase>().locationProvider
applyIf { !delayTemplateSubstitution })
}

val baseLocationProviderFactory by extending {
partialLocationProviderFactory providing ::DokkaLocationProviderFactory
partialLocationProviderFactory providing ::DokkaLocationProviderFactory applyIf { !delayTemplateSubstitution }
}

val allModulesPageGeneration by extending {
(CoreExtensions.generation
providing ::AllModulesPageGeneration
override dokkaBase.singleGeneration)
override dokkaBase.singleGeneration
applyIf { !delayTemplateSubstitution })
}

val resolveLinkCommandHandler by extending {
plugin<TemplatingPlugin>().directiveBasedCommandHandlers providing ::ResolveLinkCommandHandler
plugin<TemplatingPlugin>().directiveBasedCommandHandlers providing ::ResolveLinkCommandHandler applyIf { !delayTemplateSubstitution }
}

val multiModuleLinkResolver by extending {
externalModuleLinkResolver providing ::DefaultExternalModuleLinkResolver
externalModuleLinkResolver providing ::DefaultExternalModuleLinkResolver applyIf { !delayTemplateSubstitution }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,37 @@ 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.ContentPage
import org.jetbrains.dokka.pages.OutputExtension
import org.jetbrains.dokka.pages.PageNode
import org.jetbrains.dokka.pages.RootPageNode
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.plugability.plugin
import org.jetbrains.dokka.plugability.querySingle

open class MultimoduleLocationProvider(private val root: RootPageNode, dokkaContext: DokkaContext) :
open class MultimoduleLocationProvider(private val root: RootPageNode, dokkaContext: DokkaContext, private val outputExtension: OutputExtension) :
DokkaBaseLocationProvider(root, dokkaContext) {

private val defaultLocationProvider =
dokkaContext.plugin<AllModulesPagePlugin>().querySingle { partialLocationProviderFactory }
.getLocationProvider(root)
.getLocationProvider(root, outputExtension)
private val externalModuleLinkResolver =
dokkaContext.plugin<AllModulesPagePlugin>().querySingle { externalModuleLinkResolver }

override fun resolve(dri: DRI, sourceSets: Set<DisplaySourceSet>, context: PageNode?) =
if (dri == MultimodulePageCreator.MULTIMODULE_ROOT_DRI) pathToRoot(root) + "index"
if (dri == MultimodulePageCreator.MULTIMODULE_ROOT_DRI) pathToRoot(root) + "index$outputExtension"
else dri.takeIf { it.packageName == MULTIMODULE_PACKAGE_PLACEHOLDER }?.classNames
?.let(externalModuleLinkResolver::resolveLinkToModuleIndex)

override fun resolve(node: PageNode, context: PageNode?, skipExtension: Boolean) =
if (node is ContentPage && MultimodulePageCreator.MULTIMODULE_ROOT_DRI in node.dri) pathToRoot(root) + "index"
if (node is ContentPage && MultimodulePageCreator.MULTIMODULE_ROOT_DRI in node.dri) pathToRoot(root) + "index$outputExtension"
else defaultLocationProvider.resolve(node, context, skipExtension)

override fun pathToRoot(from: PageNode): String = defaultLocationProvider.pathToRoot(from)

override fun ancestors(node: PageNode): List<PageNode> = listOf(root)

class Factory(private val context: DokkaContext) : LocationProviderFactory {
override fun getLocationProvider(pageNode: RootPageNode) =
MultimoduleLocationProvider(pageNode, context)
override fun getLocationProvider(pageNode: RootPageNode, outputExtension: OutputExtension) =
MultimoduleLocationProvider(pageNode, context, "." + outputExtension.removePrefix("."))
}
}
16 changes: 13 additions & 3 deletions plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,21 @@ abstract class DefaultRenderer<T>(
locationProvider.resolve(page, skipExtension = true)
?: throw DokkaException("Cannot resolve path for ${page.name}")
}
val outputExtensionWithDot = "." + outputExtension.removePrefix(".")
when (page) {
is ContentPage -> outputWriter.write(path, buildPage(page) { c, p -> buildPageContent(c, p) }, ".html")
is ContentPage -> outputWriter.write(
path,
buildPage(page) { c, p -> buildPageContent(c, p) },
outputExtensionWithDot
)
is RendererSpecificPage -> when (val strategy = page.strategy) {
is RenderingStrategy.Copy -> outputWriter.writeResources(strategy.from, path)
is RenderingStrategy.Write -> outputWriter.write(path, strategy.text, "")
is RenderingStrategy.Callback -> outputWriter.write(path, strategy.instructions(this, page), ".html")
is RenderingStrategy.Callback -> outputWriter.write(
path,
strategy.instructions(this, page),
outputExtensionWithDot
)
is RenderingStrategy.DriLocationResolvableWrite -> outputWriter.write(
path,
strategy.contentToResolve { dri, sourcesets ->
Expand Down Expand Up @@ -204,7 +213,8 @@ abstract class DefaultRenderer<T>(
val newRoot = preprocessors.fold(root) { acc, t -> t(acc) }

locationProvider =
context.plugin<DokkaBase>().querySingle { locationProviderFactory }.getLocationProvider(newRoot)
context.plugin<DokkaBase>().querySingle { locationProviderFactory }
.getLocationProvider(newRoot, outputExtension)

runBlocking(Dispatchers.Default) {
renderPages(newRoot)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class PackageListService(val context: DokkaContext, val rootPage: RootPageNode)
val nonStandardLocations = mutableMapOf<String, String>()

val locationProvider =
context.plugin<DokkaBase>().querySingle { locationProviderFactory }.getLocationProvider(rootPage)
context.plugin<DokkaBase>().querySingle { locationProviderFactory }.getLocationProvider(rootPage, format.linkExtension)

fun visit(node: PageNode) {
if (node is PackagePage) {
Expand Down
2 changes: 2 additions & 0 deletions plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import java.net.URI
open class HtmlRenderer(
context: DokkaContext
) : DefaultRenderer<FlowContent>(context) {
override val outputExtension: String = "html"

private val configuration = configuration<DokkaBase, DokkaBaseConfiguration>(context)

private val sourceSetDependencyMap: Map<DokkaSourceSetID, List<DokkaSourceSetID>> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.jetbrains.dokka.base.renderers.html

import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import org.jetbrains.dokka.Platform
import org.jetbrains.dokka.base.renderers.sourceSets
import org.jetbrains.dokka.base.templating.AddToSearch
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.DisplaySourceSet
Expand Down Expand Up @@ -35,7 +36,7 @@ open class SearchbarDataInstaller(val context: DokkaContext) : PageTransformer {

private val mapper = jacksonObjectMapper()

open fun generatePagesList(pages: List<PageWithId>, locationResolver: PageResolver): List<SearchRecord> =
open fun generatePagesList(pages: List<PageWithId>, locationResolver: DriResolver): List<SearchRecord> =
pages.map { pageWithId ->
createSearchRecord(
name = pageWithId.displayableSignature,
Expand Down Expand Up @@ -64,16 +65,16 @@ open class SearchbarDataInstaller(val context: DokkaContext) : PageTransformer {
else -> emptyList()
}

private fun resolveLocation(locationResolver: PageResolver, page: ContentPage): String? =
locationResolver(page, null).also { location ->
private fun resolveLocation(locationResolver: DriResolver, page: ContentPage): String? =
locationResolver(page.dri.first(), page.sourceSets()).also { location ->
if (location.isNullOrBlank()) context.logger.warn("Cannot resolve path for ${page.dri}")
}

override fun invoke(input: RootPageNode): RootPageNode {
val page = RendererSpecificResourcePage(
name = "scripts/pages.json",
children = emptyList(),
strategy = RenderingStrategy.PageLocationResolvableWrite { resolver ->
strategy = RenderingStrategy.DriLocationResolvableWrite { resolver ->
val content = input.withDescendants().fold(emptyList<PageWithId>()) { pageList, page ->
pageList + processPage(page)
}.run {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import java.util.*
open class DokkaLocationProvider(
pageGraphRoot: RootPageNode,
dokkaContext: DokkaContext,
val extension: String = ".html"
val extension: String
) : DokkaBaseLocationProvider(pageGraphRoot, dokkaContext) {
protected open val PAGE_WITH_CHILDREN_SUFFIX = "index"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package org.jetbrains.dokka.base.resolvers.local

import org.jetbrains.dokka.pages.OutputExtension
import org.jetbrains.dokka.pages.RootPageNode
import org.jetbrains.dokka.plugability.DokkaContext
import java.util.concurrent.ConcurrentHashMap

class DokkaLocationProviderFactory(private val context: DokkaContext) : LocationProviderFactory {
private val cache = ConcurrentHashMap<CacheWrapper, LocationProvider>()

override fun getLocationProvider(pageNode: RootPageNode) = cache.computeIfAbsent(CacheWrapper(pageNode)) {
DokkaLocationProvider(pageNode, context)
override fun getLocationProvider(pageNode: RootPageNode, outputExtension: OutputExtension) = cache.computeIfAbsent(CacheWrapper(pageNode)) {
DokkaLocationProvider(pageNode, context, ".${outputExtension.removePrefix(".")}")
}

private class CacheWrapper(val pageNode: RootPageNode) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.jetbrains.dokka.base.resolvers.local

import org.jetbrains.dokka.pages.OutputExtension
import org.jetbrains.dokka.pages.RootPageNode

interface LocationProviderFactory {
fun getLocationProvider(pageNode: RootPageNode): LocationProvider
fun getLocationProvider(pageNode: RootPageNode, outputExtension: OutputExtension): LocationProvider
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package org.jetbrains.dokka.gfm.location

import org.jetbrains.dokka.base.resolvers.local.DokkaLocationProvider
import org.jetbrains.dokka.base.resolvers.local.LocationProvider
import org.jetbrains.dokka.base.resolvers.local.LocationProviderFactory
import org.jetbrains.dokka.pages.OutputExtension
import org.jetbrains.dokka.pages.RootPageNode
import org.jetbrains.dokka.plugability.DokkaContext

class MarkdownLocationProvider(
pageGraphRoot: RootPageNode,
dokkaContext: DokkaContext
) : DokkaLocationProvider(pageGraphRoot, dokkaContext, ".md") {
dokkaContext: DokkaContext,
outputExtension: OutputExtension
) : DokkaLocationProvider(pageGraphRoot, dokkaContext, outputExtension) {

class Factory(private val context: DokkaContext) : LocationProviderFactory {
override fun getLocationProvider(pageNode: RootPageNode) =
MarkdownLocationProvider(pageNode, context)
override fun getLocationProvider(pageNode: RootPageNode, outputExtension: OutputExtension): LocationProvider =
MarkdownLocationProvider(pageNode, context, "." + outputExtension.removePrefix("."))
}
}

Loading

0 comments on commit dac2f88

Please sign in to comment.