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/all-modules-page/src/main | |
parent | 1f592a7ec2786e0a0b77d224d1414ef3042caae4 (diff) | |
download | dokka-fdf8a298f586d7e334c312346b70b59c64c8d037.tar.gz dokka-fdf8a298f586d7e334c312346b70b59c64c8d037.tar.bz2 dokka-fdf8a298f586d7e334c312346b70b59c64c8d037.zip |
Empty modules filtering (#1699)
Diffstat (limited to 'plugins/all-modules-page/src/main')
4 files changed, 64 insertions, 33 deletions
diff --git a/plugins/all-modules-page/src/main/kotlin/AllModulesPageGeneration.kt b/plugins/all-modules-page/src/main/kotlin/AllModulesPageGeneration.kt index 0013feed..c11b18b2 100644 --- a/plugins/all-modules-page/src/main/kotlin/AllModulesPageGeneration.kt +++ b/plugins/all-modules-page/src/main/kotlin/AllModulesPageGeneration.kt @@ -9,6 +9,8 @@ import org.jetbrains.dokka.plugability.plugin import org.jetbrains.dokka.plugability.query import org.jetbrains.dokka.plugability.querySingle import org.jetbrains.dokka.templates.TemplatingPlugin +import org.jetbrains.dokka.templates.TemplatingResult +import org.jetbrains.dokka.transformers.pages.CreationContext import org.jetbrains.dokka.versioning.VersioningPlugin class AllModulesPageGeneration(private val context: DokkaContext) : Generation { @@ -18,9 +20,11 @@ class AllModulesPageGeneration(private val context: DokkaContext) : Generation { private val versioningPlugin by lazy { context.plugin<VersioningPlugin>() } override fun Timer.generate() { + report("Processing submodules") + val generationContext = processSubmodules() report("Creating all modules page") - val pages = createAllModulesPage() + val pages = createAllModulesPage(generationContext) report("Copy previous documentation") handlePreviousDocs() @@ -31,15 +35,19 @@ class AllModulesPageGeneration(private val context: DokkaContext) : Generation { report("Rendering") render(transformedPages) - report("Processing submodules") - processSubmodules() + report("Processing multimodule") + processMultiModule(transformedPages) + + report("Finish submodule processing") + finishProcessingSubmodules() } override val generationName = "index page for project" fun handlePreviousDocs() = versioningPlugin.querySingle { versioningHandler }.invoke() - fun createAllModulesPage() = allModulesPagePlugin.querySingle { allModulesPageCreator }.invoke() + fun createAllModulesPage(allModulesContext: DefaultAllModulesContext) = + allModulesPagePlugin.querySingle { allModulesPageCreator }.invoke(allModulesContext) fun transformAllModulesPage(pages: RootPageNode) = allModulesPagePlugin.query { allModulesPageTransformer }.fold(pages) { acc, t -> t(acc) } @@ -49,5 +57,17 @@ class AllModulesPageGeneration(private val context: DokkaContext) : Generation { } fun processSubmodules() = - templatingPlugin.querySingle { templateProcessor }.process() + templatingPlugin.querySingle { submoduleTemplateProcessor } + .process(context.configuration.modules) + .let { DefaultAllModulesContext(it) } + + fun processMultiModule(root: RootPageNode) = + templatingPlugin.querySingle { multimoduleTemplateProcessor }.process(root) + + fun finishProcessingSubmodules() = + templatingPlugin.query { templateProcessingStrategy }.forEach { it.finish(context.configuration.outputDir) } + + data class DefaultAllModulesContext(val nonEmptyModules: List<String>) : CreationContext { + constructor(templating: TemplatingResult) : this(templating.modules) + } }
\ No newline at end of file diff --git a/plugins/all-modules-page/src/main/kotlin/AllModulesPagePlugin.kt b/plugins/all-modules-page/src/main/kotlin/AllModulesPagePlugin.kt index 9f4b62ee..e6556b07 100644 --- a/plugins/all-modules-page/src/main/kotlin/AllModulesPagePlugin.kt +++ b/plugins/all-modules-page/src/main/kotlin/AllModulesPagePlugin.kt @@ -12,7 +12,7 @@ import org.jetbrains.dokka.transformers.pages.PageTransformer class AllModulesPagePlugin : DokkaPlugin() { val partialLocationProviderFactory by extensionPoint<LocationProviderFactory>() - val allModulesPageCreator by extensionPoint<PageCreator>() + val allModulesPageCreator by extensionPoint<PageCreator<AllModulesPageGeneration.DefaultAllModulesContext>>() val allModulesPageTransformer by extensionPoint<PageTransformer>() val externalModuleLinkResolver by extensionPoint<ExternalModuleLinkResolver>() diff --git a/plugins/all-modules-page/src/main/kotlin/MultimoduleLocationProvider.kt b/plugins/all-modules-page/src/main/kotlin/MultimoduleLocationProvider.kt index c7c32d55..1a323f63 100644 --- a/plugins/all-modules-page/src/main/kotlin/MultimoduleLocationProvider.kt +++ b/plugins/all-modules-page/src/main/kotlin/MultimoduleLocationProvider.kt @@ -5,24 +5,30 @@ import org.jetbrains.dokka.base.resolvers.local.DokkaBaseLocationProvider import org.jetbrains.dokka.base.resolvers.local.LocationProviderFactory import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.DisplaySourceSet +import org.jetbrains.dokka.pages.ContentPage import org.jetbrains.dokka.pages.PageNode import org.jetbrains.dokka.pages.RootPageNode import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.plugability.plugin import org.jetbrains.dokka.plugability.querySingle -open class MultimoduleLocationProvider(private val root: RootPageNode, dokkaContext: DokkaContext) : DokkaBaseLocationProvider(root, dokkaContext) { +open class MultimoduleLocationProvider(private val root: RootPageNode, dokkaContext: DokkaContext) : + DokkaBaseLocationProvider(root, dokkaContext) { - private val defaultLocationProvider = dokkaContext.plugin<AllModulesPagePlugin>().querySingle { partialLocationProviderFactory }.getLocationProvider(root) - private val externalModuleLinkResolver = dokkaContext.plugin<AllModulesPagePlugin>().querySingle { externalModuleLinkResolver } + private val defaultLocationProvider = + dokkaContext.plugin<AllModulesPagePlugin>().querySingle { partialLocationProviderFactory } + .getLocationProvider(root) + private val externalModuleLinkResolver = + dokkaContext.plugin<AllModulesPagePlugin>().querySingle { externalModuleLinkResolver } override fun resolve(dri: DRI, sourceSets: Set<DisplaySourceSet>, context: PageNode?) = - if (dri == MultimodulePageCreator.MULTIMODULE_ROOT_DRI) pathToRoot(root) - else dri.takeIf { it.packageName == MULTIMODULE_PACKAGE_PLACEHOLDER }?.classNames - ?.let(externalModuleLinkResolver::resolveLinkToModuleIndex) + if (dri == MultimodulePageCreator.MULTIMODULE_ROOT_DRI) pathToRoot(root) + "index" + else dri.takeIf { it.packageName == MULTIMODULE_PACKAGE_PLACEHOLDER }?.classNames + ?.let(externalModuleLinkResolver::resolveLinkToModuleIndex) override fun resolve(node: PageNode, context: PageNode?, skipExtension: Boolean) = - defaultLocationProvider.resolve(node, context, skipExtension) + if (node is ContentPage && MultimodulePageCreator.MULTIMODULE_ROOT_DRI in node.dri) pathToRoot(root) + "index" + else defaultLocationProvider.resolve(node, context, skipExtension) override fun pathToRoot(from: PageNode): String = defaultLocationProvider.pathToRoot(from) @@ -30,6 +36,6 @@ open class MultimoduleLocationProvider(private val root: RootPageNode, dokkaCont class Factory(private val context: DokkaContext) : LocationProviderFactory { override fun getLocationProvider(pageNode: RootPageNode) = - MultimoduleLocationProvider(pageNode, context) + MultimoduleLocationProvider(pageNode, context) } } diff --git a/plugins/all-modules-page/src/main/kotlin/MultimodulePageCreator.kt b/plugins/all-modules-page/src/main/kotlin/MultimodulePageCreator.kt index dec850b2..bcab4e65 100644 --- a/plugins/all-modules-page/src/main/kotlin/MultimodulePageCreator.kt +++ b/plugins/all-modules-page/src/main/kotlin/MultimodulePageCreator.kt @@ -29,13 +29,13 @@ import org.jetbrains.dokka.versioning.VersioningPlugin class MultimodulePageCreator( private val context: DokkaContext, -) : PageCreator { +) : PageCreator<AllModulesPageGeneration.DefaultAllModulesContext> { private val logger: DokkaLogger = context.logger private val commentsConverter by lazy { context.plugin<DokkaBase>().querySingle { commentsToContentConverter } } private val signatureProvider by lazy { context.plugin<DokkaBase>().querySingle { signatureProvider } } - override fun invoke(): RootPageNode { + override fun invoke(creationContext: AllModulesPageGeneration.DefaultAllModulesContext): RootPageNode { val modules = context.configuration.modules val sourceSetData = emptySet<DokkaSourceSet>() val builder = PageContentBuilder(commentsConverter, signatureProvider, context.logger) @@ -51,24 +51,29 @@ class MultimodulePageCreator( } header(2, "All modules:") table(styles = setOf(MultimoduleTable)) { - modules.forEach { module -> - val displayedModuleDocumentation = getDisplayedModuleDocumentation(module) - val dri = DRI(packageName = MULTIMODULE_PACKAGE_PLACEHOLDER, classNames = module.name) - val dci = DCI(setOf(dri), ContentKind.Comment) - val extraWithAnchor = PropertyContainer.withAll(SymbolAnchorHint(module.name, ContentKind.Main)) - row(setOf(dri), emptySet(), styles = emptySet(), extra = extraWithAnchor) { - +linkNode(module.name, dri, DCI(setOf(dri), ContentKind.Main), extra = extraWithAnchor) - +ContentGroup( - children = - if (displayedModuleDocumentation != null) - DocTagToContentConverter().buildContent(displayedModuleDocumentation, dci, emptySet()) - else emptyList(), - dci = dci, - sourceSets = emptySet(), - style = emptySet() - ) + modules.filter { it.name in creationContext.nonEmptyModules }.sortedByDescending { it.name } + .forEach { module -> + val displayedModuleDocumentation = getDisplayedModuleDocumentation(module) + val dri = DRI(packageName = MULTIMODULE_PACKAGE_PLACEHOLDER, classNames = module.name) + val dci = DCI(setOf(dri), ContentKind.Comment) + val extraWithAnchor = PropertyContainer.withAll(SymbolAnchorHint(module.name, ContentKind.Main)) + row(setOf(dri), emptySet(), styles = emptySet(), extra = extraWithAnchor) { + +linkNode(module.name, dri, DCI(setOf(dri), ContentKind.Main), extra = extraWithAnchor) + +ContentGroup( + children = + if (displayedModuleDocumentation != null) + DocTagToContentConverter().buildContent( + displayedModuleDocumentation, + dci, + emptySet() + ) + else emptyList(), + dci = dci, + sourceSets = emptySet(), + style = emptySet() + ) + } } - } } } return MultimoduleRootPageNode( |