Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #15: Restrict lint tasks to root project only #21

Merged
merged 2 commits into from
Oct 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class QualityPlugin : BaseExposedPlugin() {
if (project.rootProject == project) {
project.tasks.register("violationReportConsole", ValidateViolationsTask::class.java)
project.tasks.register("violationReportHtml", HtmlReportTask::class.java)
}
project.afterEvaluate {
if (project.tasks.findByName("lint") == null) {
project.tasks.register("lint", GlobalLintGlobalFinalizerTask::class.java)
project.afterEvaluate {
if (project.tasks.findByName("lint") == null) {
project.tasks.register("lint", GlobalLintGlobalFinalizerTask::class.java)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package net.twisterrob.gradle.quality

import net.twisterrob.gradle.quality.tasks.GlobalLintGlobalFinalizerTask
import net.twisterrob.gradle.test.GradleRunnerRule
import net.twisterrob.gradle.test.assertHasOutputLine
import net.twisterrob.gradle.test.assertNoOutputLine
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.TaskOutcome.SUCCESS
import org.hamcrest.Matchers.containsString
Expand All @@ -17,7 +19,7 @@ class QualityPluginTest {

@Rule @JvmField val gradle = GradleRunnerRule()

@Test fun `apply report violationReportConsole only on root project`() {
@Test fun `apply violationReportConsole only on root project`() {
`given`@
@Language("gradle")
val script = """
Expand All @@ -44,7 +46,7 @@ class QualityPluginTest {
)
}

@Test fun `apply report violationReportHtml only on root project`() {
@Test fun `apply violationReportHtml only on root project`() {
`given`@
@Language("gradle")
val script = """
Expand All @@ -70,4 +72,53 @@ class QualityPluginTest {
"Configuring task ':violationReportHtml'"
)
}

@Test fun `apply lint only on root project`() {
`given`@
@Language("gradle")
val script = """
allprojects {
apply plugin: 'net.twisterrob.quality'
tasks.withType(${GlobalLintGlobalFinalizerTask::class.qualifiedName}) {
println("Added " + it)
}
}
""".trimIndent()

val result: BuildResult
`when`@
result = gradle
.basedOn("android-all_kinds")
.run(script, "lint")
.build()

`then`@
assertEquals(SUCCESS, result.task(":lint")!!.outcome)
result.assertHasOutputLine("one task added for finalizer", "Added task ':lint'")
result.assertNoOutputLine("no other tasks added as finalizer", """Added task ':(.+?):lint'""".toRegex())
}

@Test fun `apply lint only when Android does not add lint task`() {
`given`@
@Language("gradle")
val script = """
allprojects {
apply plugin: 'net.twisterrob.quality'
tasks.withType(${GlobalLintGlobalFinalizerTask::class.qualifiedName}) {
println("Added " + it)
}
}
""".trimIndent()

val result: BuildResult
`when`@
result = gradle
.basedOn("android-root_app")
.run(script, "lint")
.build()

`then`@
assertEquals(SUCCESS, result.task(":lint")!!.outcome)
result.assertNoOutputLine("no tasks added as finalizer", """Added task '(.*?):lint'""".toRegex())
}
}
9 changes: 4 additions & 5 deletions test/src/test/resources/android-all_kinds/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ buildscript {

allprojects {
repositories {
google() // for aapt2 internal binary
jcenter() // quality plugin needs to be downloaded in test
}
plugins.all {
if (it instanceof com.android.build.gradle.BasePlugin) {
// BEWARE: InstantAppExtension overrides compileSdkVersion and hard-codes it (3.0.1 to 26, 3.2.x to 27)
android.compileSdkVersion 27
}
plugins.withType(com.android.build.gradle.BasePlugin) {
// BEWARE: InstantAppExtension overrides compileSdkVersion and hard-codes it (3.0.1 to 26, 3.2.x to 27)
android.compileSdkVersion 27
}
}