1
1
package com.ebay.plugins.metrics.develocity
2
2
3
+ import com.ebay.plugins.metrics.develocity.MetricsForDevelocityConstants.EXTENSION_NAME
4
+ import com.ebay.plugins.metrics.develocity.MetricsForDevelocityConstants.QUERY_FILTER_PROPERTY
5
+ import com.ebay.plugins.metrics.develocity.MetricsForDevelocityConstants.SUMMARIZER_ALL
6
+ import com.ebay.plugins.metrics.develocity.MetricsForDevelocityConstants.SUMMARIZER_ATTRIBUTE
7
+ import com.ebay.plugins.metrics.develocity.NameUtil.DATETIME_TASK_PATTERN
8
+ import com.ebay.plugins.metrics.develocity.NameUtil.DURATION_TASK_PATTERN
3
9
import com.ebay.plugins.metrics.develocity.projectcost.ProjectCostPlugin
4
10
import com.ebay.plugins.metrics.develocity.service.DevelocityBuildService
5
11
import com.ebay.plugins.metrics.develocity.userquery.UserQueryPlugin
@@ -20,7 +26,7 @@ import javax.inject.Inject
20
26
* Plugin implementation which defines tasks and configurations artifacts which are used to
21
27
* generate aggregate metric data based upon Develocity build scans.
22
28
*/
23
- @Suppress(" unused" ) // False positive
29
+ @Suppress(" unused" , " UnstableApiUsage " ) // False positive
24
30
internal class MetricsForDevelocityPlugin @Inject constructor(
25
31
private val providerFactory : ProviderFactory
26
32
) : Plugin<Any> {
@@ -70,6 +76,8 @@ internal class MetricsForDevelocityPlugin @Inject constructor(
70
76
}
71
77
72
78
private fun applyProject (project : Project ) {
79
+ project.dependencies.attributesSchema.attribute(SUMMARIZER_ATTRIBUTE )
80
+
73
81
if (project.parent == null ) {
74
82
applyRootProject(project)
75
83
}
@@ -135,11 +143,68 @@ internal class MetricsForDevelocityPlugin @Inject constructor(
135
143
ext,
136
144
)
137
145
146
+ /*
147
+ * Creates a rule for generating consumable configurations for date time requests.
148
+ * These can be scoped to daily or hourly time specifications.
149
+ */
150
+ project.configurations.addRule(
151
+ " Pattern: ${NameUtil .dateTime(" <YYYY>-<MM>-<DD>[T<HH>]" )} " +
152
+ " Gathers Develocity metrics for the date (and optionally hour) specified."
153
+ ) { configurationName ->
154
+ val matcher = DATETIME_TASK_PATTERN .matcher(configurationName)
155
+ if (! matcher.matches()) return @addRule
156
+
157
+ val date = matcher.group(2 )
158
+ val timeSpec: String = matcher.group(1 )
159
+ val hour: String? = matcher.group(3 )
160
+
161
+ project.configurations.register(configurationName) { config ->
162
+ with (config) {
163
+ isCanBeConsumed = true
164
+ isCanBeResolved = false
165
+ isTransitive = false
166
+ attributes.attribute(SUMMARIZER_ATTRIBUTE , SUMMARIZER_ALL )
167
+ }
168
+ }
169
+
170
+ val artifactTaskProvider = if (hour == null ) {
171
+ pluginContext.registerDaily(date)
172
+ } else {
173
+ pluginContext.registerHourly(timeSpec)
174
+ }
175
+ project.artifacts.add(configurationName, artifactTaskProvider)
176
+ }
177
+
178
+ /*
179
+ * Creates a rule for generating consumable configurations for duration-based requests.
180
+ * These can be scoped to specific time duration specifications.
181
+ */
182
+ project.configurations.addRule(
183
+ " Pattern: ${NameUtil .duration(" <Java Duration String>" )} " +
184
+ " Aggregates Develocity metrics for the current date back in time for the " +
185
+ " specified duration."
186
+ ) { configurationName ->
187
+ val matcher = DURATION_TASK_PATTERN .matcher(configurationName)
188
+ if (! matcher.matches()) return @addRule
189
+
190
+ val durationStr: String = matcher.group(1 )
191
+ val consumableConfig = project.configurations.register(configurationName)
192
+ consumableConfig.configure { config ->
193
+ with (config) {
194
+ isCanBeConsumed = true
195
+ isCanBeResolved = false
196
+ isTransitive = false
197
+ attributes.attribute(SUMMARIZER_ATTRIBUTE , SUMMARIZER_ALL )
198
+ }
199
+ }
200
+ project.artifacts.add(configurationName, pluginContext.registerDurationAggregation(durationStr))
201
+ }
202
+
138
203
/*
139
204
* Rule to register a task for a specific date and optionally hour.
140
205
*/
141
206
project.tasks.addRule(
142
- " Pattern: $TASK_PREFIX - <YYYY>-<MM>-<DD>T[ <HH>] " +
207
+ " Pattern: ${ NameUtil .dateTime( " <YYYY>-<MM>-<DD>[T <HH>]" )} " +
143
208
" Gathers Develocity metrics for the date (and optionally hour) specified."
144
209
) { taskName ->
145
210
val matcher = DATETIME_TASK_PATTERN .matcher(taskName)
@@ -162,7 +227,7 @@ internal class MetricsForDevelocityPlugin @Inject constructor(
162
227
* Rule to register a task for a time window / duration, relative to the current day and hour.
163
228
*/
164
229
project.tasks.addRule(
165
- " Pattern: $TASK_PREFIX -last- <Java Duration String> " +
230
+ " Pattern: ${ NameUtil .duration( " <Java Duration String>" )} " +
166
231
" Aggregates Develocity metrics for the current date back in time for the " +
167
232
" specified duration."
168
233
) { taskName ->
@@ -172,22 +237,14 @@ internal class MetricsForDevelocityPlugin @Inject constructor(
172
237
val durationStr: String = matcher.group(1 )
173
238
pluginContext.registerDurationAggregation(durationStr)
174
239
}
175
-
176
- ext.extensions.create(
177
- INTERNAL_EXTENSION_NAME ,
178
- MetricsForDevelocityInternalExtension ::class .java,
179
- { timeSpec: String -> pluginContext.registerHourly(timeSpec) },
180
- { dateStr: String -> pluginContext.registerDaily(dateStr) },
181
- { durationStr: String -> pluginContext.registerDurationAggregation(durationStr) },
182
- )
183
240
}
184
241
185
242
/*
186
243
* Function to register an hourly gather task. This function must be re-entrant and allow for
187
244
* the same task to be registered multiple times without error.
188
245
*/
189
246
private fun PluginContext.registerHourly (timeSpec : String ): TaskProvider <GatherHourlyTask > {
190
- val taskName = " $TASK_PREFIX - $ timeSpec"
247
+ val taskName = NameUtil .dateTime( timeSpec)
191
248
return if (project.tasks.names.contains(taskName)) {
192
249
// task already exists. Return its TaskProvider.
193
250
project.tasks.named(taskName, GatherHourlyTask ::class .java)
@@ -227,7 +284,7 @@ internal class MetricsForDevelocityPlugin @Inject constructor(
227
284
* the same task to be registered multiple times without error.
228
285
*/
229
286
private fun PluginContext.registerDaily (dateString : String ): TaskProvider <GatherAggregateTask > {
230
- val taskName = " $TASK_PREFIX - $ dateString"
287
+ val taskName = NameUtil .dateTime( dateString)
231
288
return if (project.tasks.names.contains(taskName)) {
232
289
// task already exists. Return its TaskProvider.
233
290
project.tasks.named(taskName, GatherAggregateTask ::class .java)
@@ -281,7 +338,7 @@ internal class MetricsForDevelocityPlugin @Inject constructor(
281
338
}
282
339
}.toList()
283
340
284
- val taskName = " $TASK_PREFIX -last- $ durationStr"
341
+ val taskName = NameUtil .duration( durationStr)
285
342
return if (project.tasks.names.contains(taskName)) {
286
343
// task already exists. Return its TaskProvider.
287
344
project.tasks.named(taskName, GatherAggregateTask ::class .java)
@@ -357,25 +414,6 @@ internal class MetricsForDevelocityPlugin @Inject constructor(
357
414
}
358
415
359
416
companion object {
360
- const val EXTENSION_NAME = " metricsForDevelocity"
361
- const val INTERNAL_EXTENSION_NAME = " metricsForDevelocityInternal"
362
- const val TASK_PREFIX = " metricsForDevelocity"
363
- const val TASK_GROUP = " develocity metrics"
364
- const val QUERY_FILTER_PROPERTY = " metricsForDevelocityQueryFilter"
365
-
366
- private val DATETIME_TASK_PATTERN = Regex (
367
- // Examples:
368
- // metricsForDevelocity-2024-06-01
369
- // metricsForDevelocity-2024-06-01T05
370
- " ^\\ Q$TASK_PREFIX -\\ E((\\ d{4}-\\ d{2}-\\ d{2})(?:T(\\ d{2}))?)$"
371
- ).toPattern()
372
-
373
- private val DURATION_TASK_PATTERN = Regex (
374
- // Examples:
375
- // metricsForDevelocity-last-P7D
376
- // metricsForDevelocity-last-PT8H
377
- // metricsForDevelocity-last-P2DT8H
378
- " ^\\ Q$TASK_PREFIX -last-\\ E(\\ w+)$"
379
- ).toPattern()
417
+ internal const val TASK_GROUP = " develocity metrics"
380
418
}
381
419
}
0 commit comments