This repository has been archived by the owner on Jun 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.gradle
332 lines (285 loc) · 10 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
plugins {
// lets us use kotlin
id "org.jetbrains.kotlin.jvm" version "$kotlin_version"
// provides unit test coverage
id 'jacoco'
}
// enables us to use Kotlin on the JVM
apply plugin: 'kotlin'
// enables to use "gradlew run" to run the system
apply plugin: 'application'
repositories {
mavenCentral()
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(13))
}
}
// The following text is copy-pasted from Gradle's own repo
// for how to provide Kotlin with the necessary JDK directory.
// Yeah I know it's weird-looking, but it definitely works.
//
// copied from https://github.com/gradle/gradle/blob/master/subprojects/docs/src/snippets/java/toolchain-kotlin/groovy/build.gradle
//
// It allows a user to only have any java installed, and
// gradle will pull down the proper JDK if needed and use that
// for compiling Kotlin
// tag::compiler-kotlin[]
def compiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(13)
}
tasks.withType(org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile).configureEach {
kotlinOptions.jdkHome = compiler.get().metadata.installationPath.asFile.absolutePath
}
// end::compiler-kotlin[]
group 'com.coveros.r3z'
// we'll use a variant of semantic versioning.
//
// The way it goes is, major, minor.
// if the major number changes, there's new functionality
// if the minor changes, it's only bugs fixed, non-functional improvements, or refactorings
version ''
sourceSets {
main.kotlin.srcDirs = main.kotlin.srcDirs = ['src/main/kotlin']
test.kotlin.srcDirs = test.kotlin.srcDirs = ['src/test/kotlin']
main.resources.srcDirs = ['src/main/resources']
test.resources.srcDirs = ['src/test/resources']
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
// junit, for running unit tests
// https://mvnrepository.com/artifact/junit/junit/4.13.2
testImplementation ("junit:junit:4.13.2")
// Selenium - used for testing commonly-used browsers
// https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
testImplementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.141.59'
// https://search.maven.org/artifact/io.github.bonigarcia/webdrivermanager/4.4.1/jar
testImplementation("io.github.bonigarcia:webdrivermanager:4.4.1")
}
// if you want to run this with gradle, just run
// gradlew run
//
// and then you can hit http://localhost:12345 to see
// the application
application {
mainClass.set('coverosR3z.MainKt')
}
// if you run
// gradlew jar
// you are given a jar file at build/libs/r3z.jar
// which you can run with
// java -jar build/libs/r3z.jar
jar {
manifest {
attributes(
'Main-Class': 'coverosR3z.MainKt',
"Implementation-Title": "Gradle",
"Implementation-Version": "$r3z_version",
)
}
from sourceSets.main.output
dependsOn configurations.runtimeClasspath
from {
configurations.runtimeClasspath.findAll { it.name.endsWith('jar') }.collect { zipTree(it) }
}
}
task performancetests(type: Test) {
group = "Verification"
description 'Runs the performance tests.'
useJUnit {
includeCategories 'coverosR3z.system.misc.PerformanceTestCategory'
}
jacoco {
destinationFile = file("$buildDir/jacoco/performancetest.exec")
classDumpDir = file("$buildDir/jacoco/performancetestclasspathdumps")
}
}
task apitests(type: Test) {
group = "Verification"
description 'Runs the API tests.'
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
useJUnit {
includeCategories 'coverosR3z.server.APITestCategory'
}
jacoco {
destinationFile = file("$buildDir/jacoco/apitest.exec")
classDumpDir = file("$buildDir/jacoco/apitestclasspathdumps")
}
}
task unittests(type: Test) {
group = "Verification"
description 'Runs the fastest set of tests.'
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
useJUnit {
excludeCategories 'coverosR3z.system.misc.PerformanceTestCategory',
'coverosR3z.uitests.UITestCategory',
'coverosR3z.system.misc.IntegrationTestCategory',
'coverosR3z.server.APITestCategory'
}
jacoco {
destinationFile = file("$buildDir/jacoco/unittest.exec")
classDumpDir = file("$buildDir/jacoco/unittestclasspathdumps")
}
}
task nouitest(type: Test) {
group = "Verification"
description 'Runs all the tests but UI'
useJUnit {
excludeCategories 'coverosR3z.uitests.UITestCategory'
}
}
task uitests(type: Test) {
group = "Verification"
description 'Runs the user interface (UI) tests. That is, uses the browser.'
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
useJUnit {
includeCategories 'coverosR3z.uitests.UITestCategory'
}
jacoco {
destinationFile = file("$buildDir/jacoco/uitest.exec")
classDumpDir = file("$buildDir/jacoco/uitestclasspathdumps")
}
// Fail the 'test' task on the first test failure
failFast = false
}
task integrationtests(type: Test) {
group = "Verification"
description 'Runs the integration tests. These run a little slower than unit tests.'
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
useJUnit {
includeCategories 'coverosR3z.system.misc.IntegrationTestCategory'
}
jacoco {
destinationFile = file("$buildDir/jacoco/integrationtest.exec")
classDumpDir = file("$buildDir/jacoco/integrationtestclasspathdumps")
}
}
task alltests(type: GradleBuild) {
group = "Verification"
description 'Runs all the tests, by kind, in order - unit tests, then integration, api, perf, ui'
tasks = ['unittest', 'integrationtest', 'apitest', 'performancetest', 'uitest']
}
task fasttests(type: GradleBuild) {
group = "Verification"
description 'Runs all the fast tests, by kind, in order - unit tests, then integration, api'
tasks = ['unittest', 'integrationtest', 'apitest']
}
test {
useJUnit {
// for the default test and check tasks, we'll exclude the potentially more fraught tests
excludeCategories 'coverosR3z.system.misc.PerformanceTestCategory',
'coverosR3z.uitests.UITestCategory'
}
}
tasks.withType(Test).configureEach {
// it's possible to run in parallel, but so far the speed gains aren't obvious, turning off for now
// maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
jacoco {
includes = ['coverosR3z.*']
}
testLogging {
exceptionFormat "full" // options are "full", "short". default is "short"
// uncomment the following to see the unit test progress in the output
//events "started", "passed", "skipped", "failed", "standardOut", "standardError"
// set to false to disable detailed failure logs
showExceptions true
// enable to see standard out and error streams inline with the test results
showStandardStreams false
}
// Fail the 'test' task on the first test failure
failFast = false
debugOptions {
// make the following true if you want to attach with a debugger while testing
enabled = false
port = 4455
server = true
suspend = true
}
// generate a report on coverage
finalizedBy jacocoTestReport
}
jacoco {
toolVersion = "0.8.7"
}
// Configure Jacoco, our code-coverage tool
jacocoTestReport {
getExecutionData().setFrom(fileTree(buildDir).include("/jacoco/*.exec"))
reports {
xml.enabled true
csv.enabled false
xml.destination file("${buildDir}/jacoco/jacoco.xml")
// enable a nice-looking HTML report
html.destination file("${buildDir}/reports/jacoco")
}
}
// configure our general testing to always create a report
check.dependsOn(jacocoTestReport)
/**
* Put the current Git commit sha in a file accessible while running.
*/
task('writeGitCommitToFile') {
File file = new File("src/main/resources/static/commit.html")
String contents = "Version: " + "$r3z_version" + "\nCommit sha: " + getCurrentGitHash()
file.write(contents)
}
/**
* This gnarly little method gets the current commit. It's really a simple-minded
* approach, which makes it easy to read but maybe likely to fail? time will tell.
*/
static String getCurrentGitHash() {
String headFileLocation = ".git/HEAD"
String commitLocation = ""
int locationOfSpace
String currentHead
FileReader fr_forGitHead
FileReader fr_forGitHash
String result = "EMPTY_INITIAL_VALUE"
boolean shouldExit = false
try {
fr_forGitHead = new FileReader(headFileLocation)
} catch (Exception ignored) {
return "NO_GIT_HEAD_FOUND"
}
new BufferedReader(fr_forGitHead).with { br ->
// get the directory to the current HEAD
result = "EMPTY_INITIAL_VALUE"
try {
currentHead = br.readLine()
} catch (Exception ignored) {
result = "COULD_NOT_READ_HEAD_FILE"
shouldExit = true
}
finally {
br.close()
}
locationOfSpace = currentHead.indexOf(" ")
// extract out the portion that is the directory only
// the whole contents go something like: "ref: refs/heads/master"
commitLocation = currentHead.substring(locationOfSpace + 1)
// read the file at that location (e.g. .git/refs/heads/master )
}
if (shouldExit) {
return result
}
try {
fr_forGitHash = new FileReader(".git/" + commitLocation)
} catch (Exception ignored) {
return "NO_GIT_HASH_FILE_FOUND"
}
new BufferedReader(fr_forGitHash).with { br ->
result = "EMPTY_AT_BEGINNING"
try {
result = br.readLine()
} catch (Exception ignored) {
result = "COULD_NOT_READ_COMMIT_HASH"
} finally {
br.close()
}
}
return result
}
compileKotlin {
finalizedBy writeGitCommitToFile
kotlinOptions.useIR = true
}