From 7fd9421a74fc2dc83156420c9c8a03dd31a5ef50 Mon Sep 17 00:00:00 2001 From: vmishenev Date: Thu, 2 Sep 2021 20:05:52 +0300 Subject: [PATCH] Refactor --- core/api/core.api | 4 ++ core/src/main/kotlin/CoreExtensions.kt | 2 + core/src/main/kotlin/renderers/PostAction.kt | 3 + .../docs/user_guide/versioning/versioning.md | 5 +- .../all-modules-page/api/all-modules-page.api | 5 +- .../main/kotlin/AllModulesPageGeneration.kt | 7 ++ .../kotlin/MultimoduleLocationProvider.kt | 5 +- plugins/base/api/base.api | 9 +-- plugins/base/src/main/kotlin/DokkaBase.kt | 1 - .../generation/SingleModuleGeneration.kt | 7 ++ .../main/kotlin/renderers/DefaultRenderer.kt | 4 +- .../src/main/kotlin/renderers/PostAction.kt | 3 - .../kotlin/renderers/html/HtmlRenderer.kt | 1 - .../templating/ReplaceVersionsCommand.kt | 2 +- .../templates/ReplaceVersionCommandHandler.kt | 4 +- plugins/versioning/api/versioning.api | 57 +++++++++------- ...ultPreviousDocumentationCopyPostAction.kt} | 14 ++-- .../ReplaceVersionCommandConsumer.kt | 6 +- .../versioning/VersioningConfiguration.kt | 4 +- .../kotlin/versioning/VersioningPlugin.kt | 14 ++-- ...sioningHandler.kt => VersioningStorage.kt} | 39 ++++++----- .../versioning/VersionsNavigationCreator.kt | 68 +++++++++---------- 22 files changed, 144 insertions(+), 120 deletions(-) create mode 100644 core/src/main/kotlin/renderers/PostAction.kt delete mode 100644 plugins/base/src/main/kotlin/renderers/PostAction.kt rename plugins/versioning/src/main/kotlin/versioning/{PreviousDocumentationCopier.kt => DefaultPreviousDocumentationCopyPostAction.kt} (79%) rename plugins/versioning/src/main/kotlin/versioning/{VersioningHandler.kt => VersioningStorage.kt} (61%) diff --git a/core/api/core.api b/core/api/core.api index 05a6207c9d..ed83f3a794 100644 --- a/core/api/core.api +++ b/core/api/core.api @@ -16,6 +16,7 @@ public final class org/jetbrains/dokka/CoreExtensions { public final fun getDocumentableTransformer ()Lorg/jetbrains/dokka/plugability/ExtensionPoint; public final fun getGeneration ()Lorg/jetbrains/dokka/plugability/ExtensionPoint; public final fun getPageTransformer ()Lorg/jetbrains/dokka/plugability/ExtensionPoint; + public final fun getPostActions ()Lorg/jetbrains/dokka/plugability/ExtensionPoint; public final fun getPreGenerationCheck ()Lorg/jetbrains/dokka/plugability/ExtensionPoint; public final fun getRenderer ()Lorg/jetbrains/dokka/plugability/ExtensionPoint; public final fun getSourceToDocumentableTranslator ()Lorg/jetbrains/dokka/plugability/ExtensionPoint; @@ -4288,6 +4289,9 @@ public abstract interface class org/jetbrains/dokka/plugability/WithUnsafeExtens public abstract fun getExtensionsSuppressed ()Ljava/util/List; } +public abstract interface class org/jetbrains/dokka/renderers/PostAction : kotlin/jvm/functions/Function0 { +} + public abstract interface class org/jetbrains/dokka/renderers/Renderer { public abstract fun render (Lorg/jetbrains/dokka/pages/RootPageNode;)V } diff --git a/core/src/main/kotlin/CoreExtensions.kt b/core/src/main/kotlin/CoreExtensions.kt index 66e717b4f1..0dd5780b61 100644 --- a/core/src/main/kotlin/CoreExtensions.kt +++ b/core/src/main/kotlin/CoreExtensions.kt @@ -2,6 +2,7 @@ package org.jetbrains.dokka import org.jetbrains.dokka.generation.Generation import org.jetbrains.dokka.plugability.* +import org.jetbrains.dokka.renderers.PostAction import org.jetbrains.dokka.renderers.Renderer import org.jetbrains.dokka.transformers.documentation.DocumentableMerger import org.jetbrains.dokka.transformers.documentation.DocumentableToPageTranslator @@ -21,6 +22,7 @@ object CoreExtensions { val documentableToPageTranslator by coreExtensionPoint() val pageTransformer by coreExtensionPoint() val renderer by coreExtensionPoint() + val postActions by coreExtensionPoint() private fun coreExtensionPoint() = object { operator fun provideDelegate(thisRef: CoreExtensions, property: KProperty<*>): Lazy> = diff --git a/core/src/main/kotlin/renderers/PostAction.kt b/core/src/main/kotlin/renderers/PostAction.kt new file mode 100644 index 0000000000..e47d5d22be --- /dev/null +++ b/core/src/main/kotlin/renderers/PostAction.kt @@ -0,0 +1,3 @@ +package org.jetbrains.dokka.renderers + +interface PostAction : () -> Unit \ No newline at end of file diff --git a/docs/src/doc/docs/user_guide/versioning/versioning.md b/docs/src/doc/docs/user_guide/versioning/versioning.md index 0ee0082985..e9dff82a47 100644 --- a/docs/src/doc/docs/user_guide/versioning/versioning.md +++ b/docs/src/doc/docs/user_guide/versioning/versioning.md @@ -12,7 +12,10 @@ Versioning can be configured using: (if it's specified). * versionsOrdering - an optional list of strings representing the ordering of versions that should be visible. By default, Dokka will try to use semantic versioning to create such ordering. - +* renderVersionsNavigationOnAllPages - a bool value. + By default, Dokka renders a versions navigation on all pages. + You should enable the plugin in all submodules to render a versions navigation on all pages. + Above configuration should be placed under the `pluginsConfiguration` block specific for your build tool. Configuration object is named `org.jetbrains.dokka.versioning.VersioningConfiguration`. diff --git a/plugins/all-modules-page/api/all-modules-page.api b/plugins/all-modules-page/api/all-modules-page.api index 004ea9d725..9d8bca9b48 100644 --- a/plugins/all-modules-page/api/all-modules-page.api +++ b/plugins/all-modules-page/api/all-modules-page.api @@ -7,6 +7,7 @@ public final class org/jetbrains/dokka/allModulesPage/AllModulesPageGeneration : public final fun processMultiModule (Lorg/jetbrains/dokka/pages/RootPageNode;)V public final fun processSubmodules ()Lorg/jetbrains/dokka/allModulesPage/AllModulesPageGeneration$DefaultAllModulesContext; public final fun render (Lorg/jetbrains/dokka/pages/RootPageNode;)V + public final fun runPostActions ()V public final fun transformAllModulesPage (Lorg/jetbrains/dokka/pages/RootPageNode;)Lorg/jetbrains/dokka/pages/RootPageNode; } @@ -50,8 +51,10 @@ public abstract interface class org/jetbrains/dokka/allModulesPage/ExternalModul } public class org/jetbrains/dokka/allModulesPage/MultimoduleLocationProvider : org/jetbrains/dokka/base/resolvers/local/DokkaBaseLocationProvider { - public fun (Lorg/jetbrains/dokka/pages/RootPageNode;Lorg/jetbrains/dokka/plugability/DokkaContext;)V + public fun (Lorg/jetbrains/dokka/pages/RootPageNode;Lorg/jetbrains/dokka/plugability/DokkaContext;Ljava/lang/String;)V + public synthetic fun (Lorg/jetbrains/dokka/pages/RootPageNode;Lorg/jetbrains/dokka/plugability/DokkaContext;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public fun ancestors (Lorg/jetbrains/dokka/pages/PageNode;)Ljava/util/List; + public final fun getExtension ()Ljava/lang/String; public fun pathToRoot (Lorg/jetbrains/dokka/pages/PageNode;)Ljava/lang/String; public fun resolve (Lorg/jetbrains/dokka/links/DRI;Ljava/util/Set;Lorg/jetbrains/dokka/pages/PageNode;)Ljava/lang/String; public fun resolve (Lorg/jetbrains/dokka/pages/PageNode;Lorg/jetbrains/dokka/pages/PageNode;Z)Ljava/lang/String; diff --git a/plugins/all-modules-page/src/main/kotlin/AllModulesPageGeneration.kt b/plugins/all-modules-page/src/main/kotlin/AllModulesPageGeneration.kt index b163e9cd0e..8558750eb6 100644 --- a/plugins/all-modules-page/src/main/kotlin/AllModulesPageGeneration.kt +++ b/plugins/all-modules-page/src/main/kotlin/AllModulesPageGeneration.kt @@ -35,6 +35,9 @@ class AllModulesPageGeneration(private val context: DokkaContext) : Generation { report("Finish submodule processing") finishProcessingSubmodules() + + report("Running post-actions") + runPostActions() } override val generationName = "index page for project" @@ -49,6 +52,10 @@ class AllModulesPageGeneration(private val context: DokkaContext) : Generation { context.single(CoreExtensions.renderer).render(transformedPages) } + fun runPostActions() { + context[CoreExtensions.postActions].forEach { it() } + } + fun processSubmodules() = templatingPlugin.querySingle { submoduleTemplateProcessor } .process(context.configuration.modules) diff --git a/plugins/all-modules-page/src/main/kotlin/MultimoduleLocationProvider.kt b/plugins/all-modules-page/src/main/kotlin/MultimoduleLocationProvider.kt index 9c7344e2f5..dab5be094b 100644 --- a/plugins/all-modules-page/src/main/kotlin/MultimoduleLocationProvider.kt +++ b/plugins/all-modules-page/src/main/kotlin/MultimoduleLocationProvider.kt @@ -12,7 +12,8 @@ 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) : +open class MultimoduleLocationProvider(private val root: RootPageNode, dokkaContext: DokkaContext, + val extension: String = ".html") : DokkaBaseLocationProvider(root, dokkaContext) { private val defaultLocationProvider = @@ -27,7 +28,7 @@ open class MultimoduleLocationProvider(private val root: RootPageNode, dokkaCont ?.let(externalModuleLinkResolver::resolveLinkToModuleIndex) override fun resolve(node: PageNode, context: PageNode?, skipExtension: Boolean) = - if (node is ContentPage && MultimodulePageCreator.MULTIMODULE_ROOT_DRI in node.dri) pathToRoot(root) + "index${if(skipExtension)"" else ".html"}" + if (node is ContentPage && MultimodulePageCreator.MULTIMODULE_ROOT_DRI in node.dri) pathToRoot(root) + "index" + if (!skipExtension) extension else "" else defaultLocationProvider.resolve(node, context, skipExtension) override fun pathToRoot(from: PageNode): String = defaultLocationProvider.pathToRoot(from) diff --git a/plugins/base/api/base.api b/plugins/base/api/base.api index efee187c3b..2ab821d427 100644 --- a/plugins/base/api/base.api +++ b/plugins/base/api/base.api @@ -40,7 +40,6 @@ public final class org/jetbrains/dokka/base/DokkaBase : org/jetbrains/dokka/plug public final fun getPageMerger ()Lorg/jetbrains/dokka/plugability/Extension; public final fun getPageMergerStrategy ()Lorg/jetbrains/dokka/plugability/ExtensionPoint; public final fun getPathToRootConsumer ()Lorg/jetbrains/dokka/plugability/Extension; - public final fun getPostActions ()Lorg/jetbrains/dokka/plugability/ExtensionPoint; public final fun getPreMergeDocumentableTransformer ()Lorg/jetbrains/dokka/plugability/ExtensionPoint; public final fun getPsiToDocumentableTranslator ()Lorg/jetbrains/dokka/plugability/Extension; public final fun getReplaceVersionConsumer ()Lorg/jetbrains/dokka/plugability/Extension; @@ -101,6 +100,7 @@ public final class org/jetbrains/dokka/base/generation/SingleModuleGeneration : public final fun mergeDocumentationModels (Ljava/util/List;)Lorg/jetbrains/dokka/model/DModule; public final fun render (Lorg/jetbrains/dokka/pages/RootPageNode;)V public final fun reportAfterRendering ()V + public final fun runPostActions ()V public final fun transformDocumentationModelAfterMerge (Lorg/jetbrains/dokka/model/DModule;)Lorg/jetbrains/dokka/model/DModule; public final fun transformDocumentationModelBeforeMerge (Ljava/util/List;)Ljava/util/List; public final fun transformPages (Lorg/jetbrains/dokka/pages/RootPageNode;)Lorg/jetbrains/dokka/pages/RootPageNode; @@ -245,7 +245,6 @@ public abstract class org/jetbrains/dokka/base/renderers/DefaultRenderer : org/j protected final fun getContext ()Lorg/jetbrains/dokka/plugability/DokkaContext; protected final fun getLocationProvider ()Lorg/jetbrains/dokka/base/resolvers/local/LocationProvider; protected final fun getOutputWriter ()Lorg/jetbrains/dokka/base/renderers/OutputWriter; - protected fun getPostActions ()Ljava/lang/Iterable; protected fun getPreprocessors ()Ljava/lang/Iterable; protected final fun groupDivergentInstances (Lorg/jetbrains/dokka/pages/ContentDivergentGroup;Lorg/jetbrains/dokka/pages/ContentPage;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;)Ljava/util/Map; public fun render (Lorg/jetbrains/dokka/pages/RootPageNode;)V @@ -300,9 +299,6 @@ public final class org/jetbrains/dokka/base/renderers/PackageListService$Compani public final fun renderPackageList (Ljava/util/Map;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; } -public abstract interface class org/jetbrains/dokka/base/renderers/PostAction : kotlin/jvm/functions/Function0 { -} - public final class org/jetbrains/dokka/base/renderers/RootCreator : org/jetbrains/dokka/transformers/pages/PageTransformer { public static final field INSTANCE Lorg/jetbrains/dokka/base/renderers/RootCreator; public fun invoke (Lorg/jetbrains/dokka/pages/RootPageNode;)Lorg/jetbrains/dokka/pages/RendererSpecificRootPage; @@ -371,8 +367,6 @@ public class org/jetbrains/dokka/base/renderers/html/HtmlRenderer : org/jetbrain public synthetic fun buildText (Ljava/lang/Object;Lorg/jetbrains/dokka/pages/ContentText;)V public fun buildText (Lkotlinx/html/FlowContent;Lorg/jetbrains/dokka/pages/ContentText;)V public fun clickableLogo (Lkotlinx/html/FlowContent;Lorg/jetbrains/dokka/pages/PageNode;Ljava/lang/String;)V - public synthetic fun getPostActions ()Ljava/lang/Iterable; - protected fun getPostActions ()Ljava/util/List; public synthetic fun getPreprocessors ()Ljava/lang/Iterable; protected fun getPreprocessors ()Ljava/util/List; public fun render (Lorg/jetbrains/dokka/pages/RootPageNode;)V @@ -980,7 +974,6 @@ public final class org/jetbrains/dokka/base/templating/ReplaceVersionsCommand : public fun equals (Ljava/lang/Object;)Z public final fun getLocation ()Ljava/lang/String; public fun hashCode ()I - public final fun setLocation (Ljava/lang/String;)V public fun toString ()Ljava/lang/String; } diff --git a/plugins/base/src/main/kotlin/DokkaBase.kt b/plugins/base/src/main/kotlin/DokkaBase.kt index 8332e5e2cd..fc1384618f 100644 --- a/plugins/base/src/main/kotlin/DokkaBase.kt +++ b/plugins/base/src/main/kotlin/DokkaBase.kt @@ -43,7 +43,6 @@ class DokkaBase : DokkaPlugin() { val externalLocationProviderFactory by extensionPoint() val outputWriter by extensionPoint() val htmlPreprocessors by extensionPoint() - val postActions by extensionPoint() val kotlinAnalysis by extensionPoint() val tabSortingStrategy by extensionPoint() val immediateHtmlCommandConsumer by extensionPoint() diff --git a/plugins/base/src/main/kotlin/generation/SingleModuleGeneration.kt b/plugins/base/src/main/kotlin/generation/SingleModuleGeneration.kt index e0deef17bd..5cdeeb40f3 100644 --- a/plugins/base/src/main/kotlin/generation/SingleModuleGeneration.kt +++ b/plugins/base/src/main/kotlin/generation/SingleModuleGeneration.kt @@ -46,6 +46,9 @@ class SingleModuleGeneration(private val context: DokkaContext) : Generation { report("Rendering") render(transformedPages) + report("Running post-actions") + runPostActions() + reportAfterRendering() } @@ -76,6 +79,10 @@ class SingleModuleGeneration(private val context: DokkaContext) : Generation { context.single(CoreExtensions.renderer).render(transformedPages) } + fun runPostActions() { + context[CoreExtensions.postActions].forEach { it() } + } + fun validityCheck(context: DokkaContext) { val (preGenerationCheckResult, checkMessages) = context[CoreExtensions.preGenerationCheck].fold( Pair(true, emptyList()) diff --git a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt index cb438d413f..2a21337fda 100644 --- a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt @@ -12,6 +12,7 @@ import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.plugability.plugin import org.jetbrains.dokka.plugability.querySingle +import org.jetbrains.dokka.renderers.PostAction import org.jetbrains.dokka.renderers.Renderer import org.jetbrains.dokka.transformers.pages.PageTransformer @@ -25,7 +26,6 @@ abstract class DefaultRenderer( private set protected open val preprocessors: Iterable = emptyList() - protected open val postActions: Iterable = emptyList() abstract fun T.buildHeader(level: Int, node: ContentHeader, content: T.() -> Unit) abstract fun T.buildLink(address: String, content: T.() -> Unit) @@ -210,8 +210,6 @@ abstract class DefaultRenderer( runBlocking(Dispatchers.Default) { renderPages(newRoot) } - - postActions.forEach { it() } } protected fun ContentDivergentGroup.groupDivergentInstances( diff --git a/plugins/base/src/main/kotlin/renderers/PostAction.kt b/plugins/base/src/main/kotlin/renderers/PostAction.kt deleted file mode 100644 index 62b088c646..0000000000 --- a/plugins/base/src/main/kotlin/renderers/PostAction.kt +++ /dev/null @@ -1,3 +0,0 @@ -package org.jetbrains.dokka.base.renderers - -interface PostAction : () -> Unit \ No newline at end of file diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index fa0d8b6485..10a5636a59 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -40,7 +40,6 @@ open class HtmlRenderer( private var shouldRenderSourceSetBubbles: Boolean = false override val preprocessors = context.plugin().query { htmlPreprocessors } - override val postActions = context.plugin().query { postActions } private val tabSortingStrategy = context.plugin().querySingle { tabSortingStrategy } diff --git a/plugins/base/src/main/kotlin/templating/ReplaceVersionsCommand.kt b/plugins/base/src/main/kotlin/templating/ReplaceVersionsCommand.kt index 01f35c7dd7..89f267b3d9 100644 --- a/plugins/base/src/main/kotlin/templating/ReplaceVersionsCommand.kt +++ b/plugins/base/src/main/kotlin/templating/ReplaceVersionsCommand.kt @@ -1,3 +1,3 @@ package org.jetbrains.dokka.base.templating -data class ReplaceVersionsCommand(var location: String = ""): Command \ No newline at end of file +data class ReplaceVersionsCommand(val location: String = ""): Command \ No newline at end of file diff --git a/plugins/templating/src/main/kotlin/templates/ReplaceVersionCommandHandler.kt b/plugins/templating/src/main/kotlin/templates/ReplaceVersionCommandHandler.kt index 5d2ff70ef3..8035fc83be 100644 --- a/plugins/templating/src/main/kotlin/templates/ReplaceVersionCommandHandler.kt +++ b/plugins/templating/src/main/kotlin/templates/ReplaceVersionCommandHandler.kt @@ -16,7 +16,7 @@ class ReplaceVersionCommandHandler(private val context: DokkaContext) : CommandH val position = element.elementSiblingIndex() val parent = element.parent() element.remove() - - parent.insertChildren(position, TextNode(context.configuration.moduleVersion.orEmpty())) + context.configuration.moduleVersion?.takeIf { it.isNotEmpty() } + ?.let { parent.insertChildren(position, TextNode(it)) } } } \ No newline at end of file diff --git a/plugins/versioning/api/versioning.api b/plugins/versioning/api/versioning.api index aecca69bc9..a339491a3d 100644 --- a/plugins/versioning/api/versioning.api +++ b/plugins/versioning/api/versioning.api @@ -4,18 +4,36 @@ public final class org/jetbrains/dokka/versioning/ByConfigurationVersionOrdering public fun order (Ljava/util/List;)Ljava/util/List; } -public final class org/jetbrains/dokka/versioning/DefaultVersioningHandler : org/jetbrains/dokka/versioning/VersioningHandler { +public final class org/jetbrains/dokka/versioning/CurrentVersion { + public fun (Ljava/lang/String;Ljava/io/File;)V + public final fun component1 ()Ljava/lang/String; + public final fun component2 ()Ljava/io/File; + public final fun copy (Ljava/lang/String;Ljava/io/File;)Lorg/jetbrains/dokka/versioning/CurrentVersion; + public static synthetic fun copy$default (Lorg/jetbrains/dokka/versioning/CurrentVersion;Ljava/lang/String;Ljava/io/File;ILjava/lang/Object;)Lorg/jetbrains/dokka/versioning/CurrentVersion; + public fun equals (Ljava/lang/Object;)Z + public final fun getDir ()Ljava/io/File; + public final fun getName ()Ljava/lang/String; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class org/jetbrains/dokka/versioning/DefaultPreviousDocumentationCopyPostAction : org/jetbrains/dokka/renderers/PostAction { + public fun (Lorg/jetbrains/dokka/plugability/DokkaContext;)V + public synthetic fun invoke ()Ljava/lang/Object; + public fun invoke ()V +} + +public final class org/jetbrains/dokka/versioning/DefaultVersioningStorage : org/jetbrains/dokka/versioning/VersioningStorage { public fun (Lorg/jetbrains/dokka/plugability/DokkaContext;)V - public fun currentVersion ()Ljava/io/File; + public fun createVersionFile ()V public final fun getContext ()Lorg/jetbrains/dokka/plugability/DokkaContext; + public fun getCurrentVersion ()Lorg/jetbrains/dokka/versioning/CurrentVersion; public fun getPreviousVersions ()Ljava/util/Map; - public fun getVersions ()Ljava/util/Map; } public final class org/jetbrains/dokka/versioning/HtmlVersionsNavigationCreator : org/jetbrains/dokka/versioning/VersionsNavigationCreator { public fun (Lorg/jetbrains/dokka/plugability/DokkaContext;)V public fun invoke (Ljava/io/File;)Ljava/lang/String; - public fun invoke (Ljava/lang/String;)Ljava/lang/String; } public final class org/jetbrains/dokka/versioning/MultiModuleStylesInstaller : org/jetbrains/dokka/transformers/pages/PageTransformer { @@ -73,58 +91,51 @@ public final class org/jetbrains/dokka/versioning/VersioningConfiguration : org/ public fun equals (Ljava/lang/Object;)Z public final fun getOlderVersions ()Ljava/util/List; public final fun getOlderVersionsDir ()Ljava/io/File; + public final fun getRenderVersionsNavigationOnAllPages ()Ljava/lang/Boolean; public final fun getVersion ()Ljava/lang/String; public final fun getVersionsOrdering ()Ljava/util/List; public fun hashCode ()I - public final fun isOnlyOnRootPage ()Ljava/lang/Boolean; public final fun setOlderVersions (Ljava/util/List;)V public final fun setOlderVersionsDir (Ljava/io/File;)V - public final fun setOnlyOnRootPage (Ljava/lang/Boolean;)V + public final fun setRenderVersionsNavigationOnAllPages (Ljava/lang/Boolean;)V public final fun setVersion (Ljava/lang/String;)V public final fun setVersionsOrdering (Ljava/util/List;)V public fun toString ()Ljava/lang/String; } public final class org/jetbrains/dokka/versioning/VersioningConfiguration$Companion { - public final fun getDefaultIsOnlyOnRootPage ()Z public final fun getDefaultOlderVersions ()Ljava/util/List; public final fun getDefaultOlderVersionsDir ()Ljava/io/File; + public final fun getDefaultRenderVersionsNavigationOnAllPages ()Z public final fun getDefaultVersion ()Ljava/lang/Void; public final fun getDefaultVersionsOrdering ()Ljava/util/List; } -public abstract interface class org/jetbrains/dokka/versioning/VersioningHandler { - public abstract fun currentVersion ()Ljava/io/File; - public abstract fun getPreviousVersions ()Ljava/util/Map; - public abstract fun getVersions ()Ljava/util/Map; -} - public final class org/jetbrains/dokka/versioning/VersioningPlugin : org/jetbrains/dokka/plugability/DokkaPlugin { public fun ()V public final fun getCssStyleInstaller ()Lorg/jetbrains/dokka/plugability/Extension; - public final fun getDefaultVersioningHandler ()Lorg/jetbrains/dokka/plugability/Extension; public final fun getDefaultVersioningNavigationCreator ()Lorg/jetbrains/dokka/plugability/Extension; - public final fun getPreviousDocumentationCopier ()Lorg/jetbrains/dokka/plugability/Extension; + public final fun getDefaultVersioningStorage ()Lorg/jetbrains/dokka/plugability/Extension; + public final fun getPreviousDocumentationCopyPostAction ()Lorg/jetbrains/dokka/plugability/Extension; public final fun getReplaceVersionCommandHandler ()Lorg/jetbrains/dokka/plugability/Extension; public final fun getResolveLinkConsumer ()Lorg/jetbrains/dokka/plugability/Extension; - public final fun getVersioningHandler ()Lorg/jetbrains/dokka/plugability/ExtensionPoint; + public final fun getVersioningStorage ()Lorg/jetbrains/dokka/plugability/ExtensionPoint; public final fun getVersionsDefaultOrdering ()Lorg/jetbrains/dokka/plugability/Extension; public final fun getVersionsNavigationCreator ()Lorg/jetbrains/dokka/plugability/ExtensionPoint; public final fun getVersionsOrdering ()Lorg/jetbrains/dokka/plugability/ExtensionPoint; } +public abstract interface class org/jetbrains/dokka/versioning/VersioningStorage { + public abstract fun createVersionFile ()V + public abstract fun getCurrentVersion ()Lorg/jetbrains/dokka/versioning/CurrentVersion; + public abstract fun getPreviousVersions ()Ljava/util/Map; +} + public abstract interface class org/jetbrains/dokka/versioning/VersionsNavigationCreator { public abstract fun invoke (Ljava/io/File;)Ljava/lang/String; - public abstract fun invoke (Ljava/lang/String;)Ljava/lang/String; } public abstract interface class org/jetbrains/dokka/versioning/VersionsOrdering { public abstract fun order (Ljava/util/List;)Ljava/util/List; } -public final class versioning/DefaultPreviousDocumentationCopier : org/jetbrains/dokka/base/renderers/PostAction { - public fun (Lorg/jetbrains/dokka/plugability/DokkaContext;)V - public synthetic fun invoke ()Ljava/lang/Object; - public fun invoke ()V -} - diff --git a/plugins/versioning/src/main/kotlin/versioning/PreviousDocumentationCopier.kt b/plugins/versioning/src/main/kotlin/versioning/DefaultPreviousDocumentationCopyPostAction.kt similarity index 79% rename from plugins/versioning/src/main/kotlin/versioning/PreviousDocumentationCopier.kt rename to plugins/versioning/src/main/kotlin/versioning/DefaultPreviousDocumentationCopyPostAction.kt index 1c994406ef..6ab81d3107 100644 --- a/plugins/versioning/src/main/kotlin/versioning/PreviousDocumentationCopier.kt +++ b/plugins/versioning/src/main/kotlin/versioning/DefaultPreviousDocumentationCopyPostAction.kt @@ -1,28 +1,26 @@ -package versioning +package org.jetbrains.dokka.versioning import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking -import org.jetbrains.dokka.base.renderers.PostAction +import org.jetbrains.dokka.renderers.PostAction import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.plugability.plugin import org.jetbrains.dokka.plugability.query import org.jetbrains.dokka.plugability.querySingle import org.jetbrains.dokka.templates.TemplateProcessingStrategy import org.jetbrains.dokka.templates.TemplatingPlugin -import org.jetbrains.dokka.versioning.VersioningConfiguration -import org.jetbrains.dokka.versioning.VersioningPlugin import java.io.File -class DefaultPreviousDocumentationCopier(private val context: DokkaContext) : PostAction { - private val versioningHandler by lazy { context.plugin().querySingle { versioningHandler } } +class DefaultPreviousDocumentationCopyPostAction(private val context: DokkaContext) : PostAction { + private val versioningStorage by lazy { context.plugin().querySingle { versioningStorage } } private val processingStrategies: List = context.plugin().query { templateProcessingStrategy } override fun invoke() { - versioningHandler.previousVersions.onEach { (_, dirs) -> copyVersion(dirs.src, dirs.dst) } - .toMap() + versioningStorage.createVersionFile() + versioningStorage.previousVersions.forEach { (_, dirs) -> copyVersion(dirs.src, dirs.dst) } } private fun copyVersion(versionRoot: File, targetParent: File) { diff --git a/plugins/versioning/src/main/kotlin/versioning/ReplaceVersionCommandConsumer.kt b/plugins/versioning/src/main/kotlin/versioning/ReplaceVersionCommandConsumer.kt index d058f11755..ea524c52a1 100644 --- a/plugins/versioning/src/main/kotlin/versioning/ReplaceVersionCommandConsumer.kt +++ b/plugins/versioning/src/main/kotlin/versioning/ReplaceVersionCommandConsumer.kt @@ -17,6 +17,8 @@ class ReplaceVersionCommandConsumer(context: DokkaContext) : ImmediateHtmlComman private val versionsNavigationCreator = context.plugin().querySingle { versionsNavigationCreator } + private val versioningStorage = + context.plugin().querySingle { versioningStorage } override fun canProcess(command: Command) = command is ReplaceVersionsCommand @@ -28,7 +30,7 @@ class ReplaceVersionCommandConsumer(context: DokkaContext) : ImmediateHtmlComman command as ReplaceVersionsCommand templateCommandFor(command, tagConsumer).visit { unsafe { - +versionsNavigationCreator(command.location) + +versionsNavigationCreator(versioningStorage.currentVersion.dir.resolve(command.location)) } } } @@ -41,7 +43,7 @@ class ReplaceVersionCommandConsumer(context: DokkaContext) : ImmediateHtmlComman command as ReplaceVersionsCommand return templateCommandFor(command, tagConsumer).visitAndFinalize(tagConsumer) { unsafe { - +versionsNavigationCreator(command.location) + +versionsNavigationCreator(versioningStorage.currentVersion.dir.resolve(command.location)) } } } diff --git a/plugins/versioning/src/main/kotlin/versioning/VersioningConfiguration.kt b/plugins/versioning/src/main/kotlin/versioning/VersioningConfiguration.kt index 62da82dbe2..56c7225778 100644 --- a/plugins/versioning/src/main/kotlin/versioning/VersioningConfiguration.kt +++ b/plugins/versioning/src/main/kotlin/versioning/VersioningConfiguration.kt @@ -9,7 +9,7 @@ data class VersioningConfiguration( var olderVersions: List? = defaultOlderVersions, var versionsOrdering: List? = defaultVersionsOrdering, var version: String? = defaultVersion, - var isOnlyOnRootPage: Boolean? = defaultIsOnlyOnRootPage + var renderVersionsNavigationOnAllPages: Boolean? = defaultRenderVersionsNavigationOnAllPages ) : ConfigurableBlock { internal fun versionFromConfigurationOrModule(dokkaContext: DokkaContext): String = version ?: dokkaContext.configuration.moduleVersion ?: "1.0" @@ -26,7 +26,7 @@ data class VersioningConfiguration( val defaultOlderVersions: List? = null val defaultVersionsOrdering: List? = null val defaultVersion = null - val defaultIsOnlyOnRootPage = true + val defaultRenderVersionsNavigationOnAllPages = true const val OLDER_VERSIONS_DIR = "older" const val VERSIONS_FILE = "version.json" diff --git a/plugins/versioning/src/main/kotlin/versioning/VersioningPlugin.kt b/plugins/versioning/src/main/kotlin/versioning/VersioningPlugin.kt index bc5fcf2552..f2c4be2b62 100644 --- a/plugins/versioning/src/main/kotlin/versioning/VersioningPlugin.kt +++ b/plugins/versioning/src/main/kotlin/versioning/VersioningPlugin.kt @@ -1,22 +1,22 @@ package org.jetbrains.dokka.versioning +import org.jetbrains.dokka.CoreExtensions.postActions import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.plugability.DokkaPlugin import org.jetbrains.dokka.plugability.configuration import org.jetbrains.dokka.templates.TemplatingPlugin -import versioning.DefaultPreviousDocumentationCopier class VersioningPlugin : DokkaPlugin() { - val versioningHandler by extensionPoint() + val versioningStorage by extensionPoint() val versionsNavigationCreator by extensionPoint() val versionsOrdering by extensionPoint() private val dokkaBase by lazy { plugin() } private val templatingPlugin by lazy { plugin() } - val defaultVersioningHandler by extending { - versioningHandler providing ::DefaultVersioningHandler + val defaultVersioningStorage by extending { + versioningStorage providing ::DefaultVersioningStorage } val defaultVersioningNavigationCreator by extending { versionsNavigationCreator providing ::HtmlVersionsNavigationCreator @@ -40,7 +40,7 @@ class VersioningPlugin : DokkaPlugin() { } ?: SemVerVersionOrdering() } } - val previousDocumentationCopier by extending { - dokkaBase.postActions providing ::DefaultPreviousDocumentationCopier applyIf { !delayTemplateSubstitution } - } + val previousDocumentationCopyPostAction by extending { + postActions providing ::DefaultPreviousDocumentationCopyPostAction applyIf { !delayTemplateSubstitution } + } } \ No newline at end of file diff --git a/plugins/versioning/src/main/kotlin/versioning/VersioningHandler.kt b/plugins/versioning/src/main/kotlin/versioning/VersioningStorage.kt similarity index 61% rename from plugins/versioning/src/main/kotlin/versioning/VersioningHandler.kt rename to plugins/versioning/src/main/kotlin/versioning/VersioningStorage.kt index 626d93139e..6e1dd7ca8a 100644 --- a/plugins/versioning/src/main/kotlin/versioning/VersioningHandler.kt +++ b/plugins/versioning/src/main/kotlin/versioning/VersioningStorage.kt @@ -7,44 +7,43 @@ import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.plugability.configuration import java.io.File -interface VersioningHandler { - val versions: Map +data class VersionDirs(val src: File, val dst: File) +data class CurrentVersion(val name: String, val dir: File) + +interface VersioningStorage { val previousVersions: Map - fun currentVersion(): File? + val currentVersion: CurrentVersion + fun createVersionFile() } -data class VersionDirs(val src: File, val dst: File) typealias VersionId = String -class DefaultVersioningHandler(val context: DokkaContext) : VersioningHandler { +class DefaultVersioningStorage(val context: DokkaContext) : VersioningStorage { private val mapper = ObjectMapper() private val configuration = configuration(context) override val previousVersions: Map by lazy { configuration?.let { versionsConfiguration -> - handlePreviousVersions(versionsConfiguration.allOlderVersions(), context.configuration.outputDir) + getPreviousVersions(versionsConfiguration.allOlderVersions(), context.configuration.outputDir) } ?: emptyMap() } - private val currentVersionId: Pair by lazy { + override val currentVersion: CurrentVersion by lazy { configuration?.let { versionsConfiguration -> - versionsConfiguration.versionFromConfigurationOrModule(context) to context.configuration.outputDir - }?.also { - mapper.writeValue( - it.second.resolve(VersioningConfiguration.VERSIONS_FILE), - Version(it.first) - ) - } ?: (context.configuration.moduleVersion.orEmpty() to context.configuration.outputDir) + CurrentVersion(versionsConfiguration.versionFromConfigurationOrModule(context), + context.configuration.outputDir) + }?: CurrentVersion(context.configuration.moduleVersion.orEmpty(), context.configuration.outputDir) } - override val versions: Map by lazy { - previousVersions.map { (k, v) -> k to v.dst }.toMap() + currentVersionId - } - - override fun currentVersion() = currentVersionId.second + override fun createVersionFile() { + mapper.writeValue( + currentVersion.dir.resolve(VersioningConfiguration.VERSIONS_FILE), + Version(currentVersion.name) + ) + } - private fun handlePreviousVersions(olderVersions: List, output: File): Map = + private fun getPreviousVersions(olderVersions: List, output: File): Map = versionsFrom(olderVersions).associate { (key, srcDir) -> key to VersionDirs(srcDir, output.resolve(VersioningConfiguration.OLDER_VERSIONS_DIR).resolve(key)) } diff --git a/plugins/versioning/src/main/kotlin/versioning/VersionsNavigationCreator.kt b/plugins/versioning/src/main/kotlin/versioning/VersionsNavigationCreator.kt index 0407e5ef25..7ee0dd18f2 100644 --- a/plugins/versioning/src/main/kotlin/versioning/VersionsNavigationCreator.kt +++ b/plugins/versioning/src/main/kotlin/versioning/VersionsNavigationCreator.kt @@ -1,6 +1,5 @@ package org.jetbrains.dokka.versioning -import com.jetbrains.rd.util.first import kotlinx.html.a import kotlinx.html.div import kotlinx.html.stream.appendHTML @@ -12,62 +11,61 @@ import org.jetbrains.dokka.plugability.querySingle import java.io.File interface VersionsNavigationCreator { - operator fun invoke(location: String): String operator fun invoke(output: File): String } class HtmlVersionsNavigationCreator(private val context: DokkaContext) : VersionsNavigationCreator { - private val versioningHandler by lazy { context.plugin().querySingle { versioningHandler } } + private val versioningStorage by lazy { context.plugin().querySingle { versioningStorage } } private val versionsOrdering by lazy { context.plugin().querySingle { versionsOrdering } } private val isOnlyOnRootPage = - configuration(context)?.isOnlyOnRootPage != false + configuration(context)?.renderVersionsNavigationOnAllPages == false - override fun invoke(location: String): String = - versioningHandler.currentVersion()?.let { invoke(it.resolve(location)) }.orEmpty() + private val versions: Map by lazy { + versioningStorage.previousVersions.map { (k, v) -> k to v.dst }.toMap() + + (versioningStorage.currentVersion.name to versioningStorage.currentVersion.dir) + } override fun invoke(output: File): String { - if (versioningHandler.versions.size == 1) { - return versioningHandler.versions.first().key + if (versions.size == 1) { + return versioningStorage.currentVersion.name } val position = output.takeIf { it.isDirectory } ?: output.parentFile - if(isOnlyOnRootPage ) { - fromCurrentVersion(position)?.takeIf { position != it.value }?.also { return@invoke it.key } + if (isOnlyOnRootPage) { + getActiveVersion(position)?.takeIf { + it.value == versioningStorage.currentVersion.dir + && it.value != position + }?.also { return@invoke it.key } } - return versioningHandler.versions + return versions .let { versions -> versionsOrdering.order(versions.keys.toList()).map { it to versions[it] } } .takeIf { it.isNotEmpty() } - ?.let { versions -> + ?.let { orderedVersions -> StringBuilder().appendHTML().div(classes = "versions-dropdown") { - var relativePosition: String? = null - var activeVersion = "" + val activeVersion = getActiveVersion(position) + val relativePosition: String = activeVersion?.value?.let { output.toRelativeString(it) } ?: "index.html" div(classes = "versions-dropdown-button") { - versions.minByOrNull { (_, versionLocation) -> - versionLocation?.let { position.toRelativeString(it).length } ?: 0xffffff - }?.let { (version, versionRoot) -> - relativePosition = versionRoot?.let { output.toRelativeString(it) } - activeVersion = version - text(version) - } + activeVersion?.key?.let { text(it) } } div(classes = "versions-dropdown-data") { - versions.forEach { (version, path) -> - if (version == activeVersion) { + orderedVersions.forEach { (version, path) -> + if (version == activeVersion?.key) { a(href = output.name) { text(version) } } else { - var exist = false - val absolutePath = path?.resolve(relativePosition ?: "index.html")?.takeIf { - it.exists() || - versioningHandler.previousVersions[version]?.src?.resolve( - relativePosition ?: "index.html" - )?.exists() == true - }?.also { exist = true } - ?: path?.resolve("index.html") + val isExistsFile = + if (version == versioningStorage.currentVersion.name) + path?.resolve(relativePosition)?.exists() == true + else + versioningStorage.previousVersions[version]?.src?.resolve(relativePosition) + ?.exists() == true + + val absolutePath = + if(isExistsFile) path?.resolve(relativePosition) else path?.resolve("index.html") a(href = absolutePath?.toRelativeString(position)) { - if(exist) + if (isExistsFile) text(version) else strike { text(version) } @@ -79,8 +77,8 @@ class HtmlVersionsNavigationCreator(private val context: DokkaContext) : Version }.orEmpty() } - private fun fromCurrentVersion(position: File) = - versioningHandler.versions.minByOrNull { (_, versionLocation) -> + private fun getActiveVersion(position: File) = + versions.minByOrNull { (_, versionLocation) -> versionLocation.let { position.toRelativeString(it).length } - }.takeIf { it?.value == versioningHandler.currentVersion() } + } } \ No newline at end of file