From 0acc293b5954902ab4e86ae9ba1540af40876125 Mon Sep 17 00:00:00 2001 From: Lloyd Date: Thu, 14 Apr 2016 14:24:07 +0900 Subject: [PATCH] Resolves canonical path in BaseReportWriter.relativeSource We need the canonical path for the given src because our formattedSourcePaths are canonical. The sources we iniitally store are non-canonical, provided directly through SBT's settings keys, which could contain things like simlinks and '.' or '..' characters. This causes problems when trying to resolves sources because we try to match against canonical formattedSourcePaths. Misc. - Bump SBT version - Bump PGP plugin version --- project/build.properties | 2 +- project/plugins.sbt | 2 +- .../main/scala/scoverage/report/BaseReportWriter.scala | 10 ++++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/project/build.properties b/project/build.properties index 817bc38d..43b8278c 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=0.13.9 +sbt.version=0.13.11 diff --git a/project/plugins.sbt b/project/plugins.sbt index 33096ea7..d807a3f1 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -2,6 +2,6 @@ resolvers += Classpaths.sbtPluginReleases addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.3.2") -addSbtPlugin("com.typesafe.sbt" % "sbt-pgp" % "0.8.3") +addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0") addSbtPlugin("com.github.gseitz" % "sbt-release" % "0.8.5") diff --git a/scalac-scoverage-plugin/src/main/scala/scoverage/report/BaseReportWriter.scala b/scalac-scoverage-plugin/src/main/scala/scoverage/report/BaseReportWriter.scala index e16d133b..8d3b1759 100644 --- a/scalac-scoverage-plugin/src/main/scala/scoverage/report/BaseReportWriter.scala +++ b/scalac-scoverage-plugin/src/main/scala/scoverage/report/BaseReportWriter.scala @@ -10,20 +10,22 @@ class BaseReportWriter(sourceDirectories: Seq[File], outputDir: File) { /** * Converts absolute path to relative one if any of the source directories is it's parent. * If there is no parent directory, the path is returned unchanged (absolute). - * + * * @param src absolute file path in canonical form */ def relativeSource(src: String): String = relativeSource(src, formattedSourcePaths) private def relativeSource(src: String, sourcePaths: Seq[String]): String = { + // We need the canonical path for the given src because our formattedSourcePaths are canonical + val canonicalSrc = new File(src).getCanonicalPath val sourceRoot: Option[String] = sourcePaths.find( - sourcePath => src.startsWith(sourcePath) + sourcePath => canonicalSrc.startsWith(sourcePath) ) sourceRoot match { - case Some(path: String) => src.replace(path, "") + case Some(path: String) => canonicalSrc.replace(path, "") case _ => val fmtSourcePaths: String = sourcePaths.mkString("'", "', '", "'") - throw new RuntimeException(s"No source root found for '$src' (source roots: $fmtSourcePaths)"); + throw new RuntimeException(s"No source root found for '$canonicalSrc' (source roots: $fmtSourcePaths)"); } }