-
Notifications
You must be signed in to change notification settings - Fork 166
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 maximum gradle version to 8.5 increase maximum ktlint version to 1.1.0 increase maximum kotlin version to 1.9.21 fix lint failures fixes #702 based on work in #703 fix bashisms by manually specifying correct version of libdistro-info-perl
1 parent
a826dcd
commit ca166cc
Showing
24 changed files
with
309 additions
and
68 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
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,18 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.{kt,kts}] | ||
indent_size = 4 | ||
ij_kotlin_packages_to_use_import_on_demand = unset | ||
ij_kotlin_name_count_to_use_star_import = 999 | ||
ij_kotlin_name_count_to_use_star_import_for_members = 999 | ||
ij_kotlin_allow_trailing_comma = false | ||
ij_kotlin_allow_trailing_comma_on_call_site = false | ||
ktlint_code_style=intellij_idea | ||
|
||
[*.{yml,yaml}] | ||
indent_size = 2 |
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
2 changes: 2 additions & 0 deletions
2
plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/GitHook.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
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,9 @@ | ||
package org.assertj.core.api | ||
|
||
import org.gradle.testkit.runner.BuildTask | ||
import org.gradle.testkit.runner.TaskOutcome | ||
|
||
fun ObjectAssert<BuildTask?>.hasOutcome(outcome: TaskOutcome) { | ||
this.objects.assertNotNull(this.info, this.actual) | ||
this.objects.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
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
107 changes: 107 additions & 0 deletions
107
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,107 @@ | ||
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.getMajorJavaVersion | ||
import org.jlleitschuh.gradle.ktlint.testdsl.project | ||
import org.junit.jupiter.api.Assumptions.assumeFalse | ||
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) { | ||
assumeFalse(input.minimumJava != null && getMajorJavaVersion() < input.minimumJava) | ||
assumeFalse(input.maximumJava != null && getMajorJavaVersion() > input.maximumJava) | ||
project( | ||
input.gradleVersion, | ||
projectSetup = androidProjectSetup(input.agpVersion, input.kotlinVersion, input.ktlintVersion) | ||
) { | ||
withCleanSources("src/main/java/CleanSource.kt") | ||
build(CHECK_PARENT_TASK_NAME) { | ||
assertThat(task(":$mainSourceSetCheckTaskName")).hasOutcome(TaskOutcome.SUCCESS) | ||
assertThat(task(":$kotlinScriptCheckTaskName")).hasOutcome(TaskOutcome.SUCCESS) | ||
assertThat(task(":$CHECK_PARENT_TASK_NAME")).hasOutcome(TaskOutcome.SUCCESS) | ||
} | ||
} | ||
} | ||
|
||
@ParameterizedTest | ||
@EnumSource(AndroidTestInput::class) | ||
fun `ktlint pass src kotlin`(input: AndroidTestInput) { | ||
assumeFalse(input.minimumJava != null && getMajorJavaVersion() < input.minimumJava) | ||
assumeFalse(input.maximumJava != null && getMajorJavaVersion() > input.maximumJava) | ||
project( | ||
input.gradleVersion, | ||
projectSetup = androidProjectSetup(input.agpVersion, input.kotlinVersion, input.ktlintVersion) | ||
) { | ||
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(":$kotlinScriptCheckTaskName")).hasOutcome(TaskOutcome.SUCCESS) | ||
assertThat(task(":$CHECK_PARENT_TASK_NAME")).hasOutcome(TaskOutcome.SUCCESS) | ||
} | ||
} else { | ||
build(CHECK_PARENT_TASK_NAME) { | ||
assertThat(task(":$mainSourceSetCheckTaskName")).hasOutcome(TaskOutcome.SUCCESS) | ||
assertThat(task(":$kotlinScriptCheckTaskName")).hasOutcome(TaskOutcome.SUCCESS) | ||
assertThat(task(":$CHECK_PARENT_TASK_NAME")).hasOutcome(TaskOutcome.SUCCESS) | ||
} | ||
} | ||
} | ||
} | ||
|
||
enum class AndroidTestInput( | ||
val gradleVersion: GradleVersion, | ||
val agpVersion: String, | ||
val kotlinVersion: String, | ||
val ktlintVersion: String? = null, | ||
val minimumJava: Int? = null, | ||
val maximumJava: Int? = null | ||
) { | ||
MIN( | ||
GradleVersion.version(TestVersions.minSupportedGradleVersion), | ||
TestVersions.minAgpVersion, | ||
// AGP 4.1 requires kotlin 1.5.20 | ||
"1.5.20", | ||
// old AGP doesn't properly set variant info which ktlint >= 1 requires | ||
"0.47.1", | ||
maximumJava = 17 | ||
), | ||
GRADLE_7_5_AGP_7_4( | ||
// AGP 7.4 requires Gradle 7.5 | ||
GradleVersion.version("7.5"), | ||
"7.4.2", | ||
// AGP 4.1 requires kotlin 1.5.20 | ||
"1.5.20", | ||
// old AGP doesn't properly set variant info which ktlint >= 1 requires | ||
"0.47.1", | ||
minimumJava = 11, | ||
maximumJava = 17 | ||
), | ||
MAX_GRADLE_MIN_AGP( | ||
GradleVersion.version(TestVersions.maxSupportedGradleVersion), | ||
TestVersions.minAgpVersion, | ||
// AGP 4.1 requires kotlin 1.5.20 | ||
"1.5.20" | ||
), | ||
MAX( | ||
GradleVersion.version(TestVersions.maxSupportedGradleVersion), | ||
TestVersions.maxAgpVersion, | ||
TestVersions.maxSupportedKotlinPluginVersion, | ||
minimumJava = 17 | ||
) | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
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,76 @@ | ||
package org.jlleitschuh.gradle.ktlint.testdsl | ||
|
||
import net.swiftzer.semver.SemVer | ||
import java.io.File | ||
|
||
fun androidProjectSetup( | ||
agpVersion: String, | ||
kotlinPluginVersion: String, | ||
ktlintVersion: String? = null | ||
): (File) -> Unit = { | ||
val ktLintOverride = ktlintVersion?.let { "ktlint { version = \"$it\" }\n" } ?: "" | ||
val setNamespace = if ((SemVer.parse(agpVersion) >= SemVer(7))) { | ||
" namespace = \"com.example.myapp\"\n" | ||
} else { | ||
"" | ||
} | ||
//language=Groovy | ||
it.resolve("build.gradle").writeText( | ||
""" | ||
|plugins { | ||
| id("com.android.application") | ||
| id("org.jetbrains.kotlin.android") | ||
| id("org.jlleitschuh.gradle.ktlint") | ||
|} | ||
| | ||
|repositories { | ||
| mavenCentral() | ||
|} | ||
|android { | ||
| compileSdk = 33 | ||
|$setNamespace} | ||
|$ktLintOverride | ||
""".trimMargin() | ||
) | ||
|
||
// before 4.2.0, AGP did not properly publish metadata for id resolution | ||
val oldAgpHack = if ((SemVer.parse(agpVersion) < SemVer(4, 2))) { | ||
""" | ||
| resolutionStrategy { | ||
| eachPlugin { | ||
| when (requested.id.id) { | ||
| "com.android.application" -> useModule("com.android.tools.build:gradle:$agpVersion") | ||
| } | ||
| } | ||
| } | ||
| | ||
""".trimMargin() | ||
} else { | ||
"" | ||
} | ||
val newAgp = if ((SemVer.parse(agpVersion) < SemVer(4, 2))) { | ||
"" | ||
} else { | ||
" id(\"com.android.application\") version \"$agpVersion\"\n " | ||
} | ||
|
||
//language=Groovy | ||
it.resolve("settings.gradle.kts").writeText( | ||
""" | ||
|pluginManagement { | ||
| repositories { | ||
| mavenLocal() | ||
| gradlePluginPortal() | ||
| google() | ||
| mavenCentral() | ||
| } | ||
| | ||
| plugins { | ||
| id("org.jetbrains.kotlin.android") version("$kotlinPluginVersion") | ||
| id("org.jlleitschuh.gradle.ktlint") version("${TestVersions.pluginVersion}") | ||
| $newAgp} | ||
|$oldAgpHack} | ||
| | ||
""".trimMargin() | ||
) | ||
} |
10 changes: 10 additions & 0 deletions
10
plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/testdsl/JavaUtil.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,10 @@ | ||
package org.jlleitschuh.gradle.ktlint.testdsl | ||
|
||
fun getMajorJavaVersion(): Int { | ||
val specVersion = System.getProperty("java.specification.version") | ||
return if (specVersion.startsWith("1.")) { | ||
specVersion.split(".")[1].toInt() | ||
} else { | ||
return specVersion.toInt() | ||
} | ||
} |
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