From 13bda7371cc60beaa4cc8302239efd21695b9e1f Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Fri, 2 Dec 2016 23:46:16 +0300 Subject: Now dokka-fatjar complete isolated from poisonous Gradle environment --- .../kotlin/org/jetbrains/dokka/DokkaBootstrap.kt | 22 +++++++ .../main/kotlin/org/jetbrains/dokka/DokkaLogger.kt | 8 +++ .../main/kotlin/org/jetbrains/dokka/ProxyUtils.kt | 76 ++++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 integration/src/main/kotlin/org/jetbrains/dokka/DokkaBootstrap.kt create mode 100644 integration/src/main/kotlin/org/jetbrains/dokka/DokkaLogger.kt create mode 100644 integration/src/main/kotlin/org/jetbrains/dokka/ProxyUtils.kt (limited to 'integration/src/main') diff --git a/integration/src/main/kotlin/org/jetbrains/dokka/DokkaBootstrap.kt b/integration/src/main/kotlin/org/jetbrains/dokka/DokkaBootstrap.kt new file mode 100644 index 00000000..548aceb0 --- /dev/null +++ b/integration/src/main/kotlin/org/jetbrains/dokka/DokkaBootstrap.kt @@ -0,0 +1,22 @@ +package org.jetbrains.dokka + +interface DokkaBootstrap { + + fun configure(logger: DokkaLogger, + moduleName: String, + classpath: List, + sources: List, + samples: List, + includes: List, + outputDir: String, + format: String, + includeNonPublic: Boolean, + reportUndocumented: Boolean, + skipEmptyPackages: Boolean, + skipDeprecated: Boolean, + jdkVersion: Int, + generateIndexPages: Boolean, + sourceLinks: List) + + fun generate() +} \ No newline at end of file diff --git a/integration/src/main/kotlin/org/jetbrains/dokka/DokkaLogger.kt b/integration/src/main/kotlin/org/jetbrains/dokka/DokkaLogger.kt new file mode 100644 index 00000000..fc1fac22 --- /dev/null +++ b/integration/src/main/kotlin/org/jetbrains/dokka/DokkaLogger.kt @@ -0,0 +1,8 @@ +package org.jetbrains.dokka + +interface DokkaLogger { + fun info(message: String) + fun warn(message: String) + fun error(message: String) +} + diff --git a/integration/src/main/kotlin/org/jetbrains/dokka/ProxyUtils.kt b/integration/src/main/kotlin/org/jetbrains/dokka/ProxyUtils.kt new file mode 100644 index 00000000..66356f66 --- /dev/null +++ b/integration/src/main/kotlin/org/jetbrains/dokka/ProxyUtils.kt @@ -0,0 +1,76 @@ +package org.jetbrains.dokka + +import java.lang.reflect.InvocationHandler +import java.lang.reflect.InvocationTargetException +import java.lang.reflect.Method +import java.lang.reflect.Proxy +import java.util.function.Predicate + + +/** + * Warning! Hard reflection magic used here. + * + * Creates [java.lang.reflect.Proxy] with pass through invocation algorithm, + * to create access proxy for [delegate] from [targetClassLoader] to [delegateClassLoader]. + * + * Every object type contained in method calls will be translated to proxy, if [filter.test] will success for it's class + * + */ +@Suppress("UNCHECKED_CAST") +fun automagicTypedProxy(targetClassLoader: ClassLoader, targetType: Class, + delegateClassLoader: ClassLoader, delegate: Any, + filter: Predicate>): T = + automagicProxy(targetClassLoader, targetType, delegateClassLoader, delegate, filter) as T + + +/** + * Warning! Hard reflection magic used here. + * + * Creates [java.lang.reflect.Proxy] with pass through invocation algorithm, + * to create access proxy for [delegate] from [targetClassLoader] to [delegateClassLoader]. + * + * Every object type contained in method calls will be translated to proxy, if [filter.test] will success for it's class + * + */ +fun automagicProxy(targetClassLoader: ClassLoader, targetType: Class<*>, + delegateClassLoader: ClassLoader, delegate: Any, + filter: Predicate>): Any = + Proxy.newProxyInstance( + targetClassLoader, + arrayOf(targetType), + DelegatedInvocationHandler( + delegate, + delegateClassLoader, + filter + ) + ) + +class DelegatedInvocationHandler(private val delegate: Any, + private val delegateClassLoader: ClassLoader, + private val filter: Predicate>) + : InvocationHandler { + + @Throws(Throwable::class) + override fun invoke(proxy: Any, method: Method, args: Array?): Any? { + val (argTypes, argValues) = method.parameterTypes.zip(args ?: emptyArray()).map { typeAndValue -> + val (type, value) = typeAndValue + if (filter.test(type)) { + val newType = delegateClassLoader.loadClass(type.name) + val newValue = value?.let { + automagicProxy(delegateClassLoader, newType, type.classLoader, value, filter) + } + newType to newValue + } else + typeAndValue + }.unzip() + + val delegateMethod = delegate.javaClass.getMethod(method.name, *argTypes.toTypedArray()) + try { + delegateMethod.isAccessible = true + return delegateMethod.invoke(delegate, *argValues.toTypedArray()) + } catch (ex: InvocationTargetException) { + throw ex.targetException + } + + } +} -- cgit From 546e8edfd95c16665319bc371c6ccf63706ad1e4 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Tue, 6 Dec 2016 16:05:01 +0300 Subject: Post-review changes, simplified proxies --- .../kotlin/org/jetbrains/dokka/DokkaBootstrap.kt | 4 +- .../main/kotlin/org/jetbrains/dokka/DokkaLogger.kt | 8 --- .../main/kotlin/org/jetbrains/dokka/ProxyUtils.kt | 76 ---------------------- 3 files changed, 3 insertions(+), 85 deletions(-) delete mode 100644 integration/src/main/kotlin/org/jetbrains/dokka/DokkaLogger.kt delete mode 100644 integration/src/main/kotlin/org/jetbrains/dokka/ProxyUtils.kt (limited to 'integration/src/main') diff --git a/integration/src/main/kotlin/org/jetbrains/dokka/DokkaBootstrap.kt b/integration/src/main/kotlin/org/jetbrains/dokka/DokkaBootstrap.kt index 548aceb0..50e8fb8d 100644 --- a/integration/src/main/kotlin/org/jetbrains/dokka/DokkaBootstrap.kt +++ b/integration/src/main/kotlin/org/jetbrains/dokka/DokkaBootstrap.kt @@ -1,8 +1,10 @@ package org.jetbrains.dokka +import java.util.function.BiConsumer + interface DokkaBootstrap { - fun configure(logger: DokkaLogger, + fun configure(logger: BiConsumer, moduleName: String, classpath: List, sources: List, diff --git a/integration/src/main/kotlin/org/jetbrains/dokka/DokkaLogger.kt b/integration/src/main/kotlin/org/jetbrains/dokka/DokkaLogger.kt deleted file mode 100644 index fc1fac22..00000000 --- a/integration/src/main/kotlin/org/jetbrains/dokka/DokkaLogger.kt +++ /dev/null @@ -1,8 +0,0 @@ -package org.jetbrains.dokka - -interface DokkaLogger { - fun info(message: String) - fun warn(message: String) - fun error(message: String) -} - diff --git a/integration/src/main/kotlin/org/jetbrains/dokka/ProxyUtils.kt b/integration/src/main/kotlin/org/jetbrains/dokka/ProxyUtils.kt deleted file mode 100644 index 66356f66..00000000 --- a/integration/src/main/kotlin/org/jetbrains/dokka/ProxyUtils.kt +++ /dev/null @@ -1,76 +0,0 @@ -package org.jetbrains.dokka - -import java.lang.reflect.InvocationHandler -import java.lang.reflect.InvocationTargetException -import java.lang.reflect.Method -import java.lang.reflect.Proxy -import java.util.function.Predicate - - -/** - * Warning! Hard reflection magic used here. - * - * Creates [java.lang.reflect.Proxy] with pass through invocation algorithm, - * to create access proxy for [delegate] from [targetClassLoader] to [delegateClassLoader]. - * - * Every object type contained in method calls will be translated to proxy, if [filter.test] will success for it's class - * - */ -@Suppress("UNCHECKED_CAST") -fun automagicTypedProxy(targetClassLoader: ClassLoader, targetType: Class, - delegateClassLoader: ClassLoader, delegate: Any, - filter: Predicate>): T = - automagicProxy(targetClassLoader, targetType, delegateClassLoader, delegate, filter) as T - - -/** - * Warning! Hard reflection magic used here. - * - * Creates [java.lang.reflect.Proxy] with pass through invocation algorithm, - * to create access proxy for [delegate] from [targetClassLoader] to [delegateClassLoader]. - * - * Every object type contained in method calls will be translated to proxy, if [filter.test] will success for it's class - * - */ -fun automagicProxy(targetClassLoader: ClassLoader, targetType: Class<*>, - delegateClassLoader: ClassLoader, delegate: Any, - filter: Predicate>): Any = - Proxy.newProxyInstance( - targetClassLoader, - arrayOf(targetType), - DelegatedInvocationHandler( - delegate, - delegateClassLoader, - filter - ) - ) - -class DelegatedInvocationHandler(private val delegate: Any, - private val delegateClassLoader: ClassLoader, - private val filter: Predicate>) - : InvocationHandler { - - @Throws(Throwable::class) - override fun invoke(proxy: Any, method: Method, args: Array?): Any? { - val (argTypes, argValues) = method.parameterTypes.zip(args ?: emptyArray()).map { typeAndValue -> - val (type, value) = typeAndValue - if (filter.test(type)) { - val newType = delegateClassLoader.loadClass(type.name) - val newValue = value?.let { - automagicProxy(delegateClassLoader, newType, type.classLoader, value, filter) - } - newType to newValue - } else - typeAndValue - }.unzip() - - val delegateMethod = delegate.javaClass.getMethod(method.name, *argTypes.toTypedArray()) - try { - delegateMethod.isAccessible = true - return delegateMethod.invoke(delegate, *argValues.toTypedArray()) - } catch (ex: InvocationTargetException) { - throw ex.targetException - } - - } -} -- cgit