Skip to content

Commit

Permalink
Merge pull request #11 from vlsi/patternfilterable
Browse files Browse the repository at this point in the history
Expose PatternFilterable for extra include/exclude configurations
  • Loading branch information
eskatos authored Jul 23, 2019
2 parents 6918302 + 18bd660 commit 0ac6c21
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ tasks.rat {
// List of Gradle exclude directives, defaults to ['**/.gradle/**']
excludes.add("**/build/**")

// RatTask 0.5.0+ implements PatternFilterable
exclude { it.file in configurations.someConf.files }

// Rat excludes file, one directive per line
excludeFile.set(layout.projectDirectory.file(".rat-excludes.txt"))

Expand Down
27 changes: 19 additions & 8 deletions src/main/kotlin/org/nosphere/apache/rat/RatTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import org.gradle.api.file.FileTree
import org.gradle.api.reporting.ReportingExtension
import org.gradle.api.tasks.*
import org.gradle.api.tasks.Console
import org.gradle.api.tasks.util.PatternFilterable
import org.gradle.api.tasks.util.PatternSet
import org.gradle.workers.WorkerExecutor
import org.gradle.workers.IsolationMode.PROCESS

Expand All @@ -36,9 +38,16 @@ const val ratVersion = "0.13"


@CacheableTask
open class RatTask @Inject constructor(
open class RatTask private constructor(
private val patternSet: PatternSet,
private val workerExecutor: WorkerExecutor
) : DefaultTask() {
) : DefaultTask(), PatternFilterable by patternSet {

@Inject constructor(
workerExecutor: WorkerExecutor
) : this(PatternSet().apply {
exclude("**/.gradle/**")
}, workerExecutor)

@Console
val verbose = project.objects.property<Boolean>().apply {
Expand All @@ -56,19 +65,21 @@ open class RatTask @Inject constructor(
}

@Internal
val excludes = project.objects.listProperty<String>().apply {
set(listOf("**/.gradle/**"))
}
override fun getIncludes(): MutableSet<String> = patternSet.includes

@Internal
override fun getExcludes(): MutableSet<String> = patternSet.excludes

@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
@Suppress("unused")
val inputFiles: FileTree
get() = inputDir.map {
get() =
project.fileTree(inputDir.get().asFile) {
exclude(this@RatTask.excludes.get())
if (!patternSet.isEmpty) {
include(patternSet.asSpec)
}
}
}.get()

@InputFile
@Optional
Expand Down
7 changes: 5 additions & 2 deletions src/test/kotlin/org/nosphere/apache/rat/RatPluginTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ class RatPluginTest(gradleVersion: String) : AbstractPluginTest(gradleVersion) {
tasks.rat {
verbose.set(true)
excludes = [
'build.gradle', 'settings.gradle', 'build/**', '.gradle/**', '.gradle-test-kit/**', 'guh/**',
'no-license-file.txt'
'build.gradle', 'settings.gradle', 'build/**', '.gradle/**', '.gradle-test-kit/**',
]
exclude(
'guh/**',
'no-license-file.txt'
)
}
""")
withFile("no-license-file.txt", "Nothing here.")
Expand Down

0 comments on commit 0ac6c21

Please sign in to comment.