From b82dc626a20be21b3a6cd5d02f705b3f10860c50 Mon Sep 17 00:00:00 2001 From: David Marinho Date: Mon, 26 Aug 2024 16:18:23 +0100 Subject: [PATCH] add method to normalize paths from different envs --- .../com/codacy/transformation/FileNameMatcher.scala | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/scala/com/codacy/transformation/FileNameMatcher.scala b/src/main/scala/com/codacy/transformation/FileNameMatcher.scala index 970b694a..b07b39f1 100644 --- a/src/main/scala/com/codacy/transformation/FileNameMatcher.scala +++ b/src/main/scala/com/codacy/transformation/FileNameMatcher.scala @@ -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))