@@ -23,26 +23,27 @@ class ScoverageHtmlWriter(sourceDirectory: File, outputDir: File) {
2323 coverage.packages.foreach(write)
2424 }
2525
26- def write (pack : MeasuredPackage ) {
27- val file = new
28- File (outputDir.getAbsolutePath, pack.name.replace(" <empty>" , " (empty)" ).replace('.' , '/' ) + " /package.html" )
26+ private def relativeSource (src : String ): String = src.replace(sourceDirectory.getAbsolutePath + File .separator, " " )
27+
28+ private def write (pkg : MeasuredPackage ): Unit = {
29+ // package overview files are written out using a directory structure that respects the directory name
30+ // that means package com.example declared in a class at src/main/scala/mystuff/MyClass.scala will be written
31+ // to com/example/package.html
32+ val file = new File (outputDir.getAbsolutePath, pkg.name.replace(" <empty>" , " (empty)" ).replace('.' , '/' ) + " /package.html" )
2933 file.getParentFile.mkdirs()
30- IOUtils .writeToFile(file, packageOverview(pack ).toString)
31- pack .files.foreach(write(_, file.getParentFile))
34+ IOUtils .writeToFile(file, packageOverview(pkg ).toString)
35+ pkg .files.foreach(write(_, file.getParentFile))
3236 }
3337
34- def write (mfile : MeasuredFile , dir : File ) {
35- val file = new File (dir.getAbsolutePath, IOUtils .getName(mfile.source) + " .html" )
38+ private def write (mfile : MeasuredFile , dir : File ): Unit = {
39+ // each highlighted file is written out using the same structure as the original file.
40+ val file = new File (relativeSource(mfile.source))
3641 file.getParentFile.mkdirs()
3742 IOUtils .writeToFile(file, _file(mfile).toString)
3843 }
3944
40- def _file (mfile : MeasuredFile ): Node = {
41-
42- val filename = {
43- mfile.source.replace(sourceDirectory.getAbsolutePath + " /" , " " ) + " .html"
44- }
45-
45+ private def _file (mfile : MeasuredFile ): Node = {
46+ val filename = relativeSource(mfile.source) + " .html"
4647 val css =
4748 " table.codegrid { font-family: monospace; font-size: 12px; width: auto!important; }" +
4849 " table.statementlist { width: auto!important; font-size: 13px; } " +
@@ -153,12 +154,12 @@ class ScoverageHtmlWriter(sourceDirectory: File, outputDir: File) {
153154 def packageOverview (pack : MeasuredPackage ): Node = {
154155 <html >
155156 {head}<body style =" font-family: monospace;" >
156- {classes (pack.classes, false )}
157+ {classesTable (pack.classes, false )}
157158 </body >
158159 </html >
159160 }
160161
161- def classes (classes : Iterable [MeasuredClass ], addPath : Boolean ): Node = {
162+ def classesTable (classes : Iterable [MeasuredClass ], addPath : Boolean ): Node = {
162163 <table class =" tablesorter table table-striped" style =" font-size:13px" >
163164 <thead >
164165 <tr >
@@ -199,23 +200,22 @@ class ScoverageHtmlWriter(sourceDirectory: File, outputDir: File) {
199200 </tr >
200201 </thead >
201202 <tbody >
202- {classes.toSeq.sortBy(_.simpleName) map (_class(_, addPath)) }
203+ {classes.toSeq.sortBy(_.simpleName) map classRow }
203204 </tbody >
204205 </table >
205206 }
206207
207- def _class (klass : MeasuredClass , addPath : Boolean ): Node = {
208+ def classRow (klass : MeasuredClass ): Node = {
208209
209210 val filename : String = {
210211
211- val fileRelativeToSource =
212- new File (klass.source.replace(sourceDirectory.getAbsolutePath + File .separator, " " ) + " .html" )
212+ val fileRelativeToSource = new File (relativeSource(klass.source) + " .html" )
213213 val path = fileRelativeToSource.getParent
214214 val value = fileRelativeToSource.getName
215215
216- if (addPath && path.eq(null )) {
216+ if (path.eq(null )) {
217217 " (empty)/" + value
218- } else if (addPath && path.ne(" " )) {
218+ } else if (path.ne(" " )) {
219219 // (Normalise the pathSeparator to "/" in case we are running on Windows)
220220 fileRelativeToSource.toString.replace(File .separator, " /" )
221221 } else {
@@ -415,7 +415,7 @@ class ScoverageHtmlWriter(sourceDirectory: File, outputDir: File) {
415415 {stats(coverage)}
416416 </div >
417417 <div >
418- {classes (coverage.classes, true )}
418+ {classesTable (coverage.classes, true )}
419419 </div >
420420 </div >
421421 </body >
0 commit comments