aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/DokkaBootstrapImpl.kt
diff options
context:
space:
mode:
authorPaweł Marks <pmarks@virtuslab.com>2019-10-31 16:27:28 +0100
committerPaweł Marks <pmarks@virtuslab.com>2019-10-31 16:27:28 +0100
commit6225a6dbb4b673b4a4fbda8b8405f5f6d7b4c79a (patch)
tree403e83db44366cc8d4b373eb513b33635224eef6 /core/src/main/kotlin/DokkaBootstrapImpl.kt
parent50111daf07c7afd1c1b60e9672ed6786c96efdea (diff)
downloaddokka-6225a6dbb4b673b4a4fbda8b8405f5f6d7b4c79a.tar.gz
dokka-6225a6dbb4b673b4a4fbda8b8405f5f6d7b4c79a.tar.bz2
dokka-6225a6dbb4b673b4a4fbda8b8405f5f6d7b4c79a.zip
Pseudo generator
Diffstat (limited to 'core/src/main/kotlin/DokkaBootstrapImpl.kt')
-rw-r--r--core/src/main/kotlin/DokkaBootstrapImpl.kt76
1 files changed, 76 insertions, 0 deletions
diff --git a/core/src/main/kotlin/DokkaBootstrapImpl.kt b/core/src/main/kotlin/DokkaBootstrapImpl.kt
new file mode 100644
index 00000000..b48b62d4
--- /dev/null
+++ b/core/src/main/kotlin/DokkaBootstrapImpl.kt
@@ -0,0 +1,76 @@
+package org.jetbrains.dokka
+
+import com.google.gson.Gson
+import org.jetbrains.dokka.DokkaConfiguration.PackageOptions
+
+import java.util.function.BiConsumer
+
+
+fun parsePerPackageOptions(arg: String): List<PackageOptions> {
+ if (arg.isBlank()) return emptyList()
+
+ return arg.split(";").map { it.split(",") }.map {
+ val prefix = it.first()
+ if (prefix == "")
+ throw IllegalArgumentException("Please do not register packageOptions with all match pattern, use global settings instead")
+ val args = it.subList(1, it.size)
+ val deprecated = args.find { it.endsWith("deprecated") }?.startsWith("+") ?: true
+ val reportUndocumented = args.find { it.endsWith("warnUndocumented") }?.startsWith("+") ?: true
+ val privateApi = args.find { it.endsWith("privateApi") }?.startsWith("+") ?: false
+ val suppress = args.find { it.endsWith("suppress") }?.startsWith("+") ?: false
+ PackageOptionsImpl(prefix, includeNonPublic = privateApi, reportUndocumented = reportUndocumented, skipDeprecated = !deprecated, suppress = suppress)
+ }
+}
+
+class DokkaBootstrapImpl : DokkaBootstrap {
+
+ private class DokkaProxyLogger(val consumer: BiConsumer<String, String>) : DokkaLogger {
+ override fun info(message: String) {
+ consumer.accept("info", message)
+ }
+
+ override fun warn(message: String) {
+ consumer.accept("warn", message)
+ }
+
+ override fun error(message: String) {
+ consumer.accept("error", message)
+ }
+ }
+
+ lateinit var generator: DokkaGenerator
+ val gson = Gson()
+
+ fun configure(logger: DokkaLogger, configuration: DokkaConfigurationImpl) = with(configuration) {
+
+ fun defaultLinks(config: PassConfigurationImpl): List<ExternalDocumentationLinkImpl> {
+ val links = mutableListOf<ExternalDocumentationLinkImpl>()
+ if (!config.noJdkLink)
+ links += DokkaConfiguration.ExternalDocumentationLink
+ .Builder("https://docs.oracle.com/javase/${config.jdkVersion}/docs/api/")
+ .build() as ExternalDocumentationLinkImpl
+
+ if (!config.noStdlibLink)
+ links += DokkaConfiguration.ExternalDocumentationLink
+ .Builder("https://kotlinlang.org/api/latest/jvm/stdlib/")
+ .build() as ExternalDocumentationLinkImpl
+ return links
+ }
+
+ val configurationWithLinks =
+ configuration.copy(passesConfigurations =
+ passesConfigurations
+ .map {
+ val links: List<ExternalDocumentationLinkImpl> = it.externalDocumentationLinks + defaultLinks(it)
+ it.copy(externalDocumentationLinks = links)
+ }
+ )
+
+ generator = DokkaGenerator(configurationWithLinks, logger)
+ }
+
+ override fun configure(logger: BiConsumer<String, String>, serializedConfigurationJSON: String)
+ = configure(DokkaProxyLogger(logger), gson.fromJson(serializedConfigurationJSON, DokkaConfigurationImpl::class.java))
+
+ override fun generate() = generator.generate()
+}