diff --git a/build.sbt b/build.sbt index 5f59c7e7..7328d304 100644 --- a/build.sbt +++ b/build.sbt @@ -2,7 +2,7 @@ name := "scalac-scoverage-plugin" organization := "com.sksamuel.scoverage" -version := "0.95.8" +version := "0.95.9" scalaVersion := "2.10.3" diff --git a/src/main/scala/scoverage/report/CodeGrid.scala b/src/main/scala/scoverage/report/CodeGrid.scala old mode 100644 new mode 100755 index 8c7cb019..cc856707 --- a/src/main/scala/scoverage/report/CodeGrid.scala +++ b/src/main/scala/scoverage/report/CodeGrid.scala @@ -9,10 +9,15 @@ import scala.xml.{Unparsed, Node} class CodeGrid(mfile: MeasuredFile) { case class Cell(char: Char, var status: StatementStatus) - val sep = System.getProperty("line.separator").charAt(0) + /** + * Regardless of whether the source is Unix (\n) or DOS (\r\n), the lines will end + * with \n. We split on \n and allow an optional trailing \r on the line. + * This lets us split on lines while keep the source positions matching up. + */ + val lineBreak = '\n' // note: we must reinclude the line sep to keep source positions correct. - val lines = source(mfile).split(sep).map(line => (line.toCharArray :+ '\n').map(Cell(_, NoData))) + val lines = source(mfile).split(lineBreak).map(line => (line.toCharArray :+ lineBreak).map(Cell(_, NoData))) val cells = lines.flatten mfile.statements.foreach(highlight) diff --git a/src/main/scala/scoverage/report/ScoverageHtmlWriter.scala b/src/main/scala/scoverage/report/ScoverageHtmlWriter.scala index f12bf2b7..798c6aa2 100644 --- a/src/main/scala/scoverage/report/ScoverageHtmlWriter.scala +++ b/src/main/scala/scoverage/report/ScoverageHtmlWriter.scala @@ -197,18 +197,22 @@ class ScoverageHtmlWriter(sourceDirectory: File, outputDir: File) { def _class(klass: MeasuredClass, addPath: Boolean): Node = { - val filename = { - val Match = "(.*/)?([^/]+.scala.html)$".r - klass.source.replace(sourceDirectory.getAbsolutePath + "/", "") + ".html" match { - case Match(path, value) => { - if (addPath && path.eq(null)) { - "/" + value - } else if (addPath && path.ne("")) { - path + value - } else { - value - } - } + val filename: String = { + + val fileRelativeToSource = new File( + klass.source.replace( + sourceDirectory.getAbsolutePath + File.separator, + "") + ".html") + val path = fileRelativeToSource.getParent + val value = fileRelativeToSource.getName + + if (addPath && path.eq(null)) { + "/" + value + } else if (addPath && path.ne("")) { + // (Normalise the pathSeparator to "/" in case we are running on Windows) + fileRelativeToSource.toString.replace(File.separator, "/") + } else { + value } } @@ -223,7 +227,7 @@ class ScoverageHtmlWriter(sourceDirectory: File, outputDir: File) { - {klass.statements.headOption.map(_.source.split('/').last).getOrElse("")} + {klass.statements.headOption.map(_.source.split(File.separatorChar).last).getOrElse("")} {klass.loc.toString}