Skip to content
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

provide possibility to set up data dir #262

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions src/main/scala/scoverage/ScoverageKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ object ScoverageKeys {
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")
lazy val coverageDataDir = settingKey[File]("directory where the measurements will be stored to use")
}
13 changes: 7 additions & 6 deletions src/main/scala/scoverage/ScoverageSbtPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ object ScoverageSbtPlugin extends AutoPlugin {
addCommandAlias("coverageOn", ";set coverageEnabled in ThisBuild := true") ++
addCommandAlias("coverageOff", ";set coverageEnabled in ThisBuild := false")

override def projectSettings: Seq[Setting[_]] = Seq(
override def projectSettings: Seq[Setting[_]] = super.projectSettings ++ Seq(
ivyConfigurations += ScoveragePluginConfig,
coverageReport := coverageReport0.value,
coverageAggregate := coverageAggregate0.value,
aggregate in coverageAggregate := false
aggregate in coverageAggregate := false,
coverageDataDir := crossTarget.value
) ++ coverageSettings ++ scalacSettings

private lazy val coverageSettings = Seq(
Expand Down Expand Up @@ -77,7 +78,7 @@ object ScoverageSbtPlugin extends AutoPlugin {
}
Seq(
Some(s"-Xplugin:${pluginPath.getAbsolutePath}"),
Some(s"-P:scoverage:dataDir:${crossTarget.value.getAbsolutePath}/scoverage-data"),
Some(s"-P:scoverage:dataDir:${coverageDataDir.value.getAbsolutePath}/scoverage-data"),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably remove the /scoverage-data part, as this can be set by the dataDir

Option(coverageExcludedPackages.value.trim).filter(_.nonEmpty).map(v => s"-P:scoverage:excludedPackages:$v"),
Option(coverageExcludedFiles.value.trim).filter(_.nonEmpty).map(v => s"-P:scoverage:excludedFiles:$v"),
// rangepos is broken in some releases of scala so option to turn it off
Expand All @@ -103,7 +104,7 @@ object ScoverageSbtPlugin extends AutoPlugin {
}

private lazy val coverageReport0 = Def.task {
val target = crossTarget.value
val target = coverageDataDir.value
val log = streams.value.log

log.info(s"Waiting for measurement data to sync...")
Expand Down Expand Up @@ -132,12 +133,12 @@ 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
val xmlReportFiles = coverageDataDir.all(aggregateFilter).value map (_ / "scoverage-report" / Constants
.XMLReportFilename) filter (_.isFile())
CoverageAggregator.aggregate(xmlReportFiles, coverageCleanSubprojectFiles.value) match {
case Some(cov) =>
writeReports(
crossTarget.value,
coverageDataDir.value,
sourceDirectories.all(aggregateFilter).value.flatten,
cov,
coverageOutputCobertura.value,
Expand Down
16 changes: 16 additions & 0 deletions src/sbt-test/scoverage/data-dir/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version := "0.1"

scalaVersion := "2.10.4"

libraryDependencies += "org.specs2" %% "specs2" % "2.3.13" % "test"

coverageDataDir := target.value

coverageMinimum := 80

coverageFailOnMinimum := true

resolvers ++= {
if (sys.props.get("plugin.version").map(_.endsWith("-SNAPSHOT")).getOrElse(false)) Seq(Resolver.sonatypeRepo("snapshots"))
else Seq.empty
}
14 changes: 14 additions & 0 deletions src/sbt-test/scoverage/data-dir/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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
object GoodCoverage {

def sum(num1: Int, num2: Int) = {
num1 + num2
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import org.specs2.mutable._

/**
* Created by tbarke001c on 7/8/14.
*/
class GoodCoverageSpec extends Specification {

"GoodCoverage" should {
"sum two numbers" in {
GoodCoverage.sum(1, 2) mustEqual 3
}
}
}
7 changes: 7 additions & 0 deletions src/sbt-test/scoverage/data-dir/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# run scoverage
> clean
> coverage
> test
> coverageReport
$ exists target/scoverage-data
$ exists target/scoverage-report