Skip to content

Commit 41e131f

Browse files
committed
Merge pull request #98 from gslowikowski/issue104
Support multiple source roots in report generators
2 parents 44b8256 + dcca003 commit 41e131f

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

build.sbt

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name := "sbt-scoverage"
22

33
organization := "org.scoverage"
44

5-
version := "1.0.4"
5+
version := "1.0.5-SNAPSHOT"
66

77
scalaVersion := "2.10.4"
88

@@ -13,7 +13,7 @@ sbtPlugin := true
1313
resolvers += Resolver.mavenLocal
1414

1515
libraryDependencies ++= Seq(
16-
"org.scoverage" %% "scalac-scoverage-plugin" % "1.0.4"
16+
"org.scoverage" %% "scalac-scoverage-plugin" % "1.0.5-SNAPSHOT"
1717
)
1818

1919
publishTo := Some(Resolver.url("sbt-plugin-releases",

src/main/scala/scoverage/ScoverageSbtPlugin.scala

+16-17
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ScoverageSbtPlugin extends sbt.AutoPlugin {
1111
val OrgScoverage = "org.scoverage"
1212
val ScalacRuntimeArtifact = "scalac-scoverage-runtime"
1313
val ScalacPluginArtifact = "scalac-scoverage-plugin"
14-
val ScoverageVersion = "1.0.4"
14+
val ScoverageVersion = "1.0.5-SNAPSHOT"
1515

1616
object ScoverageKeys {
1717
lazy val coverage = taskKey[Unit]("enable compiled code with instrumentation")
@@ -33,6 +33,8 @@ class ScoverageSbtPlugin extends sbt.AutoPlugin {
3333

3434
import ScoverageKeys._
3535

36+
val aggregateFilter = ScopeFilter( inAggregates(ThisProject), inConfigurations(Compile) ) // must be outside of the 'coverageAggregate' task (see: https://github.com/sbt/sbt/issues/1095 or https://github.com/sbt/sbt/issues/780)
37+
3638
override def trigger = allRequirements
3739
override lazy val projectSettings = Seq(
3840

@@ -49,8 +51,7 @@ class ScoverageSbtPlugin extends sbt.AutoPlugin {
4951

5052
loadCoverage(target, s) match {
5153
case Some(cov) => writeReports(target,
52-
baseDirectory.value,
53-
(scalaSource in Compile).value,
54+
(sourceDirectories in Compile).value,
5455
cov,
5556
coverageOutputCobertua.value,
5657
coverageOutputXML.value,
@@ -68,12 +69,12 @@ class ScoverageSbtPlugin extends sbt.AutoPlugin {
6869
coverageAggregate := {
6970
val s = (streams in Global).value
7071
s.log.info(s"Aggregating coverage from subprojects...")
71-
val base = baseDirectory.value
72-
CoverageAggregator.aggregate(base, coverageCleanSubprojectFiles.value) match {
72+
73+
val xmlReportFiles = crossTarget.all(aggregateFilter).value map (_ / "scoverage-report" / Constants.XMLReportFilename) filter (_.isFile())
74+
CoverageAggregator.aggregate(xmlReportFiles, coverageCleanSubprojectFiles.value) match {
7375
case Some(cov) =>
7476
writeReports(crossTarget.value,
75-
base,
76-
(scalaSource in Compile).value,
77+
sourceDirectories.all(aggregateFilter).value.flatten,
7778
cov,
7879
coverageOutputCobertua.value,
7980
coverageOutputXML.value,
@@ -125,15 +126,14 @@ class ScoverageSbtPlugin extends sbt.AutoPlugin {
125126
)
126127

127128
private def postTestReport = {
128-
(crossTarget, baseDirectory, scalaSource in Compile, coverageMinimum, coverageFailOnMinimum, coverageOutputCobertua, coverageOutputXML, coverageOutputHTML, coverageOutputDebug, streams in Global) map {
129-
(target, baseDirectory, compileSource, min, failOnMin, outputCobertua, outputXML, outputHTML, coverageDebug, streams) =>
129+
(crossTarget, sourceDirectories in Compile, coverageMinimum, coverageFailOnMinimum, coverageOutputCobertua, coverageOutputXML, coverageOutputHTML, coverageOutputDebug, streams in Global) map {
130+
(target, compileSources, min, failOnMin, outputCobertua, outputXML, outputHTML, coverageDebug, streams) =>
130131
Tests.Cleanup {
131132
() => if (enabled) {
132133
loadCoverage(target, streams) foreach {
133134
c =>
134135
writeReports(target,
135-
baseDirectory,
136-
compileSource,
136+
compileSources,
137137
c,
138138
outputCobertua,
139139
outputXML,
@@ -168,8 +168,7 @@ class ScoverageSbtPlugin extends sbt.AutoPlugin {
168168
}
169169

170170
private def writeReports(crossTarget: File,
171-
baseDirectory: File,
172-
compileSourceDirectory: File,
171+
compileSourceDirectories: Seq[File],
173172
coverage: Coverage,
174173
coverageOutputCobertua: Boolean,
175174
coverageOutputXML: Boolean,
@@ -185,20 +184,20 @@ class ScoverageSbtPlugin extends sbt.AutoPlugin {
185184

186185
if (coverageOutputCobertua) {
187186
s.log.info(s"Written Cobertura report [${coberturaDir.getAbsolutePath}/cobertura.xml]")
188-
new CoberturaXmlWriter(baseDirectory, coberturaDir).write(coverage)
187+
new CoberturaXmlWriter(compileSourceDirectories, coberturaDir).write(coverage)
189188
}
190189

191190
if (coverageOutputXML) {
192191
s.log.info(s"Written XML coverage report [${reportDir.getAbsolutePath}/scoverage.xml]")
193-
new ScoverageXmlWriter(compileSourceDirectory, reportDir, false).write(coverage)
192+
new ScoverageXmlWriter(compileSourceDirectories, reportDir, false).write(coverage)
194193
if (coverageDebug) {
195-
new ScoverageXmlWriter(compileSourceDirectory, reportDir, true).write(coverage)
194+
new ScoverageXmlWriter(compileSourceDirectories, reportDir, true).write(coverage)
196195
}
197196
}
198197

199198
if (coverageOutputHTML) {
200199
s.log.info(s"Written HTML coverage report [${reportDir.getAbsolutePath}/index.html]")
201-
new ScoverageHtmlWriter(compileSourceDirectory, reportDir).write(coverage)
200+
new ScoverageHtmlWriter(compileSourceDirectories, reportDir).write(coverage)
202201
}
203202

204203
s.log.info("Coverage reports completed")

0 commit comments

Comments
 (0)