Skip to content

Commit 4109477

Browse files
committed
Merge pull request #1 from SimplyScala/master
fix baseDir bug for multi-module porject & improve OverAllCheckTask
2 parents ac4a9ab + b6c17cc commit 4109477

File tree

6 files changed

+38
-24
lines changed

6 files changed

+38
-24
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
build
2+
.gradle
3+
4+
*.iml
5+
*.ipr
6+
*.iws
7+
*.idea

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,18 @@ This creates an additional task testCoverage which will run tests against instru
3333
- [x] running JUnit tests against instrumented scala code
3434
- [x] failing the build on lack of coverage
3535

36+
Then launch command :
37+
`gradle testScct` or `gradle checkScct`
38+
39+
40+
CheckScct
41+
---------
42+
43+
By default, when you launch `gradle checkScct` build fail if only 75% of project is covered by tests.
44+
45+
To configure it as you want, add this configuration :
46+
```
47+
checkScct {
48+
minimumLineRate = 0.5
49+
}
50+
```

build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ apply plugin: 'idea'
1111
apply plugin: 'maven'
1212
apply plugin: 'signing'
1313
apply plugin: 'groovy'
14-
apply plugin: 'release'
14+
//apply plugin: 'release'
1515

1616
group 'com.github.maiflai'
1717

@@ -36,11 +36,11 @@ artifacts {
3636
archives sourcesJar
3737
}
3838

39-
signing {
39+
/*signing {
4040
sign configurations.archives
41-
}
41+
}*/
4242

43-
uploadArchives {
43+
/*uploadArchives {
4444
repositories {
4545
mavenDeployer {
4646
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
@@ -80,4 +80,4 @@ uploadArchives {
8080
}
8181
}
8282
}
83-
}
83+
}*/

src/main/groovy/com/github/maiflai/OverallCheckTask.groovy

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,20 @@ import org.gradle.api.tasks.TaskAction
88
* Throws a GradleException if overall line coverage dips below the configured percentage.
99
*/
1010
class OverallCheckTask extends DefaultTask {
11-
1211
File cobertura
13-
double minimumLineRate = 1
12+
double minimumLineRate = 0.75
1413

1514
@TaskAction
1615
void requireLineCoverage() {
17-
1816
def reportDirName = project.extensions[ScctPlugin.CONFIGURATION_NAME].reportDirName
19-
if (cobertura == null){
20-
cobertura = project.file("$project.buildDir/reports/$reportDirName/cobertura.xml")
21-
}
17+
18+
if (cobertura == null) cobertura = project.file("$project.buildDir/reports/$reportDirName/cobertura.xml")
2219

2320
def xml = new XmlParser().parse(cobertura)
2421
def overallLineRate = xml.attribute('line-rate').toDouble()
2522
def difference = (minimumLineRate - overallLineRate)
26-
if (difference > 0.001) throw new GradleException("Line coverage of $overallLineRate is below $minimumLineRate by $difference")
27-
}
2823

29-
}
24+
if (difference > 1e-7)
25+
throw new GradleException("Only ${overallLineRate * 100}% of project is covered by tests instead of ${(minimumLineRate * 100).toInteger()}%!")
26+
}
27+
}

src/main/groovy/com/github/maiflai/ScctExtension.groovy

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.github.maiflai
22

33
import org.gradle.api.Action
4-
import org.gradle.api.Plugin
54
import org.gradle.api.Project
6-
import org.gradle.api.Task
75
import org.gradle.api.plugins.JavaPlugin
86
import org.gradle.api.plugins.scala.ScalaPlugin
97
import org.gradle.api.tasks.SourceSet
@@ -64,6 +62,8 @@ class ScctExtension {
6462
}
6563
t.tasks[ScctPlugin.TEST_NAME].configure {
6664
systemProperty 'scct.report.dir', "${t.buildDir}/reports/${t.extensions[ScctPlugin.CONFIGURATION_NAME].reportDirName}"
65+
systemProperty 'scct.basedir', "${t.rootDir.absolutePath}" // for multi-module checking
66+
6767
def existingClasspath = classpath
6868
classpath = t.files(t.sourceSets[ScctPlugin.CONFIGURATION_NAME].output.classesDir) +
6969
project.configurations[ScctPlugin.CONFIGURATION_NAME] +
@@ -73,8 +73,4 @@ class ScctExtension {
7373
}
7474

7575
String reportDirName = 'scct'
76-
77-
78-
}
79-
80-
76+
}

src/main/groovy/com/github/maiflai/ScctPlugin.groovy

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import org.gradle.api.Plugin
44
import org.gradle.api.Project
55

66
class ScctPlugin implements Plugin<Project> {
7-
87
static String CONFIGURATION_NAME = 'scct'
98

109
static String TEST_NAME = 'testScct'
@@ -17,5 +16,4 @@ class ScctPlugin implements Plugin<Project> {
1716
t.extensions.create(CONFIGURATION_NAME, ScctExtension, t)
1817
}
1918
}
20-
21-
}
19+
}

0 commit comments

Comments
 (0)