Skip to content

Commit 0acc293

Browse files
committed
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
1 parent f649e50 commit 0acc293

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=0.13.9
1+
sbt.version=0.13.11

project/plugins.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ resolvers += Classpaths.sbtPluginReleases
22

33
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.3.2")
44

5-
addSbtPlugin("com.typesafe.sbt" % "sbt-pgp" % "0.8.3")
5+
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")
66

77
addSbtPlugin("com.github.gseitz" % "sbt-release" % "0.8.5")

scalac-scoverage-plugin/src/main/scala/scoverage/report/BaseReportWriter.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,22 @@ class BaseReportWriter(sourceDirectories: Seq[File], outputDir: File) {
1010
/**
1111
* Converts absolute path to relative one if any of the source directories is it's parent.
1212
* If there is no parent directory, the path is returned unchanged (absolute).
13-
*
13+
*
1414
* @param src absolute file path in canonical form
1515
*/
1616
def relativeSource(src: String): String = relativeSource(src, formattedSourcePaths)
1717

1818
private def relativeSource(src: String, sourcePaths: Seq[String]): String = {
19+
// We need the canonical path for the given src because our formattedSourcePaths are canonical
20+
val canonicalSrc = new File(src).getCanonicalPath
1921
val sourceRoot: Option[String] = sourcePaths.find(
20-
sourcePath => src.startsWith(sourcePath)
22+
sourcePath => canonicalSrc.startsWith(sourcePath)
2123
)
2224
sourceRoot match {
23-
case Some(path: String) => src.replace(path, "")
25+
case Some(path: String) => canonicalSrc.replace(path, "")
2426
case _ =>
2527
val fmtSourcePaths: String = sourcePaths.mkString("'", "', '", "'")
26-
throw new RuntimeException(s"No source root found for '$src' (source roots: $fmtSourcePaths)");
28+
throw new RuntimeException(s"No source root found for '$canonicalSrc' (source roots: $fmtSourcePaths)");
2729
}
2830
}
2931

0 commit comments

Comments
 (0)