Skip to content

Commit

Permalink
Provide mechanism for configuring tasks with Develocity configuration (
Browse files Browse the repository at this point in the history
…#22)

Provide mechanism for configuring tasks with Develocity configuration

Co-authored-by: rcgonzalezf-ebay <[email protected]>
  • Loading branch information
mcumings and rcgonzalezf-ebay authored Sep 18, 2024
1 parent 4718484 commit c591925
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.ebay.plugins.metrics.develocity

import org.gradle.api.Task
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input

/**
* Interface which may be added to a task to have it be auto-configured with the Develocity
* server configuration as applied to the root project in the [MetricsForDevelocityExtension].
*
* NOTE: Access to the Develocity access key is intentionally not provided here, as it is
* would potentially be exposed due to its use as part of the czche key.
*/
interface DevelocityConfigurationInputs : Task {
/**
* The Develocity server URL. If the Gradle Develocity or Gradle Enterprise plugins are
* applied, this will be auto-configured by using the values applied to their respective
* extensions.
*/
@get:Input
val develocityServerUrl: Property<String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ internal class MetricsForDevelocityPlugin @Inject constructor(
}
}
}
// Configure tasks wanting to consume the Gradle Enterprise configuration:
project.tasks.withType(DevelocityConfigurationInputs::class.java).configureEach { task ->
task.develocityServerUrl.set(gradleExt.server)
}
}
}
settings.plugins.withId("com.gradle.develocity") {
Expand All @@ -71,6 +75,10 @@ internal class MetricsForDevelocityPlugin @Inject constructor(
}
}
}
// Configure tasks wanting to consume the Develocity configuration:
project.tasks.withType(DevelocityConfigurationInputs::class.java).configureEach { task ->
task.develocityServerUrl.set(gradleExt.server)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ebay.plugins.metrics.develocity.projectcost

import com.ebay.plugins.metrics.develocity.DevelocityConfigurationInputs
import com.ebay.plugins.metrics.develocity.MetricSummarizerTask
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
Expand All @@ -15,13 +16,10 @@ import org.gradle.api.tasks.TaskAction
* associated with the project.
*/
@CacheableTask
internal abstract class ProjectCostInspectionTask : DefaultTask(), MetricSummarizerTask {
internal abstract class ProjectCostInspectionTask : DefaultTask(), MetricSummarizerTask, DevelocityConfigurationInputs {
@get:OutputFile
internal abstract val outputFile: RegularFileProperty

@get:Input
internal abstract val develocityUrl: Property<String>

@get:Input
internal abstract val projectPath: Property<String>

Expand Down Expand Up @@ -81,7 +79,7 @@ internal abstract class ProjectCostInspectionTask : DefaultTask(), MetricSummari
separator = "\n\t",
postfix = "\n\n")
}
val baseUrl = develocityUrl.orNull?.let {
val baseUrl = develocityServerUrl.orNull?.let {
if (it.isEmpty()) {
""
} else if (it.endsWith("/")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,7 @@ internal class ProjectCostPlugin @Inject constructor(
outputFile.set(project.layout.buildDirectory.file("reports/projectCost/inspection.txt"))
}
}

project.plugins.withType(MetricsForDevelocityPlugin::class.java) {
// TODO: This violates project isolation
val serverUrlProp = project.rootProject.extensions.getByType(MetricsForDevelocityExtension::class.java).develocityServerUrl
taskProvider.configure { task ->
with(task) {
develocityUrl.set(serverUrlProp)
}
}
taskProvider.inputsFromDuration(project, durationStr, ProjectCostSummarizer.ID)
}
}
Expand Down

0 comments on commit c591925

Please sign in to comment.