From 8a057a4611684a6a4616e136d480c005997070cd Mon Sep 17 00:00:00 2001 From: Paweł Marks Date: Tue, 19 Nov 2019 16:54:47 +0100 Subject: Working extensions in plugins --- core/src/main/kotlin/plugability/DokkaContext.kt | 30 ++++++++++++++++++------ 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'core/src/main/kotlin/plugability/DokkaContext.kt') 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() + private val plugins = mutableMapOf, DokkaPlugin>() + + internal val extensions = mutableMapOf, MutableList>>() + + @PublishedApi + internal fun plugin(kclass: KClass<*>) = plugins[kclass] val pluginNames: List - 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 + } } -- cgit