forked from TEAMMATES/teammates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
754 lines (667 loc) · 25.2 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
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
apply plugin: "eclipse"
apply plugin: "eclipse-wtp"
apply plugin: "idea"
apply plugin: "war"
// apply plugin: "com.google.cloud.tools.appengine"
// see https://github.com/GoogleCloudPlatform/app-gradle-plugin/issues/125
project.pluginManager.apply com.google.cloud.tools.gradle.appengine.standard.AppEngineStandardPlugin
apply plugin: "checkstyle"
apply plugin: "pmd"
apply plugin: "com.github.spotbugs"
apply plugin: "jacoco"
apply plugin: "cz.habarta.typescript-generator"
def appengineVersion = "1.9.+"
def checkstyleVersion = "8.16"
def pmdVersion = "6.11.0"
def spotbugsVersion = "3.1.10"
def jacocoVersion = "0.8.1"
buildscript {
repositories {
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.google.cloud.tools:appengine-gradle-plugin:1.3.5"
classpath "gradle.plugin.com.github.spotbugs:spotbugs-gradle-plugin:1.6.9"
classpath "cz.habarta.typescript-generator:typescript-generator-gradle-plugin:2.11.472"
}
}
configurations {
staticAnalysis
}
repositories {
jcenter()
}
def objectify = "com.googlecode.objectify:objectify:5.1.22"
def testng = "org.testng:testng:6.14.3"
dependencies {
staticAnalysis "com.puppycrawl.tools:checkstyle:${checkstyleVersion}",
"net.sourceforge.pmd:pmd-java:${pmdVersion}",
"com.github.spotbugs:spotbugs:${spotbugsVersion}",
"de.andrena.tools.macker:macker:1.0.1",
"org.jacoco:org.jacoco.build:${jacocoVersion}"
annotationProcessor objectify
compile "com.google.appengine:appengine-api-1.0-sdk:${appengineVersion}",
"com.google.code.gson:gson:2.8.5",
"com.google.guava:guava:27.0.1-jre",
objectify,
"com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:20180219.1",
"com.mailjet:mailjet-client:4.1.1",
"com.sendgrid:sendgrid-java:4.2.1",
"com.sun.jersey:jersey-client:1.19.4",
"com.sun.jersey:jersey-core:1.19.4",
"com.sun.jersey.contribs:jersey-multipart:1.19.4",
"javax.servlet:javax.servlet-api:3.1.0",
"org.jsoup:jsoup:1.11.3"
compile("com.google.appengine.tools:appengine-gcs-client:0.7") {
// Use the newer servlet library instead
exclude group: "javax.servlet", module: "servlet-api"
}
testAnnotationProcessor testng
testCompile "com.google.appengine:appengine-api-stubs:${appengineVersion}",
"com.google.appengine:appengine-remote-api:${appengineVersion}",
"com.google.appengine:appengine-testing:${appengineVersion}",
"org.httpunit:httpunit:1.7.2",
"org.seleniumhq.selenium:selenium-java:3.141.59",
testng,
// For access to Google APIs such as HTTP transport, authentication and JSON parsing
"com.google.api-client:google-api-client:1.27.0",
// For supporting authorization code flow locally
"com.google.oauth-client:google-oauth-client-jetty:1.27.0",
// For using Gmail API
"com.google.apis:google-api-services-gmail:v1-rev20180904-1.27.0",
// For using JMeter APIs
"org.apache.jmeter:ApacheJMeter_core:5.1.1",
"org.apache.jmeter:ApacheJMeter_http:5.1.1"
}
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/client/java"
include "**/*.java"
}
resources {
srcDir "src/test/resources"
srcDir "src/e2e/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.webapi.output.**",
"teammates.common.datatransfer.questions.**"
]
removeTypeNameSuffix = "Data"
outputFile = "src/web/types/api-output.ts"
}
task generateApiRequestFormat(type: cz.habarta.typescript.generator.gradle.GenerateTask) {
classPatterns = [
"teammates.ui.webapi.request.**"
]
outputFile = "src/web/types/api-request.ts"
}
generateApiOutputFormat.dependsOn classes
generateApiRequestFormat.dependsOn classes
task generateTypes {
dependsOn generateApiOutputFormat
dependsOn generateApiRequestFormat
}
// 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/e2e/resources/test.template.properties",
"src/client/resources/client.template.properties",
"src/main/webapp/WEB-INF/appengine-web.template.xml"
]
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'
}
}
}
}
import org.gradle.plugins.ide.eclipse.model.SourceFolder
eclipse {
project {
natures "org.eclipse.jdt.core.javanature", "org.eclipse.buildship.core.gradleprojectnature", "org.eclipse.wst.jsdt.core.jsNature"
buildCommand "org.eclipse.jdt.core.javabuilder"
buildCommand "org.eclipse.buildship.core.gradleprojectbuilder"
buildCommand "org.eclipse.wst.validation.validationbuilder"
buildCommand "com.google.cloud.tools.eclipse.appengine.standard.java8.appengineWeb"
// Exclude the CLI and IntelliJ build directories
// Gradle Eclipse plugin does not support generation of resource filters yet
// Use the method lined out in https://discuss.gradle.org/t/eclipse-pluging-adding-resource-filters/5408/2
file {
withXml { xmlProvider ->
Node node = xmlProvider.asNode().filteredResources[0]
['build', 'out'].each { folder ->
Node filter = node.appendNode('filter')
filter.appendNode('id', folder.hashCode())
filter.appendNode('name', '')
filter.appendNode('type', 10)
Node matcher = filter.appendNode('matcher')
matcher.appendNode('id', 'org.eclipse.ui.ide.multiFilter')
matcher.appendNode('arguments', "1.0-name-matches-false-false-${folder}")
}
}
}
}
classpath {
containers "org.eclipse.buildship.core.gradleclasspathcontainer",
"org.eclipse.jst.server.core.container/com.google.cloud.tools.eclipse.appengine.standard.runtimeClasspathProvider/App Engine Standard Runtime"
defaultOutputDir = file("build-eclipse/classes")
file {
whenMerged { cp ->
cp.entries.findAll {
it instanceof SourceFolder && !it.path.startsWith("src/main/")
}*.output = "build-eclipse/test-classes"
}
}
}
wtp {
facet {
facets = []
facet name: "jst.web", version: "3.1"
facet name: "jst.java", version: "1.8"
facet name: "wst.jsdt.web", version: "1.0"
facet name: "com.google.cloud.tools.eclipse.appengine.facets.standard", version: "JRE8"
}
}
}
eclipseProject {
onlyIf {
!(new File(".project")).exists()
}
}
eclipseClasspath {
onlyIf {
!(new File(".classpath")).exists()
}
}
task createEclipseLaunches {
doLast {
def templatesToCopy = [
".templates/eclipseLaunches/All tests.launch.xml",
".templates/eclipseLaunches/Component tests.launch.xml",
".templates/eclipseLaunches/Failed tests.launch.xml",
".templates/eclipseLaunches/E2E tests.launch.xml"
]
templatesToCopy.findAll {
!(new File(it.replace(".templates/eclipseLaunches", ".launches").replace(".xml", ""))).exists()
}.each { filename ->
copy {
from filename
into ".launches"
rename '(.*).xml', '$1'
}
filename = filename.replace(".templates/eclipseLaunches", ".launches").replace(".xml", "")
def fileContents = new File(filename).getText("UTF-8")
def projectName = "${projectDir}".replaceAll(/.*(\/|\\)/, "")
new File(filename).text = new File(filename).getText("UTF-8").replaceAll(/\$\{project\.name\}/, projectName)
}
}
}
task setupEclipse {
description "Sets up the Eclipse-specific configurations for the project."
group "Setup"
dependsOn eclipseClasspath, eclipseProject, createEclipseLaunches
}
String intellijSetupGroup = 'IntelliJ IDEA Setup'
// IntelliJ Project Setup
// Use a different buildDir for IntelliJ builds to avoid conflict with CLI builds.
// IDE detection is achieved by checking `idea.paths.selector`, a system property that IntelliJ sets.
// Note that this property is not documented and may change anytime.
if (System.getProperty('idea.paths.selector') != null) {
// Nest the buildDir inside IntelliJ's default project compiler output directory
buildDir = new File(projectDir, 'out/build')
}
idea {
module {
// Exclude the CLI and Eclipse build directories
excludeDirs += [file('build'), file('build-eclipse')]
}
}
task setupIntellijRunConfigs(type: Copy) {
description 'Sets up the run configurations in the IntelliJ project.'
group intellijSetupGroup
doFirst {
if (!file('.idea').exists()) {
throw new GradleException('Please import the project into IntelliJ first.')
}
}
from '.templates/ideaRunConfigurations'
into '.idea/runConfigurations'
}
task setupIntellij {
description 'Sets up the IntelliJ-specific configurations for the project.'
group intellijSetupGroup
dependsOn setupIntellijRunConfigs
}
// IntelliJ project static analysis plugins setup
task copyStylelintConfiguration {
// Cannot use copy task directly when copying to project root on Windows due to the
// file-locking mechanism interfering with the way inputs and outputs are monitored
// (see https://issues.gradle.org/browse/GRADLE-3002).
// We use the copy method instead, which works because it does not do incremental
// building (inputs and outputs are not monitored).
group intellijSetupGroup
doLast {
copy {
from 'static-analysis/teammates-stylelint.yml'
into projectDir
rename { '.stylelintrc.yml' }
}
}
}
task copyIntelliJProjectPluginsSettings(type: Copy) {
group intellijSetupGroup
from '.templates/ideaPlugins'
into '.idea'
mustRunAfter copyStylelintConfiguration
}
task syncIntelliJCheckStyleVersion {
description 'Syncs the CheckStyle-IDEA version to the same with the build script.' +
'Also executes automatically during configuration phase'
group intellijSetupGroup
if (file('.idea/checkstyle-idea.xml').exists()) {
String filePath = '.idea/checkstyle-idea.xml'
Node xml = new XmlParser().parse(filePath)
Node checkStyleComponent = (Node) (xml.component.find { it.@name == 'CheckStyle-IDEA' })
Node checkStyleConfigurationMap = (Node) (checkStyleComponent.option.find { it.@name == 'configuration' })
Node checkStyleVersionEntry =
(Node) (checkStyleConfigurationMap.map.entry.find { it.@key == 'checkstyle-version' })
checkStyleVersionEntry.@value = checkstyleVersion
writeXmlToPath(xml, filePath)
}
}
task setupIntellijStaticAnalysis {
description 'Sets up the static analysis plugins in the IntelliJ project.'
group intellijSetupGroup
dependsOn copyStylelintConfiguration, copyIntelliJProjectPluginsSettings
finalizedBy syncIntelliJCheckStyleVersion
}
task downloadDependencies {
doFirst {
configurations.compile.resolve()
}
}
task downloadTestDependencies {
doFirst {
configurations.testCompile.resolve()
}
}
task downloadLinters {
doFirst {
configurations.staticAnalysis.resolve()
}
}
// RUN SERVER TASKS
compileJava.options.encoding = "UTF-8"
compileTestJava.options.encoding = "UTF-8"
appengine {
run {
port = 8080
jvmFlags = ["-Xss2m", "-Dfile.encoding=UTF-8",
// Absolute paths are not supported, the following is relative to the project directory
// These only specify the datastore/blobstore paths, but search indexes are still generated in WEB-INF/appengine-generated
"-Ddatastore.backing_store=../../appengine-generated/local_db.bin",
"-Dblobstore.backing_store=../../appengine-generated"]
}
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)
}
}
project = propsExists ? props['app.id'] : null
version = propsExists ? props['app.version'] : null
stopPreviousVersion = false
promote = false
}
}
task appengineDeployAll {
description "Deploy an App Engine application and all its extended configurations"
group "App Engine Standard environment"
dependsOn appengineDeploy, appengineDeployIndex, appengineDeployCron, appengineDeployQueue
}
// STATIC ANALYSIS TASKS
def isWindows = System.getProperty("os.name").toLowerCase().contains("windows")
checkstyle {
toolVersion = checkstyleVersion
configFile = file("static-analysis/teammates-checkstyle.xml")
}
pmd {
toolVersion = pmdVersion
consoleOutput = true
ruleSetFiles = files("static-analysis/teammates-pmd.xml", "static-analysis/teammates-pmd-6.11.0.xml", "static-analysis/teammates-pmdMain.xml")
ruleSets = []
}
spotbugs {
reportLevel = "low"
toolVersion = spotbugsVersion
includeFilter = file("$rootProject.projectDir/static-analysis/teammates-spotbugs.xml")
}
tasks.withType(com.github.spotbugs.SpotBugsTask) {
reports {
xml.enabled = false
html.enabled = false
emacs.enabled = true
}
}
spotbugsMain {
finalizedBy "printSpotbugsMainViolations"
}
task printSpotbugsMainViolations {
onlyIf {
file("${buildDir}/reports/spotbugs/main.emacs").exists()
}
doFirst {
print new File("${buildDir}/reports/spotbugs/main.emacs").getText("UTF-8")
}
}
spotbugsTest {
finalizedBy "printSpotbugsTestViolations"
}
task printSpotbugsTestViolations {
onlyIf {
file("${buildDir}/reports/spotbugs/test.emacs").exists()
}
doFirst {
print new File("${buildDir}/reports/spotbugs/test.emacs").getText("UTF-8")
}
}
task lintMain {
dependsOn checkstyleMain, pmdMain, spotbugsMain
}
task lintTest {
dependsOn checkstyleTest, pmdTest, spotbugsTest
}
task macker {
doLast {
logging.setLevel(LogLevel.INFO)
ant.taskdef(name: "macker", classpath: configurations.staticAnalysis.asPath, classname: "de.andrena.tools.macker.ant.MackerAntTask")
ant.macker(failonerror: true, verbose: false) {
rules(dir: "${projectDir}/static-analysis", includes: "teammates-macker.xml")
classes(dir: "${buildDir}/classes") {
include(name: "**/*.class")
}
}
}
}
macker.dependsOn testClasses
macker.shouldRunAfter lintMain, lintTest
task lint {
description "Runs the entire static analysis tasks for back-end."
group "Static analysis"
dependsOn lintMain, lintTest, macker
}
// TEST TASKS
def numOfTestRetries = 3
def isTravis = System.getenv("TRAVIS") != null
def isAppVeyor = System.getenv("APPVEYOR") != null
// Displays full exception; to be run after the test fails after the last retry
// For HTML tests, the exception is displayed in diff form instead of the extremely verbose full exception message
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()
if (!isAppVeyor && !isTravis) { // CI does not allow deleting files
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()})"
}
}
}
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")
}
}
test {
useTestNG()
options.useDefaultListeners = true
ignoreFailures false
maxHeapSize = "1g"
reports.html.enabled = false
reports.junitXml.enabled = false
jvmArgs "-Xss2m", "-Dfile.encoding=UTF-8"
afterTest afterTestClosure
afterSuite checkTestNgFailureClosure
testLogging {
events "passed"
}
}
task lnpTests(type: Test) {
useTestNG()
options.suites "src/e2e/resources/testng-lnp.xml"
options.useDefaultListeners = true
ignoreFailures false
maxHeapSize = "1g"
reports.html.enabled = false
reports.junitXml.enabled = false
jvmArgs "-Xss2m", "-Dfile.encoding=UTF-8"
afterTest afterTestClosure
afterSuite checkTestNgFailureClosure
testLogging {
events "passed"
}
}
task failedTests(type: Test) {
useTestNG()
options.suites "test-output/testng-failed.xml"
options.outputDirectory = file("build/reports/test-failed")
options.useDefaultListeners = true
ignoreFailures false
maxHeapSize = "1g"
reports.html.enabled = false
reports.junitXml.enabled = false
jvmArgs "-Xss2m", "-Dfile.encoding=UTF-8"
afterTest afterTestClosure
afterSuite checkTestNgFailureClosure
testLogging {
events "passed"
}
}
task componentTests {
description "Runs the full unit test suite and retries failed test up to ${numOfTestRetries} times."
group "Test"
}
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 "componentTestTry${id}"(type: Test) {
useTestNG()
options.suites isFirstTry ? "src/test/resources/testng-component.xml" : file("${buildDir}/reports/component-test-try-${id - 1}/testng-failed.xml")
options.outputDirectory = file("${buildDir}/reports/component-test-try-${id}")
options.useDefaultListeners = true
ignoreFailures = !isLastRetry
maxHeapSize = "1g"
reports.html.enabled = false
reports.junitXml.enabled = false
if (isTravis) {
jvmArgs "-Xss2m", "-Dfile.encoding=UTF-8", "-Djava.io.tmpdir=" + System.getenv("TRAVIS_BUILD_DIR")
} else {
jvmArgs "-Xss2m", "-Dfile.encoding=UTF-8"
}
testLogging {
events "passed"
}
if (isLastRetry) {
afterTest afterTestClosure
} else if (isFirstTry) {
afterSuite checkTestNgFailureClosure
}
onlyIf {
isFirstTry || file("${buildDir}/reports/component-test-try-${id - 1}/testng-failed.xml").exists()
}
}
componentTests.dependsOn "componentTestTry${id}"
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.enabled = false
reports.junitXml.enabled = false
if (isTravis) {
jvmArgs "-Xss2m", "-Dfile.encoding=UTF-8", "-Djava.io.tmpdir=" + System.getenv("TRAVIS_BUILD_DIR")
} else {
jvmArgs "-Xss2m", "-Dfile.encoding=UTF-8"
}
testLogging {
events "passed"
}
if (isLastRetry) {
afterTest afterTestClosure
} else if (isFirstTry) {
afterSuite checkTestNgFailureClosure
}
finalizedBy "killFirefox${id}", "killChromedriver${id}"
onlyIf {
isFirstTry || file("${buildDir}/reports/e2e-test-try-${id - 1}/testng-failed.xml").exists()
}
}
e2eTests.dependsOn "e2eTestTry${id}"
task "killFirefox${id}"(type: Exec) {
doFirst {
if (isWindows) {
commandLine "taskkill", "/f", "/im", "firefox.exe"
} else {
commandLine "pkill", "firefox"
}
// Silence output for this task
standardOutput = new ByteArrayOutputStream()
errorOutput = standardOutput
}
ignoreExitValue = true
outputs.upToDateWhen { false }
}
task "killChromedriver${id}"(type: Exec) {
doFirst {
if (isWindows) {
commandLine "taskkill", "/f", "/im", "chromedriver.exe"
} else {
commandLine "pkill", "chromedriver"
}
// Silence output for this task
standardOutput = new ByteArrayOutputStream()
errorOutput = standardOutput
}
ignoreExitValue = true
outputs.upToDateWhen { false }
}
}
// COVERAGE TASKS
jacoco {
toolVersion = jacocoVersion
}
task jacocoMerge(type: JacocoMerge) {
destinationFile = file("${buildDir}/jacocoMerge/jacocoMerge.exec")
executionData fileTree("${buildDir}/jacoco").files
}
task jacocoReport(type: JacocoReport) {
description "Runs coverage session from available test run data."
group "Test"
sourceDirectories = files(sourceSets.main.java.srcDirs)
classDirectories = files(sourceSets.main.output)
executionData jacocoMerge.destinationFile
reports {
xml.enabled true
html.enabled true
}
afterEvaluate {
classDirectories = files(classDirectories.files.collect {
fileTree(dir: it, exclude: ["**/*.jar"])
})
}
dependsOn jacocoMerge
}
// Helper methods
import groovy.xml.StreamingMarkupBuilder
import java.nio.charset.StandardCharsets
void writeXmlToPath(Node xml, String pathToWrite) {
new File(pathToWrite).withWriter(StandardCharsets.UTF_8.name()) { out ->
out << new StreamingMarkupBuilder().bind { mkp.xmlDeclaration() }
def xmlNodePrinter = new XmlNodePrinter(new PrintWriter(out))
xmlNodePrinter.preserveWhitespace = true
xmlNodePrinter.print(xml)
}
}