Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
vmishenev committed Sep 2, 2021
1 parent 96a6647 commit 56ee58d
Show file tree
Hide file tree
Showing 20 changed files with 133 additions and 112 deletions.
4 changes: 4 additions & 0 deletions core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/kotlin/CoreExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,6 +22,7 @@ object CoreExtensions {
val documentableToPageTranslator by coreExtensionPoint<DocumentableToPageTranslator>()
val pageTransformer by coreExtensionPoint<PageTransformer>()
val renderer by coreExtensionPoint<Renderer>()
val postActions by coreExtensionPoint<PostAction>()

private fun <T : Any> coreExtensionPoint() = object {
operator fun provideDelegate(thisRef: CoreExtensions, property: KProperty<*>): Lazy<ExtensionPoint<T>> =
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/kotlin/renderers/PostAction.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.jetbrains.dokka.renderers

interface PostAction : () -> Unit
5 changes: 4 additions & 1 deletion plugins/all-modules-page/api/all-modules-page.api
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 <init> (Lorg/jetbrains/dokka/pages/RootPageNode;Lorg/jetbrains/dokka/plugability/DokkaContext;)V
public fun <init> (Lorg/jetbrains/dokka/pages/RootPageNode;Lorg/jetbrains/dokka/plugability/DokkaContext;Ljava/lang/String;)V
public synthetic fun <init> (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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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)
Expand Down
9 changes: 1 addition & 8 deletions plugins/base/api/base.api
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 0 additions & 1 deletion plugins/base/src/main/kotlin/DokkaBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class DokkaBase : DokkaPlugin() {
val externalLocationProviderFactory by extensionPoint<ExternalLocationProviderFactory>()
val outputWriter by extensionPoint<OutputWriter>()
val htmlPreprocessors by extensionPoint<PageTransformer>()
val postActions by extensionPoint<PostAction>()
val kotlinAnalysis by extensionPoint<KotlinAnalysis>()
val tabSortingStrategy by extensionPoint<TabSortingStrategy>()
val immediateHtmlCommandConsumer by extensionPoint<ImmediateHtmlCommandConsumer>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class SingleModuleGeneration(private val context: DokkaContext) : Generation {
report("Rendering")
render(transformedPages)

report("Running post-actions")
runPostActions()

reportAfterRendering()
}

Expand Down Expand Up @@ -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<String>())
Expand Down
4 changes: 1 addition & 3 deletions plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -25,7 +26,6 @@ abstract class DefaultRenderer<T>(
private set

protected open val preprocessors: Iterable<PageTransformer> = emptyList()
protected open val postActions: Iterable<PostAction> = emptyList()

abstract fun T.buildHeader(level: Int, node: ContentHeader, content: T.() -> Unit)
abstract fun T.buildLink(address: String, content: T.() -> Unit)
Expand Down Expand Up @@ -210,8 +210,6 @@ abstract class DefaultRenderer<T>(
runBlocking(Dispatchers.Default) {
renderPages(newRoot)
}

postActions.forEach { it() }
}

protected fun ContentDivergentGroup.groupDivergentInstances(
Expand Down
3 changes: 0 additions & 3 deletions plugins/base/src/main/kotlin/renderers/PostAction.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ open class HtmlRenderer(
private var shouldRenderSourceSetBubbles: Boolean = false

override val preprocessors = context.plugin<DokkaBase>().query { htmlPreprocessors }
override val postActions = context.plugin<DokkaBase>().query { postActions }

private val tabSortingStrategy = context.plugin<DokkaBase>().querySingle { tabSortingStrategy }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package org.jetbrains.dokka.base.templating

data class ReplaceVersionsCommand(var location: String = ""): Command
data class ReplaceVersionsCommand(val location: String = ""): Command
Original file line number Diff line number Diff line change
Expand Up @@ -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)) }
}
}
51 changes: 31 additions & 20 deletions plugins/versioning/api/versioning.api
Original file line number Diff line number Diff line change
Expand Up @@ -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 <init> (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 <init> (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 <init> (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 <init> (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 {
Expand Down Expand Up @@ -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 <init> ()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 <init> (Lorg/jetbrains/dokka/plugability/DokkaContext;)V
public synthetic fun invoke ()Ljava/lang/Object;
public fun invoke ()V
}

Original file line number Diff line number Diff line change
@@ -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<VersioningPlugin>().querySingle { versioningHandler } }
class DefaultPreviousDocumentationCopyPostAction(private val context: DokkaContext) : PostAction {
private val versioningStorage by lazy { context.plugin<VersioningPlugin>().querySingle { versioningStorage } }
private val processingStrategies: List<TemplateProcessingStrategy> =
context.plugin<TemplatingPlugin>().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) {
Expand Down
Loading

0 comments on commit 56ee58d

Please sign in to comment.