aboutsummaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorMarcin Aman <marcin.aman@gmail.com>2020-10-07 13:58:46 +0200
committerGitHub <noreply@github.com>2020-10-07 13:58:46 +0200
commite9f5da45c0fcfec5f7c150229301904d7915e090 (patch)
treec094b57b37fec4c901bbfaa508268d354a4dc4c8 /core/src
parentde6019337ae0e97e73db7fa9394e88ec2de4aeed (diff)
downloaddokka-e9f5da45c0fcfec5f7c150229301904d7915e090.tar.gz
dokka-e9f5da45c0fcfec5f7c150229301904d7915e090.tar.bz2
dokka-e9f5da45c0fcfec5f7c150229301904d7915e090.zip
Make logo replaceable #1339 (#1488)
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/kotlin/configuration.kt15
-rw-r--r--core/src/main/kotlin/defaultConfiguration.kt8
-rw-r--r--core/src/main/kotlin/plugability/DokkaPlugin.kt42
3 files changed, 39 insertions, 26 deletions
diff --git a/core/src/main/kotlin/configuration.kt b/core/src/main/kotlin/configuration.kt
index f5b2254a..bc097ae4 100644
--- a/core/src/main/kotlin/configuration.kt
+++ b/core/src/main/kotlin/configuration.kt
@@ -2,6 +2,7 @@
package org.jetbrains.dokka
+import org.jetbrains.dokka.plugability.ConfigurableBlock
import org.jetbrains.dokka.utilities.parseJson
import org.jetbrains.dokka.utilities.toJsonString
import java.io.File
@@ -29,6 +30,7 @@ object DokkaDefaults {
const val sourceSetDisplayName = "JVM"
const val sourceSetName = "main"
val moduleVersion: String? = null
+ val pluginsConfiguration = mutableListOf<PluginConfigurationImpl>()
}
enum class Platform(val key: String) {
@@ -81,6 +83,7 @@ data class DokkaSourceSetID(
fun DokkaConfigurationImpl(json: String): DokkaConfigurationImpl = parseJson(json)
fun DokkaConfiguration.toJsonString(): String = toJsonString(this)
+fun <T : ConfigurableBlock> T.toJsonString(): String = toJsonString(this)
interface DokkaConfiguration : Serializable {
val moduleName: String
@@ -92,7 +95,17 @@ interface DokkaConfiguration : Serializable {
val sourceSets: List<DokkaSourceSet>
val modules: List<DokkaModuleDescription>
val pluginsClasspath: List<File>
- val pluginsConfiguration: Map<String, String>
+ val pluginsConfiguration: List<PluginConfiguration>
+
+ enum class SerializationFormat : Serializable {
+ JSON, XML
+ }
+
+ interface PluginConfiguration : Serializable {
+ val fqPluginName: String
+ val serializationFormat: SerializationFormat
+ val values: String
+ }
interface DokkaSourceSet : Serializable {
val sourceSetID: DokkaSourceSetID
diff --git a/core/src/main/kotlin/defaultConfiguration.kt b/core/src/main/kotlin/defaultConfiguration.kt
index 45bf904d..a28df152 100644
--- a/core/src/main/kotlin/defaultConfiguration.kt
+++ b/core/src/main/kotlin/defaultConfiguration.kt
@@ -12,11 +12,17 @@ data class DokkaConfigurationImpl(
override val offlineMode: Boolean = DokkaDefaults.offlineMode,
override val sourceSets: List<DokkaSourceSetImpl> = emptyList(),
override val pluginsClasspath: List<File> = emptyList(),
- override val pluginsConfiguration: Map<String, String> = emptyMap(),
+ override val pluginsConfiguration: List<PluginConfigurationImpl> = DokkaDefaults.pluginsConfiguration,
override val modules: List<DokkaModuleDescriptionImpl> = emptyList(),
override val failOnWarning: Boolean = DokkaDefaults.failOnWarning
) : DokkaConfiguration
+data class PluginConfigurationImpl(
+ override val fqPluginName: String,
+ override val serializationFormat: DokkaConfiguration.SerializationFormat,
+ override val values: String
+) : DokkaConfiguration.PluginConfiguration
+
data class DokkaSourceSetImpl(
override val displayName: String = DokkaDefaults.sourceSetDisplayName,
diff --git a/core/src/main/kotlin/plugability/DokkaPlugin.kt b/core/src/main/kotlin/plugability/DokkaPlugin.kt
index 13f59f6e..625a34e2 100644
--- a/core/src/main/kotlin/plugability/DokkaPlugin.kt
+++ b/core/src/main/kotlin/plugability/DokkaPlugin.kt
@@ -1,12 +1,13 @@
package org.jetbrains.dokka.plugability
+import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule
+import com.fasterxml.jackson.dataformat.xml.XmlMapper
+import com.fasterxml.jackson.module.kotlin.readValue
import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.utilities.parseJson
-import org.jetbrains.dokka.utilities.toJsonString
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
import kotlin.reflect.KProperty1
-import kotlin.reflect.full.createInstance
abstract class DokkaPlugin {
private val extensionDelegates = mutableListOf<KProperty<*>>()
@@ -40,12 +41,12 @@ abstract class DokkaPlugin {
internal fun internalInstall(ctx: DokkaContextConfiguration, configuration: DokkaConfiguration) {
val extensionsToInstall = extensionDelegates.asSequence()
.filterIsInstance<KProperty1<DokkaPlugin, Extension<*, *, *>>>() // should be always true
- .map { it.get(this) } + unsafePlugins.map{ it.value }
+ .map { it.get(this) } + unsafePlugins.map { it.value }
extensionsToInstall.forEach { if (configuration.(it.condition)()) ctx.installExtension(it) }
}
- protected fun <T: Any> unsafeInstall(ext: Lazy<Extension<T, *, *>>){
- unsafePlugins.add(ext)
+ protected fun <T : Any> unsafeInstall(ext: Lazy<Extension<T, *, *>>) {
+ unsafePlugins.add(ext)
}
}
@@ -53,19 +54,8 @@ interface WithUnsafeExtensionSuppression {
val extensionsSuppressed: List<Extension<*, *, *>>
}
-interface Configurable {
- val pluginsConfiguration: Map<String, String>
-}
-
interface ConfigurableBlock
-inline fun <reified P : DokkaPlugin, reified T : ConfigurableBlock> Configurable.pluginConfiguration(block: T.() -> Unit) {
- val instance = T::class.createInstance().apply(block)
-
- val mutablePluginsConfiguration = pluginsConfiguration as MutableMap<String, String>
- mutablePluginsConfiguration[P::class.qualifiedName!!] = toJsonString(instance)
-}
-
inline fun <reified P : DokkaPlugin, reified E : Any> P.query(extension: P.() -> ExtensionPoint<E>): List<E> =
context?.let { it[extension()] } ?: throwIllegalQuery()
@@ -75,11 +65,15 @@ inline fun <reified P : DokkaPlugin, reified E : Any> P.querySingle(extension: P
fun throwIllegalQuery(): Nothing =
throw IllegalStateException("Querying about plugins is only possible with dokka context initialised")
-inline fun <reified T : DokkaPlugin, reified R : ConfigurableBlock> configuration(context: DokkaContext): ReadOnlyProperty<Any?, R> {
- return ReadOnlyProperty { _, _ ->
- val configuration = context.configuration.pluginsConfiguration[
- T::class.qualifiedName ?: throw AssertionError("Plugin must be named class")
- ]
- parseJson(checkNotNull(configuration))
- }
-}
+inline fun <reified T : DokkaPlugin, reified R : ConfigurableBlock> configuration(context: DokkaContext): R? =
+ context.configuration.pluginsConfiguration.firstOrNull { it.fqPluginName == T::class.qualifiedName }
+ ?.let { configuration ->
+ when (configuration.serializationFormat) {
+ DokkaConfiguration.SerializationFormat.JSON -> parseJson(configuration.values)
+ DokkaConfiguration.SerializationFormat.XML -> XmlMapper(JacksonXmlModule().apply {
+ setDefaultUseWrapper(
+ true
+ )
+ }).readValue<R>(configuration.values)
+ }
+ }