Skip to content

Commit f599ef6

Browse files
committed
Prune file walk tree in findJavaSourceFiles
1 parent 87c311e commit f599ef6

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

server/src/main/kotlin/org/javacs/kt/CompilerClassPath.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,17 @@ class CompilerClassPath(private val config: CompilerConfiguration) : Closeable {
127127
}
128128
}
129129

130-
// TODO: Cut off branches that are excluded in the walker directly
131130
private fun findJavaSourceFiles(root: Path): Set<Path> {
132131
val sourceMatcher = FileSystems.getDefault().getPathMatcher("glob:*.java")
133132
val exclusions = SourceExclusions(root)
134-
return Files.walk(root)
135-
.filter { exclusions.isPathIncluded(it) && sourceMatcher.matches(it.fileName) }
136-
.collect(Collectors.toSet())
133+
return root.toFile().walk()
134+
.onEnter { exclusions.isPathIncluded(it.toPath()) }
135+
.map { it.toPath() }
136+
.filter {
137+
// LOG.info("At $it")
138+
sourceMatcher.matches(it)
139+
}
140+
.toSet()
137141
}
138142

139143
private fun logAdded(sources: Collection<Path>, name: String) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.javacs.kt
22

33
import org.javacs.kt.util.filePath
4+
import java.io.File
45
import java.net.URI
56
import java.nio.file.Path
67
import java.nio.file.Paths

shared/src/main/kotlin/org/javacs/kt/util/Utils.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package org.javacs.kt.util
22

33
import org.javacs.kt.LOG
44
import java.io.PrintStream
5+
import java.nio.file.Files
56
import java.nio.file.Path
67
import java.nio.file.Paths
78
import java.net.URI
89
import java.util.concurrent.CompletableFuture
10+
import java.util.stream.Stream
911

1012
fun execAndReadStdout(shellCommand: String, directory: Path): String {
1113
val process = Runtime.getRuntime().exec(shellCommand, null, directory.toFile())

0 commit comments

Comments
 (0)