Skip to content

Commit

Permalink
Merge pull request #511 from codacy/normalize-backslashes
Browse files Browse the repository at this point in the history
add a method to normalize paths from different environments, especially Windows environments because some reports might be created with backslashes
  • Loading branch information
DMarinhoCodacy authored Aug 27, 2024
2 parents 48f0bec + b82dc62 commit 5d31406
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/main/scala/com/codacy/transformation/FileNameMatcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,23 @@ object FileNameMatcher {
Try(Paths.get(filename).getFileName.toString.toLowerCase).getOrElse(filename.toLowerCase)
}

private def normalizePath(path: String): String = {
path.replace("\\", "/")
}

private def haveSameName(file: String, covFile: String): Boolean =
getFilenameFromPath(file) == getFilenameFromPath(covFile)

private def haveSamePath(file: String, covFile: String): Boolean =
file == covFile
normalizePath(file) == normalizePath(covFile)

private def fileEndsWithReportPath(file: String, covFile: String): Boolean =
file.endsWith(covFile)
normalizePath(file).endsWith(normalizePath(covFile))

private def reportEndsWithFilePath(file: String, covFile: String): Boolean =
covFile.endsWith(file)
normalizePath(covFile).endsWith(normalizePath(file))

private def isTheSameFile(file: String, covFile: String): Boolean = {

haveSameName(file, covFile) && (haveSamePath(file, covFile) ||
fileEndsWithReportPath(file, covFile) ||
reportEndsWithFilePath(file, covFile))
Expand Down

0 comments on commit 5d31406

Please sign in to comment.