-
Notifications
You must be signed in to change notification settings - Fork 5
/
checks.gradle
137 lines (124 loc) · 4.39 KB
/
checks.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
tasks.withType(Test) {
useJUnitPlatform()
testLogging {
showStandardStreams = true
events 'passed', 'skipped', 'failed'
}
}
/** Jacoco report task for custom test tasks **/
task combinedJacocoReport(type: JacocoReport) {
dependsOn tasks.withType(Test)
sourceSets sourceSets.main
executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec")
finalizedBy(jacocoTestCoverageVerification)
reports {
xml.enabled true
csv.enabled false
html.enabled true
xml.destination file("${buildDir}/reports/jacoco/test/jacocoTestReport.xml") // Required for coveralls and sonar
html.destination file("${buildDir}/reports/jacoco")
}
}
ext.jacoco = [
coverageThresholds: [
'io.github.devatherock.json.formatter.JSONFormatter': [
'BRANCH': 0.81,
'COMPLEXITY': 0.74,
'INSTRUCTION': 0.96,
'LINE': 0.94
],
'io.github.devatherock.json.formatter.JSONFormatter.1': [
'BRANCH': 0.49,
'COMPLEXITY': 0.66,
'INSTRUCTION': 0.81
],
'io.github.devatherock.json.formatter.helpers.JacksonJsonConverter': [
'INSTRUCTION': 0.82,
'LINE': 0.59
],
]
]
jacocoTestCoverageVerification {
executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec")
violationRules {
rule {
element = 'CLASS'
// Exclude classes with custom coverage rules
if(project.ext.has('jacoco') && project['jacoco'].coverageThresholds) {
excludes = project['jacoco'].coverageThresholds.keySet() as List
}
limit {
counter = 'BRANCH'
minimum = 1.00
}
limit {
counter = 'COMPLEXITY'
minimum = 1.00
}
limit {
counter = 'INSTRUCTION'
minimum = 1.00
}
limit {
counter = 'LINE'
minimum = 1.00
}
}
// Custom coverage rules
if(project.ext.has('jacoco') && project['jacoco'].coverageThresholds) {
project['jacoco'].coverageThresholds.each { className, thresholds ->
rule {
element = 'CLASS'
includes = [
className
]
limit {
counter = 'BRANCH'
minimum = thresholds['BRANCH'] ?: 1.00
}
limit {
counter = 'COMPLEXITY'
minimum = thresholds['COMPLEXITY'] ?: 1.00
}
limit {
counter = 'INSTRUCTION'
minimum = thresholds['INSTRUCTION'] ?: 1.00
}
limit {
counter = 'LINE'
minimum = thresholds['LINE'] ?: 1.00
}
}
}
}
}
}
/** SonarQube config **/
sonarqube {
def prLink = System.env['CIRCLE_PULL_REQUEST']
properties {
property 'sonar.jacoco.reportPaths', 'build/jacoco/customJsonTest.exec,build/jacoco/gsonTest.exec,build/jacoco/jacksonTest.exec,build/jacoco/jsonSimpleTest.exec'
property 'sonar.junit.reportPaths', 'build/test-results/customJsonTest,build/test-results/gsonTest,build/test-results/jacksonTest,build/test-results/jsonSimpleTest'
// Required for PR analysis
if (prLink) {
property 'sonar.pullrequest.branch', System.env['CIRCLE_BRANCH']
property 'sonar.pullrequest.key', prLink.substring(prLink.lastIndexOf('/') + 1)
property 'sonar.pullrequest.base', 'master'
property 'sonar.pullrequest.provider', 'github'
property 'sonar.pullrequest.github.repository', "devatherock/${System.env['CIRCLE_PROJECT_REPONAME']}"
property 'sonar.pullrequest.github.endpoint', 'https://api.github.com/'
}
}
}
tasks['sonarqube'].with {
dependsOn.clear()
dependsOn jsonSimpleTest
dependsOn gsonTest
dependsOn jacksonTest
dependsOn customJsonTest
}
check.dependsOn jsonSimpleTest
check.dependsOn gsonTest
check.dependsOn jacksonTest
check.dependsOn customJsonTest
check.dependsOn combinedJacocoReport