diff options
author | Marcin Aman <marcin.aman@gmail.com> | 2021-03-10 02:30:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-10 02:30:27 +0100 |
commit | 4899f65d789e47e2a9c9359d0e150a4e1f1a41f7 (patch) | |
tree | 9c7b27386f35a76a0ef05df3de04b7031d7fce62 /plugins/templating/src/main | |
parent | 9bcc94196ec388a7f8351f4190506efcd746a6fd (diff) | |
download | dokka-4899f65d789e47e2a9c9359d0e150a4e1f1a41f7.tar.gz dokka-4899f65d789e47e2a9c9359d0e150a4e1f1a41f7.tar.bz2 dokka-4899f65d789e47e2a9c9359d0e150a4e1f1a41f7.zip |
Fix multimodule sourcesets dependencies (#1766)
Diffstat (limited to 'plugins/templating/src/main')
-rw-r--r-- | plugins/templating/src/main/kotlin/templates/SourcesetDependencyProcessingStrategy.kt | 33 | ||||
-rw-r--r-- | plugins/templating/src/main/kotlin/templates/TemplatingPlugin.kt | 7 |
2 files changed, 40 insertions, 0 deletions
diff --git a/plugins/templating/src/main/kotlin/templates/SourcesetDependencyProcessingStrategy.kt b/plugins/templating/src/main/kotlin/templates/SourcesetDependencyProcessingStrategy.kt new file mode 100644 index 00000000..11bbc39a --- /dev/null +++ b/plugins/templating/src/main/kotlin/templates/SourcesetDependencyProcessingStrategy.kt @@ -0,0 +1,33 @@ +package templates + +import org.jetbrains.dokka.base.templating.AddToSourcesetDependencies +import org.jetbrains.dokka.base.templating.parseJson +import org.jetbrains.dokka.base.templating.toJsonString +import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.templates.TemplateProcessingStrategy +import java.io.File +import java.util.concurrent.ConcurrentHashMap + +private typealias Entry = Map<String, List<String>> + +class SourcesetDependencyProcessingStrategy(val context: DokkaContext) : TemplateProcessingStrategy { + private val fileName = "sourceset_dependencies.js" + private val fragments = ConcurrentHashMap<String, Entry>() + + override fun finish(output: File) { + if (fragments.isNotEmpty()) { + val content = fragments.values.fold(emptyMap<String, List<String>>()) { acc, e -> acc + e } + .let { "sourceset_dependencies = '${toJsonString(it)}'" } + output.resolve("scripts").mkdirs() + output.resolve("scripts/$fileName").writeText(content) + } + } + + override fun process(input: File, output: File): Boolean = + input.takeIf { it.name == fileName } + ?.runCatching { parseJson<AddToSourcesetDependencies>(input.readText()) } + ?.getOrNull() + ?.also { (moduleName, content) -> + fragments += (moduleName to content) + } != null +}
\ No newline at end of file diff --git a/plugins/templating/src/main/kotlin/templates/TemplatingPlugin.kt b/plugins/templating/src/main/kotlin/templates/TemplatingPlugin.kt index 546a0443..562b12c6 100644 --- a/plugins/templating/src/main/kotlin/templates/TemplatingPlugin.kt +++ b/plugins/templating/src/main/kotlin/templates/TemplatingPlugin.kt @@ -3,6 +3,7 @@ package org.jetbrains.dokka.templates import org.jetbrains.dokka.allModulesPage.templates.NavigationSearchTemplateStrategy import org.jetbrains.dokka.allModulesPage.templates.PagesSearchTemplateStrategy import org.jetbrains.dokka.plugability.DokkaPlugin +import templates.SourcesetDependencyProcessingStrategy class TemplatingPlugin : DokkaPlugin() { @@ -32,6 +33,12 @@ class TemplatingPlugin : DokkaPlugin() { } } + val sourcesetDependencyProcessingStrategy by extending { + templateProcessingStrategy providing ::SourcesetDependencyProcessingStrategy order { + before(fallbackProcessingStrategy) + } + } + val pagesSearchTemplateStrategy by extending { templateProcessingStrategy providing ::PagesSearchTemplateStrategy order { before(fallbackProcessingStrategy) |