Skip to content

Commit 4231ed8

Browse files
committed
Add File.kt
1 parent 32b7a76 commit 4231ed8

File tree

1 file changed

+24
-0
lines changed
  • affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/util

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.dropbox.affectedmoduledetector.util
2+
3+
import java.io.File
4+
5+
/**
6+
* Converts a [String] representation of a relative [File] path to sections based on the OS
7+
* specific separator character.
8+
*/
9+
fun String.toPathSections(rootProjectDir: File, gitRootDir: File): List<String> {
10+
val realSections = toOsSpecificPath()
11+
.split(File.separatorChar)
12+
.toMutableList()
13+
val projectRelativeDirectorySections = rootProjectDir
14+
.toRelativeString(gitRootDir)
15+
.split(File.separatorChar)
16+
for (directorySection in projectRelativeDirectorySections) {
17+
if (realSections.isNotEmpty() && realSections.first() == directorySection) {
18+
realSections.removeAt(0)
19+
} else {
20+
break
21+
}
22+
}
23+
return realSections.toList()
24+
}

0 commit comments

Comments
 (0)