-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix multimodule sourcesets dependencies (#1766)
- Loading branch information
1 parent
9bcc941
commit 4899f65
Showing
5 changed files
with
54 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
plugins/base/src/main/kotlin/templating/AddToSourcesetDependencies.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package org.jetbrains.dokka.base.templating | ||
|
||
data class AddToSourcesetDependencies(val moduleName: String, val content: Map<String, List<String>>) : Command |
33 changes: 33 additions & 0 deletions
33
plugins/templating/src/main/kotlin/templates/SourcesetDependencyProcessingStrategy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters