-
Notifications
You must be signed in to change notification settings - Fork 157
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
Add coverageExclude task #445
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import scoverage.reporter.ScoverageXmlWriter | |
import scoverage.serialize.Serializer | ||
|
||
import java.time.Instant | ||
import scala.tools.nsc | ||
|
||
object ScoverageSbtPlugin extends AutoPlugin { | ||
|
||
|
@@ -66,6 +67,7 @@ object ScoverageSbtPlugin extends AutoPlugin { | |
override def projectSettings: Seq[Setting[_]] = Seq( | ||
ivyConfigurations += ScoveragePluginConfig, | ||
coverageReport := coverageReport0.value, | ||
coverageExclude := coverageExclude0.value, | ||
coverageAggregate := coverageAggregate0.value, | ||
coverageAggregate / aggregate := false, | ||
coverageDataDir := crossTarget.value | ||
|
@@ -192,11 +194,45 @@ object ScoverageSbtPlugin extends AutoPlugin { | |
sjsClassifier getOrElse "" | ||
} | ||
|
||
private lazy val coverageExclude0 = Def.task { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the implementation of the task we add. |
||
implicit val log = streams.value.log | ||
|
||
val dataDir = coverageDataDir.value / "scoverage-data" | ||
val coverageFile = Serializer.coverageFile(dataDir) | ||
|
||
if (!coverageFile.exists) { | ||
log.warn(s"No coverage data found. [$coverageFile] does not exits. Run >sbt coverage test< first.") | ||
} else { | ||
log.info(s"Reading scoverage instrumentation [$coverageFile] ...") | ||
val sourceRoot = coverageSourceRoot.value.getAbsoluteFile() | ||
val coverage = Serializer.deserialize(coverageFile, sourceRoot) | ||
|
||
val filter = new RegexCoverageFilter( | ||
coverageExcludedPackages.value.split(";"), | ||
coverageExcludedFiles.value.split(";"), | ||
ScoverageOptions.default().excludedSymbols, | ||
new nsc.reporters.ConsoleReporter(new nsc.Settings()) | ||
) | ||
|
||
val statements = coverage.statements | ||
log.info(s"Filtering [${statements.size}] statements ...") | ||
val statementsToBeExcluded = statements.filter( | ||
s => !filter.isClassIncluded(s.location.fullClassName) || !filter.isFileIncluded(s.location.sourcePath) || !filter.isSymbolIncluded(s.symbolName) | ||
) | ||
|
||
log.info(s"Statements to be excluded [${statementsToBeExcluded.size}] ...") | ||
statementsToBeExcluded.foreach(s => coverage.remove(s.id)) | ||
|
||
log.info(s"(Re)Writing scoverage instrumentation [$coverageFile] ...") | ||
Serializer.serialize(coverage, coverageFile, sourceRoot) | ||
} | ||
} | ||
|
||
private lazy val coverageReport0 = Def.task { | ||
val target = coverageDataDir.value | ||
implicit val log = streams.value.log | ||
|
||
log.info(s"Waiting for measurement data to sync...") | ||
log.info(s"Waiting for measurement data to sync ...") | ||
Thread.sleep( | ||
1000 | ||
) // have noticed some delay in writing on windows, hacky but works | ||
|
@@ -222,14 +258,17 @@ object ScoverageSbtPlugin extends AutoPlugin { | |
|
||
CoverageMinimum.all.value | ||
.checkCoverage(cov, coverageFailOnMinimum.value) | ||
case None => log.warn("No coverage data, skipping reports") | ||
|
||
case None => | ||
log.warn(s"No coverage data found in [$target]. Run >sbt coverage test< first.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Making the warning more expressive. |
||
} | ||
} | ||
|
||
private lazy val coverageAggregate0 = Def.task { | ||
val target = coverageDataDir.value | ||
implicit val log = streams.value.log | ||
log.info(s"Aggregating coverage from subprojects...") | ||
|
||
log.info(s"Aggregating coverage from subprojects ...") | ||
val dataDirs = coverageDataDir.?.all(aggregateFilter).value | ||
.collect { | ||
case Some(file) if (file / Constants.DataDir).isDirectory => | ||
|
@@ -239,7 +278,7 @@ object ScoverageSbtPlugin extends AutoPlugin { | |
CoverageAggregator.aggregate(dataDirs, coverageSourceRoot.value) match { | ||
case Some(cov) => | ||
writeReports( | ||
coverageDataDir.value, | ||
target, | ||
sourceDirectories.all(aggregateFilter).value.flatten, | ||
cov, | ||
coverageOutputCobertura.value, | ||
|
@@ -255,8 +294,9 @@ object ScoverageSbtPlugin extends AutoPlugin { | |
|
||
CoverageMinimum.all.value | ||
.checkCoverage(cov, coverageFailOnMinimum.value) | ||
|
||
case None => | ||
log.info("No subproject data to aggregate, skipping reports") | ||
log.warn(s"No coverage data found to aggregate in [$target]. Run >sbt coverage test< first.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Turning it into a warning (because the other log messages are warnings) and making it more expressive |
||
} | ||
} | ||
|
||
|
@@ -272,7 +312,7 @@ object ScoverageSbtPlugin extends AutoPlugin { | |
coverageSourceEncoding: Option[String], | ||
log: Logger | ||
): Unit = { | ||
log.info(s"Generating scoverage reports...") | ||
log.info(s"Generating scoverage reports ...") | ||
|
||
val coberturaDir = crossTarget / "coverage-report" | ||
val reportDir = crossTarget / "scoverage-report" | ||
|
@@ -337,8 +377,8 @@ object ScoverageSbtPlugin extends AutoPlugin { | |
log.info("Written coverage report to TeamCity") | ||
} | ||
|
||
log.info(s"Statement coverage.: ${coverage.statementCoverageFormatted}%") | ||
log.info(s"Branch coverage....: ${coverage.branchCoverageFormatted}%") | ||
log.info(s"Statement coverage: ${coverage.statementCoverageFormatted}%") | ||
log.info(s"Branch coverage: ${coverage.branchCoverageFormatted}%") | ||
log.info("Coverage reports completed") | ||
} | ||
|
||
|
@@ -386,10 +426,10 @@ object ScoverageSbtPlugin extends AutoPlugin { | |
sourceRoot: File | ||
): Option[Coverage] = { | ||
|
||
val dataDir = crossTarget / "/scoverage-data" | ||
val dataDir = crossTarget / "scoverage-data" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixing minor broken window. |
||
val coverageFile = Serializer.coverageFile(dataDir) | ||
|
||
log.info(s"Reading scoverage instrumentation [$coverageFile]") | ||
log.info(s"Reading scoverage instrumentation [$coverageFile] ...") | ||
|
||
if (coverageFile.exists) { | ||
|
||
|
@@ -398,7 +438,7 @@ object ScoverageSbtPlugin extends AutoPlugin { | |
sourceRoot | ||
) | ||
|
||
log.info(s"Reading scoverage measurements...") | ||
log.info(s"Reading scoverage measurements ...") | ||
val measurementFiles = IOUtils.findMeasurementFiles(dataDir) | ||
val measurements = IOUtils.invoked(measurementFiles) | ||
coverage.apply(measurements) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the task that we add.