Skip to content

Commit

Permalink
Relativize paths for inclusion and exclusion filters
Browse files Browse the repository at this point in the history
(cherry picked from commit 456a602db738400a93e528c4963221f967dd5282)
  • Loading branch information
Robin Brügger authored and fluxroot committed Dec 10, 2024
1 parent 181a82a commit d967692
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/main/kotlin/ch/ergon/todochecker/TodoScanner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ internal class TodoScanner internal constructor(
*/
fun scan(): Map<JiraIssueKey, Set<Path>> =
Files.walk(directory).use { stream ->
stream.filter { path -> Files.isRegularFile(path) }
.filter(::notExcluded)
.filter(isIncluded().or(hasTextContent()))
stream
.filter { path -> Files.isRegularFile(path) }
.filter { path -> notExcluded(path, directory) }
.filter(isIncluded(directory).or(hasTextContent()))
.flatMap { path -> getTodoForFile(path).entries.stream() }
.collect(
Collectors.groupingBy(
Expand All @@ -56,21 +57,23 @@ internal class TodoScanner internal constructor(
)
}

private fun notExcluded(file: Path): Boolean {
private fun notExcluded(file: Path, directory: Path): Boolean {
val relativizedPath = directory.relativize(file)
val excluded = FileSystems.getDefault()
.getPathMatcher(exclusions)
.matches(file)
.matches(relativizedPath)
if (excluded) {
logger.info("Skipping file \"$file\": Excluded")
logger.info("Skipping file \"$relativizedPath\": Excluded")
}
return !excluded
}

private fun isIncluded(): Predicate<Path> =
private fun isIncluded(directory: Path): Predicate<Path> =
Predicate { path ->
val relativizedPath = directory.relativize(path)
FileSystems.getDefault()
.getPathMatcher(inclusions)
.matches(path)
.matches(relativizedPath)
}

private fun hasTextContent(): Predicate<Path> =
Expand Down

0 comments on commit d967692

Please # to comment.