All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ill-contrib-scoverage-worker_2.13.0.9.5-15-2be01d.source-code.ScoverageReportWorkerImpl.scala Maven / Gradle / Ivy

There is a newer version: 0.12.0-RC2-17-07e173
Show newest version
package mill.contrib.scoverage.worker

import mill.contrib.scoverage.api.ScoverageReportWorkerApi
import _root_.scoverage.Serializer.{coverageFile, deserialize}
import _root_.scoverage.IOUtils.{findMeasurementFiles, invoked}
import _root_.scoverage.report.{CoverageAggregator, ScoverageHtmlWriter, ScoverageXmlWriter}
import mill.api.Ctx
import mill.contrib.scoverage.api.ScoverageReportWorkerApi.ReportType

class ScoverageReportWorkerImpl extends ScoverageReportWorkerApi {

  override def report(reportType: ReportType, sources: Seq[os.Path], dataDirs: Seq[os.Path])(implicit  ctx: Ctx): Unit = try {
    ctx.log.info(s"Processing coverage data for ${dataDirs.size} data locations")
    CoverageAggregator.aggregate(dataDirs.map(_.toIO)) match {
      case Some(coverage) =>
        val sourceFolders = sources.map(_.toIO)
        val folder = ctx.dest
        os.makeDir.all(folder)
        reportType match {
          case ReportType.Html =>
            new ScoverageHtmlWriter(sourceFolders, folder.toIO, None)
              .write(coverage)
          case ReportType.Xml =>
            new ScoverageXmlWriter(sourceFolders, folder.toIO, false)
              .write(coverage)
          case ReportType.Console =>
            ctx.log.info(s"Statement coverage.: ${coverage.statementCoverageFormatted}%")
            ctx.log.info(s"Branch coverage....: ${coverage.branchCoverageFormatted}%")
        }
      case None =>
        ctx.log.error(s"No coverage data found in [${dataDirs.mkString(", ")}]")
    }
  } catch {
    case e =>
      ctx.log.error(s"Exception while building coverage report. ${e.getMessage()}")
      e.printStackTrace()
      throw e
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy