Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package scoverage.reporter
import java.io.File
import java.util.Date
import scala.xml.Node
import scoverage.domain.CodeGrid
import scoverage.domain.Coverage
import scoverage.domain.MeasuredClass
import scoverage.domain.MeasuredFile
import scoverage.domain.MeasuredPackage
/** @author Stephen Samuel */
class ScoverageHtmlWriter(
sourceDirectories: Seq[File],
outputDir: File,
sourceEncoding: Option[String]
) extends BaseReportWriter(sourceDirectories, outputDir, sourceEncoding) {
// to be used by gradle-scoverage plugin
def this(
sourceDirectories: Array[File],
outputDir: File,
sourceEncoding: Option[String]
) = {
this(sourceDirectories.toSeq, outputDir, sourceEncoding)
}
// for backward compatibility only
def this(sourceDirectories: Seq[File], outputDir: File) = {
this(sourceDirectories, outputDir, None);
}
// for backward compatibility only
def this(sourceDirectory: File, outputDir: File) = {
this(Seq(sourceDirectory), outputDir)
}
def write(coverage: Coverage): Unit = {
val indexFile = new File(outputDir.getAbsolutePath + "/index.html")
val cssFile = new File(outputDir.getAbsolutePath + "/pure-min.css")
val packageFile = new File(outputDir.getAbsolutePath + "/packages.html")
val overviewFile = new File(outputDir.getAbsolutePath + "/overview.html")
val index = {
val in = getClass.getResourceAsStream("/scoverage/index.html")
try IOUtils.readStreamAsString(in)
finally in.close()
}
val css = {
val in = getClass.getResourceAsStream("/scoverage/pure-min.css")
try IOUtils.readStreamAsString(in)
finally in.close()
}
IOUtils.writeToFile(indexFile, index)
IOUtils.writeToFile(cssFile, css)
IOUtils.writeToFile(packageFile, packageList(coverage).toString())
IOUtils.writeToFile(overviewFile, overview(coverage).toString())
coverage.packages.foreach(writePackage)
}
private def writePackage(pkg: MeasuredPackage): Unit = {
// package overview files are written out using a filename that respects the package name
// that means package com.example declared in a class at src/main/scala/mystuff/MyClass.scala will be written
// to com.example.html
val file = new File(outputDir, packageOverviewRelativePath(pkg))
file.getParentFile.mkdirs()
IOUtils.writeToFile(file, packageOverview(pkg).toString())
pkg.files.foreach(writeFile)
}
private def writeFile(mfile: MeasuredFile): Unit = {
// each highlighted file is written out using the same structure as the original file.
val file = new File(outputDir, relativeSource(mfile.source) + ".html")
file.getParentFile.mkdirs()
IOUtils.writeToFile(file, filePage(mfile).toString())
}
private def packageOverviewRelativePath(pkg: MeasuredPackage) =
pkg.name.replace("", "(empty)") + ".html"
private def filePage(mfile: MeasuredFile): Node = {
val filename = relativeSource(mfile.source) + ".html"
val css =
"table.codegrid { font-family: monospace; font-size: 12px; width: auto!important; }" +
"table.statementlist { width: auto!important; font-size: 13px; } " +
"table.codegrid td { padding: 0!important; border: 0!important } " +
"table td.linenumber { width: 40px!important; } "
{filename}
{plugins}
}
def classRow(klass: MeasuredClass): Node = {
val filename: String = {
val fileRelativeToSource = new File(
relativeSource(klass.source) + ".html"
)
val path = fileRelativeToSource.getParent
val value = fileRelativeToSource.getName
if (path.ne("")) {
// (Normalise the pathSeparator to "/" in case we are running on Windows)
fileRelativeToSource.toString.replace(File.separator, "/")
} else {
value
}
}
val statement0f = Math.round(klass.statementCoveragePercent).toInt.toString
val branch0f = Math.round(klass.branchCoveragePercent).toInt.toString