Skip to content

Commit 8c17a04

Browse files
committed
Use global scope for jacoco settings
This makes it easier for users to configure as they don't need to scope using 'jacocoXX in Test'
1 parent c66bb08 commit 8c17a04

File tree

8 files changed

+68
-5
lines changed

8 files changed

+68
-5
lines changed

src/main/scala/com/github/sbt/jacoco/BaseJacocoPlugin.scala

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ private[jacoco] abstract class BaseJacocoPlugin extends AutoPlugin with JacocoKe
2727
protected def srcConfig: Configuration
2828

2929
override def projectSettings: Seq[Setting[_]] =
30-
dependencyValues ++ inConfig(srcConfig)(settingValues ++ taskValues)
30+
dependencyValues ++
31+
unscopedSettingValues ++
32+
inConfig(srcConfig)(scopedSettingValues ++ taskValues)
3133

3234
protected def dependencyValues: Seq[Setting[_]] = Seq(
3335
libraryDependencies ++= {
@@ -40,7 +42,7 @@ private[jacoco] abstract class BaseJacocoPlugin extends AutoPlugin with JacocoKe
4042
}
4143
)
4244

43-
private def settingValues = Seq(
45+
private def unscopedSettingValues = Seq(
4446
jacocoDirectory := crossTarget.value / "jacoco",
4547
jacocoReportDirectory := jacocoDirectory.value / "report",
4648
jacocoSourceSettings := JacocoSourceSettings(),
@@ -49,7 +51,10 @@ private[jacoco] abstract class BaseJacocoPlugin extends AutoPlugin with JacocoKe
4951
jacocoIncludes := Seq("*"),
5052
jacocoExcludes := Seq(),
5153
jacocoInstrumentedDirectory := jacocoDirectory.value / "instrumented-classes",
52-
jacocoDataFile := jacocoDataDirectory.value / "jacoco.exec",
54+
jacocoDataFile := jacocoDataDirectory.value / "jacoco.exec"
55+
)
56+
57+
private def scopedSettingValues = Seq(
5358
javaOptions ++= {
5459
val dest = jacocoDataFile.value
5560

src/main/scala/com/github/sbt/jacoco/JacocoItPlugin.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ object JacocoItPlugin extends BaseJacocoPlugin {
6868
Defaults.itSettings ++
6969
super.projectSettings ++
7070
// move the test reports to a subdirectory to disambiguate
71-
Seq(jacocoReportDirectory in Test := (jacocoDirectory in Test).value / "report" / "test") ++
71+
Seq(jacocoReportDirectory := (jacocoDirectory in Test).value / "report" / "test") ++
7272
inConfig(IntegrationTest) {
7373
Seq(
7474
jacocoReportDirectory := jacocoDirectory.value / "report" / "it",
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name := "jacocoTest"
2+
organization := "com.navetas"
3+
4+
scalaVersion := "2.10.4"
5+
scalacOptions ++= Seq("-deprecation", "-optimize", "-unchecked", "-Xlint", "-language:_")
6+
7+
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.4" % "test"
8+
9+
jacocoReportSettings in Test := JacocoReportSettings()
10+
.withThresholds(
11+
JacocoThresholds(
12+
instruction = 100,
13+
method = 100,
14+
branch = 100,
15+
complexity = 100,
16+
line = 100,
17+
clazz = 100)
18+
)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
val pluginVersion = System.getProperty("plugin.version")
3+
if (pluginVersion == null)
4+
throw new RuntimeException("""|The system property 'plugin.version' is not defined.
5+
|Specify this property using the parameter -Dplugin.version=<version>""".stripMargin)
6+
7+
else addSbtPlugin("com.github.sbt" % "sbt-jacoco" % pluginVersion)
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package jacocotest
2+
3+
case class TestClass( val x : Int )
4+
{
5+
def double() : Int = x * 2
6+
7+
def triple() : Int = x * 3
8+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package jacocotest
2+
3+
import org.scalatest.FlatSpec
4+
5+
class TestClassTests extends FlatSpec
6+
{
7+
"TestClass" should "double a number correctly" in
8+
{
9+
assert( new TestClass( 2 ).double === 4 )
10+
}
11+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
> clean
2+
3+
# coverage should fail
4+
-> jacoco
5+
6+
# instrumented classes
7+
$ exists target/scala-2.10/jacoco/instrumented-classes
8+
9+
# results
10+
$ exists target/scala-2.10/jacoco/data/jacoco.exec
11+
12+
# html report
13+
$ exists target/scala-2.10/jacoco/report/html/index.html

src/sbt-test/sbt-jacoco/simple/build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ scalacOptions ++= Seq("-deprecation", "-optimize", "-unchecked", "-Xlint", "-lan
66

77
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.4" % "test"
88

9-
jacocoReportSettings in Test := JacocoReportSettings()
9+
jacocoReportSettings := JacocoReportSettings()
1010
.withThresholds(
1111
JacocoThresholds(
1212
instruction = 100,

0 commit comments

Comments
 (0)