forked from TEAMMATES/teammates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
574 lines (507 loc) · 17.7 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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
apply plugin: "war"
apply plugin: "com.google.cloud.tools.appengine-appyaml"
apply plugin: "checkstyle"
apply plugin: "pmd"
apply plugin: "com.github.spotbugs"
apply plugin: "jacoco"
apply plugin: "cz.habarta.typescript-generator"
def checkstyleVersion = "8.33"
def pmdVersion = "6.24.0"
def spotbugsVersion = "4.0.6"
def jacocoVersion = "0.8.5"
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.google.cloud.tools:appengine-gradle-plugin:2.3.0"
classpath "gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.4.3"
classpath("cz.habarta.typescript-generator:typescript-generator-gradle-plugin:2.24.612") {
exclude group: "org.gradle"
}
classpath "com.google.guava:guava:30.1.1-jre"
}
}
configurations {
staticAnalysis
}
repositories {
mavenCentral()
}
def objectify = "com.googlecode.objectify:objectify:6.0.7"
def testng = "org.testng:testng:7.4.0"
dependencies {
staticAnalysis("com.puppycrawl.tools:checkstyle:${checkstyleVersion}")
staticAnalysis("net.sourceforge.pmd:pmd-java:${pmdVersion}")
staticAnalysis("com.github.spotbugs:spotbugs:${spotbugsVersion}")
staticAnalysis("org.jacoco:org.jacoco.build:${jacocoVersion}")
annotationProcessor(objectify)
implementation("com.google.auth:google-auth-library-oauth2-http:0.24.1")
implementation("com.google.cloud:google-cloud-datastore:1.107.0")
implementation("com.google.cloud:google-cloud-tasks:1.33.1")
implementation("com.google.cloud:google-cloud-logging:2.3.1")
implementation("com.google.cloud:google-cloud-storage:1.116.0")
implementation("com.google.code.gson:gson:2.8.6")
implementation("com.google.guava:guava:30.1.1-jre")
implementation(objectify)
implementation("com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:20200615.1")
implementation("com.mailjet:mailjet-client:4.5.0")
implementation("com.sendgrid:sendgrid-java:4.6.0")
implementation("com.sun.jersey:jersey-client:1.19.4")
implementation("com.sun.jersey:jersey-core:1.19.4")
implementation("com.sun.jersey.contribs:jersey-multipart:1.19.4")
implementation("javax.servlet:javax.servlet-api:3.1.0")
implementation("org.apache.solr:solr-solrj:8.8.1")
implementation("org.eclipse.jetty:jetty-server:9.4.39.v20210325")
implementation("org.eclipse.jetty:jetty-webapp:9.4.39.v20210325")
implementation("org.eclipse.jetty:jetty-annotations:9.4.39.v20210325")
implementation("org.jsoup:jsoup:1.13.1")
testAnnotationProcessor(testng)
testImplementation("com.tngtech.archunit:archunit:0.11.0")
testImplementation("org.seleniumhq.selenium:selenium-java:4.0.0")
testImplementation(testng)
// For access to Google APIs such as HTTP transport, authentication and JSON parsing
testImplementation("com.google.api-client:google-api-client:1.30.9")
// For supporting authorization code flow locally
testImplementation("com.google.oauth-client:google-oauth-client-jetty:1.30.6")
// For using Gmail API
testImplementation("com.google.apis:google-api-services-gmail:v1-rev20200601-1.30.9")
// For using JMeter APIs
testImplementation("org.apache.jmeter:ApacheJMeter_core:5.4.1") {
exclude group: "org.apache.jmeter", module: "bom"
}
testImplementation("org.apache.jmeter:ApacheJMeter_http:5.4.1") {
exclude group: "org.apache.jmeter", module: "bom"
}
}
sourceSets {
main {
java {
srcDir "src/main/java"
include "**/*.java"
}
resources {
srcDir "src/main/resources"
exclude "**/*.java"
}
}
test {
java {
srcDir "src/test/java"
srcDir "src/e2e/java"
srcDir "src/lnp/java"
srcDir "src/client/java"
include "**/*.java"
}
resources {
srcDir "src/test/resources"
srcDir "src/e2e/resources"
srcDir "src/lnp/resources"
srcDir "src/client/resources"
exclude "**/*.java"
}
}
}
tasks.withType(cz.habarta.typescript.generator.gradle.GenerateTask) {
jsonLibrary = "jackson2"
optionalAnnotations = [
"javax.annotation.Nullable"
]
outputFileType = "implementationFile"
outputKind = "module"
indentString = " "
jackson2Configuration = [
fieldVisibility: "ANY",
getterVisibility: "NONE",
isGetterVisibility: "NONE",
setterVisibility: "NONE",
creatorVisibility: "NONE",
]
mapEnum = "asEnum"
nonConstEnums = true
}
task generateApiOutputFormat(type: cz.habarta.typescript.generator.gradle.GenerateTask) {
classPatterns = [
"teammates.ui.output.**",
"teammates.common.datatransfer.questions.**",
"teammates.common.datatransfer.logs.**",
]
removeTypeNameSuffix = "Data"
outputFile = "src/web/types/api-output.ts"
excludeClassPatterns = [
"teammates.ui.output.**Builder"
]
excludeClasses = [
"teammates.ui.output.SessionResultsData\$NameInfo"
]
}
task generateApiRequestFormat(type: cz.habarta.typescript.generator.gradle.GenerateTask) {
classPatterns = [
"teammates.ui.request.**",
"teammates.common.util.EmailType"
]
excludeClasses = [
"teammates.ui.request.InvalidHttpRequestBodyException"
]
outputFile = "src/web/types/api-request.ts"
}
task generateApiConstants(type: cz.habarta.typescript.generator.gradle.GenerateTask) {
classPatterns = [
"teammates.ui.constants.**"
]
jsonLibrary = 'jackson2'
outputFile = "src/web/types/api-const.ts"
}
generateApiOutputFormat.dependsOn classes
generateApiRequestFormat.dependsOn classes
generateApiConstants.dependsOn classes
task generateTypes {
dependsOn generateApiOutputFormat
dependsOn generateApiRequestFormat
dependsOn generateApiConstants
}
// SETUP TASKS
task createConfigs {
description "Sets up the project by obtaining necessary files and configurations points."
group "Setup"
doLast {
def templatesToCopy = [
"gradle.template.properties",
"src/main/resources/build.template.properties",
"src/web/environments/config.template.ts",
"src/test/resources/test.template.properties",
"src/lnp/resources/test.template.properties",
"src/e2e/resources/test.template.properties",
"src/client/resources/client.template.properties",
"src/main/appengine/app.template.yaml"
]
templatesToCopy.findAll {
!(new File(it.replace(".template", ""))).exists()
}.each {
filename -> copy {
from filename
into filename.startsWith("src/") ? new File(filename).getParent() : "${projectDir}"
rename '(.*).template(.*)', '$1$2'
}
}
}
}
task downloadDependencies {
doFirst {
configurations.compileClasspath.resolve()
}
}
task downloadTestDependencies {
doFirst {
configurations.testCompileClasspath.resolve()
}
}
task downloadLinters {
doFirst {
configurations.staticAnalysis.resolve()
}
}
// RUN SERVER TASKS
compileJava.options.encoding = "UTF-8"
compileTestJava.options.encoding = "UTF-8"
processResources {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
processTestResources {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
task explodeWar(type: Sync) {
dependsOn war
into "${buildDir}/exploded-teammates"
from project.zipTree(war.archiveFile)
outputs.upToDateWhen { false }
}
task copyDistToExplodedWar {
doLast {
copy {
from "src/web/dist"
into explodeWar.destinationDir
}
}
mustRunAfter explodeWar
}
task serverRun(type: JavaExec) {
classpath "${explodeWar.destinationDir}/WEB-INF/lib/*", "${explodeWar.destinationDir}/WEB-INF/classes/."
mainClass = "teammates.main.Application"
jvmArgs "-ea", "-Djava.util.logging.config.file=${explodeWar.destinationDir}/WEB-INF/logging-dev.properties",
"-Djava.time.zone.DefaultZoneRulesProvider=teammates.common.util.TzdbResourceZoneRulesProvider"
dependsOn explodeWar, copyDistToExplodedWar
}
task runDatastoreEmulator(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
mainClass = "teammates.storage.api.DatastoreEmulatorRunner"
}
appengine {
tools {
if (project.properties['cloud.sdk.home'] != null) {
cloudSdkHome = project.properties['cloud.sdk.home']
}
}
deploy {
String buildPropertiesPath = "${projectDir}/src/main/resources/build.properties"
boolean propsExists = new File(buildPropertiesPath).exists()
Properties props = new Properties()
if (propsExists) {
file(buildPropertiesPath).withReader {
props.load(it)
}
}
projectId = propsExists ? props['app.id'] : null
version = propsExists ? props['app.version'] : null
stopPreviousVersion = false
promote = false
}
}
task removeWarFromStagedApp {
doLast {
delete "${buildDir}/staged-app/${war.archiveName}"
}
}
task copyExplodedWarToStagedApp {
doLast {
copy {
from explodeWar.destinationDir
into "${buildDir}/staged-app"
}
}
}
task copyDistToStagedApp {
doLast {
copy {
from "src/web/dist"
into "${buildDir}/staged-app/dist"
}
}
}
appengineStage {
if (project.hasProperty("flex")) {
dependsOn explodeWar
finalizedBy removeWarFromStagedApp, copyExplodedWarToStagedApp, copyDistToStagedApp
} else {
dependsOn explodeWar, copyDistToExplodedWar
finalizedBy removeWarFromStagedApp, copyExplodedWarToStagedApp
}
}
// STATIC ANALYSIS TASKS
def isWindows = System.getProperty("os.name").toLowerCase().contains("windows")
checkstyle {
toolVersion = checkstyleVersion
configFile = file("static-analysis/teammates-checkstyle.xml")
configProperties = [
suppressions: file("static-analysis/teammates-checkstyle-suppressions.xml")
]
}
pmd {
toolVersion = pmdVersion
consoleOutput = true
ruleSetFiles = files("static-analysis/teammates-pmd.xml", "static-analysis/teammates-pmdMain.xml")
ruleSets = []
}
spotbugs {
reportLevel = "low"
toolVersion = spotbugsVersion
includeFilter = file("$rootProject.projectDir/static-analysis/teammates-spotbugs.xml")
excludeFilter = file("$rootProject.projectDir/static-analysis/teammates-spotbugs-exclude.xml")
}
tasks.withType(com.github.spotbugs.snom.SpotBugsTask) {
reports {
xml.enabled = false
html.enabled = false
text.enabled = true
}
}
spotbugsMain {
finalizedBy "printSpotbugsMainViolations"
}
task printSpotbugsMainViolations {
onlyIf {
file("${buildDir}/reports/spotbugs/main.txt").exists()
}
doFirst {
print new File("${buildDir}/reports/spotbugs/main.txt").getText("UTF-8")
}
}
spotbugsTest {
finalizedBy "printSpotbugsTestViolations"
}
task printSpotbugsTestViolations {
onlyIf {
file("${buildDir}/reports/spotbugs/test.txt").exists()
}
doFirst {
print new File("${buildDir}/reports/spotbugs/test.txt").getText("UTF-8")
}
}
task lintMain {
dependsOn checkstyleMain, pmdMain, spotbugsMain
}
task lintTest {
dependsOn checkstyleTest, pmdTest, spotbugsTest
}
import org.gradle.internal.serialize.PlaceholderException
def checkTestNgFailureClosure = { descriptor, result ->
if (result.exception instanceof PlaceholderException
&& result.exception.toString().startsWith("org.gradle.api.internal.tasks.testing.TestSuiteExecutionException")) {
result.exception.printStackTrace()
throw new GradleException("Detected TestNG failure")
}
}
// Displays full exception; to be run after the test fails after the last retry
def afterTestClosure = { descriptor, result ->
if (result.resultType == TestResult.ResultType.FAILURE && result.exception != null && result.exception.getMessage() != null) {
println ""
def msg = result.exception.getMessage()
def shouldDisplayAsDiff = msg.indexOf("<<[expected>") != -1
if (shouldDisplayAsDiff) {
def expectedFileName = "expected-${descriptor.getClassName()}"
def actualFileName = "actual-${descriptor.getClassName()}"
file("${expectedFileName}").text = msg[(msg.indexOf("<<[expected>") + 12)..(msg.indexOf("</expected]>>") - 1)]
file("${actualFileName}").text = msg[(msg.indexOf("<<[actual>") + 10)..(msg.indexOf("</actual]>>") - 1)]
def diffCommand = isWindows ? "FC" : "diff"
def process = "${diffCommand} ${expectedFileName} ${actualFileName}".execute()
println process.getText()
process.waitFor()
def deleteCommand = isWindows ? "del" : "rm"
"${deleteCommand} ${expectedFileName}".execute()
"${deleteCommand} ${actualFileName}".execute()
} else {
println "${result.exception.getClass().getName()}: ${result.exception.getMessage()}"
}
for (StackTraceElement ste : result.exception.getStackTrace()) {
if (ste.getClassName().contains("NativeMethodAccessorImpl")) {
// Everything after this line is the internal workings of TestNG, not important for us
println "\t..."
break
}
println "\tat ${ste.getClassName()}.${ste.getMethodName()}(${ste.getFileName()}:${ste.getLineNumber()})"
}
}
}
task architectureTest(type: Test) {
useTestNG()
options.suites "src/test/resources/testng-architecture.xml"
options.useDefaultListeners = true
ignoreFailures false
maxHeapSize = "1g"
reports.html.required = false
reports.junitXml.required = false
jvmArgs "-Xss2m", "-Dfile.encoding=UTF-8"
afterTest afterTestClosure
afterSuite checkTestNgFailureClosure
testLogging {
events "passed"
}
}
architectureTest.dependsOn testClasses
architectureTest.shouldRunAfter lintMain, lintTest
task lint {
description "Runs the entire static analysis tasks for back-end."
group "Static analysis"
dependsOn lintMain, lintTest, architectureTest
}
// TEST TASKS
def numOfTestRetries = 4
task lnpTests(type: Test) {
systemProperty "random.testing.seed", new Random().nextInt() // re-run tests even if they are up-to-date
useTestNG()
options.suites "src/lnp/resources/testng-lnp.xml"
options.useDefaultListeners = true
ignoreFailures false
maxHeapSize = "1g"
reports.html.required = false
reports.junitXml.required = false
jvmArgs "-Xss2m", "-Dfile.encoding=UTF-8"
afterTest afterTestClosure
afterSuite checkTestNgFailureClosure
testLogging {
events "passed", "failed", "skipped"
}
// Display the L&P test results in the build
def outputCache = new LinkedList<String>()
beforeTest { TestDescriptor td -> outputCache.clear() } // clear output cache before the test starts
onOutput { TestDescriptor td, TestOutputEvent toe -> // put output in the cache
outputCache.add(toe.getMessage())
while (outputCache.size() > 2) outputCache.remove() // keep only last 2 result lines
}
afterTest { TestDescriptor td ->
if (outputCache.size() > 0) {
println(" L&P results for ${td.className}:")
outputCache.each { print(" > $it") }
}
}
}
task componentTests(type: Test) {
description "Runs the full unit and integration test suite."
group "Test"
useTestNG()
options.suites "src/test/resources/testng-component.xml"
options.useDefaultListeners = true
ignoreFailures false
maxHeapSize = "1g"
reports.html.required = false
reports.junitXml.required = false
jvmArgs "-ea", "-Xss2m", "-Dfile.encoding=UTF-8"
afterTest afterTestClosure
afterSuite checkTestNgFailureClosure
testLogging {
events "passed"
}
}
task e2eTests {
description "Runs the full E2E test suite and retries failed test up to ${numOfTestRetries} times."
group "Test"
}
(1..numOfTestRetries + 1).each { id ->
def isFirstTry = id == 1
def isLastRetry = id == numOfTestRetries + 1
task "e2eTestTry${id}"(type: Test) {
useTestNG()
options.suites isFirstTry ? "src/e2e/resources/testng-e2e.xml" : file("${buildDir}/reports/e2e-test-try-${id - 1}/testng-failed.xml")
options.outputDirectory = file("${buildDir}/reports/e2e-test-try-${id}")
options.useDefaultListeners = true
ignoreFailures = !isLastRetry
maxHeapSize = "1g"
reports.html.required = false
reports.junitXml.required = false
jvmArgs "-Xss2m", "-Dfile.encoding=UTF-8"
testLogging {
events "passed"
}
afterTest afterTestClosure
if (isFirstTry) {
afterSuite checkTestNgFailureClosure
}
onlyIf {
isFirstTry || file("${buildDir}/reports/e2e-test-try-${id - 1}/testng-failed.xml").exists()
}
}
e2eTests.dependsOn "e2eTestTry${id}"
}
// COVERAGE TASKS
jacoco {
toolVersion = jacocoVersion
}
task jacocoReport(type: JacocoReport) {
description "Runs coverage session from available test run data."
group "Test"
sourceDirectories.from files(sourceSets.main.java.srcDirs)
classDirectories.from files(sourceSets.main.output)
executionData fileTree("${buildDir}/jacoco").files
reports {
xml.required = true
html.required = true
}
afterEvaluate {
classDirectories.from files(classDirectories.files.collect {
fileTree(dir: it, exclude: ["**/*.jar"])
})
}
}