From 7e97980071053c45a86fee26021a262c4c4b3421 Mon Sep 17 00:00:00 2001 From: Hannes Lerchl Date: Wed, 27 Sep 2023 09:45:27 +0200 Subject: [PATCH] Change "setSource", so it also applies the configured filter --- CHANGELOG.md | 1 + .../jlleitschuh/gradle/ktlint/TaskCreation.kt | 5 +++-- .../ktlint/tasks/BaseKtLintCheckTask.kt | 21 ++++++++++++++++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83cc48b7..d1711a39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/). - fix "additionalEditorconfig not supported until ktlint 0.49" warning [#712](https://github.com/JLLeitschuh/ktlint-gradle/pull/712) - update latest version text file manually [#709](https://github.com/JLLeitschuh/ktlint-gradle/pull/709) - Improve error logging [#711](https://github.com/JLLeitschuh/ktlint-gradle/pull/711) +- Fixed a case, when -on Windows- an exclude filter is ignored (maybe related to [issue: #579](https://github.com/JLLeitschuh/ktlint-gradle/issues/579) ## [11.6.0] - 2023-09-18 diff --git a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/TaskCreation.kt b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/TaskCreation.kt index 1fc92109..2eb12100 100644 --- a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/TaskCreation.kt +++ b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/TaskCreation.kt @@ -1,6 +1,7 @@ package org.jlleitschuh.gradle.ktlint import org.gradle.api.Project +import org.gradle.api.file.FileCollection import org.gradle.api.file.FileTree import org.gradle.api.tasks.TaskCollection import org.gradle.api.tasks.TaskProvider @@ -28,7 +29,7 @@ internal fun KtlintPlugin.PluginHolder.addGenerateReportsTaskToProjectMetaFormat internal fun createFormatTask( pluginHolder: KtlintPlugin.PluginHolder, sourceSetName: String, - kotlinSourceDirectories: Iterable<*> + kotlinSourceDirectories: FileCollection ): TaskProvider = pluginHolder .target .registerTask( @@ -56,7 +57,7 @@ internal fun createFormatTask( internal fun createCheckTask( pluginHolder: KtlintPlugin.PluginHolder, sourceSetName: String, - kotlinSourceDirectories: Iterable<*> + kotlinSourceDirectories: FileCollection ): TaskProvider = pluginHolder .target .registerTask( diff --git a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/tasks/BaseKtLintCheckTask.kt b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/tasks/BaseKtLintCheckTask.kt index 96f87e10..a10160d6 100644 --- a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/tasks/BaseKtLintCheckTask.kt +++ b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/tasks/BaseKtLintCheckTask.kt @@ -7,6 +7,7 @@ import org.gradle.api.GradleException import org.gradle.api.JavaVersion import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.FileCollection +import org.gradle.api.file.FileTree import org.gradle.api.file.FileTreeElement import org.gradle.api.file.FileType import org.gradle.api.file.ProjectLayout @@ -119,15 +120,29 @@ abstract class BaseKtLintCheckTask @Inject constructor( .from({ sourceFiles.asFileTree.matching(patternFilterable) }) /** - * Sets the source from this task. + * Sets the source for this task from a given file tree. + * + * Filters from configuration will be applied * * @param source given source objects will be evaluated as per [org.gradle.api.Project.file]. */ - fun setSource(source: Any): BaseKtLintCheckTask { - sourceFiles = objectFactory.fileCollection().from(source) + fun setSource(source: FileTree): BaseKtLintCheckTask { + sourceFiles = objectFactory + .fileCollection() + .from({ source.matching(patternFilterable) }) return this } + /** + * Sets the source for this task from a given file collection. + * + * Filters from configuration will be applied + * + * @param source given source objects will be evaluated as per [org.gradle.api.Project.file]. + */ + fun setSource(source: FileCollection): BaseKtLintCheckTask = + setSource(source.asFileTree) + /** * Adds some source to this task. *