-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix detection of android kotlin source directories in AGP >= 7
increase minimum supported AGP version to 4.2.2 because the plugin coordinates/id changed between 4.1 and 4.2 increase maximum gradle version to 8.5 increase maximum ktlint version to 1.1.0 fixes #702 based on work in #703
- Loading branch information
1 parent
a826dcd
commit 65ccafa
Showing
11 changed files
with
154 additions
and
32 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
11.6.1 | ||
12.0.3 |
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
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
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,10 @@ | ||
package org.assertj.core.api | ||
|
||
import org.assertj.core.internal.Objects | ||
import org.gradle.testkit.runner.BuildTask | ||
import org.gradle.testkit.runner.TaskOutcome | ||
|
||
fun ObjectAssert<BuildTask?>.hasOutcome(outcome: TaskOutcome) { | ||
Objects.instance().assertNotNull(this.info, this.actual) | ||
Objects.instance().assertEqual(this.info, this.actual!!.outcome, outcome) | ||
} |
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
62 changes: 62 additions & 0 deletions
62
plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/android/KtlintPluginAndroidTest.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,62 @@ | ||
package org.jlleitschuh.gradle.ktlint.android | ||
|
||
import net.swiftzer.semver.SemVer | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.assertj.core.api.hasOutcome | ||
import org.gradle.testkit.runner.TaskOutcome | ||
import org.gradle.util.GradleVersion | ||
import org.jlleitschuh.gradle.ktlint.AbstractPluginTest | ||
import org.jlleitschuh.gradle.ktlint.CHECK_PARENT_TASK_NAME | ||
import org.jlleitschuh.gradle.ktlint.testdsl.TestVersions | ||
import org.jlleitschuh.gradle.ktlint.testdsl.androidProjectSetup | ||
import org.jlleitschuh.gradle.ktlint.testdsl.build | ||
import org.jlleitschuh.gradle.ktlint.testdsl.project | ||
import org.junit.jupiter.params.ParameterizedTest | ||
import org.junit.jupiter.params.provider.EnumSource | ||
|
||
class KtlintPluginAndroidTest : AbstractPluginTest() { | ||
|
||
@ParameterizedTest | ||
@EnumSource(AndroidTestInput::class) | ||
fun `ktlint pass src java`(input: AndroidTestInput) { | ||
project( | ||
input.gradleVersion, | ||
projectSetup = androidProjectSetup(input.agpVersion) | ||
) { | ||
withCleanSources("src/main/java/CleanSource.kt") | ||
build(CHECK_PARENT_TASK_NAME) { | ||
assertThat(task(":$mainSourceSetCheckTaskName")).hasOutcome(TaskOutcome.SUCCESS) | ||
assertThat(task(":$CHECK_PARENT_TASK_NAME")).hasOutcome(TaskOutcome.SUCCESS) | ||
} | ||
} | ||
} | ||
|
||
@ParameterizedTest | ||
@EnumSource(AndroidTestInput::class) | ||
fun `ktlint pass src kotlin`(input: AndroidTestInput) { | ||
project( | ||
input.gradleVersion, | ||
projectSetup = androidProjectSetup(input.agpVersion) | ||
) { | ||
withCleanSources("src/main/kotlin/CleanSource.kt") | ||
if (SemVer.parse(input.agpVersion) < SemVer(7)) { | ||
build(CHECK_PARENT_TASK_NAME) { | ||
assertThat(output).contains("In AGP <7 kotlin source directories are not auto-detected.") | ||
assertThat(task(":$mainSourceSetCheckTaskName")).hasOutcome(TaskOutcome.SKIPPED) | ||
assertThat(task(":$CHECK_PARENT_TASK_NAME")).hasOutcome(TaskOutcome.UP_TO_DATE) | ||
} | ||
} else { | ||
build(CHECK_PARENT_TASK_NAME) { | ||
assertThat(task(":$mainSourceSetCheckTaskName")).hasOutcome(TaskOutcome.SUCCESS) | ||
assertThat(task(":$CHECK_PARENT_TASK_NAME")).hasOutcome(TaskOutcome.SUCCESS) | ||
} | ||
} | ||
} | ||
} | ||
|
||
enum class AndroidTestInput(val gradleVersion: GradleVersion, val agpVersion: String) { | ||
MIN(GradleVersion.version(TestVersions.minSupportedGradleVersion), TestVersions.minAgpVersion), | ||
MAX_GRADLE_MIN_AGP(GradleVersion.version(TestVersions.minSupportedGradleVersion), TestVersions.minAgpVersion), | ||
MAX(GradleVersion.version(TestVersions.maxSupportedGradleVersion), TestVersions.maxAgpVersion) | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/testdsl/AndroidSetup.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,48 @@ | ||
package org.jlleitschuh.gradle.ktlint.testdsl | ||
|
||
import java.io.File | ||
|
||
fun androidProjectSetup( | ||
agpVersion: String | ||
): (File) -> Unit = { | ||
val kotlinPluginVersion = TestVersions.maxSupportedKotlinPluginVersion | ||
//language=Groovy | ||
it.resolve("build.gradle").writeText( | ||
""" | ||
|plugins { | ||
| id("org.jetbrains.kotlin.android") | ||
| id("org.jlleitschuh.gradle.ktlint") | ||
| id("com.android.application") | ||
|} | ||
| | ||
|repositories { | ||
| mavenCentral() | ||
|} | ||
|android { | ||
| compileSdk = 33 | ||
|} | ||
| | ||
""".trimMargin() | ||
) | ||
|
||
//language=Groovy | ||
it.resolve("settings.gradle").writeText( | ||
""" | ||
|pluginManagement { | ||
| repositories { | ||
| mavenLocal() | ||
| gradlePluginPortal() | ||
| google() | ||
| mavenCentral() | ||
| } | ||
| | ||
| plugins { | ||
| id 'org.jetbrains.kotlin.android' version '$kotlinPluginVersion' | ||
| id 'org.jlleitschuh.gradle.ktlint' version '${TestVersions.pluginVersion}' | ||
| id("com.android.application") version "$agpVersion" | ||
| } | ||
|} | ||
| | ||
""".trimMargin() | ||
) | ||
} |
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