Skip to content

Commit 5d31406

Browse files
Merge pull request #511 from codacy/normalize-backslashes
add a method to normalize paths from different environments, especially Windows environments because some reports might be created with backslashes
2 parents 48f0bec + b82dc62 commit 5d31406

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/main/scala/com/codacy/transformation/FileNameMatcher.scala

+7-4
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,23 @@ object FileNameMatcher {
1616
Try(Paths.get(filename).getFileName.toString.toLowerCase).getOrElse(filename.toLowerCase)
1717
}
1818

19+
private def normalizePath(path: String): String = {
20+
path.replace("\\", "/")
21+
}
22+
1923
private def haveSameName(file: String, covFile: String): Boolean =
2024
getFilenameFromPath(file) == getFilenameFromPath(covFile)
2125

2226
private def haveSamePath(file: String, covFile: String): Boolean =
23-
file == covFile
27+
normalizePath(file) == normalizePath(covFile)
2428

2529
private def fileEndsWithReportPath(file: String, covFile: String): Boolean =
26-
file.endsWith(covFile)
30+
normalizePath(file).endsWith(normalizePath(covFile))
2731

2832
private def reportEndsWithFilePath(file: String, covFile: String): Boolean =
29-
covFile.endsWith(file)
33+
normalizePath(covFile).endsWith(normalizePath(file))
3034

3135
private def isTheSameFile(file: String, covFile: String): Boolean = {
32-
3336
haveSameName(file, covFile) && (haveSamePath(file, covFile) ||
3437
fileEndsWithReportPath(file, covFile) ||
3538
reportEndsWithFilePath(file, covFile))

0 commit comments

Comments
 (0)