From dac6ba2a589aa1e8a9f4a9c7af32026be77776b3 Mon Sep 17 00:00:00 2001 From: Paweł Marks Date: Thu, 14 Nov 2019 15:18:56 +0100 Subject: First plugin draft --- core/src/main/kotlin/DokkaGenerator.kt | 14 +++++++++++- core/src/main/kotlin/plugability/DokkaContext.kt | 27 ++++++++++++++++++++++++ core/src/main/kotlin/plugability/DokkaPlugin.kt | 6 ++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 core/src/main/kotlin/plugability/DokkaContext.kt create mode 100644 core/src/main/kotlin/plugability/DokkaPlugin.kt (limited to 'core/src') diff --git a/core/src/main/kotlin/DokkaGenerator.kt b/core/src/main/kotlin/DokkaGenerator.kt index 11f583b3..a522ea40 100644 --- a/core/src/main/kotlin/DokkaGenerator.kt +++ b/core/src/main/kotlin/DokkaGenerator.kt @@ -2,11 +2,11 @@ package org.jetbrains.dokka import org.jetbrains.dokka.Model.Module import org.jetbrains.dokka.Model.transformers.DocumentationNodesMerger -//import org.jetbrains.dokka.Utilities.genericPretty import org.jetbrains.dokka.Utilities.pretty import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.pages.MarkdownToContentConverter import org.jetbrains.dokka.pages.PlatformData +import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.renderers.FileWriter import org.jetbrains.dokka.renderers.HtmlRenderer import org.jetbrains.dokka.resolvers.DefaultLocationProvider @@ -23,6 +23,18 @@ class DokkaGenerator( private val logger: DokkaLogger ) { fun generate(): Unit { + + logger.info("Initializing plugins") + val context = DokkaContext.from(configuration.pluginsClasspath) + context.pluginNames.also { names -> + logger.info("Loaded plugins: $names") + names.groupingBy { it }.eachCount().filter { it.value > 1 }.forEach { + logger.warn("Duplicate plugin name: ${it.key}. It will make debugging much harder.") + } + } + + + configuration.passesConfigurations.map { pass -> AnalysisEnvironment(DokkaMessageCollector(logger), pass.analysisPlatform).run { if (analysisPlatform == Platform.jvm) { diff --git a/core/src/main/kotlin/plugability/DokkaContext.kt b/core/src/main/kotlin/plugability/DokkaContext.kt new file mode 100644 index 00000000..7da4d9a7 --- /dev/null +++ b/core/src/main/kotlin/plugability/DokkaContext.kt @@ -0,0 +1,27 @@ +package org.jetbrains.dokka.plugability + +import java.io.File +import java.net.URLClassLoader +import java.util.* + + +class DokkaContext private constructor() { + private val plugins = mutableListOf() + + val pluginNames: List + get() = plugins.map { it.name } + + private fun install(plugin: DokkaPlugin) { + plugins += plugin + plugin.install(this) + } + + companion object { + fun from(pluginsClasspath: Iterable) = DokkaContext().apply { + pluginsClasspath.map { it.relativeTo(File(".").absoluteFile).toURI().toURL() } + .toTypedArray() + .let { ServiceLoader.load(DokkaPlugin::class.java, URLClassLoader(it, this.javaClass.classLoader)) } + .forEach { install(it) } + } + } +} \ No newline at end of file diff --git a/core/src/main/kotlin/plugability/DokkaPlugin.kt b/core/src/main/kotlin/plugability/DokkaPlugin.kt new file mode 100644 index 00000000..2654bcee --- /dev/null +++ b/core/src/main/kotlin/plugability/DokkaPlugin.kt @@ -0,0 +1,6 @@ +package org.jetbrains.dokka.plugability + +interface DokkaPlugin { + val name: String + fun install(context: DokkaContext) +} \ No newline at end of file -- cgit