-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from usefulness/filter_sourcesets
- Loading branch information
Showing
11 changed files
with
192 additions
and
19 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
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
12 changes: 6 additions & 6 deletions
12
...radle-plugin/src/main/kotlin/io/github/usefulness/pluginapplier/KotlinSourceSetApplier.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 |
---|---|---|
@@ -1,19 +1,19 @@ | ||
package io.github.usefulness.pluginapplier | ||
|
||
import io.github.usefulness.KtlintGradleExtension | ||
import io.github.usefulness.SourceSetAction | ||
import io.github.usefulness.SourceSetApplier | ||
import io.github.usefulness.id | ||
import org.gradle.api.Project | ||
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension | ||
|
||
internal object KotlinSourceSetApplier : SourceSetApplier { | ||
override fun applyToAll(project: Project, action: SourceSetAction) { | ||
getSourceSets(project).configureEach { sourceSet -> | ||
sourceSet.kotlin.let { directorySet -> | ||
action(directorySet.name.id, project.provider { directorySet }) | ||
|
||
override fun applyToAll(project: Project, extension: KtlintGradleExtension, action: SourceSetAction) { | ||
project.extensions.getByType(KotlinProjectExtension::class.java).sourceSets.configureEach { sourceSet -> | ||
if (!sourceSet.name.startsWith("generatedByKsp") || !extension.ignoreKspGeneratedSources.get()) { | ||
action(sourceSet.kotlin.name.id, project.provider { sourceSet.kotlin }) | ||
} | ||
} | ||
} | ||
|
||
private fun getSourceSets(project: Project) = project.extensions.getByType(KotlinProjectExtension::class.java).sourceSets | ||
} |
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
163 changes: 163 additions & 0 deletions
163
ktlint-gradle-plugin/src/test/kotlin/io/github/usefulness/functional/ThirdPartyPlugins.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,163 @@ | ||
package io.github.usefulness.functional | ||
|
||
import io.github.usefulness.functional.utils.editorConfig | ||
import io.github.usefulness.functional.utils.kotlinClass | ||
import io.github.usefulness.functional.utils.resolve | ||
import io.github.usefulness.functional.utils.settingsFile | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
|
||
class ThirdPartyPlugins : WithGradleTest.Android() { | ||
|
||
@Test | ||
fun kspKotlin() { | ||
testProjectDir.apply { | ||
resolve("settings.gradle") { writeText(settingsFile) } | ||
resolve(".editorconfig") { writeText(editorConfig) } | ||
resolve("build.gradle") { | ||
// language=groovy | ||
writeText( | ||
""" | ||
plugins { | ||
id 'org.jetbrains.kotlin.jvm' | ||
id 'com.google.devtools.ksp' | ||
id 'io.github.usefulness.ktlint-gradle-plugin' | ||
} | ||
repositories.mavenCentral() | ||
dependencies { | ||
ksp "com.google.dagger:dagger-compiler:2.48" | ||
} | ||
""".trimIndent(), | ||
) | ||
} | ||
resolve("src/main/kotlin/KotlinClass.kt") { | ||
writeText(kotlinClass("KotlinClass")) | ||
} | ||
} | ||
|
||
val result = build("lintKotlin") | ||
|
||
assertThat(result.tasks.map { it.path }).containsExactlyInAnyOrder( | ||
":lintKotlinTest", | ||
":lintKotlinMain", | ||
":lintKotlin", | ||
) | ||
testProjectDir.resolve("build.gradle") { | ||
appendText( | ||
// language=groovy | ||
""" | ||
ktlint { | ||
ignoreKspGeneratedSources = false | ||
} | ||
""".trimIndent(), | ||
) | ||
} | ||
|
||
val onlyMain = build("lintKotlin") | ||
|
||
assertThat(onlyMain.tasks.map { it.path }).containsAll( | ||
listOf( | ||
":compileKotlin", | ||
":compileJava", | ||
":lintKotlinGeneratedByKspTestKotlin", | ||
":lintKotlinTest", | ||
":lintKotlinMain", | ||
":lintKotlin", | ||
), | ||
) | ||
} | ||
|
||
@Test | ||
fun kspAndroid() { | ||
testProjectDir.apply { | ||
resolve("settings.gradle") { writeText(settingsFile) } | ||
resolve(".editorconfig") { writeText(editorConfig) } | ||
resolve("build.gradle") { | ||
// language=groovy | ||
writeText( | ||
""" | ||
plugins { | ||
id 'com.android.library' | ||
id 'org.jetbrains.kotlin.android' | ||
id 'com.google.devtools.ksp' | ||
id 'io.github.usefulness.ktlint-gradle-plugin' | ||
} | ||
android { | ||
namespace 'io.github.usefulness' | ||
compileSdk 33 | ||
defaultConfig { | ||
minSdkVersion 23 | ||
} | ||
} | ||
repositories.mavenCentral() | ||
dependencies { | ||
ksp "com.google.dagger:dagger-compiler:2.48" | ||
} | ||
""".trimIndent(), | ||
) | ||
} | ||
resolve("src/main/kotlin/KotlinClass.kt") { | ||
writeText(kotlinClass("KotlinClass")) | ||
} | ||
} | ||
|
||
val result = build("lintKotlin") | ||
|
||
assertThat(result.tasks.map { it.path }).containsExactlyInAnyOrder( | ||
":lintKotlinTestFixturesRelease", | ||
":lintKotlinTestDebug", | ||
":lintKotlinAndroidTest", | ||
":lintKotlinTestFixtures", | ||
":lintKotlinTestFixturesDebug", | ||
":lintKotlinRelease", | ||
":lintKotlinTest", | ||
":lintKotlinTestRelease", | ||
":lintKotlinMain", | ||
":lintKotlinDebug", | ||
":lintKotlinAndroidTestRelease", | ||
":lintKotlinAndroidTestDebug", | ||
":lintKotlin", | ||
) | ||
|
||
testProjectDir.resolve("build.gradle") { | ||
appendText( | ||
// language=groovy | ||
""" | ||
ktlint { | ||
ignoreKspGeneratedSources = false | ||
} | ||
""".trimIndent(), | ||
) | ||
} | ||
|
||
val onlyMain = build("lintKotlin") | ||
|
||
assertThat(onlyMain.tasks.map { it.path }).containsExactlyInAnyOrder( | ||
":lintKotlinTestFixturesRelease", | ||
":lintKotlinTestDebug", | ||
":lintKotlinAndroidTest", | ||
":lintKotlinTestFixtures", | ||
":lintKotlinTestFixturesDebug", | ||
":lintKotlinRelease", | ||
":lintKotlinTest", | ||
":lintKotlinTestRelease", | ||
":lintKotlinMain", | ||
":lintKotlinDebug", | ||
":lintKotlinAndroidTestRelease", | ||
":lintKotlinAndroidTestDebug", | ||
":lintKotlin", | ||
) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -22,6 +22,8 @@ internal val androidManifest = | |
|
||
internal val editorConfig = | ||
""" | ||
root = true | ||
[*.kt] | ||
""".trimIndent() |