-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
206 lines (171 loc) · 5.52 KB
/
build.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
plugins {
id 'groovy'
id 'java'
id 'jacoco'
id 'net.saliman.cobertura' version '4.0.0'
}
group 'emt'
version '1.0-SNAPSHOT'
def agent_archive = "test-agent.jar"
// Coverage settings
def minimum_instruction_coverage = 0.99
def minimum_branch_coverage = 0.98
def coverage_include_classes = "com/emt/**"
sourceCompatibility = source_compatibility
repositories {
mavenCentral()
maven { url 'https://repo.jenkins-ci.org/releases/' }
}
dependencies {
implementation "org.codehaus.groovy:groovy-all:${groovyVersion}"
implementation 'org.eclipse.hudson:hudson-core:3.2.1'
implementation 'org.jenkins-ci.plugins.workflow:workflow-support:2.22@jar'
implementation 'com.cloudbees:groovy-cps:1.32@jar'
testImplementation 'com.lesfurets:jenkins-pipeline-unit:1.14'
testImplementation 'junit:junit:4.13'
testImplementation 'net.sf.json-lib:json-lib:2.4:jdk15'
testImplementation 'org.spockframework:spock-core:1.3-groovy-2.4'
testImplementation 'org.mockito:mockito-core:4.5.0'
testImplementation 'org.mockito:mockito-inline:4.5.0'
testImplementation 'com.google.guava:guava:23.5-jre'
testImplementation 'net.bytebuddy:byte-buddy:1.9.10'
}
sourceSets {
main {
java {
srcDirs = []
}
groovy {
srcDirs = ['src', 'vars']
}
}
test {
java {
srcDirs = []
}
groovy {
srcDirs = ['test/src', 'test/vars']
}
}
}
import org.apache.tools.ant.taskdefs.condition.Os
tasks.register('agentJar', Jar) {
description 'Assembles a jar archive containing the Java agent.'
dependsOn 'compileTestJava', 'compileTestGroovy'
archiveFileName = agent_archive
from(["${buildDir}/classes/java/test/com/emt/util/TestInstrumentationAgent.class"])
manifest {
attributes(
'Premain-Class': 'com.emt.util.TestInstrumentationAgent',
'Can-Redefine-Classes': 'true',
'Can-Retransform-Classes': 'true',
'Can-Set-Native-Method-Prefix': 'true',
'Implementation-Title': "ClassLogger",
'Implementation-Version': rootProject.version
)
}
}
compileGroovy {
String compiler_config_file = 'config/groovyCompilerConfig.groovy'
inputs.file(compiler_config_file)
doFirst {
if (enable_cps) {
println 'Compiling Groovy with CPS'
groovyOptions.configurationScript = file(compiler_config_file)
//horrible no-good hack to add groovy-cps to groovyClasspath
groovyClasspath += sourceSets.main.compileClasspath
}
}
}
test {
dependsOn 'agentJar'
doFirst {
systemProperty 'com.emt.use_cps', enable_cps
systemProperty 'com.emt.unit_testing_enabled', true
}
doFirst {
jvmArgs = ["-javaagent:${buildDir}/libs/${agent_archive}"]
if (project.os == 'linux') {
// Fix for 'com.sun.tools.attach.AttachNotSupportedException at LinuxVirtualMachine.java'
jvmArgs += ['-XX:+StartAttachListener']
}
}
}
cobertura {
coverageIncludes = ['.*com.emt.*']
coverageFormats = ['html', 'xml']
coverageIgnoreMethodAnnotations = ['com.emt.common.CoverageIgnoreGenerated']
}
jacoco {
toolVersion = jacoco_version
}
jacocoTestReport {
dependsOn test // tests are required to run before generating the report
reports {
xml.enabled true
xml.destination file("${buildDir}/reports/jacoco/coverage.xml")
csv.enabled false
html.destination file("${buildDir}/reports/coverage")
}
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, include: [
coverage_include_classes
])
}))
}
finalizedBy jacocoTestCoverageVerification
}
jacocoTestCoverageVerification {
// to run coverage verification during the build (and fail when appropriate)
dependsOn jacocoTestReport
violationRules {
rule {
limit {
counter = 'INSTRUCTION'
value = 'COVEREDRATIO'
minimum = minimum_instruction_coverage
}
limit {
counter = 'BRANCH'
value = 'COVEREDRATIO'
minimum = minimum_branch_coverage
}
// JaCoCo isn't very reliable at reporting line coverage
//limit {
// counter = 'LINE'
// value = 'COVEREDRATIO'
// minimum = 1.0
//}
}
}
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, include: [
coverage_include_classes
])
}))
}
}
// NOTE: Disable groovy optimizations to get more accurate coverage results
// See https://pbetkier.github.io/2014/08/07/groovy-code-coverage-issues.html
gradle.taskGraph.whenReady { graph ->
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
project.ext.os = 'windows'
} else if (Os.isFamily(Os.FAMILY_UNIX) && !Os.isFamily(Os.FAMILY_MAC)) {
project.ext.os = 'linux'
}
if (graph.hasTask(':cobertura') || graph.hasTask(':jacocoTestReport')) {
compileGroovy.groovyOptions.optimizationOptions.all = false
project.ext.enable_cps = false
} else if (graph.hasTask(test)) {
println 'Enabling CPS'
project.ext.enable_cps = true
}
}
if (hasProperty('buildScan')) {
buildScan {
termsOfServiceUrl = 'https://gradle.com/terms-of-service'
termsOfServiceAgree = 'yes'
}
}