Skip to content

Commit 2ae36a2

Browse files
authored
Merge pull request #123 from eyalroth/issues/120/coverage-type-config
Fix configuration of coverage type check
2 parents 7940992 + 5233c8e commit 2ae36a2

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

src/functionalTest/resources/projects/scala-single-module/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ test {
2626

2727
scoverage {
2828
minimumRate = 0.3
29+
coverageType = "Line"
2930
}
3031

3132
if (hasProperty("excludedFile")) {

src/main/groovy/org/scoverage/OverallCheckTask.groovy

+19-6
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,21 @@ import java.text.NumberFormat
1515
* Handles different types of coverage Scoverage can measure.
1616
*/
1717
enum CoverageType {
18-
Line('cobertura.xml', 'line-rate', 1.0),
19-
Statement('scoverage.xml', 'statement-rate', 100.0),
20-
Branch('scoverage.xml', 'branch-rate', 100.0)
18+
Line('Line', 'cobertura.xml', 'line-rate', 1.0),
19+
Statement('Statement', 'scoverage.xml', 'statement-rate', 100.0),
20+
Branch('Branch', 'scoverage.xml', 'branch-rate', 100.0)
2121

22+
/** Name of enum option the way it appears in the build configuration */
23+
String configurationName
2224
/** Name of file with coverage data */
2325
String fileName
2426
/** Name of param in XML file with coverage value */
2527
String paramName
2628
/** Used to normalize coverage value */
2729
private double factor
2830

29-
private CoverageType(String fileName, String paramName, double factor) {
31+
private CoverageType(String configurationName, String fileName, String paramName, double factor) {
32+
this.configurationName = configurationName
3033
this.fileName = fileName
3134
this.paramName = paramName
3235
this.factor = factor
@@ -36,6 +39,12 @@ enum CoverageType {
3639
Double normalize(Double value) {
3740
return value / factor
3841
}
42+
43+
static CoverageType find(String configurationName) {
44+
CoverageType.values().find {
45+
it.configurationName.toLowerCase() == configurationName.toLowerCase()
46+
}
47+
}
3948
}
4049

4150
/**
@@ -46,7 +55,7 @@ class OverallCheckTask extends DefaultTask {
4655

4756
/** Type of coverage to check. Available options: Line, Statement and Branch */
4857
@Input
49-
final Property<CoverageType> coverageType = project.objects.property(CoverageType)
58+
final Property<String> coverageType = project.objects.property(String)
5059
@Input
5160
final Property<BigDecimal> minimumRate = project.objects.property(BigDecimal)
5261

@@ -61,7 +70,11 @@ class OverallCheckTask extends DefaultTask {
6170
void requireLineCoverage() {
6271
NumberFormat nf = NumberFormat.getInstance(locale.get())
6372

64-
Exception failure = checkLineCoverage(nf, reportDir.get(), coverageType.get(), minimumRate.get().doubleValue())
73+
CoverageType coverageType = CoverageType.find(this.coverageType.get())
74+
if (coverageType == null) {
75+
throw new GradleException("Unknown coverage type ${this.coverageType.get()}")
76+
}
77+
Exception failure = checkLineCoverage(nf, reportDir.get(), coverageType, minimumRate.get().doubleValue())
6578

6679
if (failure) throw failure
6780
}

src/main/groovy/org/scoverage/ScoverageExtension.groovy

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class ScoverageExtension {
4040

4141
final Property<Boolean> deleteReportsOnAggregation
4242

43-
final Property<CoverageType> coverageType
43+
final Property<String> coverageType
4444
final Property<BigDecimal> minimumRate
4545

4646
ScoverageExtension(Project project) {
@@ -87,8 +87,8 @@ class ScoverageExtension {
8787
deleteReportsOnAggregation = project.objects.property(Boolean)
8888
deleteReportsOnAggregation.set(false)
8989

90-
coverageType = project.objects.property(CoverageType)
91-
coverageType.set(CoverageType.Statement)
90+
coverageType = project.objects.property(String)
91+
coverageType.set(CoverageType.Statement.configurationName)
9292

9393
minimumRate = project.objects.property(BigDecimal)
9494
minimumRate.set(0.75)

0 commit comments

Comments
 (0)