@@ -15,18 +15,21 @@ import java.text.NumberFormat
15
15
* Handles different types of coverage Scoverage can measure.
16
16
*/
17
17
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 )
21
21
22
+ /** Name of enum option the way it appears in the build configuration */
23
+ String configurationName
22
24
/** Name of file with coverage data */
23
25
String fileName
24
26
/** Name of param in XML file with coverage value */
25
27
String paramName
26
28
/** Used to normalize coverage value */
27
29
private double factor
28
30
29
- private CoverageType (String fileName , String paramName , double factor ) {
31
+ private CoverageType (String configurationName , String fileName , String paramName , double factor ) {
32
+ this . configurationName = configurationName
30
33
this . fileName = fileName
31
34
this . paramName = paramName
32
35
this . factor = factor
@@ -36,6 +39,12 @@ enum CoverageType {
36
39
Double normalize (Double value ) {
37
40
return value / factor
38
41
}
42
+
43
+ static CoverageType find (String configurationName ) {
44
+ CoverageType . values(). find {
45
+ it. configurationName. toLowerCase() == configurationName. toLowerCase()
46
+ }
47
+ }
39
48
}
40
49
41
50
/**
@@ -46,7 +55,7 @@ class OverallCheckTask extends DefaultTask {
46
55
47
56
/* * Type of coverage to check. Available options: Line, Statement and Branch */
48
57
@Input
49
- final Property<CoverageType > coverageType = project. objects. property(CoverageType )
58
+ final Property<String > coverageType = project. objects. property(String )
50
59
@Input
51
60
final Property<BigDecimal > minimumRate = project. objects. property(BigDecimal )
52
61
@@ -61,7 +70,11 @@ class OverallCheckTask extends DefaultTask {
61
70
void requireLineCoverage () {
62
71
NumberFormat nf = NumberFormat . getInstance(locale. get())
63
72
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())
65
78
66
79
if (failure) throw failure
67
80
}
0 commit comments