Skip to content

Instantly share code, notes, and snippets.

View jonnycaley's full-sized avatar
💻
Working

Jonny Caley jonnycaley

💻
Working
View GitHub Profile
@jonnycaley
jonnycaley / BuildTimeLoggerPlugin.kt
Created June 18, 2022 17:30
BuildTimeLoggerPlugin - parsing cacheable values
val buildReporterService = gradle.sharedServices.registerIfAbsent("build-reporter-service", BuildReporterService::class.java) { service ->
service.parameters.getBuildTaskNames().set(gradle.startParameter.taskNames.joinToString())
service.parameters.getGradleVersion().set(gradle.gradleVersion)
}
@jonnycaley
jonnycaley / BuildReporterService.kt
Created June 18, 2022 17:28
BuildReporterService - parsing cacheable values
abstract class BuildReporterService : BuildService<BuildReporterService.Params>, AutoCloseable {
interface Params : BuildServiceParameters {
fun getBuildTaskNames(): Property<String>
fun getGradleVersion(): Property<String>
}
override fun close() {
val buildTaskNames = parameters.getBuildTaskNames().get()
val gradleVersion = parameters.getGradleVersion().get()
@jonnycaley
jonnycaley / BuildTimeLoggerPlugin.kt
Created June 18, 2022 15:44
BuildTimeLoggerPlugin - register build reporter service
class BuildTimeLoggerPlugin : Plugin<Project> {
override fun apply(project: Project) {
val gradle = project.gradle
val buildDurationService = registerBuildDurationService(gradle)
val buildTaskService = registerBuildTaskService(gradle)
registerBuildReporterService(gradle, buildDurationService, buildTaskService)
}
@jonnycaley
jonnycaley / BuildReporterService.kt
Last active June 18, 2022 16:33
BuildReporterService - report data from other services
abstract class BuildReporterService : BuildService<BuildReporterService.Params>, BuildOperationListener, AutoCloseable {
interface Params : BuildServiceParameters {
fun getBuildDurationServiceProvider(): Property<Provider<BuildDurationService>>
fun getBuildTaskServiceProvider(): Property<Provider<BuildTaskService>>
}
override fun started(p0: BuildOperationDescriptor, p1: OperationStartEvent) {}
override fun progress(p0: OperationIdentifier, p1: OperationProgressEvent) {}
@jonnycaley
jonnycaley / BuildTimeLoggerPlugin.kt
Created June 18, 2022 13:57
BuildTimeLoggerPlugin - register build task service
class BuildTimeLoggerPlugin : Plugin<Project> {
override fun apply(project: Project) {
val gradle = project.gradle
val buildTaskService = registerBuildTaskService(gradle)
}
private fun registerBuildTaskService(gradle: Gradle): Provider<BuildTaskService> {
val registry = gradle.serviceRegistry()[BuildEventListenerRegistryInternal::class.java]
val buildTaskService = gradle.sharedServices.registerIfAbsent("build-task-service", BuildTaskService::class.java) { }
@jonnycaley
jonnycaley / BuildTaskService.kt
Last active June 21, 2022 08:17
BuildTaskService - capturing task execution information
abstract class BuildTaskService : BuildService<BuildServiceParameters.None>, OperationCompletionListener {
var fromCacheTasksCount = 0
var upToDateTasksCount = 0
var executedTasksCount = 0
var buildPhaseFailureMessage: String? = null
val buildPhaseFailed: Boolean
get() = buildPhaseFailureMessage != null
@jonnycaley
jonnycaley / BuildDurationService.kt
Last active June 21, 2022 08:10
BuildDurationService - build and configuration time
abstract class BuildDurationService : BuildService<BuildServiceParameters.None>, BuildOperationListener, AutoCloseable {
var buildDuration: Long? = null
var configurationDuration: Long? = null
var configurationPhaseFailed = true
override fun started(p0: BuildOperationDescriptor, p1: OperationStartEvent) {}
override fun progress(p0: OperationIdentifier, p1: OperationProgressEvent) {}
@jonnycaley
jonnycaley / BuildDurationService.kt
Last active June 21, 2022 08:10
BuildDurationService - Capturing build time
abstract class BuildDurationService : BuildService<BuildServiceParameters.None>, BuildOperationListener, AutoCloseable {
var buildDuration: Long? = null
override fun started(p0: BuildOperationDescriptor, p1: OperationStartEvent) {}
override fun progress(p0: OperationIdentifier, p1: OperationProgressEvent) {}
override fun finished(buildOperationDescriptor: BuildOperationDescriptor, operationFinishEvent: OperationFinishEvent) {
if (buildOperationDescriptor.details is RunRootBuildWorkBuildOperationType.Details) {
@jonnycaley
jonnycaley / BuildTimeLoggerPlugin.kt
Last active June 18, 2022 14:00
Register BuildDurationService
class BuildTimeLoggerPlugin : Plugin<Project> {
override fun apply(project: Project) {
val gradle = project.gradle
val buildDurationService = registerBuildDurationService(gradle)
}
private fun registerBuildDurationService(gradle: Gradle): Provider<BuildDurationService> {
val registry = gradle.serviceRegistry()[BuildEventListenerRegistryInternal::class.java]
val buildDurationService = gradle.sharedServices.registerIfAbsent("build-duration-service", BuildDurationService::class.java) { }
package com.dropbox.affectedmoduledetector
import java.io.File
class AffectedModuleConfiguration {
/**
* Folder to place the log in
*/
var logFolder: String? = null