Skip to content

Commit

Permalink
fix formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
runningcode committed Jul 15, 2024
1 parent a1c8139 commit 0afc0b5
Show file tree
Hide file tree
Showing 33 changed files with 197 additions and 203 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,5 @@ class AppleRosettaTranslationCheck(
}
}

override fun onFinish(): List<String> {
return emptyList()
}
override fun onFinish(): List<String> = emptyList()
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ class BuildCacheConnectionMeasurer(
private val buildOperations: OperationEvents,
private val extension: DoctorExtension,
private val intervalMeasurer: IntervalMeasurer,
) : BuildStartFinishListener, HasBuildScanTag {
) : BuildStartFinishListener,
HasBuildScanTag {
private val slowNetworkPrinter = SlowNetworkPrinter("Build Cache")
private val downloadEvents = Collections.synchronizedList(mutableListOf<ExternalDownloadEvent>())
private lateinit var disposable: Disposable

override fun onStart() {
disposable =
buildOperations.finishes()
buildOperations
.finishes()
.filter {
(it.result is BuildCacheRemoteLoadBuildOperationType.Result) &&
(it.result as BuildCacheRemoteLoadBuildOperationType.Result).isHit
}
.map {
}.map {
fromGradleType(it)
}
.subscribe {
}.subscribe {
downloadEvents.add(it)
}
}
Expand All @@ -43,8 +43,7 @@ class BuildCacheConnectionMeasurer(
synchronized(downloadEvents) {
val totalBytes =
requireNotNull(downloadEvents) { "downloadEvents list cannot be null" }
.sumBy {
event ->
.sumBy { event ->
requireNotNull(
requireNotNull(event) { "ExternalDownloadEvent cannot be null" }.byteTotal,
) { "byteTotal cannot be null" }.toInt()
Expand All @@ -67,7 +66,11 @@ class BuildCacheConnectionMeasurer(
}
}

data class ExternalDownloadEvent(val start: Long, val end: Long, val byteTotal: Long) {
data class ExternalDownloadEvent(
val start: Long,
val end: Long,
val byteTotal: Long,
) {
companion object {
private val logger = LoggerFactory.getLogger(ExternalDownloadEvent::class.java)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import org.gradle.api.services.BuildService
import org.gradle.api.services.BuildServiceParameters
import java.util.LinkedList

abstract class BuildFinishService : BuildService<BuildServiceParameters.None>, AutoCloseable {
abstract class BuildFinishService :
BuildService<BuildServiceParameters.None>,
AutoCloseable {
private val closeList = LinkedList<AutoCloseable>()

fun closeMeWhenFinished(closeable: AutoCloseable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import org.gradle.internal.operations.OperationIdentifier
import org.gradle.internal.operations.OperationProgressEvent
import org.gradle.internal.operations.OperationStartEvent

abstract class BuildOperationListenerService : BuildService<BuildOperationListenerService.Params>, BuildOperationListener {
abstract class BuildOperationListenerService :
BuildService<BuildOperationListenerService.Params>,
BuildOperationListener {
interface Params : BuildServiceParameters {
fun getNegativeAvoidanceThreshold(): Property<Int>
}
Expand Down Expand Up @@ -39,7 +41,5 @@ abstract class BuildOperationListenerService : BuildService<BuildOperationListen
buildOperations.finished(buildOperation, finishEvent)
}

fun getOperations(): OperationEvents {
return buildOperations
}
fun getOperations(): OperationEvents = buildOperations
}
13 changes: 6 additions & 7 deletions doctor-plugin/src/main/java/com/osacky/doctor/BuildOperations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import org.gradle.internal.operations.OperationProgressEvent
import org.gradle.internal.operations.OperationStartEvent
import java.util.concurrent.ConcurrentHashMap

class BuildOperations(negativeAvoidanceThreshold: Property<Int>) : OperationEvents, BuildOperationListener {
class BuildOperations(
negativeAvoidanceThreshold: Property<Int>,
) : OperationEvents,
BuildOperationListener {
// TODO move this out of this class
// When multiple threads are accessing this HashMap, a ClassCastException may be thrown.
private val snapshotIdsMap = ConcurrentHashMap<OperationIdentifier, SnapshotTaskInputsBuildOperationType.Result>()
Expand Down Expand Up @@ -60,9 +63,7 @@ class BuildOperations(negativeAvoidanceThreshold: Property<Int>) : OperationEven
}
}

fun slowerFromCacheCollector(): SlowerFromCacheCollector {
return slowerFromCacheCollector
}
fun slowerFromCacheCollector(): SlowerFromCacheCollector = slowerFromCacheCollector

// TODO move this out of this class
fun cacheKeys(): List<HashCode> {
Expand All @@ -79,9 +80,7 @@ class BuildOperations(negativeAvoidanceThreshold: Property<Int>) : OperationEven
return cacheKeys
}

fun tasksRan(): Int {
return executeTaskIdsMap.entries.filter { it.value.skipMessage == null }.size
}
fun tasksRan(): Int = executeTaskIdsMap.entries.filter { it.value.skipMessage == null }.size

override fun starts(): Observable<OperationStartEvent> = starts.hide()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,17 @@ class NoOpBuildScanAdapter : BuildScanAdapter {
override fun setTermsOfUseUrl(p0: String?) {
}

override fun getTermsOfUseUrl(): String? {
throw UnsupportedOperationException("not implemented")
}
override fun getTermsOfUseUrl(): String? = throw UnsupportedOperationException("not implemented")

override fun setTermsOfUseAgree(p0: String?) {
}

override fun getTermsOfUseAgree(): String? {
throw UnsupportedOperationException("not implemented")
}
override fun getTermsOfUseAgree(): String? = throw UnsupportedOperationException("not implemented")

override fun setUploadInBackground(p0: Boolean) {
}

override fun isUploadInBackground(): Boolean {
throw UnsupportedOperationException("not implemented")
}
override fun isUploadInBackground(): Boolean = throw UnsupportedOperationException("not implemented")

override fun publishAlways() {
}
Expand All @@ -77,18 +71,12 @@ class NoOpBuildScanAdapter : BuildScanAdapter {
override fun publishOnFailureIf(p0: Boolean) {
}

override fun getObfuscation(): BuildScanObfuscationAdapter? {
throw UnsupportedOperationException("not implemented")
}
override fun getObfuscation(): BuildScanObfuscationAdapter? = throw UnsupportedOperationException("not implemented")

override fun obfuscation(p0: Action<in BuildScanObfuscationAdapter>?) {
}

override fun getCapture(): BuildScanCaptureAdapter? {
throw UnsupportedOperationException("not implemented")
}
override fun getCapture(): BuildScanCaptureAdapter? = throw UnsupportedOperationException("not implemented")

override fun capture(p0: Action<in BuildScanCaptureAdapter>?) {
throw UnsupportedOperationException("not implemented")
}
override fun capture(p0: Action<in BuildScanCaptureAdapter>?): Unit = throw UnsupportedOperationException("not implemented")
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import org.gradle.kotlin.dsl.newInstance
import org.gradle.kotlin.dsl.property
import javax.inject.Inject

open class DoctorExtension(objects: ObjectFactory) {
open class DoctorExtension(
objects: ObjectFactory,
) {
internal val javaHomeHandler = objects.newInstance<JavaHomeHandler>()

/**
Expand Down Expand Up @@ -102,7 +104,9 @@ open class DoctorExtension(objects: ObjectFactory) {

abstract class JavaHomeHandler
@Inject
constructor(objects: ObjectFactory) {
constructor(
objects: ObjectFactory,
) {
/**
* Ensure that we are using `JAVA_HOME` to build with this Gradle.
*/
Expand Down
24 changes: 12 additions & 12 deletions doctor-plugin/src/main/java/com/osacky/doctor/DoctorPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ class DoctorPlugin : Plugin<Project> {

if (shouldUseCoCaClasses()) {
val closeService =
target.gradle.sharedServices.registerIfAbsent("close-service", BuildFinishService::class.java) { }.get()
target.gradle.sharedServices
.registerIfAbsent("close-service", BuildFinishService::class.java) { }
.get()
closeService.closeMeWhenFinished {
runnable.execute(list)
}
Expand Down Expand Up @@ -248,18 +250,17 @@ class DoctorPlugin : Plugin<Project> {
private fun createDaemonChecker(
operatingSystem: OperatingSystem,
cliCommandExecutor: CliCommandExecutor,
): DaemonChecker {
return when {
): DaemonChecker =
when {
operatingSystem.isLinux || operatingSystem.isMacOsX -> UnixDaemonChecker(cliCommandExecutor)
else -> UnsupportedOsDaemonChecker
}
}

private fun getOperationEvents(
target: Project,
extension: DoctorExtension,
): OperationEvents {
return if (shouldUseCoCaClasses()) {
): OperationEvents =
if (shouldUseCoCaClasses()) {
val listenerService =
target.gradle.sharedServices.registerIfAbsent("listener-service", BuildOperationListenerService::class.java) {
this.parameters.getNegativeAvoidanceThreshold().set(extension.negativeAvoidanceThreshold)
Expand All @@ -272,20 +273,19 @@ class DoctorPlugin : Plugin<Project> {
target.gradle.buildOperationListenerManager.addListener(ops)
ops
}
}

/**
* Gradle now ignores empty directories starting in 6.8
* https://docs.gradle.org/6.8-rc-1/release-notes.html#performance-improvements
**/
private fun gradleIgnoresEmptyDirectories(): Boolean {
return GradleVersion.current() >= GradleVersion.version("6.8-rc-1")
}
private fun gradleIgnoresEmptyDirectories(): Boolean = GradleVersion.current() >= GradleVersion.version("6.8-rc-1")

private val Gradle.buildOperationListenerManager get() = (this as GradleInternal).services[BuildOperationListenerManager::class.java]

class TheActionThing(private val pillBoxPrinter: PillBoxPrinter, private val buildScanApi: BuildScanAdapter) :
Action<List<BuildStartFinishListener>> {
class TheActionThing(
private val pillBoxPrinter: PillBoxPrinter,
private val buildScanApi: BuildScanAdapter,
) : Action<List<BuildStartFinishListener>> {
override fun execute(list: List<BuildStartFinishListener>) {
val thingsToPrint: List<String> =
list.flatMap {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ class DownloadSpeedMeasurer(
private val buildOperations: OperationEvents,
private val extension: DoctorExtension,
private val intervalMeasurer: IntervalMeasurer,
) : BuildStartFinishListener, HasBuildScanTag {
) : BuildStartFinishListener,
HasBuildScanTag {
private val slowNetworkPrinter = SlowNetworkPrinter("External Repos")
private val downloadEvents = Collections.synchronizedList(mutableListOf<ExternalDownloadEvent>())
private lateinit var disposable: Disposable

override fun onStart() {
disposable =
buildOperations.finishes()
buildOperations
.finishes()
.filter { it.result is ExternalResourceReadBuildOperationType.Result }
.map { fromGradleType(it) }
.subscribe { event ->
Expand Down Expand Up @@ -54,7 +56,11 @@ class DownloadSpeedMeasurer(
return emptyList()
}

data class ExternalDownloadEvent(val start: Long, val end: Long, val byteTotal: Long) {
data class ExternalDownloadEvent(
val start: Long,
val end: Long,
val byteTotal: Long,
) {
companion object {
fun fromGradleType(event: OperationFinishEvent): ExternalDownloadEvent {
val result = event.result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class GarbagePrinter(
private val clock: Clock,
private val collector: DirtyBeanCollector,
private val extension: DoctorExtension,
) : BuildStartFinishListener, HasBuildScanTag {
) : BuildStartFinishListener,
HasBuildScanTag {
private val startGarbageTime = collector.collect()
private val startBuildTime = clock.upTimeMillis()
private val formatter = NumberFormat.getPercentInstance()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ import org.gradle.api.internal.tasks.compile.CompileJavaBuildOperationType
class JavaAnnotationTime(
private val operationEvents: OperationEvents,
private val doctorExtension: DoctorExtension,
) : BuildStartFinishListener, HasBuildScanTag {
) : BuildStartFinishListener,
HasBuildScanTag {
private var totalDaggerTime = 0

private val disposable = CompositeDisposable()

override fun onStart() {
disposable +=
operationEvents.finishResultsOfType(CompileJavaBuildOperationType.Result::class.java)
operationEvents
.finishResultsOfType(CompileJavaBuildOperationType.Result::class.java)
.filter { it.annotationProcessorDetails != null }
.map { it.annotationProcessorDetails }
.map { detailsList -> detailsList.filter { it.className.contains("dagger") }.sumBy { it.executionTimeInMillis.toInt() } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ class JavaGCFlagChecker(
}
}

override fun onFinish(): List<String> {
return emptyList()
}
override fun onFinish(): List<String> = emptyList()

/**
* Returns the Java version as an Int in a backward compatible way.
Expand Down
12 changes: 7 additions & 5 deletions doctor-plugin/src/main/java/com/osacky/doctor/JavaHomeCheck.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class JavaHomeCheck(
private val pillBoxPrinter: PillBoxPrinter,
private val prescriptionsGenerator: JavaHomeCheckPrescriptionsGenerator =
DefaultPrescriptionGenerator { javaHomeHandler.extraMessage.orNull },
) : BuildStartFinishListener, HasBuildScanTag {
) : BuildStartFinishListener,
HasBuildScanTag {
private val gradleJavaExecutablePath by lazy { resolveExecutableJavaPath(jvmVariables.gradleJavaHome) }
private val environmentJavaExecutablePath by lazy { resolveEnvironmentJavaHome(jvmVariables.environmentJavaHome) }
private val recordedErrors = Collections.synchronizedSet(LinkedHashSet<String>())
Expand All @@ -37,9 +38,7 @@ class JavaHomeCheck(
ensureJavaHomeMatchesGradleHome()
}

override fun onFinish(): List<String> {
return recordedErrors.toList()
}
override fun onFinish(): List<String> = recordedErrors.toList()

override fun addCustomValues(buildScanApi: BuildScanAdapter) {
buildScanApi.tag(JAVA_HOME_TAG)
Expand Down Expand Up @@ -95,4 +94,7 @@ class JavaHomeCheck(
}
}

data class JvmVariables(val environmentJavaHome: String?, val gradleJavaHome: String)
data class JvmVariables(
val environmentJavaHome: String?,
val gradleJavaHome: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package com.osacky.doctor

import org.gradle.api.Project

class JetifierWarning(private val doctorExtension: DoctorExtension, private val project: Project) : BuildStartFinishListener {
class JetifierWarning(
private val doctorExtension: DoctorExtension,
private val project: Project,
) : BuildStartFinishListener {
override fun onStart() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import java.util.concurrent.atomic.AtomicInteger
class KotlinCompileDaemonFallbackDetector(
private val project: Project,
private val extension: DoctorExtension,
) : BuildStartFinishListener, HasBuildScanTag {
) : BuildStartFinishListener,
HasBuildScanTag {
private val fallbackCounter = AtomicInteger(0)
private val loggingService = project.gradle.serviceOf<LoggingManagerInternal>()
private val failureEventListener = FailureEventListener(fallbackCounter)
Expand Down Expand Up @@ -77,8 +78,7 @@ internal class FailureEventListener(
}
}

private fun isFallbackMessage(event: OutputEvent): Boolean {
return event is LogEvent &&
private fun isFallbackMessage(event: OutputEvent): Boolean =
event is LogEvent &&
event.message.contains("Could not connect to kotlin daemon. Using fallback strategy.")
}
}
Loading

0 comments on commit 0afc0b5

Please sign in to comment.