From c24e9b5b0f0ac9a80ff36282fe708e4ee0ecf707 Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Tue, 1 Sep 2020 09:54:41 +0200 Subject: Implement exitGenerationGracefully API --- core/src/main/kotlin/DokkaGenerator.kt | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'core') diff --git a/core/src/main/kotlin/DokkaGenerator.kt b/core/src/main/kotlin/DokkaGenerator.kt index 2ba0c0a4..0921e5bc 100644 --- a/core/src/main/kotlin/DokkaGenerator.kt +++ b/core/src/main/kotlin/DokkaGenerator.kt @@ -73,6 +73,7 @@ class DokkaGenerator( context: DokkaContext ) = context.configuration.sourceSets .flatMap { sourceSet -> translateSources(sourceSet, context) } + .also { modules -> if (modules.isEmpty()) exitGenerationGracefully("Nothing to document") } fun transformDocumentationModelBeforeMerge( modulesFromPlatforms: List, @@ -160,7 +161,15 @@ private fun timed(logger: DokkaLogger? = null, block: Timer.() -> Unit): Timer = Timer(System.currentTimeMillis(), logger).apply { try { block() + } catch (exit: GracefulGenerationExit) { + report("Exiting Generation: ${exit.reason}") } finally { report("") } } + +private fun exitGenerationGracefully(reason: String): Nothing { + throw GracefulGenerationExit(reason) +} + +private class GracefulGenerationExit(val reason: String) : Throwable() -- cgit