forked from TEAMMATES/teammates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
682 lines (604 loc) · 24 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
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: "findbugs"
apply plugin: "jacoco"
def appengineVersion = "1.9.+"
def checkstyleVersion = "8.8"
def pmdVersion = "6.1.0"
def findbugsVersion = "3.0.1"
def jacocoVersion = "0.8.0"
def guavaVersion = "22.0"
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "com.google.cloud.tools:appengine-gradle-plugin:1.3.5"
}
}
configurations {
staticAnalysis
}
configurations.all {
resolutionStrategy {
eachDependency { DependencyResolveDetails details ->
// Replace all instances of Guava JDK5 Backport with vanilla Guava.
// We have to be very careful when updating libraries that depend on Guava and make sure
// the Guava version used in every library is not too far away from the Guava JDK5 Backport
// because Guava is not fully backwards compatible due to its deprecation policy.
// Currently, the only instance of `guava-jdk5` is used by `google-api-client`.
// This has been fixed in https://github.com/google/google-api-java-client/pull/1070 but has
// not been released as of the time of writing. Once the new version (>1.23.0) is released,
// we can update the `google-api-client` dependency and remove this block of code.
if (details.requested.group == 'com.google.guava' && details.requested.name == 'guava-jdk5') {
details.useTarget 'com.google.guava:guava:${guavaVersion}'
}
}
}
}
repositories {
jcenter()
}
def objectify = "com.googlecode.objectify:objectify:5.1.22"
def testng = "org.testng:testng:6.9.4"
dependencies {
staticAnalysis "com.puppycrawl.tools:checkstyle:${checkstyleVersion}",
"net.sourceforge.pmd:pmd-java:${pmdVersion}",
"com.google.code.findbugs:findbugs:${findbugsVersion}",
"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.appengine.tools:appengine-gcs-client:0.7",
"com.google.code.gson:gson:2.8.2",
"com.google.guava:guava:${guavaVersion}",
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.1.2",
"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",
"org.apache.taglibs:taglibs-standard-impl:1.2.5",
"org.jsoup:jsoup:1.11.2"
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:2.53.1",
testng,
"org.kohsuke:wordnet-random-name:1.3",
// For access of Google APIs such as HTTP transport, authentication and JSON parsing
"com.google.api-client:google-api-client:1.23.0",
// For supporting authorization code flow locally
"com.google.oauth-client:google-oauth-client-jetty:1.23.0",
// For using Gmail API
"com.google.apis:google-api-services-gmail:v1-rev82-1.23.0"
}
sourceSets {
main {
java {
srcDir "src/main/java"
include "**/*.java"
}
resources {
srcDir "src/main/resources"
exclude "**/*.java"
}
}
test {
java {
srcDir "src/test/java"
srcDir "src/client/java"
include "**/*.java"
}
resources {
srcDir "src/test/resources"
exclude "**/*.java"
}
}
}
// 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/test/resources/test.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/CI tests.launch.xml",
".templates/eclipseLaunches/Failed tests.launch.xml",
".templates/eclipseLaunches/Local 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
}
// 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 appengineWebXmlPath = "${projectDir}/src/main/webapp/WEB-INF/appengine-web.xml"
Node appengineWebXml = new File(appengineWebXmlPath).exists() ? new XmlParser().parse(appengineWebXmlPath) : null
project = appengineWebXml == null ? null : appengineWebXml.application.text()
version = appengineWebXml == null ? null : appengineWebXml.version.text()
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-pmdMain.xml")
ruleSets = []
}
findbugs {
toolVersion = findbugsVersion
visitors = [
"FindDeadLocalStores"
]
}
tasks.withType(FindBugs) {
reports {
xml.enabled = false
html.enabled = true
}
}
task downloadStaticAnalysisTools {
description "Downloads all static analysis tools."
group "Static analysis"
doFirst {
configurations.staticAnalysis.resolve()
}
}
task lintMain {
dependsOn checkstyleMain, pmdMain, findbugsMain
}
task lintTest {
dependsOn checkstyleTest, pmdTest, findbugsTest
}
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
def failedXmlPath = "test-output/testng-failed.xml"
def failedXmlUrl = "https://gist.githubusercontent.com/anonymous/gist_id/raw/"
// 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>") + 11)..(msg.indexOf("</expected>>") - 1)]
file("${actualFileName}").text = msg[(msg.indexOf("<<actual>") + 9)..(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
testLogging {
events "passed"
}
}
task localTests(type: Test) {
useTestNG()
options.suites "src/test/testng-local.xml"
options.outputDirectory = file("build/reports/test-local")
options.useDefaultListeners = true
ignoreFailures false
maxHeapSize = "1g"
reports.html.enabled = false
reports.junitXml.enabled = false
jvmArgs "-Xss2m", "-Dfile.encoding=UTF-8"
afterTest afterTestClosure
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
testLogging {
events "passed"
}
}
task ciTests {
description "Runs the full 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 "testTry${id}"(type: Test) {
useTestNG()
options.suites isFirstTry ? "src/test/testng-ci.xml" : "build/reports/test-try-${id - 1}/testng-failed.xml"
options.outputDirectory = file("build/reports/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("build/reports/test-try-${id - 1}/testng-failed.xml").exists()
}
}
ciTests.dependsOn "testTry${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 }
}
}
task generateFailedCmd(type: Exec) {
def os = new ByteArrayOutputStream()
doFirst {
commandLine "gist", "-p", "build/reports/test-try-${numOfTestRetries + 1}/testng-failed.xml"
standardOutput = os
}
doLast {
def gistUrl = os.toString()
def gistHash = gistUrl.substring(gistUrl.lastIndexOf("/") + 1).replaceAll("\\s", "")
println "Run failed tests locally by downloading the XML file containing the failed tests using the command:"
println "Windows: gradlew.bat -Pgist=${gistHash} downloadFailedXml"
println "Linux/OS X: ./gradlew -Pgist=${gistHash} downloadFailedXml"
println "followed by running \"Failed tests\" in Eclipse/IntelliJ or using the following command:"
println "Windows: gradlew.bat failedTests"
println "Linux/OS X: ./gradlew failedTests"
}
}
task cleanTestOutputDir {
doLast {
def testOutputDir = new File("test-output")
testOutputDir.deleteDir()
}
}
task downloadFailedXml {
description "Downloads testng-failed.xml from a failed run in Travis/AppVeyor."
group "Test"
onlyIf {
project.hasProperty("gist")
}
doFirst {
def failedXml = new File(failedXmlPath)
failedXml.getParentFile().mkdirs()
def downloadUrl = failedXmlUrl.replace(/gist_id/, project.getProperty("gist"))
new URL(downloadUrl).withInputStream{i -> failedXml.withOutputStream{ it << i }}
}
doLast {
println "The XML file containing the failed tests has been downloaded successfully."
println "You can now run the failed tests locally."
}
dependsOn cleanTestOutputDir
}
// 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, sourceSets.test.java.srcDirs)
classDirectories = files(sourceSets.main.output, sourceSets.test.output)
executionData jacocoMerge.destinationFile
reports {
xml.enabled true
html.enabled true
}
afterEvaluate {
classDirectories = files(classDirectories.files.collect {
fileTree(dir: it, exclude: ["**/*.jar", "teammates/client/**/*", "**/*Filter.class", "**/*Servlet.class"])
})
}
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)
}
}