Skip to content

Commit 256d910

Browse files
committed
Merge pull request #18 from RichardBradley/issue-17-windows-issues
Issue #17 - windows issues
2 parents 597555a + b060ef5 commit 256d910

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name := "scalac-scoverage-plugin"
22

33
organization := "com.sksamuel.scoverage"
44

5-
version := "0.95.8"
5+
version := "0.95.9"
66

77
scalaVersion := "2.10.3"
88

src/main/scala/scoverage/report/CodeGrid.scala

100644100755
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@ import scala.xml.{Unparsed, Node}
99
class CodeGrid(mfile: MeasuredFile) {
1010
case class Cell(char: Char, var status: StatementStatus)
1111

12-
val sep = System.getProperty("line.separator").charAt(0)
12+
/**
13+
* Regardless of whether the source is Unix (\n) or DOS (\r\n), the lines will end
14+
* with \n. We split on \n and allow an optional trailing \r on the line.
15+
* This lets us split on lines while keep the source positions matching up.
16+
*/
17+
val lineBreak = '\n'
1318

1419
// note: we must reinclude the line sep to keep source positions correct.
15-
val lines = source(mfile).split(sep).map(line => (line.toCharArray :+ '\n').map(Cell(_, NoData)))
20+
val lines = source(mfile).split(lineBreak).map(line => (line.toCharArray :+ lineBreak).map(Cell(_, NoData)))
1621
val cells = lines.flatten
1722

1823
mfile.statements.foreach(highlight)

src/main/scala/scoverage/report/ScoverageHtmlWriter.scala

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -197,18 +197,22 @@ class ScoverageHtmlWriter(sourceDirectory: File, outputDir: File) {
197197

198198
def _class(klass: MeasuredClass, addPath: Boolean): Node = {
199199

200-
val filename = {
201-
val Match = "(.*/)?([^/]+.scala.html)$".r
202-
klass.source.replace(sourceDirectory.getAbsolutePath + "/", "") + ".html" match {
203-
case Match(path, value) => {
204-
if (addPath && path.eq(null)) {
205-
"<empty>/" + value
206-
} else if (addPath && path.ne("")) {
207-
path + value
208-
} else {
209-
value
210-
}
211-
}
200+
val filename: String = {
201+
202+
val fileRelativeToSource = new File(
203+
klass.source.replace(
204+
sourceDirectory.getAbsolutePath + File.separator,
205+
"") + ".html")
206+
val path = fileRelativeToSource.getParent
207+
val value = fileRelativeToSource.getName
208+
209+
if (addPath && path.eq(null)) {
210+
"<empty>/" + value
211+
} else if (addPath && path.ne("")) {
212+
// (Normalise the pathSeparator to "/" in case we are running on Windows)
213+
fileRelativeToSource.toString.replace(File.separator, "/")
214+
} else {
215+
value
212216
}
213217
}
214218

@@ -223,7 +227,7 @@ class ScoverageHtmlWriter(sourceDirectory: File, outputDir: File) {
223227
</a>
224228
</td>
225229
<td>
226-
{klass.statements.headOption.map(_.source.split('/').last).getOrElse("")}
230+
{klass.statements.headOption.map(_.source.split(File.separatorChar).last).getOrElse("")}
227231
</td>
228232
<td>
229233
{klass.loc.toString}

0 commit comments

Comments
 (0)