Skip to content

Commit bf4b84b

Browse files
committed
Updated HTML writer to not use apache commons IO
1 parent ba4b9f2 commit bf4b84b

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

scalac-scoverage-plugin/src/main/scala/scoverage/IOUtils.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ import scala.io.Source
1010
/** @author Stephen Samuel */
1111
object IOUtils {
1212

13+
def readStreamAsString(in: InputStream): String = Source.fromInputStream(in).mkString
14+
15+
private val UnixSeperator: Char = '/'
16+
private val WindowsSeperator: Char = '\\'
17+
18+
def getName(path: String): Any = {
19+
val index = {
20+
val lastUnixPos = path.lastIndexOf(UnixSeperator)
21+
val lastWindowsPos = path.lastIndexOf(WindowsSeperator)
22+
Math.max(lastUnixPos, lastWindowsPos)
23+
}
24+
path.drop(index + 1)
25+
}
1326

1427
def clean(dataDir: File): Unit = findMeasurementFiles(dataDir).foreach(_.delete)
1528
def clean(dataDir: String): Unit = clean(new File(dataDir))

scalac-scoverage-plugin/src/main/scala/scoverage/report/ScoverageHtmlWriter.scala

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ package scoverage.report
33
import java.io.File
44
import java.util.Date
55

6-
import _root_.scoverage.{Coverage, MeasuredClass, MeasuredFile, MeasuredPackage}
7-
import org.apache.commons.io.{FileUtils, FilenameUtils}
6+
import scoverage._
87

98
import scala.xml.Node
109

@@ -16,24 +15,26 @@ class ScoverageHtmlWriter(sourceDirectory: File, outputDir: File) {
1615
val packageFile = new File(outputDir.getAbsolutePath + "/packages.html")
1716
val overviewFile = new File(outputDir.getAbsolutePath + "/overview.html")
1817

19-
FileUtils.copyInputStreamToFile(getClass.getResourceAsStream("/scoverage/index.html"), indexFile)
20-
FileUtils.write(packageFile, packages(coverage).toString())
21-
FileUtils.write(overviewFile, overview(coverage).toString())
18+
val index = IOUtils.readStreamAsString(getClass.getResourceAsStream("/scoverage/index.html"))
19+
IOUtils.writeToFile(indexFile, index)
20+
IOUtils.writeToFile(packageFile, packages(coverage).toString)
21+
IOUtils.writeToFile(overviewFile, overview(coverage).toString)
2222

2323
coverage.packages.foreach(write)
2424
}
2525

2626
def write(pack: MeasuredPackage) {
27-
val file = new File(outputDir.getAbsolutePath + "/" + pack.name.replace("<empty>", "(empty)").replace('.', '/') + "/package.html")
27+
val file = new
28+
File(outputDir.getAbsolutePath, pack.name.replace("<empty>", "(empty)").replace('.', '/') + "/package.html")
2829
file.getParentFile.mkdirs()
29-
FileUtils.write(file, packageClasses(pack).toString())
30+
IOUtils.writeToFile(file, packageOverview(pack).toString)
3031
pack.files.foreach(write(_, file.getParentFile))
3132
}
3233

3334
def write(mfile: MeasuredFile, dir: File) {
34-
val file = new File(dir.getAbsolutePath + "/" + FilenameUtils.getName(mfile.source) + ".html")
35+
val file = new File(dir.getAbsolutePath, IOUtils.getName(mfile.source) + ".html")
3536
file.getParentFile.mkdirs()
36-
FileUtils.write(file, _file(mfile).toString())
37+
IOUtils.writeToFile(file, _file(mfile).toString)
3738
}
3839

3940
def _file(mfile: MeasuredFile): Node = {
@@ -149,7 +150,7 @@ class ScoverageHtmlWriter(sourceDirectory: File, outputDir: File) {
149150
</head>
150151
}
151152

152-
def packageClasses(pack: MeasuredPackage): Node = {
153+
def packageOverview(pack: MeasuredPackage): Node = {
153154
<html>
154155
{head}<body style="font-family: monospace;">
155156
{classes(pack.classes, false)}
@@ -207,10 +208,8 @@ class ScoverageHtmlWriter(sourceDirectory: File, outputDir: File) {
207208

208209
val filename: String = {
209210

210-
val fileRelativeToSource = new File(
211-
klass.source.replace(
212-
sourceDirectory.getAbsolutePath + File.separator,
213-
"") + ".html")
211+
val fileRelativeToSource =
212+
new File(klass.source.replace(sourceDirectory.getAbsolutePath + File.separator, "") + ".html")
214213
val path = fileRelativeToSource.getParent
215214
val value = fileRelativeToSource.getName
216215

0 commit comments

Comments
 (0)