-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTool.groovy
35 lines (32 loc) · 1.1 KB
/
Tool.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.nio.file.*
import java.nio.file.attribute.BasicFileAttributes
@groovy.transform.ToString
class Tool {
String name
List<String> identityFiles
boolean match(File dir) {
boolean existInProjectRoot = identityFiles.any { new File(dir, it).exists() }
if (existInProjectRoot) {
return true
} else {
return findRecursively(dir)
}
}
boolean findRecursively(File dir) {
boolean findIt = false
Files.walkFileTree(dir.toPath(),
[] as Set,
100,
new SimpleFileVisitor<Path>() {
@Override
FileVisitResult preVisitDirectory(Path path, BasicFileAttributes attrs) throws IOException {
if (identityFiles.any { Files.exists(path.resolve(it), LinkOption.NOFOLLOW_LINKS) }) {
findIt = true
return FileVisitResult.TERMINATE
}
return FileVisitResult.CONTINUE
}
})
return findIt
}
}