diff options
author | Andrzej Ratajczak <andrzej.ratajczak98@gmail.com> | 2020-04-01 17:02:18 +0200 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-04-30 12:37:30 +0200 |
commit | 7f9d595f604e269fb918dc69cf2f80c19aef58c2 (patch) | |
tree | 132d84a71c3aae87894ecce9a618ca9df12f2dc7 /core/src/main | |
parent | badb811e6de55c460301ae3f911f3d7c0dc9e39e (diff) | |
download | dokka-7f9d595f604e269fb918dc69cf2f80c19aef58c2.tar.gz dokka-7f9d595f604e269fb918dc69cf2f80c19aef58c2.tar.bz2 dokka-7f9d595f604e269fb918dc69cf2f80c19aef58c2.zip |
Adds possibility to configure plugins
Diffstat (limited to 'core/src/main')
-rw-r--r-- | core/src/main/kotlin/configuration.kt | 3 | ||||
-rw-r--r-- | core/src/main/kotlin/defaultConfiguration.kt | 3 | ||||
-rw-r--r-- | core/src/main/kotlin/plugability/DokkaPlugin.kt | 26 |
3 files changed, 31 insertions, 1 deletions
diff --git a/core/src/main/kotlin/configuration.kt b/core/src/main/kotlin/configuration.kt index 19835fa4..34671c4e 100644 --- a/core/src/main/kotlin/configuration.kt +++ b/core/src/main/kotlin/configuration.kt @@ -33,6 +33,7 @@ interface DokkaConfiguration { val passesConfigurations: List<PassConfiguration> val impliedPlatforms: List<String> val pluginsClasspath: List<File> + val pluginsConfiguration: Map<String, String> interface PassConfiguration { val moduleName: String @@ -100,3 +101,5 @@ interface DokkaConfiguration { } } } + + diff --git a/core/src/main/kotlin/defaultConfiguration.kt b/core/src/main/kotlin/defaultConfiguration.kt index b0c12015..ae674ea1 100644 --- a/core/src/main/kotlin/defaultConfiguration.kt +++ b/core/src/main/kotlin/defaultConfiguration.kt @@ -10,7 +10,8 @@ data class DokkaConfigurationImpl( override val cacheRoot: String?, override val impliedPlatforms: List<String>, override val passesConfigurations: List<PassConfigurationImpl>, - override var pluginsClasspath: List<File> + override val pluginsClasspath: List<File>, + override val pluginsConfiguration: Map<String, String> ) : DokkaConfiguration data class PassConfigurationImpl ( diff --git a/core/src/main/kotlin/plugability/DokkaPlugin.kt b/core/src/main/kotlin/plugability/DokkaPlugin.kt index d8fb7892..24f417d8 100644 --- a/core/src/main/kotlin/plugability/DokkaPlugin.kt +++ b/core/src/main/kotlin/plugability/DokkaPlugin.kt @@ -1,9 +1,12 @@ package org.jetbrains.dokka.plugability +import com.google.gson.Gson import org.jetbrains.dokka.DokkaConfiguration +import org.jetbrains.kotlin.utils.addToStdlib.cast import kotlin.properties.ReadOnlyProperty import kotlin.reflect.KProperty import kotlin.reflect.KProperty1 +import kotlin.reflect.full.createInstance private typealias ExtensionDelegate<T> = ReadOnlyProperty<DokkaPlugin, Extension<T>> @@ -49,6 +52,18 @@ abstract class DokkaPlugin { } } +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) + pluginsConfiguration.cast<MutableMap<String, String>>()[P::class.qualifiedName!!] = + Gson().toJson(instance, T::class.java) +} + inline fun <reified P : DokkaPlugin, reified E : Any> P.query(extension: P.() -> ExtensionPoint<E>): List<E> = context?.let { it[extension()] } ?: throwIllegalQuery() @@ -57,3 +72,14 @@ 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 object : ReadOnlyProperty<Any?, R> { + override fun getValue(thisRef: Any?, property: KProperty<*>): R { + return context.configuration.pluginsConfiguration.get(T::class.qualifiedName + ?: throw AssertionError("Plugin must be named class")).let { + Gson().fromJson(it, R::class.java) + } + } + } +}
\ No newline at end of file |