diff --git a/doctor-plugin/src/main/java/com/osacky/doctor/AppleRosettaTranslationCheck.kt b/doctor-plugin/src/main/java/com/osacky/doctor/AppleRosettaTranslationCheck.kt index 1b32b248..3c970aff 100644 --- a/doctor-plugin/src/main/java/com/osacky/doctor/AppleRosettaTranslationCheck.kt +++ b/doctor-plugin/src/main/java/com/osacky/doctor/AppleRosettaTranslationCheck.kt @@ -42,7 +42,5 @@ class AppleRosettaTranslationCheck( } } - override fun onFinish(): List { - return emptyList() - } + override fun onFinish(): List = emptyList() } diff --git a/doctor-plugin/src/main/java/com/osacky/doctor/BuildCacheConnectionMeasurer.kt b/doctor-plugin/src/main/java/com/osacky/doctor/BuildCacheConnectionMeasurer.kt index f8af1a4f..be4344a4 100644 --- a/doctor-plugin/src/main/java/com/osacky/doctor/BuildCacheConnectionMeasurer.kt +++ b/doctor-plugin/src/main/java/com/osacky/doctor/BuildCacheConnectionMeasurer.kt @@ -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()) 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) } } @@ -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() @@ -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) diff --git a/doctor-plugin/src/main/java/com/osacky/doctor/BuildFinishService.kt b/doctor-plugin/src/main/java/com/osacky/doctor/BuildFinishService.kt index db878b9c..2fab77cb 100644 --- a/doctor-plugin/src/main/java/com/osacky/doctor/BuildFinishService.kt +++ b/doctor-plugin/src/main/java/com/osacky/doctor/BuildFinishService.kt @@ -4,7 +4,9 @@ import org.gradle.api.services.BuildService import org.gradle.api.services.BuildServiceParameters import java.util.LinkedList -abstract class BuildFinishService : BuildService, AutoCloseable { +abstract class BuildFinishService : + BuildService, + AutoCloseable { private val closeList = LinkedList() fun closeMeWhenFinished(closeable: AutoCloseable) { diff --git a/doctor-plugin/src/main/java/com/osacky/doctor/BuildOperationListenerService.kt b/doctor-plugin/src/main/java/com/osacky/doctor/BuildOperationListenerService.kt index 8997b8cd..10a2b673 100644 --- a/doctor-plugin/src/main/java/com/osacky/doctor/BuildOperationListenerService.kt +++ b/doctor-plugin/src/main/java/com/osacky/doctor/BuildOperationListenerService.kt @@ -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, BuildOperationListener { +abstract class BuildOperationListenerService : + BuildService, + BuildOperationListener { interface Params : BuildServiceParameters { fun getNegativeAvoidanceThreshold(): Property } @@ -39,7 +41,5 @@ abstract class BuildOperationListenerService : BuildService) : OperationEvents, BuildOperationListener { +class BuildOperations( + negativeAvoidanceThreshold: Property, +) : 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() @@ -60,9 +63,7 @@ class BuildOperations(negativeAvoidanceThreshold: Property) : OperationEven } } - fun slowerFromCacheCollector(): SlowerFromCacheCollector { - return slowerFromCacheCollector - } + fun slowerFromCacheCollector(): SlowerFromCacheCollector = slowerFromCacheCollector // TODO move this out of this class fun cacheKeys(): List { @@ -79,9 +80,7 @@ class BuildOperations(negativeAvoidanceThreshold: Property) : 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 = starts.hide() diff --git a/doctor-plugin/src/main/java/com/osacky/doctor/DevelocityApiFinder.kt b/doctor-plugin/src/main/java/com/osacky/doctor/DevelocityApiFinder.kt index 17af3e75..cfeb7f95 100644 --- a/doctor-plugin/src/main/java/com/osacky/doctor/DevelocityApiFinder.kt +++ b/doctor-plugin/src/main/java/com/osacky/doctor/DevelocityApiFinder.kt @@ -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() { } @@ -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?) { } - override fun getCapture(): BuildScanCaptureAdapter? { - throw UnsupportedOperationException("not implemented") - } + override fun getCapture(): BuildScanCaptureAdapter? = throw UnsupportedOperationException("not implemented") - override fun capture(p0: Action?) { - throw UnsupportedOperationException("not implemented") - } + override fun capture(p0: Action?): Unit = throw UnsupportedOperationException("not implemented") } diff --git a/doctor-plugin/src/main/java/com/osacky/doctor/DoctorExtension.kt b/doctor-plugin/src/main/java/com/osacky/doctor/DoctorExtension.kt index 5598a043..d286e8ca 100644 --- a/doctor-plugin/src/main/java/com/osacky/doctor/DoctorExtension.kt +++ b/doctor-plugin/src/main/java/com/osacky/doctor/DoctorExtension.kt @@ -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() /** @@ -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. */ diff --git a/doctor-plugin/src/main/java/com/osacky/doctor/DoctorPlugin.kt b/doctor-plugin/src/main/java/com/osacky/doctor/DoctorPlugin.kt index 5e65a8d1..a55a49d0 100644 --- a/doctor-plugin/src/main/java/com/osacky/doctor/DoctorPlugin.kt +++ b/doctor-plugin/src/main/java/com/osacky/doctor/DoctorPlugin.kt @@ -189,7 +189,9 @@ class DoctorPlugin : Plugin { 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) } @@ -248,18 +250,17 @@ class DoctorPlugin : Plugin { 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) @@ -272,20 +273,19 @@ class DoctorPlugin : Plugin { 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> { + class TheActionThing( + private val pillBoxPrinter: PillBoxPrinter, + private val buildScanApi: BuildScanAdapter, + ) : Action> { override fun execute(list: List) { val thingsToPrint: List = list.flatMap { diff --git a/doctor-plugin/src/main/java/com/osacky/doctor/DownloadSpeedMeasurer.kt b/doctor-plugin/src/main/java/com/osacky/doctor/DownloadSpeedMeasurer.kt index 5794ba64..3c3a83ad 100644 --- a/doctor-plugin/src/main/java/com/osacky/doctor/DownloadSpeedMeasurer.kt +++ b/doctor-plugin/src/main/java/com/osacky/doctor/DownloadSpeedMeasurer.kt @@ -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()) private lateinit var disposable: Disposable override fun onStart() { disposable = - buildOperations.finishes() + buildOperations + .finishes() .filter { it.result is ExternalResourceReadBuildOperationType.Result } .map { fromGradleType(it) } .subscribe { event -> @@ -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 diff --git a/doctor-plugin/src/main/java/com/osacky/doctor/GarbagePrinter.kt b/doctor-plugin/src/main/java/com/osacky/doctor/GarbagePrinter.kt index e6a0d546..c1c5e30f 100644 --- a/doctor-plugin/src/main/java/com/osacky/doctor/GarbagePrinter.kt +++ b/doctor-plugin/src/main/java/com/osacky/doctor/GarbagePrinter.kt @@ -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() diff --git a/doctor-plugin/src/main/java/com/osacky/doctor/JavaAnnotationTime.kt b/doctor-plugin/src/main/java/com/osacky/doctor/JavaAnnotationTime.kt index e10a91e3..300e4e33 100644 --- a/doctor-plugin/src/main/java/com/osacky/doctor/JavaAnnotationTime.kt +++ b/doctor-plugin/src/main/java/com/osacky/doctor/JavaAnnotationTime.kt @@ -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() } } diff --git a/doctor-plugin/src/main/java/com/osacky/doctor/JavaGCFlagChecker.kt b/doctor-plugin/src/main/java/com/osacky/doctor/JavaGCFlagChecker.kt index 203cc134..63aa1bf1 100644 --- a/doctor-plugin/src/main/java/com/osacky/doctor/JavaGCFlagChecker.kt +++ b/doctor-plugin/src/main/java/com/osacky/doctor/JavaGCFlagChecker.kt @@ -31,9 +31,7 @@ class JavaGCFlagChecker( } } - override fun onFinish(): List { - return emptyList() - } + override fun onFinish(): List = emptyList() /** * Returns the Java version as an Int in a backward compatible way. diff --git a/doctor-plugin/src/main/java/com/osacky/doctor/JavaHomeCheck.kt b/doctor-plugin/src/main/java/com/osacky/doctor/JavaHomeCheck.kt index 2aa851c5..6e48614b 100644 --- a/doctor-plugin/src/main/java/com/osacky/doctor/JavaHomeCheck.kt +++ b/doctor-plugin/src/main/java/com/osacky/doctor/JavaHomeCheck.kt @@ -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()) @@ -37,9 +38,7 @@ class JavaHomeCheck( ensureJavaHomeMatchesGradleHome() } - override fun onFinish(): List { - return recordedErrors.toList() - } + override fun onFinish(): List = recordedErrors.toList() override fun addCustomValues(buildScanApi: BuildScanAdapter) { buildScanApi.tag(JAVA_HOME_TAG) @@ -95,4 +94,7 @@ class JavaHomeCheck( } } -data class JvmVariables(val environmentJavaHome: String?, val gradleJavaHome: String) +data class JvmVariables( + val environmentJavaHome: String?, + val gradleJavaHome: String, +) diff --git a/doctor-plugin/src/main/java/com/osacky/doctor/JetifierWarning.kt b/doctor-plugin/src/main/java/com/osacky/doctor/JetifierWarning.kt index ce146dee..c9bca6a4 100644 --- a/doctor-plugin/src/main/java/com/osacky/doctor/JetifierWarning.kt +++ b/doctor-plugin/src/main/java/com/osacky/doctor/JetifierWarning.kt @@ -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() { } diff --git a/doctor-plugin/src/main/java/com/osacky/doctor/KotlinCompileDaemonFallbackDetector.kt b/doctor-plugin/src/main/java/com/osacky/doctor/KotlinCompileDaemonFallbackDetector.kt index 9d107228..776745d7 100644 --- a/doctor-plugin/src/main/java/com/osacky/doctor/KotlinCompileDaemonFallbackDetector.kt +++ b/doctor-plugin/src/main/java/com/osacky/doctor/KotlinCompileDaemonFallbackDetector.kt @@ -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() private val failureEventListener = FailureEventListener(fallbackCounter) @@ -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.") - } } diff --git a/doctor-plugin/src/main/java/com/osacky/doctor/OperationEvents.kt b/doctor-plugin/src/main/java/com/osacky/doctor/OperationEvents.kt index bcffb59d..0d03933c 100644 --- a/doctor-plugin/src/main/java/com/osacky/doctor/OperationEvents.kt +++ b/doctor-plugin/src/main/java/com/osacky/doctor/OperationEvents.kt @@ -12,19 +12,17 @@ interface OperationEvents { fun finishes(): Observable - fun progressDetailsOfType(clazz: Class): Observable { - return progress() + fun progressDetailsOfType(clazz: Class): Observable = + progress() .filter { it.details != null } .map { it.details } .filter { clazz.isAssignableFrom(it!!::class.java) } .cast(clazz) - } - fun finishResultsOfType(clazz: Class): Observable { - return finishes() + fun finishResultsOfType(clazz: Class): Observable = + finishes() .filter { it.result != null } .map { it.result } .filter { clazz.isAssignableFrom(it!!::class.java) } .cast(clazz) - } } diff --git a/doctor-plugin/src/main/java/com/osacky/doctor/RemoteCacheEstimation.kt b/doctor-plugin/src/main/java/com/osacky/doctor/RemoteCacheEstimation.kt index b7814333..a6e67f2d 100644 --- a/doctor-plugin/src/main/java/com/osacky/doctor/RemoteCacheEstimation.kt +++ b/doctor-plugin/src/main/java/com/osacky/doctor/RemoteCacheEstimation.kt @@ -38,17 +38,17 @@ class RemoteCacheEstimation( if (rerunLargeOutputTasks) { // Look up tasks by name so we don't depend on the Android Plugin. // If the task has a different build type (not debug), it likely won't work here though. - tasks.matching { - it.name == "processDebugResources" || - it.name == "mergeDebugJavaResource" || - it.name == "mergeDebugAssets" || - it.name == "mergeDebugResources" || - it.name == "bundleLibResDebug" || - it.name == "packageDebugResources" || - it.name == "mergeDebugNativeLibs" || - it.name == "generateDebugUnitTestStubRFile" - } - .configureEach { + tasks + .matching { + it.name == "processDebugResources" || + it.name == "mergeDebugJavaResource" || + it.name == "mergeDebugAssets" || + it.name == "mergeDebugResources" || + it.name == "bundleLibResDebug" || + it.name == "packageDebugResources" || + it.name == "mergeDebugNativeLibs" || + it.name == "generateDebugUnitTestStubRFile" + }.configureEach { outputs.upToDateWhen { false } } } @@ -119,7 +119,9 @@ class RemoteCacheEstimation( } private fun gradleLocalCacheDir(): File { - val gradleInternalCacheDir = (project.gradle as GradleInternal).settings.buildCache.local.directory + val gradleInternalCacheDir = + (project.gradle as GradleInternal) + .settings.buildCache.local.directory return if (gradleInternalCacheDir != null) { when (gradleInternalCacheDir) { is File -> { diff --git a/doctor-plugin/src/main/java/com/osacky/doctor/SlowerFromCacheCollector.kt b/doctor-plugin/src/main/java/com/osacky/doctor/SlowerFromCacheCollector.kt index aca47189..c7448739 100644 --- a/doctor-plugin/src/main/java/com/osacky/doctor/SlowerFromCacheCollector.kt +++ b/doctor-plugin/src/main/java/com/osacky/doctor/SlowerFromCacheCollector.kt @@ -10,7 +10,10 @@ import org.gradle.internal.operations.OperationFinishEvent /** * Keeps track of which classes were slower to fetch from the cache than to re-run locally. */ -class SlowerFromCacheCollector(private val negativeAvoidanceThreshold: Provider) : BuildStartFinishListener, HasBuildScanTag { +class SlowerFromCacheCollector( + private val negativeAvoidanceThreshold: Provider, +) : BuildStartFinishListener, + HasBuildScanTag { private val longerTaskList = mutableListOf() fun onEvent( diff --git a/doctor-plugin/src/main/java/com/osacky/doctor/internal/CliCommandExecutor.kt b/doctor-plugin/src/main/java/com/osacky/doctor/internal/CliCommandExecutor.kt index bdba7808..670fa5f8 100644 --- a/doctor-plugin/src/main/java/com/osacky/doctor/internal/CliCommandExecutor.kt +++ b/doctor-plugin/src/main/java/com/osacky/doctor/internal/CliCommandExecutor.kt @@ -4,28 +4,31 @@ import org.gradle.api.Project import org.gradle.util.GradleVersion import java.io.InputStream -class CliCommandExecutor(private val project: Project) { +class CliCommandExecutor( + private val project: Project, +) { fun execute( command: Array, ignoreExitValue: Boolean = false, - ): String { - return if (GradleVersion.current() >= GradleVersion.version("7.5")) { + ): String = + if (GradleVersion.current() >= GradleVersion.version("7.5")) { executeWithConfigCacheSupport(command, ignoreExitValue) } else { executeInLegacyWay(command, ignoreExitValue) } - } @Suppress("UnstableApiUsage") private fun executeWithConfigCacheSupport( command: Array, ignoreExitValue: Boolean = false, - ): String { - return project.providers.exec { - commandLine(*command) - isIgnoreExitValue = ignoreExitValue - }.standardOutput.asText.get().trim() - } + ): String = + project.providers + .exec { + commandLine(*command) + isIgnoreExitValue = ignoreExitValue + }.standardOutput.asText + .get() + .trim() private fun executeInLegacyWay( command: Array, diff --git a/doctor-plugin/src/main/java/com/osacky/doctor/internal/Clock.kt b/doctor-plugin/src/main/java/com/osacky/doctor/internal/Clock.kt index 4a8ce020..b5785688 100644 --- a/doctor-plugin/src/main/java/com/osacky/doctor/internal/Clock.kt +++ b/doctor-plugin/src/main/java/com/osacky/doctor/internal/Clock.kt @@ -9,15 +9,9 @@ interface Clock { } class SystemClock : Clock { - override fun upTime(): Long { - return System.nanoTime() - } + override fun upTime(): Long = System.nanoTime() - override fun upTimeMillis(): Long { - return upTime().toMillis() - } + override fun upTimeMillis(): Long = upTime().toMillis() - private fun Long.toMillis(): Long { - return TimeUnit.NANOSECONDS.toMillis(this) - } + private fun Long.toMillis(): Long = TimeUnit.NANOSECONDS.toMillis(this) } diff --git a/doctor-plugin/src/main/java/com/osacky/doctor/internal/CoCaHelpers.kt b/doctor-plugin/src/main/java/com/osacky/doctor/internal/CoCaHelpers.kt index 42b5fc84..b3aaab15 100644 --- a/doctor-plugin/src/main/java/com/osacky/doctor/internal/CoCaHelpers.kt +++ b/doctor-plugin/src/main/java/com/osacky/doctor/internal/CoCaHelpers.kt @@ -6,13 +6,9 @@ import java.util.Optional fun shouldUseCoCaClasses(): Boolean = isGradle65OrNewer() -fun isGradle65OrNewer(): Boolean { - return GradleVersion.current() >= GradleVersion.version("6.5") -} +fun isGradle65OrNewer(): Boolean = GradleVersion.current() >= GradleVersion.version("6.5") -fun isGradle74OrNewer(): Boolean { - return GradleVersion.current() >= GradleVersion.version("7.4") -} +fun isGradle74OrNewer(): Boolean = GradleVersion.current() >= GradleVersion.version("7.4") fun sysProperty( name: String, diff --git a/doctor-plugin/src/main/java/com/osacky/doctor/internal/DirtyBeanCollector.kt b/doctor-plugin/src/main/java/com/osacky/doctor/internal/DirtyBeanCollector.kt index ee21b3e4..a9014a05 100644 --- a/doctor-plugin/src/main/java/com/osacky/doctor/internal/DirtyBeanCollector.kt +++ b/doctor-plugin/src/main/java/com/osacky/doctor/internal/DirtyBeanCollector.kt @@ -3,7 +3,5 @@ package com.osacky.doctor.internal import java.lang.management.ManagementFactory class DirtyBeanCollector { - fun collect(): Int { - return ManagementFactory.getGarbageCollectorMXBeans().sumBy { it.collectionTime.toInt() } - } + fun collect(): Int = ManagementFactory.getGarbageCollectorMXBeans().sumBy { it.collectionTime.toInt() } } diff --git a/doctor-plugin/src/main/java/com/osacky/doctor/internal/JavaHomeCheckPrescriptionsGenerator.kt b/doctor-plugin/src/main/java/com/osacky/doctor/internal/JavaHomeCheckPrescriptionsGenerator.kt index 04df9ef8..c62c89c8 100644 --- a/doctor-plugin/src/main/java/com/osacky/doctor/internal/JavaHomeCheckPrescriptionsGenerator.kt +++ b/doctor-plugin/src/main/java/com/osacky/doctor/internal/JavaHomeCheckPrescriptionsGenerator.kt @@ -47,8 +47,9 @@ interface JavaHomeCheckPrescriptionsGenerator { ): String } -internal class DefaultPrescriptionGenerator(private val extraMessage: () -> String?) : - JavaHomeCheckPrescriptionsGenerator { +internal class DefaultPrescriptionGenerator( + private val extraMessage: () -> String?, +) : JavaHomeCheckPrescriptionsGenerator { override fun generateJavaHomeIsNotSetMessage() = String.format(NO_JAVA_HOME_MESSAGE, extraMessage().orEmpty()).trimIndent() override fun generateJavaHomeMismatchesGradleHome( @@ -58,11 +59,12 @@ internal class DefaultPrescriptionGenerator(private val extraMessage: () -> Stri val javaHomeMessage = javaHomeLocation?.let { String.format(JAVA_HOME_AT_LOCATION, it) } ?: NO_JAVA_HOME val gradleJavaHomeMessage = String.format(GRADLE_JAVA_HOME_AT_LOCATION, gradleJavaHomeLocation) - return String.format( - JAVA_HOME_DOESNT_MATCH_GRADLE_HOME, - javaHomeMessage, - gradleJavaHomeMessage, - extraMessage().orEmpty(), - ).trimIndent() + return String + .format( + JAVA_HOME_DOESNT_MATCH_GRADLE_HOME, + javaHomeMessage, + gradleJavaHomeMessage, + extraMessage().orEmpty(), + ).trimIndent() } } diff --git a/doctor-plugin/src/main/java/com/osacky/doctor/internal/PillBoxPrinter.kt b/doctor-plugin/src/main/java/com/osacky/doctor/internal/PillBoxPrinter.kt index 3cd9e82d..b9a1b421 100644 --- a/doctor-plugin/src/main/java/com/osacky/doctor/internal/PillBoxPrinter.kt +++ b/doctor-plugin/src/main/java/com/osacky/doctor/internal/PillBoxPrinter.kt @@ -5,7 +5,9 @@ import org.gradle.api.logging.Logger /** * Prints strings inside a nicely fitted pill box. */ -class PillBoxPrinter(private val logger: Logger) { +class PillBoxPrinter( + private val logger: Logger, +) { private val messageLength = 100 private val title = "Gradle Doctor Prescriptions" @@ -20,23 +22,21 @@ class PillBoxPrinter(private val logger: Logger) { } } - private fun createTitle(lineLength: Int): String { - return " $title ".padStart(lineLength / 2 + 10, '=').padEnd(lineLength + 4, '=') - } + private fun createTitle(lineLength: Int): String = " $title ".padStart(lineLength / 2 + 10, '=').padEnd(lineLength + 4, '=') - private fun createEnding(lineLength: Int): String { - return "".padEnd(lineLength + 4, '=') - } + private fun createEnding(lineLength: Int): String = "".padEnd(lineLength + 4, '=') fun padMessage(message: String): String { - return message.split('\n').flatMap { line -> - val chunked = line.chunked(messageLength) - if (chunked.isEmpty()) { - return@flatMap listOf("| ${"".padEnd(messageLength)} |") - } else { - return@flatMap chunked.map { "| ${it.padEnd(messageLength)} |" } - } - }.joinToString("\n") + return message + .split('\n') + .flatMap { line -> + val chunked = line.chunked(messageLength) + if (chunked.isEmpty()) { + return@flatMap listOf("| ${"".padEnd(messageLength)} |") + } else { + return@flatMap chunked.map { "| ${it.padEnd(messageLength)} |" } + } + }.joinToString("\n") } fun createPill(message: String): String { diff --git a/doctor-plugin/src/main/java/com/osacky/doctor/internal/SlowNetworkPrinter.kt b/doctor-plugin/src/main/java/com/osacky/doctor/internal/SlowNetworkPrinter.kt index abcd7896..e31ac86f 100644 --- a/doctor-plugin/src/main/java/com/osacky/doctor/internal/SlowNetworkPrinter.kt +++ b/doctor-plugin/src/main/java/com/osacky/doctor/internal/SlowNetworkPrinter.kt @@ -1,6 +1,8 @@ package com.osacky.doctor.internal -class SlowNetworkPrinter(private val type: String) { +class SlowNetworkPrinter( + private val type: String, +) { fun obtainMessage( totalBytes: Int, totalTime: Long, diff --git a/doctor-plugin/src/main/java/com/osacky/doctor/internal/UnixDaemonChecker.kt b/doctor-plugin/src/main/java/com/osacky/doctor/internal/UnixDaemonChecker.kt index e5c787d5..49c09975 100644 --- a/doctor-plugin/src/main/java/com/osacky/doctor/internal/UnixDaemonChecker.kt +++ b/doctor-plugin/src/main/java/com/osacky/doctor/internal/UnixDaemonChecker.kt @@ -1,6 +1,8 @@ package com.osacky.doctor.internal -class UnixDaemonChecker(private val cliCommandExecutor: CliCommandExecutor) : DaemonChecker { +class UnixDaemonChecker( + private val cliCommandExecutor: CliCommandExecutor, +) : DaemonChecker { override fun check(): String? { val numberOfDaemons = numberOfDaemons() return if (numberOfDaemons > 1) { @@ -23,8 +25,8 @@ class UnixDaemonChecker(private val cliCommandExecutor: CliCommandExecutor) : Da } } - private fun numberOfDaemons(): Int { - return cliCommandExecutor - .execute(arrayOf("/bin/bash", "-c", "ps aux | grep GradleDaemon | wc -l")).toInt() - 2 - } + private fun numberOfDaemons(): Int = + cliCommandExecutor + .execute(arrayOf("/bin/bash", "-c", "ps aux | grep GradleDaemon | wc -l")) + .toInt() - 2 } diff --git a/doctor-plugin/src/test/java/com/osacky/doctor/ConfigurationCacheTest.kt b/doctor-plugin/src/test/java/com/osacky/doctor/ConfigurationCacheTest.kt index efaf38f1..922de691 100644 --- a/doctor-plugin/src/test/java/com/osacky/doctor/ConfigurationCacheTest.kt +++ b/doctor-plugin/src/test/java/com/osacky/doctor/ConfigurationCacheTest.kt @@ -31,7 +31,8 @@ class ConfigurationCacheTest { testProjectRoot.setupFixture(fixtureName) val runner = - GradleRunner.create() + GradleRunner + .create() .forwardOutput() .withArguments("assemble", "--configuration-cache") .withProjectDir(testProjectRoot.root) diff --git a/doctor-plugin/src/test/java/com/osacky/doctor/JavaHomeCheckTest.kt b/doctor-plugin/src/test/java/com/osacky/doctor/JavaHomeCheckTest.kt index 4fde7940..fafae732 100644 --- a/doctor-plugin/src/test/java/com/osacky/doctor/JavaHomeCheckTest.kt +++ b/doctor-plugin/src/test/java/com/osacky/doctor/JavaHomeCheckTest.kt @@ -180,12 +180,14 @@ class JavaHomeCheckTest { // creating the sdkman "current" symlink and pointing to zulu val sdkmanEnvironmentJavaHome = - javaDistributionsRootFolderPath.resolve("current") + javaDistributionsRootFolderPath + .resolve("current") .createSymbolicLinkPointingTo(zuluRootFolderPath.toAbsolutePath()) val javaExecutableFolder = javaHomePath.resolve(JAVA_EXECUTABLES_FOLDER).createDirectories() // creating zulu bin symlink and pointing it to the actual /Contents/Home/bin folder - zuluRootFolderPath.resolve(JAVA_EXECUTABLES_FOLDER) + zuluRootFolderPath + .resolve(JAVA_EXECUTABLES_FOLDER) .createSymbolicLinkPointingTo(javaExecutableFolder.toAbsolutePath()) // environmentJavaHome=***/Users/doctor/.sdkman/candidates/java/current and gradleJavaHome=***/Users/doctor/.sdkman/candidates/java/17.0.10-zulu/zulu-17.jdk/Contents/Home @@ -205,11 +207,10 @@ class JavaHomeCheckTest { whenever(javaHomeHandler.extraMessage).thenReturn(errorMessageProperty) } - private fun setupJavaHomePathStructure(folders: Array): Path { - return Paths.get(testProjectRoot.root.path, *folders).also { + private fun setupJavaHomePathStructure(folders: Array): Path = + Paths.get(testProjectRoot.root.path, *folders).also { it.createDirectories() } - } private fun setupIdenticalJvmVariables(): JvmVariables { val legitPath = javaHomePath.pathString diff --git a/doctor-plugin/src/test/java/com/osacky/doctor/JetifierWarningTest.kt b/doctor-plugin/src/test/java/com/osacky/doctor/JetifierWarningTest.kt index 76de8935..3cbb2093 100644 --- a/doctor-plugin/src/test/java/com/osacky/doctor/JetifierWarningTest.kt +++ b/doctor-plugin/src/test/java/com/osacky/doctor/JetifierWarningTest.kt @@ -30,7 +30,8 @@ class JetifierWarningTest { ) val result = - GradleRunner.create() + GradleRunner + .create() .forwardOutput() .withArguments("help", "-Pandroid.enableJetifier=true") .withPluginClasspath() @@ -73,7 +74,8 @@ class JetifierWarningTest { ) val result = - GradleRunner.create() + GradleRunner + .create() .forwardOutput() .withArguments("help", "-Pandroid.enableJetifier=false") .withPluginClasspath() diff --git a/doctor-plugin/src/test/java/com/osacky/doctor/PluginIntegrationTest.kt b/doctor-plugin/src/test/java/com/osacky/doctor/PluginIntegrationTest.kt index b8aca961..56caccde 100644 --- a/doctor-plugin/src/test/java/com/osacky/doctor/PluginIntegrationTest.kt +++ b/doctor-plugin/src/test/java/com/osacky/doctor/PluginIntegrationTest.kt @@ -16,7 +16,9 @@ import org.junit.runners.Parameterized import java.io.File @RunWith(Parameterized::class) -class PluginIntegrationTest constructor(private val version: String) { +class PluginIntegrationTest constructor( + private val version: String, +) { val agpVersion = "4.0.1" @get:Rule val testProjectRoot = TemporaryFolder() @@ -146,8 +148,7 @@ class PluginIntegrationTest constructor(private val version: String) { |> =============================== Gradle Doctor Prescriptions ============================================ | | Gradle is not using JAVA_HOME. | | | JAVA_HOME is foo | - | """ - .trimMargin("|"), + | """.trimMargin("|"), ) } @@ -183,8 +184,7 @@ class PluginIntegrationTest constructor(private val version: String) { |> =============================== Gradle Doctor Prescriptions ============================================ | | Gradle is not using JAVA_HOME. | | | JAVA_HOME is foo | - | """ - .trimMargin("|"), + | """.trimMargin("|"), ) } @@ -446,12 +446,12 @@ class PluginIntegrationTest constructor(private val version: String) { assertThat(result.output).contains("SUCCESS") } - private fun createRunner(): GradleRunner { - return GradleRunner.create() + private fun createRunner(): GradleRunner = + GradleRunner + .create() .withProjectDir(testProjectRoot.root) .withPluginClasspath() .withGradleVersion(version) - } private fun assumeEmptyDirectoriesInInput() { Assume.assumeTrue(GradleVersion.version(version) < GradleVersion.version("6.8")) diff --git a/doctor-plugin/src/test/java/com/osacky/doctor/ProjectRootIntegrationTest.kt b/doctor-plugin/src/test/java/com/osacky/doctor/ProjectRootIntegrationTest.kt index 2f37aab1..e4c68e68 100644 --- a/doctor-plugin/src/test/java/com/osacky/doctor/ProjectRootIntegrationTest.kt +++ b/doctor-plugin/src/test/java/com/osacky/doctor/ProjectRootIntegrationTest.kt @@ -18,7 +18,8 @@ class ProjectRootIntegrationTest { testProjectRoot.setupFixture(fixtureName) val result = - GradleRunner.create() + GradleRunner + .create() .withProjectDir(testProjectRoot.root) .withPluginClasspath() .withGradleVersion("6.1.1") diff --git a/doctor-plugin/src/test/java/com/osacky/doctor/SlowerFromCacheCollectorTest.kt b/doctor-plugin/src/test/java/com/osacky/doctor/SlowerFromCacheCollectorTest.kt index cfc40a6c..447676bd 100644 --- a/doctor-plugin/src/test/java/com/osacky/doctor/SlowerFromCacheCollectorTest.kt +++ b/doctor-plugin/src/test/java/com/osacky/doctor/SlowerFromCacheCollectorTest.kt @@ -62,54 +62,36 @@ internal class SlowerFromCacheCollectorTest { fun finishWithTime( originExecutionTime: Long, thisExecutionTime: Long = 6, - ): OperationFinishEvent { - return OperationFinishEvent(0, thisExecutionTime, null, Result(originExecutionTime)) - } + ): OperationFinishEvent = OperationFinishEvent(0, thisExecutionTime, null, Result(originExecutionTime)) - fun descriptorWithName(name: String): BuildOperationDescriptor { - return BuildOperationDescriptor.displayName(name) + fun descriptorWithName(name: String): BuildOperationDescriptor = + BuildOperationDescriptor + .displayName(name) .build() - } - internal class Result(private val originExecutionTime: Long) : ExecuteTaskBuildOperationType.Result { - override fun getSkipMessage(): String? { - throw NotImplementedError() - } + internal class Result( + private val originExecutionTime: Long, + ) : ExecuteTaskBuildOperationType.Result { + override fun getSkipMessage(): String? = throw NotImplementedError() - override fun getSkipReasonMessage(): String? { - throw NotImplementedError() - } + override fun getSkipReasonMessage(): String? = throw NotImplementedError() - override fun isActionable(): Boolean { - throw NotImplementedError() - } + override fun isActionable(): Boolean = throw NotImplementedError() - override fun getOriginBuildInvocationId(): String? { - throw NotImplementedError() - } + override fun getOriginBuildInvocationId(): String? = throw NotImplementedError() override fun getOriginBuildCacheKeyBytes(): ByteArray? { TODO("Not yet implemented") } - override fun getOriginExecutionTime(): Long { - return originExecutionTime - } + override fun getOriginExecutionTime(): Long = originExecutionTime - override fun getCachingDisabledReasonMessage(): String? { - throw NotImplementedError() - } + override fun getCachingDisabledReasonMessage(): String? = throw NotImplementedError() - override fun getCachingDisabledReasonCategory(): String? { - throw NotImplementedError() - } + override fun getCachingDisabledReasonCategory(): String? = throw NotImplementedError() - override fun getUpToDateMessages(): MutableList { - throw NotImplementedError() - } + override fun getUpToDateMessages(): MutableList = throw NotImplementedError() - override fun isIncremental(): Boolean { - throw NotImplementedError() - } + override fun isIncremental(): Boolean = throw NotImplementedError() } } diff --git a/doctor-plugin/src/test/java/com/osacky/doctor/TestDaggerTime.kt b/doctor-plugin/src/test/java/com/osacky/doctor/TestDaggerTime.kt index 7e0c3b6e..feedfd40 100644 --- a/doctor-plugin/src/test/java/com/osacky/doctor/TestDaggerTime.kt +++ b/doctor-plugin/src/test/java/com/osacky/doctor/TestDaggerTime.kt @@ -37,7 +37,8 @@ class TestDaggerTime { testProjectRoot.setupFixture(fixtureName) val result = - GradleRunner.create() + GradleRunner + .create() .withProjectDir(testProjectRoot.root) .withPluginClasspath() .withArguments("assemble")