aboutsummaryrefslogtreecommitdiff
path: root/runners/cli
diff options
context:
space:
mode:
Diffstat (limited to 'runners/cli')
-rw-r--r--runners/cli/api/cli.api1
-rw-r--r--runners/cli/build.gradle.kts1
-rw-r--r--runners/cli/src/main/kotlin/cli/main.kt27
-rw-r--r--runners/cli/src/test/kotlin/cli/CliTest.kt30
-rw-r--r--runners/cli/src/test/resources/my-file.json51
5 files changed, 100 insertions, 10 deletions
diff --git a/runners/cli/api/cli.api b/runners/cli/api/cli.api
index e1e52c05..208235ae 100644
--- a/runners/cli/api/cli.api
+++ b/runners/cli/api/cli.api
@@ -89,6 +89,7 @@ public final class org/jetbrains/dokka/GlobalArguments : org/jetbrains/dokka/Dok
public final class org/jetbrains/dokka/MainKt {
public static final fun defaultLinks (Lorg/jetbrains/dokka/DokkaConfiguration$DokkaSourceSet;)Ljava/util/List;
+ public static final fun initializeConfiguration (Lorg/jetbrains/dokka/GlobalArguments;)Lorg/jetbrains/dokka/DokkaConfiguration;
public static final fun main ([Ljava/lang/String;)V
public static final fun parseLinks (Ljava/util/List;)Ljava/util/List;
}
diff --git a/runners/cli/build.gradle.kts b/runners/cli/build.gradle.kts
index 08fadec9..2785e92f 100644
--- a/runners/cli/build.gradle.kts
+++ b/runners/cli/build.gradle.kts
@@ -10,6 +10,7 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-cli-jvm:0.3.3")
implementation(project(":core"))
implementation(kotlin("stdlib"))
+ testImplementation(kotlin("test-junit"))
}
tasks {
diff --git a/runners/cli/src/main/kotlin/cli/main.kt b/runners/cli/src/main/kotlin/cli/main.kt
index 739539a9..1dc32a45 100644
--- a/runners/cli/src/main/kotlin/cli/main.kt
+++ b/runners/cli/src/main/kotlin/cli/main.kt
@@ -2,10 +2,7 @@ package org.jetbrains.dokka
import kotlinx.cli.*
import org.jetbrains.dokka.DokkaConfiguration.ExternalDocumentationLink
-import org.jetbrains.dokka.utilities.DokkaConsoleLogger
-import org.jetbrains.dokka.utilities.DokkaLogger
-import org.jetbrains.dokka.utilities.LoggingLevel
-import org.jetbrains.dokka.utilities.cast
+import org.jetbrains.dokka.utilities.*
import java.io.*
import java.net.MalformedURLException
import java.net.URL
@@ -80,6 +77,7 @@ class GlobalArguments(args: Array<String>) : DokkaConfiguration {
private val _includes by parser.option(
ArgTypeFile,
+ fullName = "includes",
description = "Markdown files that would be displayed in multi-module page separated by the semicolon `;`)"
).delimiter(";")
@@ -406,14 +404,23 @@ fun parseLinks(links: List<String>): List<ExternalDocumentationLink> {
}
}
+fun initializeConfiguration(globalArguments: GlobalArguments): DokkaConfiguration = if (globalArguments.json != null) {
+ val jsonContent = Paths.get(checkNotNull(globalArguments.json)).toFile().readText()
+ val globals = GlobalDokkaConfiguration(jsonContent)
+ val dokkaConfigurationImpl = DokkaConfigurationImpl(jsonContent)
+
+ dokkaConfigurationImpl.apply(globals).apply {
+ sourceSets.forEach {
+ it.externalDocumentationLinks.cast<MutableSet<ExternalDocumentationLink>>().addAll(defaultLinks(it))
+ }
+ }
+ } else {
+ globalArguments
+ }
+
fun main(args: Array<String>) {
val globalArguments = GlobalArguments(args)
- val configuration = if (globalArguments.json != null)
- DokkaConfigurationImpl(
- Paths.get(checkNotNull(globalArguments.json)).toFile().readText()
- )
- else
- globalArguments
+ val configuration = initializeConfiguration(globalArguments)
DokkaGenerator(configuration, globalArguments.logger).generate()
}
diff --git a/runners/cli/src/test/kotlin/cli/CliTest.kt b/runners/cli/src/test/kotlin/cli/CliTest.kt
new file mode 100644
index 00000000..5910e938
--- /dev/null
+++ b/runners/cli/src/test/kotlin/cli/CliTest.kt
@@ -0,0 +1,30 @@
+package org.jetbrains.dokka
+
+import junit.framework.Assert.assertTrue
+import org.junit.Test
+import java.lang.IllegalStateException
+import java.nio.file.Paths
+import kotlin.test.assertEquals
+
+class CliIntegrationTest {
+
+ @Test
+ fun `should apply global settings to all source sets`() {
+ val jsonPath = Paths.get(javaClass.getResource("/my-file.json")?.toURI() ?: throw IllegalStateException("No JSON found!")).toFile().toString()
+ val globalArguments = GlobalArguments(arrayOf(jsonPath))
+
+ val configuration = initializeConfiguration(globalArguments)
+
+ configuration.sourceSets.forEach {
+ assertTrue(it.perPackageOptions.isNotEmpty())
+ assertTrue(it.sourceLinks.isNotEmpty())
+ assertTrue(it.externalDocumentationLinks.isNotEmpty())
+
+ assertTrue(it.externalDocumentationLinks.any { it.url.toString() == "https://docs.oracle.com/javase/8/docs/api/" })
+ assertEquals(it.sourceLinks.single().localDirectory, "/home/Vadim.Mishenev/dokka/examples/cli/src/main/kotlin")
+ assertEquals(it.perPackageOptions.single().matchingRegex, "my-custom-regex")
+ }
+
+ }
+
+}
diff --git a/runners/cli/src/test/resources/my-file.json b/runners/cli/src/test/resources/my-file.json
new file mode 100644
index 00000000..49dda814
--- /dev/null
+++ b/runners/cli/src/test/resources/my-file.json
@@ -0,0 +1,51 @@
+{
+ "moduleName": "Dokka Example",
+ "moduleVersion": null,
+ "outputDir": "$outputPath",
+ "pluginsClasspath": ["$pluginsClasspath"],
+ "cacheRoot": null,
+ "offlineMode": false,
+ "sourceLinks": [{
+ "localDirectory": "/home/Vadim.Mishenev/dokka/examples/cli/src/main/kotlin",
+ "remoteUrl": "https://github.com/Kotlin/dokka/tree/master/examples/gradle/dokka-gradle-example/src/main/kotlin",
+ "remoteLineSuffix": "#L"
+ }],
+ "externalDocumentationLinks": [{
+ "url": "https://docs.oracle.com/javase/8/docs/api/",
+ "packageListUrl": "https://docs.oracle.com/javase/8/docs/api/package-list"
+ }],
+ "perPackageOptions": [{
+ "matchingRegex": "my-custom-regex",
+ "skipDeprecated": "true",
+ "reportUndocumented": "true",
+ "includeNonPublic": "true",
+ "documentedVisibilities": ["PUBLIC", "PRIVATE", "PROTECTED", "INTERNAL", "PACKAGE"]
+ }],
+ "sourceSets": [
+ {
+ "displayName": "jvm",
+ "sourceSetID": {
+ "scopeId": ":dokkaHtml",
+ "sourceSetName": "main"
+ },
+ "sourceRoots": [
+ "$projectPath"
+ ],
+ "dependentSourceSets": [],
+ "samples": [],
+ "includes": [],
+ "includeNonPublic": false,
+ "reportUndocumented": false,
+ "skipEmptyPackages": true,
+ "skipDeprecated": false,
+ "jdkVersion": 8,
+ "sourceLinks": [],
+ "perPackageOptions": [],
+ "externalDocumentationLinks": [],
+ "noStdlibLink": false,
+ "noJdkLink": false,
+ "suppressedFiles": [],
+ "analysisPlatform": "jvm"
+ }
+ ]
+}