From 007aacb9ae3b228d0cef45ff5beb066b1dcd4cdc Mon Sep 17 00:00:00 2001 From: Paweł Marks Date: Fri, 15 Nov 2019 10:23:35 +0100 Subject: Adds simplest classpath checking for plugins --- core/src/main/kotlin/plugability/DokkaContext.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/core/src/main/kotlin/plugability/DokkaContext.kt b/core/src/main/kotlin/plugability/DokkaContext.kt index 7da4d9a7..b54d8ed0 100644 --- a/core/src/main/kotlin/plugability/DokkaContext.kt +++ b/core/src/main/kotlin/plugability/DokkaContext.kt @@ -20,8 +20,17 @@ class DokkaContext private constructor() { 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)) } + .let { URLClassLoader(it, this.javaClass.classLoader) } + .also { checkClasspath(it) } + .let { ServiceLoader.load(DokkaPlugin::class.java, it) } .forEach { install(it) } } } -} \ No newline at end of file + + 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") + } + } +} -- cgit