Skip to content

Commit

Permalink
added option to display branch coverage in new Scala report, converte…
Browse files Browse the repository at this point in the history
…d Java to Scala, fixed ScalaDoc warning, misc small other cleanup
  • Loading branch information
Joachim Hofer committed Oct 19, 2013
1 parent f914fa3 commit 52d0940
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 79 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ name := "jacoco4sbt"

organization := "de.johoop"

version := "2.1.1"
version := "2.1.2-SNAPSHOT"

resolvers += "Sonatype Release" at "https://oss.sonatype.org/content/repositories/releases"

scalaVersion := "2.10.2"
scalaVersion := "2.10.3"

libraryDependencies ++= Seq(
"org.jacoco" % "org.jacoco.core" % "0.6.3.201306030806" artifacts(Artifact("org.jacoco.core", "jar", "jar")),
Expand Down
4 changes: 4 additions & 0 deletions publish.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,9 @@ pomExtra := (
<id>paddymahoney</id>
<name>Patrick Mahoney</name>
</developer>
<developer>
<id>retronym</id>
<name>Jason Zaugg</name>
</developer>
</developers>
)
9 changes: 8 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ See the **[Wiki](https://bitbucket.org/jmhofer/jacoco4sbt/wiki/)** for details.

## Change Log

* *2.1.2*
* Added a Scala-specific report format (contributed by Jason)

* *2.1.1*

* Updated for sbt 0.13.0 (final)
Expand All @@ -27,7 +30,11 @@ See the **[Wiki](https://bitbucket.org/jmhofer/jacoco4sbt/wiki/)** for details.

## Contributors

Many thanks to [Andreas Flierl](https://bitbucket.org/asflierl), [Joost den Boer](https://bitbucket.org/diversit) and [Patrick Mahoney](https://bitbucket.org/paddymahoney) for their awesome contributions!
Many thanks to
[Andreas Flierl](https://bitbucket.org/asflierl),
[Jason Zaugg](https://bitbucket.org/retronym),
[Joost den Boer](https://bitbucket.org/diversit) and
[Patrick Mahoney](https://bitbucket.org/paddymahoney) for their awesome contributions!

## License

Expand Down
13 changes: 2 additions & 11 deletions src/main/scala/de/johoop/jacoco4sbt/FormattedReport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,13 @@
package de.johoop.jacoco4sbt

import org.jacoco.report.FileMultiReportOutput
import org.jacoco.report.IMultiReportOutput
import org.jacoco.report.IReportVisitor
import org.jacoco.report.xml.XMLFormatter
import org.jacoco.report.html.HTMLFormatter
import org.jacoco.report.csv.CSVFormatter
import java.io.File
import java.io.FileOutputStream

object FormattedReport {
def apply(format: String, encoding: String) = format match {
case "html" => HTMLReport(encoding)
case "xml" => XMLReport(encoding)
case "csv" => CSVReport(encoding)
}
}

sealed abstract class FormattedReport {
val encoding : String
def visitor(directory: File) : IReportVisitor
Expand All @@ -41,9 +32,9 @@ case class HTMLReport(encoding: String = "utf-8") extends FormattedReport {
}
}

case class ScalaHTMLReport(encoding: String = "utf-8") extends FormattedReport {
case class ScalaHTMLReport(encoding: String = "utf-8", withBranchCoverage: Boolean = false) extends FormattedReport {
def visitor(directory: File) = {
val formatter = new ScalaHtmlFormatter
val formatter = new ScalaHtmlFormatter(withBranchCoverage)
formatter setOutputEncoding encoding
formatter createVisitor new FileMultiReportOutput(new File(directory, "html"))
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/scala/de/johoop/jacoco4sbt/Report.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ package de.johoop.jacoco4sbt

import org.jacoco.core.data._
import org.jacoco.core.analysis._
import org.jacoco.report._
import html.HTMLFormatter

import java.io.File
import java.io.FileInputStream
Expand Down Expand Up @@ -54,7 +52,7 @@ class Report(executionDataFile: File, classDirectories: Seq[File],
val coverageBuilder = new CoverageBuilder
val analyzer = new FilteringAnalyzer(executionDataStore, coverageBuilder)

classDirectories foreach { analyzer analyzeAll _ }
classDirectories foreach (analyzer analyzeAll)

coverageBuilder getBundle reportTitle
}
Expand All @@ -64,7 +62,7 @@ class Report(executionDataFile: File, classDirectories: Seq[File],

val visitor = reportFormat.visitor(reportDirectory)

visitor.visitInfo(sessionInfoStore.getInfos, executionDataStore.getContents);
visitor.visitInfo(sessionInfoStore.getInfos, executionDataStore.getContents)
visitor.visitBundle(bundleCoverage, new DirectoriesSourceFileLocator(sourceDirectories, sourceEncoding, tabWidth))

visitor.visitEnd()
Expand Down
60 changes: 0 additions & 60 deletions src/main/scala/de/johoop/jacoco4sbt/ScalaHtmlFormatter.java

This file was deleted.

47 changes: 47 additions & 0 deletions src/main/scala/de/johoop/jacoco4sbt/ScalaHtmlFormatter.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package de.johoop.jacoco4sbt

import org.jacoco.core.analysis.ICoverageNode
import org.jacoco.report.html.HTMLFormatter
import org.jacoco.report.internal.html.resources.Styles
import org.jacoco.report.internal.html.table._
import scala.Some

/**
* Omits displaying instruction and branch coverage in the coverage tables,
* as Scala generates null checks which make these too noisy.
*
* TODO: Find a way to remove them from the annotated source code reports, too.
*/
class ScalaHtmlFormatter(withBranchCoverage: Boolean) extends HTMLFormatter {
private var table: Option[Table] = None

setLanguageNames(new ScalaLanguageNames)

override def getTable: Table = {
table getOrElse {
val newTable = createTable
table = Some(newTable)
newTable
}
}

private def createTable: Table = {
val t: Table = new Table
t.add("Element", null, new LabelColumn, false)
t.add("Missed Lines", Styles.BAR, new BarColumn(ICoverageNode.CounterEntity.LINE, getLocale), true)
t.add("Total Lines", Styles.CTR1, CounterColumn.newTotal(ICoverageNode.CounterEntity.LINE, getLocale), false)
if (withBranchCoverage) {
t.add("Missed Branches", Styles.BAR, new BarColumn(ICoverageNode.CounterEntity.BRANCH, getLocale), false)
t.add("Cov.", Styles.CTR2, new PercentageColumn(ICoverageNode.CounterEntity.BRANCH, getLocale), false)
}
addMissedTotalColumns(t, "Methods", ICoverageNode.CounterEntity.METHOD)
addMissedTotalColumns(t, "Classes", ICoverageNode.CounterEntity.CLASS)

t
}

private def addMissedTotalColumns(table: Table, label: String, entity: ICoverageNode.CounterEntity) {
table.add("Missed", Styles.CTR1, CounterColumn.newMissed(entity, getLocale), false)
table.add(label, Styles.CTR2, CounterColumn.newTotal(entity, getLocale), false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import scala.collection.JavaConverters._
* - classes contains static forwarders to methods in the companion object (for convenient Java interop)
* - methods in (boxed) value classes forward to the method body in the companion object
* - implicit classes creates a factory method beside the class.
* - lazy vals have an accessor that forwards to $lzycompute, which is the method
* - lazy vals have an accessor that forwards to `\$lzycompute`, which is the method
* with the interesting code.
*/
object ScalaForwarderDetector {
Expand Down

0 comments on commit 52d0940

Please sign in to comment.