Skip to content

Commit 8b7738f

Browse files
committed
Use PathMatchers for exclusion patterns
1 parent 5ec8ac2 commit 8b7738f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

shared/src/main/kotlin/org/javacs/kt/SourceExclusions.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ package org.javacs.kt
33
import org.javacs.kt.util.filePath
44
import java.io.File
55
import java.net.URI
6+
import java.nio.file.FileSystems
67
import java.nio.file.Path
78
import java.nio.file.Paths
89

910
// TODO: Read exclusions from gitignore/settings.json/... instead of
1011
// hardcoding them
1112
class SourceExclusions(private val workspaceRoots: Collection<Path>) {
12-
private val excludedFolders = listOf(".git", "bin", "build", "target", "node_modules")
13+
private val excludedPatterns = listOf(".*", "bin", "build", "node_modules", "target").map { FileSystems.getDefault().getPathMatcher("glob:$it") }
1314

1415
constructor(workspaceRoot: Path) : this(listOf(workspaceRoot)) {}
1516

@@ -26,10 +27,10 @@ class SourceExclusions(private val workspaceRoots: Collection<Path>) {
2627

2728
/** Tests whether the given path is not excluded. */
2829
fun isPathIncluded(file: Path): Boolean = workspaceRoots.any { file.startsWith(it) }
29-
&& excludedFolders.none {
30+
&& excludedPatterns.none { pattern ->
3031
workspaceRoots
3132
.mapNotNull { if (file.startsWith(it)) it.relativize(file) else null }
3233
.flatMap { it } // Extract path segments
33-
.any { segment -> segment.toString() == it }
34+
.any(pattern::matches)
3435
}
3536
}

0 commit comments

Comments
 (0)