From 02f30b142aa467d3a24cc52a1fe3f2fed7ea1e33 Mon Sep 17 00:00:00 2001 From: Ignat Beresnev Date: Thu, 31 Aug 2023 20:16:01 +0200 Subject: Enable explicit API mode (#3139) --- .../kotlin/org/jetbrains/dokka/CliArgumentTypes.kt | 19 ++++++----- .../kotlin/org/jetbrains/dokka/GlobalArguments.kt | 38 +++++++++++----------- .../main/kotlin/org/jetbrains/dokka/LinkMapper.kt | 4 +-- .../src/main/kotlin/org/jetbrains/dokka/main.kt | 4 +-- 4 files changed, 34 insertions(+), 31 deletions(-) (limited to 'runners/cli/src/main/kotlin') diff --git a/runners/cli/src/main/kotlin/org/jetbrains/dokka/CliArgumentTypes.kt b/runners/cli/src/main/kotlin/org/jetbrains/dokka/CliArgumentTypes.kt index b889bdc6..1c6b0ba4 100644 --- a/runners/cli/src/main/kotlin/org/jetbrains/dokka/CliArgumentTypes.kt +++ b/runners/cli/src/main/kotlin/org/jetbrains/dokka/CliArgumentTypes.kt @@ -11,20 +11,23 @@ import java.io.File import java.nio.file.Paths -object ArgTypeFile : ArgType(true) { +public object ArgTypeFile : ArgType(true) { override fun convert(value: kotlin.String, name: kotlin.String): File = Paths.get(value).toRealPath().toFile() override val description: kotlin.String get() = "{ String that represents a directory / file path }" } -object ArgTypePlatform : ArgType(true) { +public object ArgTypePlatform : ArgType(true) { override fun convert(value: kotlin.String, name: kotlin.String): Platform = Platform.fromString(value) override val description: kotlin.String get() = "{ String that represents a Kotlin platform. Possible values: jvm/js/native/common/android }" } -object ArgTypeVisibility : ArgType(true) { - override fun convert(value: kotlin.String, name: kotlin.String) = DokkaConfiguration.Visibility.fromString(value) +public object ArgTypeVisibility : ArgType(true) { + override fun convert(value: kotlin.String, name: kotlin.String): DokkaConfiguration.Visibility { + return DokkaConfiguration.Visibility.fromString(value) + } + override val description: kotlin.String get() = "{ String that represents a visibility modifier. Possible values: ${getPossibleVisibilityValues()}" @@ -32,7 +35,7 @@ object ArgTypeVisibility : ArgType(true) { DokkaConfiguration.Visibility.values().joinToString(separator = ", ") } -object ArgTypePlugin : ArgType(true) { +public object ArgTypePlugin : ArgType(true) { override fun convert( value: kotlin.String, name: kotlin.String @@ -52,7 +55,7 @@ object ArgTypePlugin : ArgType(true) { "Quotation marks (`\"`) inside json must be escaped. }" } -object ArgTypeSourceLinkDefinition : ArgType(true) { +public object ArgTypeSourceLinkDefinition : ArgType(true) { override fun convert(value: kotlin.String, name: kotlin.String): DokkaConfiguration.SourceLinkDefinition { return if (value.isNotEmpty() && value.contains("=")) SourceLinkDefinitionImpl.parseSourceLinkDefinition(value) @@ -68,7 +71,7 @@ object ArgTypeSourceLinkDefinition : ArgType) : +public data class ArgTypeArgument(val moduleName: CLIEntity) : ArgType(true) { override fun convert(value: kotlin.String, name: kotlin.String): DokkaConfiguration.DokkaSourceSet = (if (moduleName.valueOrigin != ArgParser.ValueOrigin.UNSET && moduleName.valueOrigin != ArgParser.ValueOrigin.UNDEFINED) { @@ -84,7 +87,7 @@ data class ArgTypeArgument(val moduleName: CLIEntity) : } // Workaround for printing nested parsers help -data class ArgTypeHelpSourceSet(val moduleName: CLIEntity) : ArgType(false) { +public data class ArgTypeHelpSourceSet(val moduleName: CLIEntity) : ArgType(false) { override fun convert(value: kotlin.String, name: kotlin.String): Any = Any().also { parseSourceSet(moduleName.value, arrayOf("-h")) } diff --git a/runners/cli/src/main/kotlin/org/jetbrains/dokka/GlobalArguments.kt b/runners/cli/src/main/kotlin/org/jetbrains/dokka/GlobalArguments.kt index f8e04053..5c95f63f 100644 --- a/runners/cli/src/main/kotlin/org/jetbrains/dokka/GlobalArguments.kt +++ b/runners/cli/src/main/kotlin/org/jetbrains/dokka/GlobalArguments.kt @@ -11,11 +11,11 @@ import org.jetbrains.dokka.utilities.LoggingLevel import org.jetbrains.dokka.utilities.cast import java.io.File -class GlobalArguments(args: Array) : DokkaConfiguration { +public class GlobalArguments(args: Array) : DokkaConfiguration { - val parser = ArgParser("dokka-cli", prefixStyle = ArgParser.OptionPrefixStyle.JVM) + public val parser: ArgParser = ArgParser("dokka-cli", prefixStyle = ArgParser.OptionPrefixStyle.JVM) - val json: String? by parser.argument(ArgType.String, description = "JSON configuration file path").optional() + public val json: String? by parser.argument(ArgType.String, description = "JSON configuration file path").optional() private val _moduleName = parser.option( ArgType.String, @@ -25,50 +25,50 @@ class GlobalArguments(args: Array) : DokkaConfiguration { override val moduleName: String by _moduleName - override val moduleVersion by parser.option( + override val moduleVersion: String? by parser.option( ArgType.String, description = "Documented version", fullName = "moduleVersion" ) - override val outputDir by parser.option(ArgTypeFile, description = "Output directory path, ./dokka by default") + override val outputDir: File by parser.option(ArgTypeFile, description = "Output directory path, ./dokka by default") .default(DokkaDefaults.outputDir) - override val cacheRoot = null + override val cacheRoot: File? = null - override val sourceSets by parser.option( + override val sourceSets: List by parser.option( ArgTypeArgument(_moduleName), description = "Configuration for a Dokka source set. Contains nested configuration.", fullName = "sourceSet" ).multiple() - override val pluginsConfiguration by parser.option( + override val pluginsConfiguration: List by parser.option( ArgTypePlugin, description = "Configuration for Dokka plugins. Accepts multiple values separated by `^^`." ).delimiter("^^") - override val pluginsClasspath by parser.option( + override val pluginsClasspath: List by parser.option( ArgTypeFile, fullName = "pluginsClasspath", description = "List of jars with Dokka plugins and their dependencies. Accepts multiple paths separated by semicolons" ).delimiter(";") - override val offlineMode by parser.option( + override val offlineMode: Boolean by parser.option( ArgType.Boolean, description = "Whether to resolve remote files/links over network" ).default(DokkaDefaults.offlineMode) - override val failOnWarning by parser.option( + override val failOnWarning: Boolean by parser.option( ArgType.Boolean, description = "Whether to fail documentation generation if Dokka has emitted a warning or an error" ).default(DokkaDefaults.failOnWarning) - override val delayTemplateSubstitution by parser.option( + override val delayTemplateSubstitution: Boolean by parser.option( ArgType.Boolean, description = "Delay substitution of some elements. Used in incremental builds of multimodule projects" ).default(DokkaDefaults.delayTemplateSubstitution) - val noSuppressObviousFunctions: Boolean by parser.option( + public val noSuppressObviousFunctions: Boolean by parser.option( ArgType.Boolean, description = "Whether to suppress obvious functions such as inherited from `kotlin.Any` and `java.lang.Object`" ).default(!DokkaDefaults.suppressObviousFunctions) @@ -91,31 +91,31 @@ class GlobalArguments(args: Array) : DokkaConfiguration { override val finalizeCoroutines: Boolean = true - val globalPackageOptions by parser.option( + public val globalPackageOptions: List by parser.option( ArgType.String, description = "Global list of package configurations in format " + "\"matchingRegexp,-deprecated,-privateApi,+warnUndocumented,+suppress;...\". " + "Accepts multiple values separated by semicolons. " ).delimiter(";") - val globalLinks by parser.option( + public val globalLinks: List by parser.option( ArgType.String, description = "Global external documentation links in format {url}^{packageListUrl}. " + "Accepts multiple values separated by `^^`" ).delimiter("^^") - val globalSrcLink by parser.option( + public val globalSrcLink: List by parser.option( ArgType.String, description = "Global mapping between a source directory and a Web service for browsing the code. " + "Accepts multiple paths separated by semicolons" ).delimiter(";") - val helpSourceSet by parser.option( + public val helpSourceSet: Any? by parser.option( ArgTypeHelpSourceSet(_moduleName), description = "Prints help for nested -sourceSet configuration" ) - val loggingLevel by parser.option( + public val loggingLevel: LoggingLevel by parser.option( ArgType.Choice(toVariant = { when (it.toUpperCase().trim()) { "DEBUG", "" -> LoggingLevel.DEBUG @@ -134,7 +134,7 @@ class GlobalArguments(args: Array) : DokkaConfiguration { override val modules: List = emptyList() - val logger: DokkaLogger by lazy { + public val logger: DokkaLogger by lazy { DokkaConsoleLogger(loggingLevel) } diff --git a/runners/cli/src/main/kotlin/org/jetbrains/dokka/LinkMapper.kt b/runners/cli/src/main/kotlin/org/jetbrains/dokka/LinkMapper.kt index 7d22f6d9..dbfa8db1 100644 --- a/runners/cli/src/main/kotlin/org/jetbrains/dokka/LinkMapper.kt +++ b/runners/cli/src/main/kotlin/org/jetbrains/dokka/LinkMapper.kt @@ -9,7 +9,7 @@ import java.net.MalformedURLException import java.net.URL @OptIn(ExperimentalStdlibApi::class) // for buildList -fun defaultLinks(config: DokkaConfiguration.DokkaSourceSet): MutableList = +public fun defaultLinks(config: DokkaConfiguration.DokkaSourceSet): MutableList = buildList { if (!config.noJdkLink) { add(DokkaConfiguration.ExternalDocumentationLink.jdk(config.jdkVersion)) @@ -21,7 +21,7 @@ fun defaultLinks(config: DokkaConfiguration.DokkaSourceSet): MutableList): List { +public fun parseLinks(links: List): List { val (parsedLinks, parsedOfflineLinks) = links .map { it.split("^").map { it.trim() }.filter { it.isNotBlank() } } .filter { it.isNotEmpty() } diff --git a/runners/cli/src/main/kotlin/org/jetbrains/dokka/main.kt b/runners/cli/src/main/kotlin/org/jetbrains/dokka/main.kt index 4a2a27ca..e1949a93 100644 --- a/runners/cli/src/main/kotlin/org/jetbrains/dokka/main.kt +++ b/runners/cli/src/main/kotlin/org/jetbrains/dokka/main.kt @@ -8,13 +8,13 @@ import org.jetbrains.dokka.DokkaConfiguration.ExternalDocumentationLink import org.jetbrains.dokka.utilities.* import java.nio.file.Paths -fun main(args: Array) { +public fun main(args: Array) { val globalArguments = GlobalArguments(args) val configuration = initializeConfiguration(globalArguments) DokkaGenerator(configuration, globalArguments.logger).generate() } -fun initializeConfiguration(globalArguments: GlobalArguments): DokkaConfiguration { +public fun initializeConfiguration(globalArguments: GlobalArguments): DokkaConfiguration { return if (globalArguments.json != null) { val jsonContent = Paths.get(checkNotNull(globalArguments.json)).toFile().readText() val globals = GlobalDokkaConfiguration(jsonContent) -- cgit