aboutsummaryrefslogtreecommitdiff
path: root/runners
diff options
context:
space:
mode:
authorSimon Ogorodnik <Simon.Ogorodnik@jetbrains.com>2016-12-06 16:05:01 +0300
committerSimon Ogorodnik <Simon.Ogorodnik@jetbrains.com>2016-12-06 16:05:01 +0300
commit546e8edfd95c16665319bc371c6ccf63706ad1e4 (patch)
tree1db397a9efc5545c1e27db3fc2d920cfab35550a /runners
parent13bda7371cc60beaa4cc8302239efd21695b9e1f (diff)
downloaddokka-546e8edfd95c16665319bc371c6ccf63706ad1e4.tar.gz
dokka-546e8edfd95c16665319bc371c6ccf63706ad1e4.tar.bz2
dokka-546e8edfd95c16665319bc371c6ccf63706ad1e4.zip
Post-review changes, simplified proxies
Diffstat (limited to 'runners')
-rw-r--r--runners/gradle-plugin/src/main/kotlin/ProxyUtils.kt46
-rw-r--r--runners/gradle-plugin/src/main/kotlin/logger.kt18
-rw-r--r--runners/gradle-plugin/src/main/kotlin/main.kt19
3 files changed, 56 insertions, 27 deletions
diff --git a/runners/gradle-plugin/src/main/kotlin/ProxyUtils.kt b/runners/gradle-plugin/src/main/kotlin/ProxyUtils.kt
new file mode 100644
index 00000000..7bdf2f9d
--- /dev/null
+++ b/runners/gradle-plugin/src/main/kotlin/ProxyUtils.kt
@@ -0,0 +1,46 @@
+package org.jetbrains.dokka
+
+import java.lang.reflect.InvocationHandler
+import java.lang.reflect.InvocationTargetException
+import java.lang.reflect.Method
+import java.lang.reflect.Proxy
+
+
+/**
+ * Warning! Hard reflection magic used here.
+ *
+ * Creates [java.lang.reflect.Proxy] with pass through invocation algorithm,
+ * to create access proxy for [delegate] into [targetClassLoader].
+ */
+@Suppress("UNCHECKED_CAST")
+inline fun <reified T : Any> automagicTypedProxy(targetClassLoader: ClassLoader, delegate: Any): T =
+ automagicProxy(targetClassLoader, T::class.java, delegate) as T
+
+
+/**
+ * Warning! Hard reflection magic used here.
+ *
+ * Creates [java.lang.reflect.Proxy] with pass through invocation algorithm,
+ * to create access proxy for [delegate] into [targetClassLoader].
+ *
+ */
+fun automagicProxy(targetClassLoader: ClassLoader, targetType: Class<*>, delegate: Any): Any =
+ Proxy.newProxyInstance(
+ targetClassLoader,
+ arrayOf(targetType),
+ DelegatedInvocationHandler(delegate)
+ )
+
+class DelegatedInvocationHandler(private val delegate: Any) : InvocationHandler {
+
+ @Throws(Throwable::class)
+ override fun invoke(proxy: Any, method: Method, args: Array<Any?>?): Any? {
+ val delegateMethod = delegate.javaClass.getMethod(method.name, *method.parameterTypes)
+ try {
+ delegateMethod.isAccessible = true
+ return delegateMethod.invoke(delegate, *(args ?: emptyArray()))
+ } catch (ex: InvocationTargetException) {
+ throw ex.targetException
+ }
+ }
+}
diff --git a/runners/gradle-plugin/src/main/kotlin/logger.kt b/runners/gradle-plugin/src/main/kotlin/logger.kt
deleted file mode 100644
index 715c1f04..00000000
--- a/runners/gradle-plugin/src/main/kotlin/logger.kt
+++ /dev/null
@@ -1,18 +0,0 @@
-package org.jetbrains.dokka.gradle
-
-import org.gradle.api.logging.Logger
-import org.jetbrains.dokka.DokkaLogger
-
-class DokkaGradleLogger(val logger: Logger) : DokkaLogger {
- override fun error(message: String) {
- logger.error(message)
- }
-
- override fun info(message: String) {
- logger.info(message)
- }
-
- override fun warn(message: String) {
- logger.warn(message)
- }
-} \ No newline at end of file
diff --git a/runners/gradle-plugin/src/main/kotlin/main.kt b/runners/gradle-plugin/src/main/kotlin/main.kt
index f3e46c4d..51061415 100644
--- a/runners/gradle-plugin/src/main/kotlin/main.kt
+++ b/runners/gradle-plugin/src/main/kotlin/main.kt
@@ -15,7 +15,7 @@ import java.io.File
import java.io.Serializable
import java.net.URLClassLoader
import java.util.*
-import java.util.function.Predicate
+import java.util.function.BiConsumer
open class DokkaPlugin : Plugin<Project> {
@@ -124,15 +124,16 @@ open class DokkaTask : DefaultTask() {
val bootstrapInstance = bootstrapClass.constructors.first().newInstance()
- val bootstrapProxy = automagicTypedProxy(javaClass.classLoader,
- DokkaBootstrap::class.java,
- fatJarClassLoader!!,
- bootstrapInstance,
- Predicate { it.name.startsWith("org.jetbrains.dokka") }
- )
+ val bootstrapProxy: DokkaBootstrap = automagicTypedProxy(javaClass.classLoader, bootstrapInstance)
bootstrapProxy.configure(
- DokkaGradleLogger(logger),
+ BiConsumer { level, message ->
+ when (level) {
+ "info" -> logger.info(message)
+ "warn" -> logger.warn(message)
+ "error" -> logger.error(message)
+ }
+ },
moduleName,
classpath.map { it.absolutePath },
sourceDirectories.map { it.absolutePath },
@@ -148,7 +149,7 @@ open class DokkaTask : DefaultTask() {
true,
linkMappings.map {
val path = project.file(it.dir).absolutePath
- return@map "$path=${it.url}${it.suffix}"
+ "$path=${it.url}${it.suffix}"
})
bootstrapProxy.generate()