Skip to content

Commit

Permalink
Add warning when Jetifier is enabled.
Browse files Browse the repository at this point in the history
Fixes #82
  • Loading branch information
runningcode committed Sep 21, 2020
1 parent 51580cf commit 0c1eea0
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 1 deletion.
Expand Up @@ -41,6 +41,11 @@ open class DoctorExtension(objects: ObjectFactory) {
*/
val allowBuildingAllAndroidAppsSimultaneously = objects.property<Boolean>().convention(false)

/**
* Warn if using Android Jetifier
*/
val warnWhenJetifierEnabled = objects.property<Boolean>().convention(true)

/**
* Configures `JAVA_HOME`-specific behavior.
*/
Expand Down
Expand Up @@ -44,7 +44,8 @@ class DoctorPlugin : Plugin<Project> {
val downloadSpeedMeasurer = DownloadSpeedMeasurer(buildOperations, extension, intervalMeasurer)
val buildCacheConnectionMeasurer = BuildCacheConnectionMeasurer(buildOperations, extension, intervalMeasurer)
val buildCacheKey = RemoteCacheEstimation((buildOperations as BuildOperations), target, clock)
val list = listOf(daemonChecker, javaHomeCheck, garbagePrinter, javaAnnotationTime, downloadSpeedMeasurer, buildCacheConnectionMeasurer, buildCacheKey)
val jetifierWarning = JetifierWarning(extension, target)
val list = listOf(daemonChecker, javaHomeCheck, garbagePrinter, javaAnnotationTime, downloadSpeedMeasurer, buildCacheConnectionMeasurer, buildCacheKey, jetifierWarning)

garbagePrinter.onStart()
javaAnnotationTime.onStart()
Expand Down
22 changes: 22 additions & 0 deletions doctor-plugin/src/main/java/com/osacky/doctor/JetifierWarning.kt
@@ -0,0 +1,22 @@
package com.osacky.doctor

import org.gradle.api.Project

class JetifierWarning(private val doctorExtension: DoctorExtension, private val project: Project) : BuildStartFinishListener {

override fun onStart() {
}

override fun onFinish(): List<String> {
val isJetifierEnabled = project.findProperty(jetifierFlag) as String?
if (doctorExtension.warnWhenJetifierEnabled.get() && isJetifierEnabled != null && isJetifierEnabled == "true") {
return listOf("Jetifier was enabled which means your builds are slower.")
} else {
return emptyList()
}
}

companion object {
const val jetifierFlag = "android.enableJetifier"
}
}
@@ -0,0 +1,71 @@
package com.osacky.doctor

import com.google.common.truth.Truth.assertThat
import org.gradle.testkit.runner.GradleRunner
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder

class JetifierWarningTest {

@get:Rule
val testProjectRoot = TemporaryFolder()

val jetifierWarning = "Jetifier was enabled which means your builds are slower."

@Test
fun testJetifierEnabledShowsWarning() {
testProjectRoot.writeBuildGradle(
"""
|plugins {
| id "com.osacky.doctor"
|}
|doctor {
| disallowMultipleDaemons = false
| javaHome {
| ensureJavaHomeMatches = false
| }
|}
""".trimMargin("|")
)

val result = GradleRunner.create()
.forwardOutput()
.withArguments("help", "-Pandroid.enableJetifier=true")
.withPluginClasspath()
.withProjectDir(testProjectRoot.root)
.build()

assertThat(result.output).contains("BUILD SUCCESSFUL")
assertThat(result.output).contains("Gradle Doctor Prescriptions")
assertThat(result.output).contains(jetifierWarning)
}

@Test
fun testJetifierDisabledShowNoWarning() {
testProjectRoot.writeBuildGradle(
"""
|plugins {
| id "com.osacky.doctor"
|}
|doctor {
| disallowMultipleDaemons = false
| javaHome {
| ensureJavaHomeMatches = false
| }
|}
""".trimMargin("|")
)

val result = GradleRunner.create()
.forwardOutput()
.withArguments("help", "-Pandroid.enableJetifier=false")
.withPluginClasspath()
.withProjectDir(testProjectRoot.root)
.build()

assertThat(result.output).contains("BUILD SUCCESSFUL")
assertThat(result.output).doesNotContain(jetifierWarning)
assertThat(result.output).doesNotContain("Gradle Doctor Prescriptions")
}
}

0 comments on commit 0c1eea0

Please sign in to comment.