From 1882138d0558d0465c97f34ac86a7b5102de0191 Mon Sep 17 00:00:00 2001 From: Andrzej Ratajczak Date: Tue, 4 Feb 2020 11:53:31 +0100 Subject: Adds conditional plugin linking --- core/src/main/kotlin/plugability/extensions.kt | 31 ++++++++++++++++++++------ 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'core/src/main/kotlin/plugability/extensions.kt') diff --git a/core/src/main/kotlin/plugability/extensions.kt b/core/src/main/kotlin/plugability/extensions.kt index 42bf3900..4cbb61eb 100644 --- a/core/src/main/kotlin/plugability/extensions.kt +++ b/core/src/main/kotlin/plugability/extensions.kt @@ -1,5 +1,7 @@ package org.jetbrains.dokka.plugability +import org.jetbrains.dokka.DokkaConfiguration + data class ExtensionPoint internal constructor( internal val pluginClass: String, internal val pointName: String @@ -12,7 +14,8 @@ abstract class Extension internal constructor( internal val pluginClass: String, internal val extensionName: String, internal val action: LazyEvaluated, - internal val ordering: (OrderDsl.() -> Unit)? = null + internal val ordering: (OrderDsl.() -> Unit)? = null, + internal val condition: DokkaConfiguration.() -> Boolean = { true } ) { override fun toString() = "Extension: $pluginClass/$extensionName" @@ -21,6 +24,8 @@ abstract class Extension internal constructor( else false override fun hashCode() = listOf(pluginClass, extensionName).hashCode() + + abstract fun setCondition(condition: (DokkaConfiguration.() -> Boolean)): Extension } class ExtensionOrdered internal constructor( @@ -28,27 +33,37 @@ class ExtensionOrdered internal constructor( pluginClass: String, extensionName: String, action: LazyEvaluated, - ordering: (OrderDsl.() -> Unit) + ordering: (OrderDsl.() -> Unit), + condition: DokkaConfiguration.() -> Boolean = { true } ) : Extension( extensionPoint, pluginClass, extensionName, action, - ordering -) + ordering, + condition +) { + override fun setCondition(condition: DokkaConfiguration.() -> Boolean) = + ExtensionOrdered(extensionPoint, pluginClass, extensionName, action, ordering!!, condition) +} class ExtensionUnordered internal constructor( extensionPoint: ExtensionPoint, pluginClass: String, extensionName: String, - action: LazyEvaluated + action: LazyEvaluated, + condition: DokkaConfiguration.() -> Boolean = { true } ) : Extension( extensionPoint, pluginClass, extensionName, action, - null -) + null, + condition +) { + override fun setCondition(condition: DokkaConfiguration.() -> Boolean) = + ExtensionUnordered(extensionPoint, pluginClass, extensionName, action, condition) +} internal data class Ordering(val previous: Set>, val following: Set>) @@ -66,6 +81,8 @@ class ExtendingDSL(private val pluginClass: String, private val extensionName: S infix fun ExtensionUnordered.order(block: OrderDsl.() -> Unit) = ExtensionOrdered(extensionPoint, pluginClass, extensionName, action, block) + + infix fun Extension.applyIf(condition: DokkaConfiguration.() -> Boolean): Extension = this.setCondition(condition) } @ExtensionsDsl -- cgit