Skip to content

Commit

Permalink
Move enableLogHtmlPublicationLink property from LogHtmlPublicationL…
Browse files Browse the repository at this point in the history
…inkTask into PluginFeaturesService (#3845)

* Move `enableLogHtmlPublicationLink` property from LogHtmlPublicationLinkTask into PluginFeaturesService

KT-71347
  • Loading branch information
adam-enko authored Oct 15, 2024
1 parent b037efb commit 7027da8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,29 @@ 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.
*
* 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<PluginFeaturesService.Params> {
internal abstract class PluginFeaturesService
@DokkaInternalApi
@Inject
constructor(
providers: ProviderFactory,
) : BuildService<PluginFeaturesService.Params> {

interface Params : BuildServiceParameters {
/** @see [PluginFeaturesService.primaryService] */
Expand Down Expand Up @@ -241,6 +249,29 @@ internal abstract class PluginFeaturesService : BuildService<PluginFeaturesServi
}
}

/**
* 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 single user's 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
* ```
*/
val enableLogHtmlPublicationLink: Provider<Boolean> =
providers.gradleProperty("org.jetbrains.dokka.gradle.enableLogHtmlPublicationLink")
.toBoolean()
.orElse(true)

companion object {
private val logger = Logging.getLogger(PluginFeaturesService::class.java)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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].
*
* ---
*
Expand Down Expand Up @@ -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") {
Expand All @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit 7027da8

Please sign in to comment.