diff options
8 files changed, 142 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 diff --git a/core/test-api/src/main/kotlin/testApi/testRunner/DokkaTestGenerator.kt b/core/test-api/src/main/kotlin/testApi/testRunner/DokkaTestGenerator.kt index 414919dc..98f8965c 100644 --- a/core/test-api/src/main/kotlin/testApi/testRunner/DokkaTestGenerator.kt +++ b/core/test-api/src/main/kotlin/testApi/testRunner/DokkaTestGenerator.kt @@ -19,6 +19,10 @@ internal class DokkaTestGenerator( dokkaGenerator.initializePlugins(configuration, logger, additionalPlugins) pluginsSetupStage(context) + verificationStage { + dokkaGenerator.validityCheck(context) + } + val modulesFromPlatforms = dokkaGenerator.createDocumentationModels(context) documentablesCreationStage(modulesFromPlatforms) diff --git a/core/test-api/src/main/kotlin/testApi/testRunner/TestRunner.kt b/core/test-api/src/main/kotlin/testApi/testRunner/TestRunner.kt index db253a9d..0b3068fc 100644 --- a/core/test-api/src/main/kotlin/testApi/testRunner/TestRunner.kt +++ b/core/test-api/src/main/kotlin/testApi/testRunner/TestRunner.kt @@ -140,6 +140,7 @@ abstract class AbstractCoreTest( protected class TestBuilder { var pluginsSetupStage: (DokkaContext) -> Unit = {} + var verificationStage: (() -> Unit) -> Unit = {} var documentablesCreationStage: (List<DModule>) -> Unit = {} var documentablesFirstTransformationStep: (List<DModule>) -> Unit = {} var documentablesMergingStage: (DModule) -> Unit = {} @@ -151,6 +152,7 @@ abstract class AbstractCoreTest( @PublishedApi internal fun build() = TestMethods( pluginsSetupStage, + verificationStage, documentablesCreationStage, documentablesFirstTransformationStep, documentablesMergingStage, @@ -193,6 +195,7 @@ abstract class AbstractCoreTest( data class TestMethods( val pluginsSetupStage: (DokkaContext) -> Unit, + val verificationStage: (() -> Unit) -> Unit, val documentablesCreationStage: (List<DModule>) -> Unit, val documentablesFirstTransformationStep: (List<DModule>) -> Unit, val documentablesMergingStage: (DModule) -> Unit, diff --git a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/JavadocPlugin.kt b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/JavadocPlugin.kt index ae3281a1..560083e4 100644 --- a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/JavadocPlugin.kt +++ b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/JavadocPlugin.kt @@ -10,6 +10,7 @@ import org.jetbrains.dokka.base.renderers.RootCreator import org.jetbrains.dokka.base.resolvers.shared.RecognizedLinkFormat import org.jetbrains.dokka.javadoc.pages.* import org.jetbrains.dokka.javadoc.transformers.documentables.JavadocDocumentableJVMSourceSetFilter +import org.jetbrains.dokka.javadoc.validity.MultiplatformConfiguredChecker import org.jetbrains.dokka.kotlinAsJava.KotlinAsJavaPlugin import org.jetbrains.dokka.plugability.DokkaPlugin import org.jetbrains.dokka.plugability.querySingle @@ -28,6 +29,12 @@ class JavadocPlugin : DokkaPlugin() { override dokkaBasePlugin.htmlRenderer) } + val javadocMultiplatformCheck by extending { + CoreExtensions.preGenerationCheck providing { context -> + MultiplatformConfiguredChecker(context) + } + } + val pageTranslator by extending { CoreExtensions.documentableToPageTranslator providing { context -> JavadocDocumentableToPageTranslator( diff --git a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/validity/MultiplatformConfiguredChecker.kt b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/validity/MultiplatformConfiguredChecker.kt new file mode 100644 index 00000000..36d84a09 --- /dev/null +++ b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/validity/MultiplatformConfiguredChecker.kt @@ -0,0 +1,22 @@ +package org.jetbrains.dokka.javadoc.validity + +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.validity.PreGenerationChecker +import org.jetbrains.dokka.validity.PreGenerationCheckerOutput + +class MultiplatformConfiguredChecker(val context: DokkaContext) : PreGenerationChecker { + + override fun invoke(): PreGenerationCheckerOutput { + val isSinglePlatform = context.configuration.sourceSets.all { sourceSet -> + val platform = sourceSet.analysisPlatform + (platform == Platform.jvm || platform == Platform.common) + } + return PreGenerationCheckerOutput(isSinglePlatform, listOfNotNull(errorMessage.takeUnless { isSinglePlatform })) + } + + companion object { + const val errorMessage = + "Dokka Javadoc plugin currently does not support generating documentation for multiplatform project. Please, adjust your configuration" + } +}
\ No newline at end of file diff --git a/plugins/javadoc/src/test/kotlin/org/jetbrains/dokka/javadoc/validity/MultiplatformConfiguredCheckerTest.kt b/plugins/javadoc/src/test/kotlin/org/jetbrains/dokka/javadoc/validity/MultiplatformConfiguredCheckerTest.kt new file mode 100644 index 00000000..9d70f444 --- /dev/null +++ b/plugins/javadoc/src/test/kotlin/org/jetbrains/dokka/javadoc/validity/MultiplatformConfiguredCheckerTest.kt @@ -0,0 +1,80 @@ +package org.jetbrains.dokka.javadoc.validity + +import org.jetbrains.dokka.DokkaConfigurationImpl +import org.jetbrains.dokka.DokkaException +import org.jetbrains.dokka.ExternalDocumentationLink +import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest +import org.junit.jupiter.api.Test +import kotlin.test.assertFalse +import kotlin.test.assertTrue + +class MultiplatformConfiguredCheckerTest : AbstractCoreTest() { + + val mppConfig: DokkaConfigurationImpl = dokkaConfiguration { + format = "javadoc" + sourceSets { + sourceSet { + sourceRoots = listOf("src") + analysisPlatform = "jvm" + externalDocumentationLinks = listOf( + ExternalDocumentationLink("https://docs.oracle.com/javase/8/docs/api/"), + ExternalDocumentationLink("https://kotlinlang.org/api/latest/jvm/stdlib/") + ) + } + sourceSet { + sourceRoots = listOf("src") + analysisPlatform = "js" + externalDocumentationLinks = listOf( + ExternalDocumentationLink("https://docs.oracle.com/javase/8/docs/api/"), + ExternalDocumentationLink("https://kotlinlang.org/api/latest/jvm/stdlib/") + ) + } + } + } + + val sppConfig: DokkaConfigurationImpl = dokkaConfiguration { + format = "javadoc" + sourceSets { + sourceSet { + sourceRoots = listOf("src") + analysisPlatform = "jvm" + externalDocumentationLinks = listOf( + ExternalDocumentationLink("https://docs.oracle.com/javase/8/docs/api/"), + ExternalDocumentationLink("https://kotlinlang.org/api/latest/jvm/stdlib/") + ) + } + } + } + + @Test + fun `mpp config should fail for javadoc`() { + testInline("", mppConfig) { + verificationStage = { verification -> + var mppDetected = false + try { + verification() + } catch (e: DokkaException) { + mppDetected = + e.localizedMessage == "Pre-generation validity check failed: ${MultiplatformConfiguredChecker.errorMessage}" + } + assertTrue(mppDetected, "MPP configuration not detected") + } + } + } + + @Test + fun `spp config should not fail for javadoc`() { + testInline("", sppConfig) { + verificationStage = { verification -> + var mppDetected = false + try { + verification() + } catch (e: DokkaException) { + mppDetected = + e.localizedMessage == "Pre-generation validity check failed: ${MultiplatformConfiguredChecker.errorMessage}" + } + assertFalse(mppDetected, "SPP taken as multiplatform") + } + } + } +}
\ No newline at end of file |