Skip to content

Commit

Permalink
Fix isolated projects compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszkwiecinski authored and lwasyl committed Aug 28, 2024
1 parent 9c01983 commit c4a2482
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public class KtlintGradlePlugin : Plugin<Project> {
val ktlintConfiguration = createKtlintConfiguration(pluginExtension)
val ruleSetConfiguration = createRuleSetConfiguration(ktlintConfiguration)
val reportersConfiguration = createReportersConfiguration(ktlintConfiguration)
val recognisedEditorConfigs = generateSequence(project) { it.parent }
.map { it.layout.projectDirectory.file(".editorconfig").asFile }
val recognisedEditorConfigs = generateSequence(projectDir) { if (it == rootProject.projectDir) null else it.parentFile }
.map { it.resolve(".editorconfig") }
.toList()

tasks.register("validateEditorConfigForKtlint", CheckEditorConfigTask::class.java) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,39 @@ internal class KotlinProjectTest : WithGradleTest.Kotlin() {
}
}

@Test
fun `plugin is compatible with isolated projects`() {
settingsFile().apply {
appendText("include ':foo:bar'")
}
buildFile().also { it.copyTo(testProjectDir.resolve("foo/bar/build.gradle")) }
kotlinSourceFile(
"CustomObject.kt",
"""
object CustomObject
""".trimIndent(),
)

build("lintKotlin", "-Dorg.gradle.unsafe.isolated-projects=true").apply {
assertThat(task(":lintKotlin")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
assertThat(output).contains("Configuration cache entry stored")
}
build("lintKotlin", "-Dorg.gradle.unsafe.isolated-projects=true").apply {
assertThat(task(":lintKotlin")?.outcome).isEqualTo(TaskOutcome.UP_TO_DATE)
assertThat(output).contains("Configuration cache entry reused.")
}

build("formatKotlin", "-Dorg.gradle.unsafe.isolated-projects=true").apply {
assertThat(task(":formatKotlin")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
assertThat(output).contains("Configuration cache entry stored")
}
build("formatKotlin", "-Dorg.gradle.unsafe.isolated-projects=true").apply {
assertThat(task(":formatKotlin")?.outcome).isEqualTo(TaskOutcome.UP_TO_DATE)
assertThat(output).contains("Configuration cache entry reused.")
}
}

@Test
fun `plugin resolves dynamically loaded RuleSetProviders`() {
settingsFile()
Expand Down Expand Up @@ -520,7 +553,7 @@ internal class KotlinProjectTest : WithGradleTest.Kotlin() {
}

private fun settingsFile() = settingsFile.apply {
writeText("rootProject.name = 'ktlint-gradle-test-project'")
writeText("rootProject.name = 'ktlint-gradle-test-project'\n")
}

private fun editorConfig() = editorconfigFile.apply {
Expand Down

0 comments on commit c4a2482

Please sign in to comment.