diff --git a/core/api/core.api b/core/api/core.api index 05a6207c9d4..ed83f3a794b 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 66e717b4f1b..0dd5780b612 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 00000000000..e47d5d22bed --- /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/plugins/all-modules-page/api/all-modules-page.api b/plugins/all-modules-page/api/all-modules-page.api index 004ea9d7250..9d8bca9b481 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 b163e9cd0e4..0e16af32895 100644 --- a/plugins/all-modules-page/src/main/kotlin/AllModulesPageGeneration.kt +++ b/plugins/all-modules-page/src/main/kotlin/AllModulesPageGeneration.kt @@ -33,6 +33,9 @@ class AllModulesPageGeneration(private val context: DokkaContext) : Generation { report("Processing multimodule") processMultiModule(transformedPages) + report("Running post-actions") + runPostActions() + report("Finish submodule processing") finishProcessingSubmodules() } @@ -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 9c7344e2f5e..dab5be094b5 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 efee187c3bb..2ab821d427b 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 8332e5e2cd1..fc1384618f0 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 e0deef17bd6..5cdeeb40f3d 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 cb438d413f7..2a21337fda3 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 62b088c6461..00000000000 --- 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 fa0d8b64857..10a5636a59c 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 01f35c7dd71..89f267b3d96 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 5d2ff70ef3f..8035fc83bee 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 aecca69bc93..596c3e8f908 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 { @@ -93,38 +111,31 @@ public final class org/jetbrains/dokka/versioning/VersioningConfiguration$Compan 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 1c994406efc..6ab81d3107a 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 d058f11755e..ea524c52a17 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/VersioningPlugin.kt b/plugins/versioning/src/main/kotlin/versioning/VersioningPlugin.kt index bc5fcf2552a..f2c4be2b626 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 626d93139ec..6e1dd7ca8ae 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 0407e5ef255..83aafb3e59d 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 - 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 } + 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