From 7027da812e8b3120a56830d9790a27f57fa7d27c Mon Sep 17 00:00:00 2001 From: Adam <152864218+adam-enko@users.noreply.github.com> Date: Tue, 15 Oct 2024 18:16:06 +0200 Subject: [PATCH] Move `enableLogHtmlPublicationLink` property from LogHtmlPublicationLinkTask into PluginFeaturesService (#3845) * Move `enableLogHtmlPublicationLink` property from LogHtmlPublicationLinkTask into PluginFeaturesService KT-71347 --- .../api/dokka-gradle-plugin.api | 1 - .../kotlin/internal/PluginFeaturesService.kt | 33 ++++++++++++- .../tasks/LogHtmlPublicationLinkTask.kt | 47 +++++-------------- 3 files changed, 44 insertions(+), 37 deletions(-) diff --git a/dokka-runners/dokka-gradle-plugin/api/dokka-gradle-plugin.api b/dokka-runners/dokka-gradle-plugin/api/dokka-gradle-plugin.api index ea1124d178..87fd0b9688 100644 --- a/dokka-runners/dokka-gradle-plugin/api/dokka-gradle-plugin.api +++ b/dokka-runners/dokka-gradle-plugin/api/dokka-gradle-plugin.api @@ -556,7 +556,6 @@ public abstract class org/jetbrains/dokka/gradle/tasks/DokkaGenerateTask : org/j public abstract class org/jetbrains/dokka/gradle/tasks/LogHtmlPublicationLinkTask : org/jetbrains/dokka/gradle/tasks/DokkaBaseTask { public static final field Companion Lorg/jetbrains/dokka/gradle/tasks/LogHtmlPublicationLinkTask$Companion; - public static final field ENABLE_TASK_PROPERTY_NAME Ljava/lang/String; public final fun exec ()V public abstract fun getIndexHtmlPath ()Lorg/gradle/api/provider/Property; public abstract fun getServerUri ()Lorg/gradle/api/provider/Property; diff --git a/dokka-runners/dokka-gradle-plugin/src/main/kotlin/internal/PluginFeaturesService.kt b/dokka-runners/dokka-gradle-plugin/src/main/kotlin/internal/PluginFeaturesService.kt index db5b2be04b..b64574d1d7 100644 --- a/dokka-runners/dokka-gradle-plugin/src/main/kotlin/internal/PluginFeaturesService.kt +++ b/dokka-runners/dokka-gradle-plugin/src/main/kotlin/internal/PluginFeaturesService.kt @@ -10,13 +10,16 @@ import org.gradle.api.Project import org.gradle.api.logging.Logging import org.gradle.api.provider.Property import org.gradle.api.provider.Provider +import org.gradle.api.provider.ProviderFactory import org.gradle.api.services.BuildService import org.gradle.api.services.BuildServiceParameters import org.gradle.kotlin.dsl.extra import org.gradle.kotlin.dsl.provideDelegate import org.jetbrains.dokka.gradle.internal.PluginFeaturesService.PluginMode.* +import org.jetbrains.dokka.gradle.tasks.LogHtmlPublicationLinkTask import java.io.File import java.util.* +import javax.inject.Inject /** * Internal utility service for managing Dokka Plugin features and warnings. @@ -24,7 +27,12 @@ import java.util.* * Using a [BuildService] is most useful for only logging a single warning for the whole project, * regardless of how many subprojects have applied DGP. */ -internal abstract class PluginFeaturesService : BuildService { +internal abstract class PluginFeaturesService +@DokkaInternalApi +@Inject +constructor( + providers: ProviderFactory, +) : BuildService { interface Params : BuildServiceParameters { /** @see [PluginFeaturesService.primaryService] */ @@ -241,6 +249,29 @@ internal abstract class PluginFeaturesService : BuildService = + providers.gradleProperty("org.jetbrains.dokka.gradle.enableLogHtmlPublicationLink") + .toBoolean() + .orElse(true) + companion object { private val logger = Logging.getLogger(PluginFeaturesService::class.java) diff --git a/dokka-runners/dokka-gradle-plugin/src/main/kotlin/tasks/LogHtmlPublicationLinkTask.kt b/dokka-runners/dokka-gradle-plugin/src/main/kotlin/tasks/LogHtmlPublicationLinkTask.kt index 6a97345817..6d543313fb 100644 --- a/dokka-runners/dokka-gradle-plugin/src/main/kotlin/tasks/LogHtmlPublicationLinkTask.kt +++ b/dokka-runners/dokka-gradle-plugin/src/main/kotlin/tasks/LogHtmlPublicationLinkTask.kt @@ -12,8 +12,8 @@ import org.gradle.api.tasks.TaskAction import org.gradle.api.tasks.UntrackedTask import org.gradle.kotlin.dsl.of import org.jetbrains.dokka.gradle.internal.DokkaInternalApi +import org.jetbrains.dokka.gradle.internal.PluginFeaturesService.Companion.pluginFeaturesService import org.jetbrains.dokka.gradle.internal.appendPath -import org.jetbrains.dokka.gradle.tasks.LogHtmlPublicationLinkTask.Companion.ENABLE_TASK_PROPERTY_NAME import org.slf4j.LoggerFactory import java.net.HttpURLConnection import java.net.URI @@ -28,8 +28,8 @@ import javax.inject.Inject * [IntelliJ's built-in server](https://www.jetbrains.com/help/phpstorm/php-built-in-web-server.html#ws_html_preview_output_built_in_browser)† * to host the file. * - * - * This task can be disabled using the [ENABLE_TASK_PROPERTY_NAME] project property. + * This task can be disabled via a Gradle property. + * See [org.jetbrains.dokka.gradle.internal.PluginFeaturesService.enableLogHtmlPublicationLink]. * * --- * @@ -88,18 +88,9 @@ constructor( // to display this task prominently. group = "other" - val serverActive = providers.of(ServerActiveCheck::class) { - parameters.uri.convention(serverUri) - } - super.onlyIf("server URL is reachable") { serverActive.get() } - - val logHtmlPublicationLinkTaskEnabled = providers - .gradleProperty(ENABLE_TASK_PROPERTY_NAME) - .map(String::toBoolean) - .orElse(true) - - super.onlyIf("task is enabled via property") { - logHtmlPublicationLinkTaskEnabled.get() + val enableLogHtmlPublicationLink = project.pluginFeaturesService.enableLogHtmlPublicationLink + super.onlyIf("task is enabled via 'enableLogHtmlPublicationLink' property") { + enableLogHtmlPublicationLink.get() } super.onlyIf("${::serverUri.name} is present") { @@ -109,6 +100,11 @@ constructor( super.onlyIf("${::indexHtmlPath.name} is present") { !indexHtmlPath.orNull.isNullOrBlank() } + + val serverActive = providers.of(ServerActiveCheck::class) { + parameters.uri.convention(serverUri) + } + super.onlyIf("server URL is reachable") { serverActive.get() } } @TaskAction @@ -194,24 +190,5 @@ constructor( // } } - companion object { - /** - * Control whether the [LogHtmlPublicationLinkTask] task is enabled. Useful for disabling the - * task locally, or in CI/CD, or for tests. - * - * It can be set in any `gradle.properties` file. For example, on a specific machine: - * - * ```properties - * # $GRADLE_USER_HOME/gradle.properties - * org.jetbrains.dokka.gradle.enabledLogHtmlPublicationLink=false - * ``` - * - * or via an environment variable - * - * ```env - * ORG_GRADLE_PROJECT_org.jetbrains.dokka.gradle.enabledLogHtmlPublicationLink=false - * ``` - */ - const val ENABLE_TASK_PROPERTY_NAME = "org.jetbrains.dokka.gradle.enableLogHtmlPublicationLink" - } + companion object }