Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add warning when Jetifier is enabled.
Fixes #82
- Loading branch information
1 parent
51580cf
commit 0c1eea0
Showing
4 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
doctor-plugin/src/main/java/com/osacky/doctor/JetifierWarning.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
doctor-plugin/src/test/java/com/osacky/doctor/JetifierWarningTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} | ||
} |