aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/plugability/DokkaContext.kt
diff options
context:
space:
mode:
authorPaweł Marks <pmarks@virtuslab.com>2019-11-19 16:54:47 +0100
committerBłażej Kardyś <bkardys@virtuslab.com>2019-11-25 16:24:16 +0100
commit8a057a4611684a6a4616e136d480c005997070cd (patch)
tree47068c1ae3af98ce82a6f66c5eea52aa67d823c6 /core/src/main/kotlin/plugability/DokkaContext.kt
parent007aacb9ae3b228d0cef45ff5beb066b1dcd4cdc (diff)
downloaddokka-8a057a4611684a6a4616e136d480c005997070cd.tar.gz
dokka-8a057a4611684a6a4616e136d480c005997070cd.tar.bz2
dokka-8a057a4611684a6a4616e136d480c005997070cd.zip
Working extensions in plugins
Diffstat (limited to 'core/src/main/kotlin/plugability/DokkaContext.kt')
-rw-r--r--core/src/main/kotlin/plugability/DokkaContext.kt30
1 files changed, 23 insertions, 7 deletions
diff --git a/core/src/main/kotlin/plugability/DokkaContext.kt b/core/src/main/kotlin/plugability/DokkaContext.kt
index b54d8ed0..d67f34b1 100644
--- a/core/src/main/kotlin/plugability/DokkaContext.kt
+++ b/core/src/main/kotlin/plugability/DokkaContext.kt
@@ -3,17 +3,27 @@ package org.jetbrains.dokka.plugability
import java.io.File
import java.net.URLClassLoader
import java.util.*
+import kotlin.reflect.KClass
class DokkaContext private constructor() {
- private val plugins = mutableListOf<DokkaPlugin>()
+ private val plugins = mutableMapOf<KClass<*>, DokkaPlugin>()
+
+ internal val extensions = mutableMapOf<ExtensionPoint<*>, MutableList<Extension<*>>>()
+
+ @PublishedApi
+ internal fun plugin(kclass: KClass<*>) = plugins[kclass]
val pluginNames: List<String>
- get() = plugins.map { it.name }
+ get() = plugins.values.map { it::class.qualifiedName.toString() }
+
+ val loadedListForDebug
+ get() = extensions.run { keys + values.flatten() }.toList()
+ .joinToString(prefix = "[\n", separator = ",\n", postfix = "\n]") { "\t$it" }
private fun install(plugin: DokkaPlugin) {
- plugins += plugin
- plugin.install(this)
+ plugins[plugin::class] = plugin
+ plugin.internalInstall(this)
}
companion object {
@@ -28,9 +38,15 @@ class DokkaContext private constructor() {
}
private fun checkClasspath(classLoader: URLClassLoader) {
- classLoader.findResource(javaClass.name.replace('.','/') + ".class")?.also {
- throw AssertionError("Dokka API found on plugins classpath. This will lead to subtle bugs. " +
- "Please fix your plugins dependencies or exclude dokka api artifact from plugin classpath")
+ classLoader.findResource(javaClass.name.replace('.', '/') + ".class")?.also {
+ throw AssertionError(
+ "Dokka API found on plugins classpath. This will lead to subtle bugs. " +
+ "Please fix your plugins dependencies or exclude dokka api artifact from plugin classpath"
+ )
}
}
+
+ internal fun addExtension(it: Extension<*>) {
+ extensions.getOrPut(it.extensionPoint, ::mutableListOf) += it
+ }
}