Skip to content

Commit

Permalink
Change "setSource", so it also applies the configured filter
Browse files Browse the repository at this point in the history
  • Loading branch information
hlerchl committed Oct 4, 2023
1 parent cf3bcf7 commit 215bc02
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 [#715](https://github.com/JLLeitschuh/ktlint-gradle/pull/715)

## [11.6.0] - 2023-09-18

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -28,7 +29,7 @@ internal fun KtlintPlugin.PluginHolder.addGenerateReportsTaskToProjectMetaFormat
internal fun createFormatTask(
pluginHolder: KtlintPlugin.PluginHolder,
sourceSetName: String,
kotlinSourceDirectories: Iterable<*>
kotlinSourceDirectories: FileCollection
): TaskProvider<KtLintFormatTask> = pluginHolder
.target
.registerTask(
Expand Down Expand Up @@ -56,7 +57,7 @@ internal fun createFormatTask(
internal fun createCheckTask(
pluginHolder: KtlintPlugin.PluginHolder,
sourceSetName: String,
kotlinSourceDirectories: Iterable<*>
kotlinSourceDirectories: FileCollection
): TaskProvider<KtLintCheckTask> = pluginHolder
.target
.registerTask(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 215bc02

Please sign in to comment.