aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/kotlin')
-rw-r--r--core/src/main/kotlin/CoreExtensions.kt2
-rw-r--r--core/src/main/kotlin/DokkaGenerator.kt12
-rw-r--r--core/src/main/kotlin/validity/PreGenerationChecker.kt12
3 files changed, 26 insertions, 0 deletions
diff --git a/core/src/main/kotlin/CoreExtensions.kt b/core/src/main/kotlin/CoreExtensions.kt
index b8689154..f5fb7604 100644
--- a/core/src/main/kotlin/CoreExtensions.kt
+++ b/core/src/main/kotlin/CoreExtensions.kt
@@ -9,9 +9,11 @@ import org.jetbrains.dokka.transformers.documentation.PreMergeDocumentableTransf
import org.jetbrains.dokka.transformers.pages.PageCreator
import org.jetbrains.dokka.transformers.pages.PageTransformer
import org.jetbrains.dokka.transformers.sources.SourceToDocumentableTranslator
+import org.jetbrains.dokka.validity.PreGenerationChecker
import kotlin.reflect.KProperty
object CoreExtensions {
+ val preGenerationCheck by coreExtension<PreGenerationChecker>()
val sourceToDocumentableTranslator by coreExtension<SourceToDocumentableTranslator>()
val preMergeDocumentableTransformer by coreExtension<PreMergeDocumentableTransformer>()
val documentableMerger by coreExtension<DocumentableMerger>()
diff --git a/core/src/main/kotlin/DokkaGenerator.kt b/core/src/main/kotlin/DokkaGenerator.kt
index bee85325..b6216bdb 100644
--- a/core/src/main/kotlin/DokkaGenerator.kt
+++ b/core/src/main/kotlin/DokkaGenerator.kt
@@ -28,6 +28,9 @@ class DokkaGenerator(
report("Initializing plugins")
val context = initializePlugins(configuration, logger)
+ report("Validity check")
+ validityCheck(context)
+
report("Creating documentation models")
val modulesFromPlatforms = createDocumentationModels(context)
@@ -136,6 +139,15 @@ class DokkaGenerator(
}
}
+ fun validityCheck(context: DokkaContext) {
+ val (preGenerationCheckResult, checkMessages) = context[CoreExtensions.preGenerationCheck].fold(
+ Pair(true, emptyList<String>())
+ ) { acc, checker -> checker() + acc }
+ if (!preGenerationCheckResult) throw DokkaException(
+ "Pre-generation validity check failed: ${checkMessages.joinToString(",")}"
+ )
+ }
+
private suspend fun translateSources(sourceSet: DokkaSourceSet, context: DokkaContext) =
context[CoreExtensions.sourceToDocumentableTranslator].parallelMap {
it.invoke(sourceSet, context)
diff --git a/core/src/main/kotlin/validity/PreGenerationChecker.kt b/core/src/main/kotlin/validity/PreGenerationChecker.kt
new file mode 100644
index 00000000..7cdad59b
--- /dev/null
+++ b/core/src/main/kotlin/validity/PreGenerationChecker.kt
@@ -0,0 +1,12 @@
+package org.jetbrains.dokka.validity
+
+interface PreGenerationChecker : () -> PreGenerationCheckerOutput {
+
+ override fun invoke(): PreGenerationCheckerOutput
+}
+
+data class PreGenerationCheckerOutput(val result: Boolean, val messages: List<String>) {
+
+ operator fun plus(pair: Pair<Boolean, List<String>>) =
+ Pair(result && pair.first, messages + pair.second)
+} \ No newline at end of file