File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed
codepropertygraph/src/main/scala/io/shiftleft/utils Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change 1
1
package io .shiftleft .utils
2
2
3
- import better . files . File
3
+ import java . nio . file .{ Files , Path , Paths }
4
4
5
5
import scala .annotation .tailrec
6
6
@@ -15,27 +15,31 @@ import scala.annotation.tailrec
15
15
* with this setting any more.
16
16
*/
17
17
object ProjectRoot {
18
+ val FileNameToSearchForEnvVar = " FILE_IN_PROJECT_ROOT"
18
19
19
- private val SEARCH_DEPTH = 4
20
20
object SearchDepthExceededError extends Error
21
+
22
+ private val SEARCH_DEPTH = 4
23
+ private lazy val filenameToSearchFor =
24
+ sys.env
25
+ .get(FileNameToSearchForEnvVar )
26
+ .getOrElse(" .git" )
21
27
22
28
def relativise (path : String ): String =
23
29
s " $findRelativePath$path"
24
30
25
31
def findRelativePath : String = {
26
- val fileThatOnlyExistsInRoot = " .git"
27
-
28
32
@ tailrec def loop (depth : Int ): String = {
29
33
val pathPrefix = " ./" + " ../" * depth
30
- if (File ( s " $pathPrefix$fileThatOnlyExistsInRoot " ).exists ) pathPrefix
34
+ if (Files .exists( Paths .get( s " $pathPrefix$filenameToSearchFor " )) ) pathPrefix
31
35
else if (depth < SEARCH_DEPTH ) loop(depth + 1 )
32
36
else throw SearchDepthExceededError
33
37
}
34
38
35
39
loop(0 )
36
40
}
37
41
38
- def find : File =
39
- File (findRelativePath)
42
+ def find : Path =
43
+ Paths .get (findRelativePath)
40
44
41
45
}
You can’t perform that action at this time.
0 commit comments