diff options
Diffstat (limited to 'plugins/all-modules-page/src')
7 files changed, 82 insertions, 39 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( diff --git a/plugins/all-modules-page/src/test/kotlin/MultiModuleDokkaTestGenerator.kt b/plugins/all-modules-page/src/test/kotlin/MultiModuleDokkaTestGenerator.kt index c8542dfe..9213c90b 100644 --- a/plugins/all-modules-page/src/test/kotlin/MultiModuleDokkaTestGenerator.kt +++ b/plugins/all-modules-page/src/test/kotlin/MultiModuleDokkaTestGenerator.kt @@ -34,7 +34,10 @@ class MultiModuleDokkaTestGenerator( val generation = context.single(CoreExtensions.generation) as AllModulesPageGeneration - val allModulesPage = generation.createAllModulesPage() + val generationContext = generation.processSubmodules() + submoduleProcessingStage(context) + + val allModulesPage = generation.createAllModulesPage(generationContext) allModulesPageCreationStage(allModulesPage) val transformedPages = generation.transformAllModulesPage(allModulesPage) @@ -43,8 +46,11 @@ class MultiModuleDokkaTestGenerator( generation.render(transformedPages) renderingStage(transformedPages, context) - generation.processSubmodules() - submoduleProcessingStage(context) + generation.processMultiModule(transformedPages) + processMultiModule(transformedPages) + + generation.finishProcessingSubmodules() + finishProcessingSubmodules(context) } } @@ -55,6 +61,8 @@ open class MultiModuleTestMethods( open val pagesTransformationStage: (RootPageNode) -> Unit, open val renderingStage: (RootPageNode, DokkaContext) -> Unit, open val submoduleProcessingStage: (DokkaContext) -> Unit, + open val processMultiModule: (RootPageNode) -> Unit, + open val finishProcessingSubmodules: (DokkaContext) -> Unit, ) : TestMethods class MultiModuleTestBuilder : TestBuilder<MultiModuleTestMethods>() { @@ -63,6 +71,8 @@ class MultiModuleTestBuilder : TestBuilder<MultiModuleTestMethods>() { var pagesTransformationStage: (RootPageNode) -> Unit = {} var renderingStage: (RootPageNode, DokkaContext) -> Unit = { _, _ -> } var submoduleProcessingStage: (DokkaContext) -> Unit = {} + var processMultiModule: (RootPageNode) -> Unit = {} + var finishProcessingSubmodules: (DokkaContext) -> Unit = {} override fun build() = MultiModuleTestMethods( pluginsSetupStage, @@ -70,6 +80,8 @@ class MultiModuleTestBuilder : TestBuilder<MultiModuleTestMethods>() { pagesTransformationStage, renderingStage, submoduleProcessingStage, + processMultiModule, + finishProcessingSubmodules ) } diff --git a/plugins/all-modules-page/src/test/kotlin/templates/ResolveLinkCommandResolutionTest.kt b/plugins/all-modules-page/src/test/kotlin/templates/ResolveLinkCommandResolutionTest.kt index cbf254a0..2637714f 100644 --- a/plugins/all-modules-page/src/test/kotlin/templates/ResolveLinkCommandResolutionTest.kt +++ b/plugins/all-modules-page/src/test/kotlin/templates/ResolveLinkCommandResolutionTest.kt @@ -60,7 +60,7 @@ class ResolveLinkCommandResolutionTest : MultiModuleAbstractTest() { val configuration = configuration() testFromData(configuration, preserveOutputLocation = true) { - submoduleProcessingStage = { + finishProcessingSubmodules = { assertHtmlEqualsIgnoringWhitespace(expected, contentFile.readText()) } } @@ -89,7 +89,7 @@ class ResolveLinkCommandResolutionTest : MultiModuleAbstractTest() { val configuration = configuration() testFromData(configuration, preserveOutputLocation = true) { - submoduleProcessingStage = { + finishProcessingSubmodules = { assertHtmlEqualsIgnoringWhitespace(expected, contentFile.readText()) } } diff --git a/plugins/all-modules-page/src/test/kotlin/templates/ResolveLinkGfmCommandResolutionTest.kt b/plugins/all-modules-page/src/test/kotlin/templates/ResolveLinkGfmCommandResolutionTest.kt index 75576727..185a179d 100644 --- a/plugins/all-modules-page/src/test/kotlin/templates/ResolveLinkGfmCommandResolutionTest.kt +++ b/plugins/all-modules-page/src/test/kotlin/templates/ResolveLinkGfmCommandResolutionTest.kt @@ -55,7 +55,7 @@ class ResolveLinkGfmCommandResolutionTest : MultiModuleAbstractTest() { val configuration = configuration() testFromData(configuration, pluginOverrides = listOf(GfmTemplateProcessingPlugin(), GfmPlugin()), preserveOutputLocation = true) { - submoduleProcessingStage = { + finishProcessingSubmodules = { assertEquals(expected, content.readText().trim()) } } |