aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/src/main/kotlin/DokkaGenerator.kt41
-rw-r--r--core/src/main/kotlin/transformers/sources/AsyncSourceToDocumentableTranslator.kt5
-rw-r--r--plugins/all-modules-page/src/main/kotlin/AllModulesPageGeneration.kt2
-rw-r--r--plugins/base/src/main/kotlin/generation/SingleModuleGeneration.kt5
4 files changed, 45 insertions, 8 deletions
diff --git a/core/src/main/kotlin/DokkaGenerator.kt b/core/src/main/kotlin/DokkaGenerator.kt
index e3dcf626..9241d728 100644
--- a/core/src/main/kotlin/DokkaGenerator.kt
+++ b/core/src/main/kotlin/DokkaGenerator.kt
@@ -2,10 +2,15 @@
package org.jetbrains.dokka
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.InternalCoroutinesApi
+import kotlinx.coroutines.scheduling.ExperimentalCoroutineDispatcher
import org.jetbrains.dokka.generation.GracefulGenerationExit
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.plugability.DokkaPlugin
import org.jetbrains.dokka.utilities.DokkaLogger
+import kotlin.reflect.full.memberProperties
+import kotlin.reflect.jvm.isAccessible
/**
* DokkaGenerator is the main entry point for generating documentation
@@ -16,15 +21,22 @@ class DokkaGenerator(
private val configuration: DokkaConfiguration,
private val logger: DokkaLogger
) {
+
fun generate() = timed(logger) {
report("Initializing plugins")
val context = initializePlugins(configuration, logger)
- context.single(CoreExtensions.generation).run {
- logger.progress("Dokka is performing: $generationName")
- generate()
+ runCatching {
+ context.single(CoreExtensions.generation).run {
+ logger.progress("Dokka is performing: $generationName")
+ generate()
+ }
+ }.exceptionOrNull()?.let { e ->
+ finalizeCoroutines()
+ throw e
}
+ finalizeCoroutines()
}.dump("\n\n === TIME MEASUREMENT ===\n")
fun initializePlugins(
@@ -32,6 +44,29 @@ class DokkaGenerator(
logger: DokkaLogger,
additionalPlugins: List<DokkaPlugin> = emptyList()
) = DokkaContext.create(configuration, logger, additionalPlugins)
+
+ private fun finalizeCoroutines() {
+ runCatching {
+ Dispatchers.Default.closeExecutor()
+
+ Dispatchers.IO.let { dispatcher ->
+ dispatcher::class.memberProperties.find {
+ it.name == "dispatcher"
+ }?.also {
+ it.isAccessible = true
+ }?.call(dispatcher)
+ }?.closeExecutor()
+ }
+ }
+
+ @OptIn(InternalCoroutinesApi::class)
+ private fun Any.closeExecutor() = (this as ExperimentalCoroutineDispatcher).also {
+ it.executor::class.members
+ .find { it.name == "close" }
+ ?.also {
+ it.isAccessible = true
+ }?.call(it.executor)
+ }
}
class Timer internal constructor(startTime: Long, private val logger: DokkaLogger?) {
diff --git a/core/src/main/kotlin/transformers/sources/AsyncSourceToDocumentableTranslator.kt b/core/src/main/kotlin/transformers/sources/AsyncSourceToDocumentableTranslator.kt
index 19113446..3c00be5a 100644
--- a/core/src/main/kotlin/transformers/sources/AsyncSourceToDocumentableTranslator.kt
+++ b/core/src/main/kotlin/transformers/sources/AsyncSourceToDocumentableTranslator.kt
@@ -1,5 +1,6 @@
package org.jetbrains.dokka.transformers.sources
+import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.model.DModule
@@ -9,7 +10,7 @@ interface AsyncSourceToDocumentableTranslator : SourceToDocumentableTranslator {
suspend fun invokeSuspending(sourceSet: DokkaConfiguration.DokkaSourceSet, context: DokkaContext): DModule
override fun invoke(sourceSet: DokkaConfiguration.DokkaSourceSet, context: DokkaContext): DModule =
- runBlocking {
+ runBlocking(Dispatchers.Default) {
invokeSuspending(sourceSet, context)
}
-} \ No newline at end of file
+}
diff --git a/plugins/all-modules-page/src/main/kotlin/AllModulesPageGeneration.kt b/plugins/all-modules-page/src/main/kotlin/AllModulesPageGeneration.kt
index c11b18b2..21c624ef 100644
--- a/plugins/all-modules-page/src/main/kotlin/AllModulesPageGeneration.kt
+++ b/plugins/all-modules-page/src/main/kotlin/AllModulesPageGeneration.kt
@@ -70,4 +70,4 @@ class AllModulesPageGeneration(private val context: DokkaContext) : Generation {
data class DefaultAllModulesContext(val nonEmptyModules: List<String>) : CreationContext {
constructor(templating: TemplatingResult) : this(templating.modules)
}
-} \ No newline at end of file
+}
diff --git a/plugins/base/src/main/kotlin/generation/SingleModuleGeneration.kt b/plugins/base/src/main/kotlin/generation/SingleModuleGeneration.kt
index 9bf61af9..e0deef17 100644
--- a/plugins/base/src/main/kotlin/generation/SingleModuleGeneration.kt
+++ b/plugins/base/src/main/kotlin/generation/SingleModuleGeneration.kt
@@ -19,6 +19,7 @@ import org.jetbrains.dokka.utilities.parallelMap
import org.jetbrains.dokka.utilities.report
class SingleModuleGeneration(private val context: DokkaContext) : Generation {
+
override fun Timer.generate() {
report("Validity check")
validityCheck(context)
@@ -48,7 +49,7 @@ class SingleModuleGeneration(private val context: DokkaContext) : Generation {
reportAfterRendering()
}
- override val generationName = " documentation for ${context.configuration.moduleName}"
+ override val generationName = "documentation for ${context.configuration.moduleName}"
fun createDocumentationModels() = runBlocking(Dispatchers.Default) {
context.configuration.sourceSets.parallelMap { sourceSet -> translateSources(sourceSet, context) }.flatten()
@@ -105,4 +106,4 @@ class SingleModuleGeneration(private val context: DokkaContext) : Generation {
else -> translator.invoke(sourceSet, context)
}
}
-} \ No newline at end of file
+}