-
Notifications
You must be signed in to change notification settings - Fork 0
/
checks.gradle
140 lines (126 loc) · 4.87 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
138
139
140
apply from: "${getPropertyValue('gradle.includes.location', 'https://raw.githubusercontent.com/devatherock/gradle-includes/master')}/non-test-checks.gradle"
if(project.plugins.findPlugin('jacoco')) {
jacoco {
toolVersion = '0.8.8'
}
jacocoTestReport {
if(project.ext.has('jacoco') && project['jacoco'].exclusions) {
afterEvaluate {
classDirectories.from = files(classDirectories.files.collect {
fileTree(dir: it, exclude: project['jacoco'].exclusions)
})
}
}
reports {
xml.required = true
csv.required = false
html.required = true
xml.outputLocation = file("${buildDir}/reports/jacoco/test/jacocoTestReport.xml") // Required for coveralls and sonar
html.outputLocation = file("${buildDir}/reports/jacoco")
}
}
jacocoTestCoverageVerification {
if(project.ext.has('jacoco') && project['jacoco'].exclusions) {
afterEvaluate {
classDirectories.from = files(classDirectories.files.collect {
fileTree(dir: it, exclude: project['jacoco'].exclusions)
})
}
}
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
}
}
}
}
}
}
jacocoTestReport.finalizedBy jacocoTestCoverageVerification
test {
finalizedBy jacocoTestReport
}
}
tasks.withType(Test) {
testLogging {
showStandardStreams = Boolean.getBoolean('test.logs')
events 'passed', 'failed'
}
}
/** SonarQube config **/
if(project.plugins.findPlugin('org.sonarqube')) {
sonarqube {
def prLink = System.env['CIRCLE_PULL_REQUEST']
properties {
property 'sonar.junit.reportPaths', 'build/test-results/test'
property 'sonar.organization', 'devaprasadh-github'
property 'sonar.host.url', 'https://sonarcloud.io'
property 'sonar.issue.ignore.block', 'e1'
property 'sonar.issue.ignore.block.e1.beginBlockRegexp', '@sonar-stop'
property 'sonar.issue.ignore.block.e1.endBlockRegexp', '@sonar-start'
// 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/'
}
}
}
}
/**
* Fetches the value of a gradle property
*
* @param propertyName
* @param propertyValueDefault
* @return the property value
*/
String getPropertyValue(String propertyName, String propertyValueDefault = null) {
return project.hasProperty(propertyName) ? project[propertyName] : propertyValueDefault
}