diff options
author | Marcin Aman <marcin.aman@gmail.com> | 2021-01-21 00:34:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-21 00:34:43 +0100 |
commit | fdf8a298f586d7e334c312346b70b59c64c8d037 (patch) | |
tree | d9e92e920c24f442df6339e19b27225d7d01d21b /plugins/base/src/main/kotlin | |
parent | 1f592a7ec2786e0a0b77d224d1414ef3042caae4 (diff) | |
download | dokka-fdf8a298f586d7e334c312346b70b59c64c8d037.tar.gz dokka-fdf8a298f586d7e334c312346b70b59c64c8d037.tar.bz2 dokka-fdf8a298f586d7e334c312346b70b59c64c8d037.zip |
Empty modules filtering (#1699)
Diffstat (limited to 'plugins/base/src/main/kotlin')
5 files changed, 36 insertions, 14 deletions
diff --git a/plugins/base/src/main/kotlin/DokkaBase.kt b/plugins/base/src/main/kotlin/DokkaBase.kt index ac070ab4..938c7701 100644 --- a/plugins/base/src/main/kotlin/DokkaBase.kt +++ b/plugins/base/src/main/kotlin/DokkaBase.kt @@ -80,6 +80,12 @@ class DokkaBase : DokkaPlugin() { } } + val emptyModulesFilter by extending { + preMergeDocumentableTransformer with EmptyModulesFilterTransformer() order { + after(emptyPackagesFilter) + } + } + val modulesAndPackagesDocumentation by extending { preMergeDocumentableTransformer providing ::ModuleAndPackageDocumentationTransformer } diff --git a/plugins/base/src/main/kotlin/generation/SingleModuleGeneration.kt b/plugins/base/src/main/kotlin/generation/SingleModuleGeneration.kt index 1689a1dd..9bf61af9 100644 --- a/plugins/base/src/main/kotlin/generation/SingleModuleGeneration.kt +++ b/plugins/base/src/main/kotlin/generation/SingleModuleGeneration.kt @@ -1,4 +1,3 @@ - package org.jetbrains.dokka.base.generation import kotlinx.coroutines.Dispatchers @@ -32,6 +31,7 @@ class SingleModuleGeneration(private val context: DokkaContext) : Generation { report("Merging documentation models") val documentationModel = mergeDocumentationModels(transformedDocumentationBeforeMerge) + ?: exitGenerationGracefully("Nothing to document") report("Transforming documentation model after merging") val transformedDocumentation = transformDocumentationModelAfterMerge(documentationModel) @@ -56,7 +56,8 @@ class SingleModuleGeneration(private val context: DokkaContext) : Generation { } fun transformDocumentationModelBeforeMerge(modulesFromPlatforms: List<DModule>) = - context.plugin<DokkaBase>().query { preMergeDocumentableTransformer }.fold(modulesFromPlatforms) { acc, t -> t(acc) } + context.plugin<DokkaBase>().query { preMergeDocumentableTransformer } + .fold(modulesFromPlatforms) { acc, t -> t(acc) } fun mergeDocumentationModels(modulesFromPlatforms: List<DModule>) = context.single(CoreExtensions.documentableMerger).invoke(modulesFromPlatforms) @@ -99,7 +100,7 @@ class SingleModuleGeneration(private val context: DokkaContext) : Generation { private suspend fun translateSources(sourceSet: DokkaConfiguration.DokkaSourceSet, context: DokkaContext) = context[CoreExtensions.sourceToDocumentableTranslator].parallelMap { translator -> - when(translator){ + when (translator) { is AsyncSourceToDocumentableTranslator -> translator.invokeSuspending(sourceSet, context) else -> translator.invoke(sourceSet, context) } diff --git a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt index d76ba597..2694adc9 100644 --- a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt @@ -7,7 +7,6 @@ import kotlinx.coroutines.runBlocking import org.jetbrains.dokka.DokkaException import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.base.resolvers.local.LocationProvider -import org.jetbrains.dokka.base.resolvers.local.resolveOrThrow import org.jetbrains.dokka.model.DisplaySourceSet import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.plugability.DokkaContext @@ -169,12 +168,20 @@ abstract class DefaultRenderer<T>( is RenderingStrategy.Copy -> outputWriter.writeResources(strategy.from, path) is RenderingStrategy.Write -> outputWriter.write(path, strategy.text, "") is RenderingStrategy.Callback -> outputWriter.write(path, strategy.instructions(this, page), ".html") - is RenderingStrategy.DriLocationResolvableWrite -> outputWriter.write(path, strategy.contentToResolve { dri, sourcesets -> - locationProvider.resolve(dri, sourcesets) - }, "") - is RenderingStrategy.PageLocationResolvableWrite -> outputWriter.write(path, strategy.contentToResolve { pageToLocate, context -> - locationProvider.resolve(pageToLocate, context) - }, "") + is RenderingStrategy.DriLocationResolvableWrite -> outputWriter.write( + path, + strategy.contentToResolve { dri, sourcesets -> + locationProvider.resolve(dri, sourcesets) + }, + "" + ) + is RenderingStrategy.PageLocationResolvableWrite -> outputWriter.write( + path, + strategy.contentToResolve { pageToLocate, context -> + locationProvider.resolve(pageToLocate, context) + }, + "" + ) RenderingStrategy.DoNothing -> Unit } else -> throw AssertionError( diff --git a/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt b/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt index 4c931230..94e27424 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt @@ -12,9 +12,8 @@ import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult internal class DefaultDocumentableMerger(val context: DokkaContext) : DocumentableMerger { private val dependencyInfo = context.getDependencyInfo() - override fun invoke(modules: Collection<DModule>): DModule { - - return modules.reduce { left, right -> + override fun invoke(modules: Collection<DModule>): DModule? = + modules.reduceOrNull { left, right -> val list = listOf(left, right) DModule( name = modules.map { it.name }.distinct().joinToString("|"), @@ -26,7 +25,6 @@ internal class DefaultDocumentableMerger(val context: DokkaContext) : Documentab sourceSets = list.flatMap { it.sourceSets }.toSet() ).mergeExtras(left, right) } - } private fun DokkaContext.getDependencyInfo() : Map<DokkaConfiguration.DokkaSourceSet, List<DokkaConfiguration.DokkaSourceSet>> { diff --git a/plugins/base/src/main/kotlin/transformers/documentables/EmptyModulesFilterTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/EmptyModulesFilterTransformer.kt new file mode 100644 index 00000000..fa31c5c3 --- /dev/null +++ b/plugins/base/src/main/kotlin/transformers/documentables/EmptyModulesFilterTransformer.kt @@ -0,0 +1,10 @@ +package org.jetbrains.dokka.base.transformers.documentables + +import org.jetbrains.dokka.model.DModule +import org.jetbrains.dokka.transformers.documentation.PreMergeDocumentableTransformer + +class EmptyModulesFilterTransformer : PreMergeDocumentableTransformer { + override fun invoke(modules: List<DModule>): List<DModule> { + return modules.filter { it.children.isNotEmpty() } + } +}
\ No newline at end of file |