Skip to content

Aggregate raw coverage data instead of scoverage XML reports #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ turn it back off when you're done running reports, use the `coverageOff` command

Sample project with scoverage in both sbt and maven - [the scoverage samples project](https://github.com/scoverage/sbt-scoverage-samples).

## Notes on upgrading to version 1.6.0

* `coverageAggregate` aggregates raw coverage data, not coverage xml reports for modules.
There is no requirement to generate individual coverage reports for modules (`coverageReport`)
before generating aggregated report (`coverageAggregate`).

If only aggregated report is required, not executing `coverageReport` can reduce the build time significantly.

## Notes on upgrading to version 1.3.0

* The object containing the keys has changed from nested to top level so you might need to adjust the import. It's also an auto plugin now, so you might not need the import at all.
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ resolvers ++= {
if (isSnapshot.value) Seq(Resolver.sonatypeRepo("snapshots")) else Nil
}

libraryDependencies += "org.scoverage" %% "scalac-scoverage-plugin" % "1.4.0-M5"
libraryDependencies += "org.scoverage" %% "scalac-scoverage-plugin" % "1.4.0-SNAPSHOT"

publishMavenStyle := true

Expand Down
1 change: 1 addition & 0 deletions src/main/scala/scoverage/ScoverageKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ object ScoverageKeys {
lazy val coverageOutputXML = settingKey[Boolean]("enables xml report generation")
lazy val coverageOutputHTML = settingKey[Boolean]("enables html report generation")
lazy val coverageOutputDebug = settingKey[Boolean]("turn on the debug report")
@deprecated("", "1.6.0")
lazy val coverageCleanSubprojectFiles = settingKey[Boolean]("removes subproject data after an aggregation")
lazy val coverageOutputTeamCity = settingKey[Boolean]("turn on teamcity reporting")
lazy val coverageScalacPluginVersion = settingKey[String]("version of scalac-scoverage-plugin to use")
Expand Down
9 changes: 4 additions & 5 deletions src/main/scala/scoverage/ScoverageSbtPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package scoverage
import sbt.Keys._
import sbt._
import sbt.plugins.JvmPlugin
import scoverage.report.{CoverageAggregator, CoberturaXmlWriter, ScoverageHtmlWriter, ScoverageXmlWriter}
import scoverage.report.{CoberturaXmlWriter, CoverageAggregator, ScoverageHtmlWriter, ScoverageXmlWriter}

object ScoverageSbtPlugin extends AutoPlugin {

val OrgScoverage = "org.scoverage"
val ScalacRuntimeArtifact = "scalac-scoverage-runtime"
val ScalacPluginArtifact = "scalac-scoverage-plugin"
// this should match the version defined in build.sbt
val DefaultScoverageVersion = "1.4.0-M5"
val DefaultScoverageVersion = "1.4.0-SNAPSHOT"
val autoImport = ScoverageKeys
lazy val ScoveragePluginConfig = config("scoveragePlugin").hide

Expand Down Expand Up @@ -132,9 +132,8 @@ object ScoverageSbtPlugin extends AutoPlugin {
val log = streams.value.log
log.info(s"Aggregating coverage from subprojects...")

val xmlReportFiles = crossTarget.all(aggregateFilter).value map (_ / "scoverage-report" / Constants
.XMLReportFilename) filter (_.isFile())
CoverageAggregator.aggregate(xmlReportFiles, coverageCleanSubprojectFiles.value) match {
val dataDirs = crossTarget.all(aggregateFilter).value map (_ / Constants.DataDir) filter (_.isDirectory)
CoverageAggregator.aggregate(dataDirs) match {
case Some(cov) =>
writeReports(
crossTarget.value,
Expand Down
40 changes: 40 additions & 0 deletions src/sbt-test/scoverage/aggregate-only/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
The projects test aggregation of coverage reports from two sub-projects.
The sub-projects are in the directories partA and partB.
*/

lazy val commonSettings = Seq(
organization := "org.scoverage",
version := "0.1.0",
scalaVersion := "2.10.4"
)

lazy val specs2Lib = "org.specs2" %% "specs2" % "2.3.13" % "test"

def module(name: String) = {
val id = s"part$name"
Project(id = id, base = file(id))
.settings(commonSettings: _*)
.settings(
Keys.name := name,
libraryDependencies += specs2Lib
)
}

lazy val partA = module("A")
lazy val partB = module("B")

lazy val root = (project in file("."))
.settings(commonSettings:_*)
.settings(
name := "root",
test := { }
).aggregate(
partA,
partB
)

resolvers in ThisBuild ++= {
if (sys.props.get("plugin.version").map(_.endsWith("-SNAPSHOT")).getOrElse(false)) Seq(Resolver.sonatypeRepo("snapshots"))
else Seq.empty
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.scoverage.issue53.part.a

/**
* Created by Mikhail Kokho on 7/10/2015.
*/
object AdderScala {

def add(x: Int, y: Int) = x + y

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import org.specs2.mutable._
import org.scoverage.issue53.part.a.AdderScala

/**
* Created by Mikhail Kokho on 7/10/2015.
*/
class AdderTestSuite extends Specification {
"Adder" should {
"sum two numbers" in {
AdderScala.add(1, 2) mustEqual 3
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

package org.scoverage.issue53.part.b

/**
* Created by Mikhail Kokho on 7/10/2015.
*/
object SubtractorScala {

def minus(x: Int, y: Int) = x - y

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import org.specs2.mutable._
import org.scoverage.issue53.part.b.SubtractorScala

/**
* Created by Mikhail Kokho on 7/10/2015.
*/
class SubtractorTestSuite extends Specification {
"Subtractor" should {
"subtract two numbers" in {
SubtractorScala.minus(2, 1) mustEqual 1
}
}
}

14 changes: 14 additions & 0 deletions src/sbt-test/scoverage/aggregate-only/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
val pluginVersion = sys.props.getOrElse(
"plugin.version",
throw new RuntimeException(
"""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin))

addSbtPlugin("org.scoverage" % "sbt-scoverage" % pluginVersion)

resolvers ++= {
if (pluginVersion.endsWith("-SNAPSHOT"))
Seq(Resolver.sonatypeRepo("snapshots"))
else
Seq.empty
}
14 changes: 14 additions & 0 deletions src/sbt-test/scoverage/aggregate-only/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# run scoverage using the coverage task
> clean
> coverage
> test
# There should be scoverage-data directories for modules
$ exists partA/target/scala-2.10/scoverage-data
$ exists partB/target/scala-2.10/scoverage-data
# Generate aggregated reports without generating per-module reports first
> coverageAggregate
# There shouldn't be scoverage-report directories for modules
-$ exists partA/target/scala-2.10/scoverage-report
-$ exists partB/target/scala-2.10/scoverage-report
# There should be a root scoverage-report directory
$ exists target/scala-2.10/scoverage-report