Skip to content

Commit c591925

Browse files
Provide mechanism for configuring tasks with Develocity configuration (#22)
Provide mechanism for configuring tasks with Develocity configuration Co-authored-by: rcgonzalezf-ebay <[email protected]>
1 parent 4718484 commit c591925

File tree

4 files changed

+33
-13
lines changed

4 files changed

+33
-13
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.ebay.plugins.metrics.develocity
2+
3+
import org.gradle.api.Task
4+
import org.gradle.api.provider.Property
5+
import org.gradle.api.tasks.Input
6+
7+
/**
8+
* Interface which may be added to a task to have it be auto-configured with the Develocity
9+
* server configuration as applied to the root project in the [MetricsForDevelocityExtension].
10+
*
11+
* NOTE: Access to the Develocity access key is intentionally not provided here, as it is
12+
* would potentially be exposed due to its use as part of the czche key.
13+
*/
14+
interface DevelocityConfigurationInputs : Task {
15+
/**
16+
* The Develocity server URL. If the Gradle Develocity or Gradle Enterprise plugins are
17+
* applied, this will be auto-configured by using the values applied to their respective
18+
* extensions.
19+
*/
20+
@get:Input
21+
val develocityServerUrl: Property<String>
22+
}

src/main/kotlin/com/ebay/plugins/metrics/develocity/MetricsForDevelocityPlugin.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ internal class MetricsForDevelocityPlugin @Inject constructor(
5858
}
5959
}
6060
}
61+
// Configure tasks wanting to consume the Gradle Enterprise configuration:
62+
project.tasks.withType(DevelocityConfigurationInputs::class.java).configureEach { task ->
63+
task.develocityServerUrl.set(gradleExt.server)
64+
}
6165
}
6266
}
6367
settings.plugins.withId("com.gradle.develocity") {
@@ -71,6 +75,10 @@ internal class MetricsForDevelocityPlugin @Inject constructor(
7175
}
7276
}
7377
}
78+
// Configure tasks wanting to consume the Develocity configuration:
79+
project.tasks.withType(DevelocityConfigurationInputs::class.java).configureEach { task ->
80+
task.develocityServerUrl.set(gradleExt.server)
81+
}
7482
}
7583
}
7684
}

src/main/kotlin/com/ebay/plugins/metrics/develocity/projectcost/ProjectCostInspectionTask.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.ebay.plugins.metrics.develocity.projectcost
22

3+
import com.ebay.plugins.metrics.develocity.DevelocityConfigurationInputs
34
import com.ebay.plugins.metrics.develocity.MetricSummarizerTask
45
import org.gradle.api.DefaultTask
56
import org.gradle.api.GradleException
@@ -15,13 +16,10 @@ import org.gradle.api.tasks.TaskAction
1516
* associated with the project.
1617
*/
1718
@CacheableTask
18-
internal abstract class ProjectCostInspectionTask : DefaultTask(), MetricSummarizerTask {
19+
internal abstract class ProjectCostInspectionTask : DefaultTask(), MetricSummarizerTask, DevelocityConfigurationInputs {
1920
@get:OutputFile
2021
internal abstract val outputFile: RegularFileProperty
2122

22-
@get:Input
23-
internal abstract val develocityUrl: Property<String>
24-
2523
@get:Input
2624
internal abstract val projectPath: Property<String>
2725

@@ -81,7 +79,7 @@ internal abstract class ProjectCostInspectionTask : DefaultTask(), MetricSummari
8179
separator = "\n\t",
8280
postfix = "\n\n")
8381
}
84-
val baseUrl = develocityUrl.orNull?.let {
82+
val baseUrl = develocityServerUrl.orNull?.let {
8583
if (it.isEmpty()) {
8684
""
8785
} else if (it.endsWith("/")) {

src/main/kotlin/com/ebay/plugins/metrics/develocity/projectcost/ProjectCostPlugin.kt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,7 @@ internal class ProjectCostPlugin @Inject constructor(
7676
outputFile.set(project.layout.buildDirectory.file("reports/projectCost/inspection.txt"))
7777
}
7878
}
79-
8079
project.plugins.withType(MetricsForDevelocityPlugin::class.java) {
81-
// TODO: This violates project isolation
82-
val serverUrlProp = project.rootProject.extensions.getByType(MetricsForDevelocityExtension::class.java).develocityServerUrl
83-
taskProvider.configure { task ->
84-
with(task) {
85-
develocityUrl.set(serverUrlProp)
86-
}
87-
}
8880
taskProvider.inputsFromDuration(project, durationStr, ProjectCostSummarizer.ID)
8981
}
9082
}

0 commit comments

Comments
 (0)