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 11package io .shiftleft .utils
22
3- import better . files . File
3+ import java . nio . file .{ Files , Path , Paths }
44
55import scala .annotation .tailrec
66
@@ -15,27 +15,31 @@ import scala.annotation.tailrec
1515 * with this setting any more.
1616 */
1717object ProjectRoot {
18+ val FileNameToSearchForEnvVar = " FILE_IN_PROJECT_ROOT"
1819
19- private val SEARCH_DEPTH = 4
2020 object SearchDepthExceededError extends Error
2121
22+ private val SEARCH_DEPTH = 4
23+ private lazy val filenameToSearchFor =
24+ sys.env
25+ .get(FileNameToSearchForEnvVar )
26+ .getOrElse(" .git" )
27+
2228 def relativise (path : String ): String =
2329 s " $findRelativePath$path"
2430
2531 def findRelativePath : String = {
26- val fileThatOnlyExistsInRoot = " .git"
27-
2832 @ tailrec def loop (depth : Int ): String = {
2933 val pathPrefix = " ./" + " ../" * depth
30- if (File ( s " $pathPrefix$fileThatOnlyExistsInRoot " ).exists ) pathPrefix
34+ if (Files .exists( Paths .get( s " $pathPrefix$filenameToSearchFor " )) ) pathPrefix
3135 else if (depth < SEARCH_DEPTH ) loop(depth + 1 )
3236 else throw SearchDepthExceededError
3337 }
3438
3539 loop(0 )
3640 }
3741
38- def find : File =
39- File (findRelativePath)
42+ def find : Path =
43+ Paths .get (findRelativePath)
4044
4145}
You can’t perform that action at this time.
0 commit comments