Skip to content

Commit 9cb8a0d

Browse files
committed
Add OS specific handling to findContainingProject
1 parent f1bf939 commit 9cb8a0d

File tree

1 file changed

+4
-17
lines changed
  • affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector

1 file changed

+4
-17
lines changed

affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/ProjectGraph.kt

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,11 @@ internal class ProjectGraph(project: Project, val gitRoot: File, val logger: Log
5252
* Finds the project that contains the given file.
5353
* The file's path prefix should match the project's path.
5454
*/
55-
fun findContainingProject(filePath: String): Project? {
56-
val sections = filePath.split(File.separatorChar)
57-
val realSections = sections.toMutableList()
58-
val projectRelativeDir = findProjectRelativeDir()
59-
for (dir in projectRelativeDir) {
60-
if (realSections.isNotEmpty() && dir == realSections.first()) {
61-
realSections.removeAt(0)
62-
} else {
63-
break
64-
}
65-
}
66-
67-
logger?.info("finding containing project for $filePath , sections: $realSections")
68-
return rootNode.find(realSections, 0)
69-
}
55+
fun findContainingProject(relativeFilePath: String): Project? {
56+
val pathSections = relativeFilePath.toPathSections(rootProjectDir, gitRoot)
7057

71-
private fun findProjectRelativeDir(): List<String> {
72-
return rootProjectDir.toRelativeString(gitRoot).split(File.separatorChar)
58+
logger?.info("finding containing project for $relativeFilePath , sections: $pathSections")
59+
return rootNode.find(pathSections, 0)
7360
}
7461

7562
private class Node(val logger: Logger? = null) {

0 commit comments

Comments
 (0)