From e9f5da45c0fcfec5f7c150229301904d7915e090 Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Wed, 7 Oct 2020 13:58:46 +0200 Subject: Make logo replaceable #1339 (#1488) --- .../jetbrains/dokka/gradle/AbstractDokkaTask.kt | 39 +++++++++++++++++++--- .../jetbrains/dokka/gradle/DokkaCollectorTask.kt | 1 + .../jetbrains/dokka/gradle/DokkaMultiModuleTask.kt | 3 +- .../kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt | 11 +++--- .../kotlin/org/jetbrains/dokka/gradle/utils.kt | 1 - 5 files changed, 41 insertions(+), 14 deletions(-) (limited to 'runners/gradle-plugin/src/main') diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaTask.kt index 9dab1f04..77b4b2e1 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaTask.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaTask.kt @@ -8,17 +8,19 @@ import org.gradle.api.DefaultTask import org.gradle.api.Task import org.gradle.api.artifacts.Configuration import org.gradle.api.plugins.JavaBasePlugin +import org.gradle.api.provider.ListProperty import org.gradle.api.provider.MapProperty import org.gradle.api.provider.Property import org.gradle.api.tasks.* +import org.gradle.kotlin.dsl.listProperty import org.gradle.kotlin.dsl.mapProperty -import org.jetbrains.dokka.DokkaBootstrap -import org.jetbrains.dokka.DokkaConfigurationImpl -import org.jetbrains.dokka.DokkaDefaults -import org.jetbrains.dokka.toJsonString +import org.jetbrains.dokka.* +import org.jetbrains.dokka.plugability.ConfigurableBlock +import org.jetbrains.dokka.plugability.DokkaPlugin import java.io.File import java.util.function.BiConsumer import kotlin.reflect.KClass +import kotlin.reflect.full.createInstance abstract class AbstractDokkaTask( private val bootstrapClass: KClass = DokkaBootstrap::class @@ -49,7 +51,23 @@ abstract class AbstractDokkaTask( .safeConvention(DokkaDefaults.offlineMode) @Input - val pluginsConfiguration: MapProperty = project.objects.mapProperty() + val pluginsConfiguration: ListProperty = project.objects.listProperty() + + /** + * Used to keep compatibility with gradle using Kotlin lower than 1.3.50 + */ + @Input + val pluginsMapConfiguration: MapProperty = project.objects.mapProperty() + + inline fun pluginConfiguration(block: T.() -> Unit) { + val instance = T::class.createInstance().apply(block) + val pluginConfiguration = PluginConfigurationImpl( + fqPluginName = P::class.qualifiedName!!, + serializationFormat = DokkaConfiguration.SerializationFormat.JSON, + values = instance.toJsonString() + ) + pluginsConfiguration.add(pluginConfiguration) + } @Classpath val plugins: Configuration = project.maybeCreateDokkaPluginConfiguration(name) @@ -84,4 +102,15 @@ abstract class AbstractDokkaTask( init { group = JavaBasePlugin.DOCUMENTATION_GROUP } + + internal fun buildPluginsConfiguration(): List { + val manuallyConfigured = pluginsMapConfiguration.getSafe().entries.map { entry -> + PluginConfigurationImpl( + entry.key, + DokkaConfiguration.SerializationFormat.JSON, + entry.value + ) + } + return pluginsConfiguration.getSafe().mapNotNull { it as? PluginConfigurationImpl } + manuallyConfigured + } } diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt index cd53398a..b0fc5f22 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt @@ -17,6 +17,7 @@ abstract class DokkaCollectorTask : AbstractDokkaParentTask() { failOnWarning = failOnWarning.getSafe(), offlineMode = offlineMode.getSafe(), pluginsClasspath = plugins.resolve().toList(), + pluginsConfiguration = buildPluginsConfiguration() ) val subprojectDokkaConfigurations = childDokkaTasks.map { dokkaTask -> dokkaTask.buildDokkaConfiguration() } diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleTask.kt index 92560c94..03e0b4d7 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleTask.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleTask.kt @@ -6,6 +6,7 @@ import org.gradle.api.tasks.* import org.jetbrains.dokka.DokkaConfigurationImpl import org.jetbrains.dokka.DokkaModuleDescriptionImpl import org.jetbrains.dokka.DokkaMultimoduleBootstrapImpl +import org.jetbrains.dokka.PluginConfigurationImpl import java.io.File @Suppress("unused") // Shall provide source compatibility if possible @@ -49,7 +50,7 @@ abstract class DokkaMultiModuleTask : AbstractDokkaParentTask(DokkaMultimoduleBo moduleName = moduleName.getSafe(), outputDir = outputDirectory.getSafe(), cacheRoot = cacheRoot.getSafe(), - pluginsConfiguration = pluginsConfiguration.getSafe(), + pluginsConfiguration = buildPluginsConfiguration(), failOnWarning = failOnWarning.getSafe(), offlineMode = offlineMode.getSafe(), pluginsClasspath = plugins.resolve().toList(), diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt index ed3989af..9944bacb 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt @@ -4,9 +4,7 @@ import org.gradle.api.NamedDomainObjectContainer import org.gradle.api.internal.plugins.DslObject import org.gradle.api.tasks.Internal import org.gradle.api.tasks.Nested -import org.jetbrains.dokka.DokkaBootstrapImpl -import org.jetbrains.dokka.DokkaConfigurationImpl -import org.jetbrains.dokka.build +import org.jetbrains.dokka.* abstract class DokkaTask : AbstractDokkaTask(DokkaBootstrapImpl::class) { @@ -34,8 +32,8 @@ abstract class DokkaTask : AbstractDokkaTask(DokkaBootstrapImpl::class) { .also(::checkSourceSetDependencies) .filterNot { it.suppress.getSafe() } - override fun buildDokkaConfiguration(): DokkaConfigurationImpl { - return DokkaConfigurationImpl( + override fun buildDokkaConfiguration(): DokkaConfigurationImpl = + DokkaConfigurationImpl( moduleName = moduleName.getSafe(), moduleVersion = moduleVersion.orNull, outputDir = outputDirectory.getSafe(), @@ -43,8 +41,7 @@ abstract class DokkaTask : AbstractDokkaTask(DokkaBootstrapImpl::class) { offlineMode = offlineMode.getSafe(), failOnWarning = failOnWarning.getSafe(), sourceSets = unsuppressedSourceSets.build(), - pluginsConfiguration = pluginsConfiguration.getSafe(), + pluginsConfiguration = buildPluginsConfiguration(), pluginsClasspath = plugins.resolve().toList() ) - } } diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/utils.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/utils.kt index 14b2a045..1c0c8080 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/utils.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/utils.kt @@ -7,7 +7,6 @@ import org.gradle.api.provider.HasMultipleValues import org.gradle.api.provider.Property import org.gradle.api.provider.Provider import org.gradle.util.Path -import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import org.jetbrains.kotlin.gradle.plugin.KotlinTarget -- cgit