Skip to content

Commit 19dc512

Browse files
committed
Merge pull request #9 from margussipria/html-report-fix
Fixed scoverage html writer class links
2 parents dcc3eba + dbf3ec2 commit 19dc512

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

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

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ class ScoverageHtmlWriter(sourceDirectory: File, outputDir: File) {
3838
}
3939

4040
def _file(mfile: MeasuredFile): Node = {
41+
42+
val filename = {
43+
mfile.source.replace(sourceDirectory.getAbsolutePath + "/", "") + ".html"
44+
}
45+
4146
val css =
4247
"table.codegrid { font-family: monospace; font-size: 12px; width: auto!important; }" +
4348
"table.statementlist { width: auto!important; font-size: 13px; } " +
@@ -47,7 +52,7 @@ class ScoverageHtmlWriter(sourceDirectory: File, outputDir: File) {
4752
<head>
4853
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
4954
<title id='title'>
50-
{mfile.source}
55+
{filename}
5156
</title>
5257
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css"/>
5358
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
@@ -139,12 +144,12 @@ class ScoverageHtmlWriter(sourceDirectory: File, outputDir: File) {
139144
def packageClasses(pack: MeasuredPackage): Node = {
140145
<html>
141146
{head}<body style="font-family: monospace;">
142-
{classes(pack.classes)}
147+
{classes(pack.classes, false)}
143148
</body>
144149
</html>
145150
}
146151

147-
def classes(classes: Iterable[MeasuredClass]): Node = {
152+
def classes(classes: Iterable[MeasuredClass], addPath: Boolean): Node = {
148153
<table class="table table-striped" style="font-size:13px">
149154
<thead>
150155
<tr>
@@ -185,15 +190,26 @@ class ScoverageHtmlWriter(sourceDirectory: File, outputDir: File) {
185190
</tr>
186191
</thead>
187192
<tbody>
188-
{classes.toSeq.sortBy(_.simpleName) map _class}
193+
{classes.toSeq.sortBy(_.simpleName) map (_class(_, addPath))}
189194
</tbody>
190195
</table>
191196
}
192197

193-
def _class(klass: MeasuredClass): Node = {
198+
def _class(klass: MeasuredClass, addPath: Boolean): Node = {
194199

195200
val filename = {
196-
outputDir + klass.source.replace(sourceDirectory.getAbsolutePath, "") + ".html"
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+
}
212+
}
197213
}
198214

199215
val statement0f = Math.round(klass.statementCoveragePercent).toInt.toString
@@ -387,7 +403,7 @@ class ScoverageHtmlWriter(sourceDirectory: File, outputDir: File) {
387403
{stats(coverage)}
388404
</div>
389405
<div>
390-
{classes(coverage.classes)}
406+
{classes(coverage.classes, true)}
391407
</div>
392408
</div>
393409
</body>

0 commit comments

Comments
 (0)