From b81e87746f00b7aafaea5dbf667f90c640ab3e0a Mon Sep 17 00:00:00 2001 From: Richard Bradley Date: Tue, 4 Mar 2014 14:32:14 +0000 Subject: [PATCH 1/3] Fix CodeGrid line breaks when running on windows --- src/main/scala/scoverage/report/CodeGrid.scala | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) mode change 100644 => 100755 src/main/scala/scoverage/report/CodeGrid.scala 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) From 41e7f852da71accaf0e3b783236a02d7fa486a00 Mon Sep 17 00:00:00 2001 From: Richard Bradley Date: Tue, 4 Mar 2014 15:22:25 +0000 Subject: [PATCH 2/3] Fix file links in report when generated on Windows --- .../report/ScoverageHtmlWriter.scala | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) 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} From b060ef598d119b96d0269f222a1dbbd5edf546f3 Mon Sep 17 00:00:00 2001 From: Richard Bradley Date: Tue, 4 Mar 2014 15:26:28 +0000 Subject: [PATCH 3/3] Bump version for recent Windows fixes --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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"