diff options
3 files changed, 58 insertions, 10 deletions
diff --git a/core/src/main/kotlin/DokkaBootstrap.kt b/core/src/main/kotlin/DokkaBootstrap.kt index ffaae03e..159172a5 100644 --- a/core/src/main/kotlin/DokkaBootstrap.kt +++ b/core/src/main/kotlin/DokkaBootstrap.kt @@ -1,8 +1,11 @@ package org.jetbrains.dokka import java.util.function.BiConsumer +import kotlin.jvm.Throws interface DokkaBootstrap { fun configure(serializedConfigurationJSON: String, logger: BiConsumer<String, String>) + + @Throws(Throwable::class) fun generate() } diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ProxyUtils.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ProxyUtils.kt index 85b6ea3b..468f597f 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ProxyUtils.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ProxyUtils.kt @@ -1,9 +1,6 @@ package org.jetbrains.dokka.gradle -import java.lang.reflect.InvocationHandler -import java.lang.reflect.InvocationTargetException -import java.lang.reflect.Method -import java.lang.reflect.Proxy +import java.lang.reflect.* /** @@ -14,7 +11,7 @@ import java.lang.reflect.Proxy */ @Suppress("UNCHECKED_CAST") internal inline fun <reified T : Any> automagicTypedProxy(targetClassLoader: ClassLoader, delegate: Any): T = - automagicProxy(targetClassLoader, T::class.java, delegate) as T + automagicProxy(targetClassLoader, T::class.java, delegate) as T /** @@ -25,11 +22,11 @@ internal inline fun <reified T : Any> automagicTypedProxy(targetClassLoader: Cla * */ internal fun automagicProxy(targetClassLoader: ClassLoader, targetType: Class<*>, delegate: Any): Any = - Proxy.newProxyInstance( - targetClassLoader, - arrayOf(targetType), - DelegatedInvocationHandler(delegate) - ) + Proxy.newProxyInstance( + targetClassLoader, + arrayOf(targetType), + DelegatedInvocationHandler(delegate) + ) internal class DelegatedInvocationHandler(private val delegate: Any) : InvocationHandler { diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/AutomagicProxyTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/AutomagicProxyTest.kt new file mode 100644 index 00000000..e981d6fe --- /dev/null +++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/AutomagicProxyTest.kt @@ -0,0 +1,48 @@ +package org.jetbrains.dokka.gradle + +import org.jetbrains.dokka.DokkaBootstrap +import org.jetbrains.dokka.gradle.AutomagicProxyTest.TestInterface +import java.util.function.BiConsumer +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertFailsWith + + +class AutomagicProxyTest { + + private class TestException(message: String, cause: Throwable?) : Exception(message, cause) + + private fun interface TestInterface { + @Throws(Throwable::class) + operator fun invoke(): Int + } + + @Test + fun `simple method invocation`() { + val instance = TestInterface { 0 } + val proxy = automagicTypedProxy<TestInterface>(instance.javaClass.classLoader, instance) + assertEquals(0, proxy()) + } + + @Test + fun `exception throw in DokkaBootstrap is not wrapped inside UndeclaredThrowableException`() { + val instanceThrowingTestException = object : DokkaBootstrap { + override fun configure(serializedConfigurationJSON: String, logger: BiConsumer<String, String>) = Unit + override fun generate() { + throw TestException("Test Exception Message", Exception("Cause Exception Message")) + } + } + + val proxy = automagicTypedProxy<DokkaBootstrap>( + instanceThrowingTestException.javaClass.classLoader, + instanceThrowingTestException + ) + + val exception = assertFailsWith<TestException> { + proxy.generate() + } + + assertEquals("Test Exception Message", exception.message) + assertEquals("Cause Exception Message", exception.cause?.message) + } +} |