aboutsummaryrefslogtreecommitdiff
path: root/integration-tests/cli
diff options
context:
space:
mode:
authorAndrzej Ratajczak <32793002+BarkingBad@users.noreply.github.com>2022-01-12 15:04:59 +0100
committerGitHub <noreply@github.com>2022-01-12 17:04:59 +0300
commit6b729257b89ff5a19a52045efa386349feec0bc6 (patch)
tree790ca1fc300466496dc18e045997d4818b7a50e1 /integration-tests/cli
parentb30db0aeafd5663dce3d3020f3dde6599ec368f3 (diff)
downloaddokka-6b729257b89ff5a19a52045efa386349feec0bc6.tar.gz
dokka-6b729257b89ff5a19a52045efa386349feec0bc6.tar.bz2
dokka-6b729257b89ff5a19a52045efa386349feec0bc6.zip
Add global settings to JSON dokka cli input (#2292)
* Add global settings to JSON dokka cli input * Apply requested changes * Move initialization of global arguments to extension function in core module
Diffstat (limited to 'integration-tests/cli')
-rw-r--r--integration-tests/cli/src/integrationTest/kotlin/org/jetbrains/dokka/it/cli/CliIntegrationTest.kt111
-rw-r--r--integration-tests/cli/src/integrationTest/kotlin/org/jetbrains/dokka/it/cli/jsonBuilder.kt52
-rw-r--r--integration-tests/cli/src/integrationTest/resources/my-file.json0
3 files changed, 162 insertions, 1 deletions
diff --git a/integration-tests/cli/src/integrationTest/kotlin/org/jetbrains/dokka/it/cli/CliIntegrationTest.kt b/integration-tests/cli/src/integrationTest/kotlin/org/jetbrains/dokka/it/cli/CliIntegrationTest.kt
index b87badd7..b94df32a 100644
--- a/integration-tests/cli/src/integrationTest/kotlin/org/jetbrains/dokka/it/cli/CliIntegrationTest.kt
+++ b/integration-tests/cli/src/integrationTest/kotlin/org/jetbrains/dokka/it/cli/CliIntegrationTest.kt
@@ -2,6 +2,8 @@ package org.jetbrains.dokka.it.cli
import org.jetbrains.dokka.it.awaitProcessResult
import java.io.File
+import java.io.PrintWriter
+import java.lang.IllegalStateException
import kotlin.test.*
class CliIntegrationTest : AbstractCliIntegrationTest() {
@@ -193,7 +195,7 @@ class CliIntegrationTest : AbstractCliIntegrationTest() {
}
@Test
- fun `logging level should be respected`(){
+ fun `logging level should be respected`() {
val dokkaOutputDir = File(projectDir, "output")
assertTrue(dokkaOutputDir.mkdirs())
val process = ProcessBuilder(
@@ -259,4 +261,111 @@ class CliIntegrationTest : AbstractCliIntegrationTest() {
)
)
}
+
+
+ @Test
+ fun `should accept json as input configuration`() {
+ val dokkaOutputDir = File(projectDir, "output")
+ assertTrue(dokkaOutputDir.mkdirs())
+ val jsonPath = javaClass.getResource("/my-file.json")?.path ?: throw IllegalStateException("No JSON found!")
+ PrintWriter(jsonPath).run {
+ write(jsonBuilder(dokkaOutputDir.path, basePluginJarFile.path, File(projectDir, "src").path, reportUndocumented = true))
+ close()
+ }
+
+ val process = ProcessBuilder(
+ "java", "-jar", cliJarFile.path, jsonPath
+ ).redirectErrorStream(true).start()
+
+ val result = process.awaitProcessResult()
+ assertEquals(0, result.exitCode, "Expected exitCode 0 (Success)")
+
+ val extensionLoadedRegex = Regex("""Extension: org\.jetbrains\.dokka\.base\.DokkaBase""")
+ val amountOfExtensionsLoaded = extensionLoadedRegex.findAll(result.output).count()
+
+ assertTrue(
+ amountOfExtensionsLoaded > 10,
+ "Expected more than 10 extensions being present (found $amountOfExtensionsLoaded)"
+ )
+
+ val undocumentedReportRegex = Regex("""Undocumented:""")
+ val amountOfUndocumentedReports = undocumentedReportRegex.findAll(result.output).count()
+ assertTrue(
+ amountOfUndocumentedReports > 0,
+ "Expected at least one report of undocumented code (found $amountOfUndocumentedReports)"
+ )
+
+ assertTrue(dokkaOutputDir.isDirectory, "Missing dokka output directory")
+ }
+
+ /**
+ * This test disables global `reportUndocumneted` property and set `reportUndocumented` via perPackageOptions to
+ * make sure that global settings apply to dokka context.
+ */
+ @Test
+ fun `global settings should overwrite package options in configuration`() {
+ val dokkaOutputDir = File(projectDir, "output")
+ assertTrue(dokkaOutputDir.mkdirs())
+ val jsonPath = javaClass.getResource("/my-file.json")?.path ?: throw IllegalStateException("No JSON found!")
+ PrintWriter(jsonPath).run {
+ write(
+ jsonBuilder(
+ outputPath = dokkaOutputDir.path,
+ pluginsClasspath = basePluginJarFile.path,
+ projectPath = File(projectDir, "src").path,
+ globalSourceLinks = """
+ {
+ "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"
+ }
+ """.trimIndent(),
+ globalExternalDocumentationLinks = """
+ {
+ "url": "https://docs.oracle.com/javase/8/docs/api/",
+ "packageListUrl": "https://docs.oracle.com/javase/8/docs/api/package-list"
+ },
+ {
+ "url": "https://kotlinlang.org/api/latest/jvm/stdlib/",
+ "packageListUrl": "https://kotlinlang.org/api/latest/jvm/stdlib/package-list"
+ }
+ """.trimIndent(),
+ globalPerPackageOptions = """
+ {
+ "matchingRegex": ".*",
+ "skipDeprecated": "true",
+ "reportUndocumented": "true",
+ "documentedVisibilities": ["PUBLIC", "PRIVATE", "PROTECTED", "INTERNAL", "PACKAGE"]
+ }
+ """.trimIndent(),
+ reportUndocumented = false
+ ),
+ )
+ close()
+ }
+
+ val process = ProcessBuilder(
+ "java", "-jar", cliJarFile.path, jsonPath
+ ).redirectErrorStream(true).start()
+
+ val result = process.awaitProcessResult()
+ assertEquals(0, result.exitCode, "Expected exitCode 0 (Success)")
+
+ val extensionLoadedRegex = Regex("""Extension: org\.jetbrains\.dokka\.base\.DokkaBase""")
+ val amountOfExtensionsLoaded = extensionLoadedRegex.findAll(result.output).count()
+
+ assertTrue(
+ amountOfExtensionsLoaded > 10,
+ "Expected more than 10 extensions being present (found $amountOfExtensionsLoaded)"
+ )
+
+ val undocumentedReportRegex = Regex("""Undocumented:""")
+ val amountOfUndocumentedReports = undocumentedReportRegex.findAll(result.output).count()
+ assertTrue(
+ amountOfUndocumentedReports > 0,
+ "Expected at least one report of undocumented code (found $amountOfUndocumentedReports)"
+ )
+
+ assertTrue(dokkaOutputDir.isDirectory, "Missing dokka output directory")
+ }
}
diff --git a/integration-tests/cli/src/integrationTest/kotlin/org/jetbrains/dokka/it/cli/jsonBuilder.kt b/integration-tests/cli/src/integrationTest/kotlin/org/jetbrains/dokka/it/cli/jsonBuilder.kt
new file mode 100644
index 00000000..d5d1df82
--- /dev/null
+++ b/integration-tests/cli/src/integrationTest/kotlin/org/jetbrains/dokka/it/cli/jsonBuilder.kt
@@ -0,0 +1,52 @@
+package org.jetbrains.dokka.it.cli
+
+fun jsonBuilder(
+ outputPath: String,
+ pluginsClasspath: String,
+ projectPath: String,
+ globalSourceLinks: String = "",
+ globalExternalDocumentationLinks: String = "",
+ globalPerPackageOptions: String = "",
+ reportUndocumented: Boolean = false
+
+): String {
+ return """{
+ "moduleName": "Dokka Example",
+ "moduleVersion": null,
+ "outputDir": "$outputPath",
+ "pluginsClasspath": ["$pluginsClasspath"],
+ "cacheRoot": null,
+ "offlineMode": false,
+ "sourceLinks": [$globalSourceLinks],
+ "externalDocumentationLinks": [$globalExternalDocumentationLinks],
+ "perPackageOptions": [$globalPerPackageOptions],
+ "sourceSets": [
+ {
+ "displayName": "jvm",
+ "sourceSetID": {
+ "scopeId": ":dokkaHtml",
+ "sourceSetName": "main"
+ },
+ "sourceRoots": [
+ "$projectPath"
+ ],
+ "dependentSourceSets": [],
+ "samples": [],
+ "includes": [],
+ "includeNonPublic": false,
+ "reportUndocumented": $reportUndocumented,
+ "skipEmptyPackages": true,
+ "skipDeprecated": false,
+ "jdkVersion": 8,
+ "sourceLinks": [],
+ "perPackageOptions": [],
+ "externalDocumentationLinks": [],
+ "noStdlibLink": false,
+ "noJdkLink": false,
+ "suppressedFiles": [],
+ "analysisPlatform": "jvm"
+ }
+ ]
+}
+"""
+}
diff --git a/integration-tests/cli/src/integrationTest/resources/my-file.json b/integration-tests/cli/src/integrationTest/resources/my-file.json
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/integration-tests/cli/src/integrationTest/resources/my-file.json