From 6225a6dbb4b673b4a4fbda8b8405f5f6d7b4c79a Mon Sep 17 00:00:00 2001 From: Paweł Marks Date: Thu, 31 Oct 2019 16:27:28 +0100 Subject: Pseudo generator --- core/src/main/kotlin/DokkaBootstrapImpl.kt | 76 ++++++++++++++++++++++++++++++ core/src/main/kotlin/DokkaGenerator.kt | 13 +++++ 2 files changed, 89 insertions(+) create mode 100644 core/src/main/kotlin/DokkaBootstrapImpl.kt create mode 100644 core/src/main/kotlin/DokkaGenerator.kt (limited to 'core/src') 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 { + 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) : 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 { + val links = mutableListOf() + 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 = it.externalDocumentationLinks + defaultLinks(it) + it.copy(externalDocumentationLinks = links) + } + ) + + generator = DokkaGenerator(configurationWithLinks, logger) + } + + override fun configure(logger: BiConsumer, serializedConfigurationJSON: String) + = configure(DokkaProxyLogger(logger), gson.fromJson(serializedConfigurationJSON, DokkaConfigurationImpl::class.java)) + + override fun generate() = generator.generate() +} diff --git a/core/src/main/kotlin/DokkaGenerator.kt b/core/src/main/kotlin/DokkaGenerator.kt new file mode 100644 index 00000000..abb6f069 --- /dev/null +++ b/core/src/main/kotlin/DokkaGenerator.kt @@ -0,0 +1,13 @@ +package org.jetbrains.dokka + +class DokkaGenerator( + private val configurationWithLinks: DokkaConfiguration, + private val logger: DokkaLogger +) { + fun generate() { + println("RUNNED") + logger.error("runned") + throw AssertionError() + } + +} -- cgit