diff options
-rw-r--r-- | core/src/main/kotlin/DokkaGenerator.kt | 9 | ||||
-rw-r--r-- | plugins/base/src/test/kotlin/basic/AbortGracefullyOnMissingDocumentablesTest.kt | 18 |
2 files changed, 27 insertions, 0 deletions
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<DModule>, @@ -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() diff --git a/plugins/base/src/test/kotlin/basic/AbortGracefullyOnMissingDocumentablesTest.kt b/plugins/base/src/test/kotlin/basic/AbortGracefullyOnMissingDocumentablesTest.kt new file mode 100644 index 00000000..0262760d --- /dev/null +++ b/plugins/base/src/test/kotlin/basic/AbortGracefullyOnMissingDocumentablesTest.kt @@ -0,0 +1,18 @@ +package basic + +import org.jetbrains.dokka.DokkaGenerator +import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest +import org.junit.jupiter.api.Test +import kotlin.test.assertTrue + +class AbortGracefullyOnMissingDocumentablesTest: AbstractCoreTest() { + @Test + fun `Generation aborts Gracefully with no Documentables`() { + DokkaGenerator(dokkaConfiguration { }, logger).generate() + + assertTrue( + logger.progressMessages.any { message -> "Exiting Generation: Nothing to document" == message }, + "Expected graceful exit message. Found: ${logger.progressMessages}" + ) + } +} |