aboutsummaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorsebastian.sellmair <sebastian.sellmair@jetbrains.com>2020-07-18 12:18:59 +0200
committerSebastian Sellmair <34319766+sellmair@users.noreply.github.com>2020-08-14 17:51:11 +0200
commiteae1ce49d18c2978b49166ea502bf2c109a85504 (patch)
tree477f39e33f14c71042f06eecc938d6efaa95e66c /core/src
parent6c635551ed3ea0cfe5f04b54a98cb28225061d26 (diff)
downloaddokka-eae1ce49d18c2978b49166ea502bf2c109a85504.tar.gz
dokka-eae1ce49d18c2978b49166ea502bf2c109a85504.tar.bz2
dokka-eae1ce49d18c2978b49166ea502bf2c109a85504.zip
Simplify Dokka Gradle Plugin
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/kotlin/DokkaBootstrapImpl.kt34
-rw-r--r--core/src/main/kotlin/configuration.kt46
-rw-r--r--core/src/main/kotlin/defaultConfiguration.kt25
-rw-r--r--core/src/main/kotlin/utilities/json.kt4
-rw-r--r--core/src/test/kotlin/utilities/DokkaConfigurationJsonTest.kt10
5 files changed, 57 insertions, 62 deletions
diff --git a/core/src/main/kotlin/DokkaBootstrapImpl.kt b/core/src/main/kotlin/DokkaBootstrapImpl.kt
index a2efab41..584d8b8c 100644
--- a/core/src/main/kotlin/DokkaBootstrapImpl.kt
+++ b/core/src/main/kotlin/DokkaBootstrapImpl.kt
@@ -70,38 +70,8 @@ class DokkaBootstrapImpl : DokkaBootstrap {
private lateinit var generator: DokkaGenerator
- fun configure(logger: DokkaLogger, configuration: DokkaConfigurationImpl) = with(configuration) {
-
- fun defaultLinks(config: DokkaSourceSetImpl): List<ExternalDocumentationLinkImpl> {
- val links = mutableListOf<ExternalDocumentationLinkImpl>()
- if (!config.noJdkLink) {
- val javadocLink =
- if (config.jdkVersion < 11) "https://docs.oracle.com/javase/${config.jdkVersion}/docs/api/"
- else "https://docs.oracle.com/en/java/javase/${config.jdkVersion}/docs/api/java.base/"
- val packageListLink =
- if (config.jdkVersion < 11) "${javadocLink}/package-list"
- else "https://docs.oracle.com/en/java/javase/${config.jdkVersion}/docs/api/element-list"
- links += DokkaConfiguration.ExternalDocumentationLink
- .Builder(javadocLink, packageListLink)
- .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(
- sourceSets = sourceSets.map {
- val links: List<ExternalDocumentationLinkImpl> =
- it.externalDocumentationLinks + defaultLinks(it)
- it.copy(externalDocumentationLinks = links)
- }
- )
-
- generator = DokkaGenerator(configurationWithLinks, logger)
+ fun configure(logger: DokkaLogger, configuration: DokkaConfigurationImpl) {
+ generator = DokkaGenerator(configuration, logger)
}
override fun configure(serializedConfigurationJSON: String, logger: BiConsumer<String, String>) = configure(
diff --git a/core/src/main/kotlin/configuration.kt b/core/src/main/kotlin/configuration.kt
index 91ee4d64..67c55861 100644
--- a/core/src/main/kotlin/configuration.kt
+++ b/core/src/main/kotlin/configuration.kt
@@ -2,16 +2,16 @@
package org.jetbrains.dokka
-import org.jetbrains.dokka.utilities.toJsonString
import org.jetbrains.dokka.utilities.parseJson
+import org.jetbrains.dokka.utilities.toJsonString
import java.io.File
import java.io.Serializable
import java.net.URL
object DokkaDefaults {
- const val outputDir = "./dokka"
+ val outputDir = File("./dokka")
const val format: String = "html"
- val cacheRoot: String? = null
+ val cacheRoot: File? = null
const val offlineMode: Boolean = false
const val failOnWarning: Boolean = false
@@ -51,6 +51,14 @@ enum class Platform(val key: String) {
}
}
+interface DokkaConfigurationBuilder<T : Any> {
+ fun build(): T
+}
+
+fun <T : Any> Iterable<DokkaConfigurationBuilder<T>>.build(): List<T> {
+ return this.map { it.build() }
+}
+
data class DokkaSourceSetID(
val moduleName: String,
val sourceSetName: String
@@ -65,8 +73,8 @@ fun DokkaConfigurationImpl(json: String): DokkaConfigurationImpl = parseJson(jso
fun DokkaConfiguration.toJsonString(): String = toJsonString(this)
interface DokkaConfiguration : Serializable {
- val outputDir: String
- val cacheRoot: String?
+ val outputDir: File
+ val cacheRoot: File?
val offlineMode: Boolean
val failOnWarning: Boolean
val sourceSets: List<DokkaSourceSet>
@@ -78,11 +86,11 @@ interface DokkaConfiguration : Serializable {
val sourceSetID: DokkaSourceSetID
val displayName: String
val moduleDisplayName: String
- val classpath: List<String>
+ val classpath: List<File>
val sourceRoots: List<SourceRoot>
val dependentSourceSets: Set<DokkaSourceSetID>
- val samples: List<String>
- val includes: List<String>
+ val samples: List<File>
+ val includes: List<File>
val includeNonPublic: Boolean
val includeRootPackage: Boolean
val reportUndocumented: Boolean
@@ -96,12 +104,12 @@ interface DokkaConfiguration : Serializable {
val apiVersion: String?
val noStdlibLink: Boolean
val noJdkLink: Boolean
- val suppressedFiles: List<String>
+ val suppressedFiles: List<File>
val analysisPlatform: Platform
}
interface SourceRoot : Serializable {
- val path: String
+ val directory: File
}
interface SourceLinkDefinition : Serializable {
@@ -112,8 +120,8 @@ interface DokkaConfiguration : Serializable {
interface DokkaModuleDescription : Serializable {
val name: String
- val path: String
- val docFile: String
+ val path: File
+ val docFile: File
}
interface PackageOptions : Serializable {
@@ -135,7 +143,7 @@ interface DokkaConfiguration : Serializable {
constructor(root: String, packageList: String? = null) : this(URL(root), packageList?.let { URL(it) })
- fun build(): ExternalDocumentationLink =
+ fun build(): ExternalDocumentationLinkImpl =
if (packageListUrl != null && url != null)
ExternalDocumentationLinkImpl(url!!, packageListUrl!!)
else if (url != null)
@@ -146,4 +154,16 @@ interface DokkaConfiguration : Serializable {
}
}
+fun ExternalDocumentationLink(
+ url: URL? = null,
+ packageListUrl: URL? = null
+): ExternalDocumentationLinkImpl =
+ DokkaConfiguration.ExternalDocumentationLink.Builder(url = url, packageListUrl = packageListUrl).build()
+
+
+fun ExternalDocumentationLink(
+ url: String, packageListUrl: String? = null
+): ExternalDocumentationLinkImpl =
+ DokkaConfiguration.ExternalDocumentationLink.Builder(root = url, packageList = packageListUrl).build()
+
diff --git a/core/src/main/kotlin/defaultConfiguration.kt b/core/src/main/kotlin/defaultConfiguration.kt
index 8e38e8d5..384ce392 100644
--- a/core/src/main/kotlin/defaultConfiguration.kt
+++ b/core/src/main/kotlin/defaultConfiguration.kt
@@ -3,10 +3,12 @@ package org.jetbrains.dokka
import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet
import java.io.File
import java.net.URL
+import kotlin.reflect.full.memberProperties
+import kotlin.reflect.full.primaryConstructor
data class DokkaConfigurationImpl(
- override val outputDir: String = DokkaDefaults.outputDir,
- override val cacheRoot: String? = DokkaDefaults.cacheRoot,
+ override val outputDir: File = DokkaDefaults.outputDir,
+ override val cacheRoot: File? = DokkaDefaults.cacheRoot,
override val offlineMode: Boolean = DokkaDefaults.offlineMode,
override val sourceSets: List<DokkaSourceSetImpl> = emptyList(),
override val pluginsClasspath: List<File> = emptyList(),
@@ -15,15 +17,16 @@ data class DokkaConfigurationImpl(
override val failOnWarning: Boolean = DokkaDefaults.failOnWarning
) : DokkaConfiguration
+
data class DokkaSourceSetImpl(
override val moduleDisplayName: String,
override val displayName: String = DokkaDefaults.sourceSetDisplayName,
override val sourceSetID: DokkaSourceSetID,
- override val classpath: List<String> = emptyList(),
+ override val classpath: List<File> = emptyList(),
override val sourceRoots: List<SourceRootImpl>,
override val dependentSourceSets: Set<DokkaSourceSetID> = emptySet(),
- override val samples: List<String> = emptyList(),
- override val includes: List<String> = emptyList(),
+ override val samples: List<File> = emptyList(),
+ override val includes: List<File> = emptyList(),
override val includeNonPublic: Boolean = DokkaDefaults.includeNonPublic,
override val includeRootPackage: Boolean = DokkaDefaults.includeRootPackage,
override val reportUndocumented: Boolean = DokkaDefaults.reportUndocumented,
@@ -37,19 +40,21 @@ data class DokkaSourceSetImpl(
override val apiVersion: String? = null,
override val noStdlibLink: Boolean = DokkaDefaults.noStdlibLink,
override val noJdkLink: Boolean = DokkaDefaults.noJdkLink,
- override val suppressedFiles: List<String> = emptyList(),
+ override val suppressedFiles: List<File> = emptyList(),
override val analysisPlatform: Platform = DokkaDefaults.analysisPlatform
) : DokkaSourceSet
data class DokkaModuleDescriptionImpl(
override val name: String,
- override val path: String,
- override val docFile: String
+ override val path: File,
+ override val docFile: File
) : DokkaConfiguration.DokkaModuleDescription
data class SourceRootImpl(
- override val path: String
-) : DokkaConfiguration.SourceRoot
+ override val directory: File
+) : DokkaConfiguration.SourceRoot {
+ constructor(directoryPath: String) : this(File(directoryPath))
+}
data class SourceLinkDefinitionImpl(
override val path: String,
diff --git a/core/src/main/kotlin/utilities/json.kt b/core/src/main/kotlin/utilities/json.kt
index 9e4677aa..feac2b23 100644
--- a/core/src/main/kotlin/utilities/json.kt
+++ b/core/src/main/kotlin/utilities/json.kt
@@ -56,10 +56,10 @@ private object FileSerializer : StdScalarSerializer<File>(File::class.java) {
private object SourceRootSerializer : StdScalarSerializer<SourceRoot>(SourceRoot::class.java) {
override fun serialize(value: SourceRoot, g: JsonGenerator, provider: SerializerProvider) {
- g.writeString(value.path)
+ g.writeString(value.directory.path)
}
}
private object SourceRootImplDeserializer : StdScalarDeserializer<SourceRootImpl>(SourceRootImpl::class.java) {
- override fun deserialize(p: JsonParser, ctxt: DeserializationContext): SourceRootImpl = SourceRootImpl(p.text)
+ override fun deserialize(p: JsonParser, ctxt: DeserializationContext): SourceRootImpl = SourceRootImpl(File(p.text))
}
diff --git a/core/src/test/kotlin/utilities/DokkaConfigurationJsonTest.kt b/core/src/test/kotlin/utilities/DokkaConfigurationJsonTest.kt
index e954c82c..35755f50 100644
--- a/core/src/test/kotlin/utilities/DokkaConfigurationJsonTest.kt
+++ b/core/src/test/kotlin/utilities/DokkaConfigurationJsonTest.kt
@@ -9,12 +9,12 @@ class DokkaConfigurationJsonTest {
@Test
fun `simple configuration toJsonString then parseJson`() {
val configuration = DokkaConfigurationImpl(
- outputDir = "customOutputDir",
+ outputDir = File("customOutputDir"),
pluginsClasspath = listOf(File("plugins/customPlugin.jar")),
sourceSets = listOf(
DokkaSourceSetImpl(
moduleDisplayName = "customModuleDisplayName",
- sourceRoots = listOf(SourceRootImpl("customSourceRoot")),
+ sourceRoots = listOf(SourceRootImpl(File("customSourceRoot"))),
sourceSetID = DokkaSourceSetID("customModuleName", "customSourceSetName")
)
)
@@ -48,14 +48,14 @@ class DokkaConfigurationJsonTest {
val parsedConfiguration = DokkaConfigurationImpl(json)
assertEquals(
DokkaConfigurationImpl(
- outputDir = "customOutputDir",
+ outputDir = File("customOutputDir"),
pluginsClasspath = listOf(File("plugins/customPlugin.jar")),
sourceSets = listOf(
DokkaSourceSetImpl(
moduleDisplayName = "customModuleDisplayName",
- sourceRoots = listOf(SourceRootImpl("customSourceRoot")),
+ sourceRoots = listOf(SourceRootImpl(File("customSourceRoot"))),
sourceSetID = DokkaSourceSetID("customModuleName", "customSourceSetName"),
- classpath = listOf("classpath/custom1.jar", "classpath/custom2.jar")
+ classpath = listOf(File("classpath/custom1.jar"), File("classpath/custom2.jar"))
)
)
),