forked from TEAMMATES/teammates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
558 lines (489 loc) · 19.4 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
apply plugin: "eclipse"
apply plugin: "war"
apply plugin: "appengine"
apply plugin: "checkstyle"
apply plugin: "pmd"
apply plugin: "findbugs"
apply plugin: "jacoco"
def appengineVersion = "1.9.27"
def checkstyleVersion = "6.19"
def pmdVersion = "5.5.2"
def findbugsVersion = "3.0.1"
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "com.google.appengine:gradle-appengine-plugin:1.9.27"
}
}
configurations {
staticAnalysis
enhancer
exclude
testExclude
}
configurations.all {
resolutionStrategy {
force "com.google.appengine:appengine-api-1.0-sdk:${appengineVersion}"
}
}
repositories {
mavenCentral()
}
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"
appengineSdk "com.google.appengine:appengine-java-sdk:${appengineVersion}"
compile "com.google.appengine.tools:appengine-gcs-client:0.4.4",
"com.google.appengine:appengine-api-labs:${appengineVersion}",
"com.google.code.gson:gson:2.8.0",
"com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:20160924.1",
"com.mailjet:mailjet-client:4.0.5",
"com.sendgrid:sendgrid-java:2.2.2",
"com.sun.jersey:jersey-client:1.19.3",
"com.sun.jersey:jersey-core:1.19.3",
"com.sun.jersey.contribs:jersey-multipart:1.19.3",
"joda-time:joda-time:2.9.6",
"org.apache.taglibs:taglibs-standard-impl:1.2.5",
"org.jsoup:jsoup:1.10.1"
exclude "com.google.appengine:appengine-api-1.0-sdk:${appengineVersion}",
"com.google.appengine:appengine-endpoints-deps:${appengineVersion}",
"com.google.appengine:appengine-endpoints:${appengineVersion}",
"com.google.appengine:appengine-jsr107cache:${appengineVersion}",
"com.google.appengine.orm:datanucleus-appengine:1.0.10",
"javax.jdo:jdo2-api:2.3-eb",
"net.sf.jsr107cache:jsr107cache:1.1",
"org.apache.geronimo.specs:geronimo-jpa_3.0_spec:1.1.1",
"org.apache.geronimo.specs:geronimo-jta_1.1_spec:1.1.1",
"org.datanucleus:datanucleus-core:1.1.5",
"org.datanucleus:datanucleus-jpa:1.1.5",
"xerces:xercesImpl:2.11.0"
runtime configurations.exclude
enhancer "javax.jdo:jdo2-api:2.3-eb",
"joda-time:joda-time:2.9.6",
"com.google.appengine.orm:datanucleus-appengine:1.0.10",
"org.datanucleus:datanucleus-core:1.1.5",
"org.datanucleus:datanucleus-jpa:1.1.5",
"com.google.appengine:appengine-api-1.0-sdk:${appengineVersion}"
testCompile "com.google.appengine:appengine-api-stubs:${appengineVersion}",
"com.google.appengine:appengine-remote-api:${appengineVersion}",
"com.google.appengine:appengine-testing:${appengineVersion}",
"httpunit:httpunit:1.7",
"javax.mail:mail:1.4.7",
"org.seleniumhq.selenium:selenium-java:2.53.1",
"org.testng:testng:6.9.4"
testExclude "com.google.appengine:appengine-tools-sdk:${appengineVersion}"
testRuntime configurations.testExclude
}
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
import org.gradle.plugins.ide.eclipse.model.SourceFolder
eclipse {
project {
natures "org.eclipse.jdt.core.javanature", "com.google.appengine.eclipse.core.gaeNature", "org.eclipse.wst.jsdt.core.jsNature"
buildCommand "org.eclipse.jdt.core.javabuilder"
buildCommand "com.google.gdt.eclipse.core.webAppProjectValidator"
buildCommand "com.google.appengine.eclipse.core.enhancerbuilder"
buildCommand "com.google.appengine.eclipse.core.projectValidator"
buildCommand "org.eclipse.wst.validation.validationbuilder"
}
classpath {
containers "com.google.appengine.eclipse.core.GAE_CONTAINER"
defaultOutputDir = file("src/main/webapp/WEB-INF/classes")
sourceSets = [sourceSets.main, sourceSets.test]
minusConfigurations = [configurations.exclude, configurations.testExclude]
file {
whenMerged { cp ->
cp.entries.findAll {
it instanceof SourceFolder && !it.path.startsWith("src/main/")
}*.output = "target/test-classes"
// Method to put mail.jar on top of the classpath
// This is necessary because placing it in its default place causes unintended name clash
def nonMailEntries = cp.entries.findAll{ entry ->
!entry.path.contains("mail-1.4.7")
}
cp.entries.removeAll(nonMailEntries)
cp.entries.addAll(nonMailEntries)
}
}
}
}
eclipseProject {
onlyIf {
!(new File(".project")).exists()
}
}
eclipseClasspath {
onlyIf {
!(new File(".classpath")).exists()
}
}
task createConfigs << {
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'
}
}
}
task createLaunches << {
def templatesToCopy = [
".launches/All tests.launch.xml",
".launches/All tests (GodMode).launch.xml",
".launches/Failed tests.launch.xml",
".launches/Failed tests (GodMode).launch.xml",
".launches/Local tests.launch.xml",
".launches/CI tests.launch.xml",
".launches/Staging tests.launch.xml"
]
templatesToCopy.findAll {
!(new File(it.replace(".xml", ""))).exists()
}.each {
filename -> copy {
from filename
into new File(filename).getParent()
rename '(.*).xml', '$1'
}
filename = filename.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 copyDepsToWebInfLib(type: Copy) {
from configurations.runtime
into "src/main/webapp/WEB-INF/lib/"
rename("datanucleus-appengine-1.0.10.jar", "datanucleus-appengine-1.0.10.final.jar")
rename("appengine-endpoints-deps-1.9.27.jar", "appengine-endpoints-deps.jar")
rename("appengine-endpoints-1.9.27.jar", "appengine-endpoints.jar")
rename("appengine-api-labs-1.9.27.jar", "appengine-api-labs.jar")
}
task resetEclipseDeps {
description "Updates the project's dependencies to be used by Eclipse configurations"
group "Setup"
doFirst {
delete ".classpath",
"src/main/webapp/WEB-INF/lib"
}
finalizedBy eclipseClasspath, copyDepsToWebInfLib
}
task printUserHomeDir << {
println "Your Gradle user directory is: ${gradle.gradleUserHomeDir}"
}
task setup {
description "Sets up the project by obtaining necessary files and configurations points."
group "Setup"
dependsOn eclipseProject, createConfigs, createLaunches
}
// RUN SERVER TASKS
compileJava.options.encoding = "UTF-8"
compileTestJava.options.encoding = "UTF-8"
appengine {
httpPort = 8888
downloadSdk = true
jvmFlags = ["-Duser.timezone=UTC", "-Xss2m", "-Dfile.encoding=UTF-8"]
appcfg {
oauth2 = true
}
}
appengineRun {
if (project.hasProperty("disable_daemon")) {
daemon = false
} else {
daemon = true
}
}
task removeDuplicateLibs(type: Delete) {
delete "${buildDir}/exploded-app/WEB-INF/lib/datanucleus-appengine-1.0.10.final.jar",
"${buildDir}/exploded-app/WEB-INF/lib/appengine-endpoints-deps.jar",
"${buildDir}/exploded-app/WEB-INF/lib/appengine-endpoints.jar",
"${buildDir}/exploded-app/WEB-INF/lib/appengine-api-labs.jar"
}
appengineExplodeApp.finalizedBy removeDuplicateLibs
task enhancerRun << {
def path = System.getProperty("java.class.path") + ":" + project.gradle.gradleUserHomeDir + "/appengine-sdk/appengine-java-sdk-${appengineVersion}/lib/appengine-tools-api.jar"
ant.taskdef(name: "enhance", classpath: path, classname: "com.google.appengine.tools.enhancer.EnhancerTask")
ant.enhance(failonerror: true, verbose: true) {
classpath {
pathelement(path: path)
pathelement(path: sourceSets.main.output.classesDir.canonicalPath)
pathelement(path: project.configurations.enhancer.asPath)
}
fileset(dir: sourceSets.main.output.classesDir.canonicalPath, includes: "teammates/storage/entity/*.class")
arg(value: "-enhancerVersion"); arg(value: "v1")
arg(value: "-api"); arg(value: "JPA")
}
}
enhancerRun.dependsOn appengineDownloadSdk
enhancerRun.dependsOn project.classes
enhancerRun.shouldRunAfter project.testClasses
war.dependsOn enhancerRun
// STATIC ANALYSIS TASKS
def isWindows = System.getProperty("os.name").toLowerCase().contains("windows")
task eslint(type: Exec) {
def command = ["eslint"]
def jsDirs = ["src/main/webapp/js/*.js", "src/main/webapp/dev/*.js"]
def jsonDirs = ["src/main/webapp/js/*.json", "src/main/resources/*.json", "src/test/resources/data/*.json"]
def configFile = ["-c", "static-analysis/teammates-eslint.yml"]
commandLine = (isWindows ? ["cmd", "/c"] : []) + command + jsDirs + jsonDirs + configFile
}
task stylelint(type: Exec) {
def command = ["stylelint"]
def cssDirs = ["src/main/webapp/stylesheets/*.css"]
def configFile = ["--config", "static-analysis/teammates-stylelint.yml"]
commandLine = (isWindows ? ["cmd", "/c"] : []) + command + cssDirs + configFile
}
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 = []
}
pmdMain.dependsOn compileJava
pmdTest.dependsOn compileTestJava
findbugs {
toolVersion = findbugsVersion
visitors = [
"FindDeadLocalStores"
]
}
tasks.withType(FindBugs) {
reports {
xml.enabled = false
html.enabled = true
}
}
task installEslint(type: Exec) {
commandLine "npm", "install", "eslint@3.11.1", "eslint-plugin-json@1.2.0"
}
task installStylelint(type: Exec) {
commandLine "npm", "install", "stylelint@7.6.0"
}
task downloadStaticAnalysisTools {
description "Downloads all static analysis tools."
group "Static analysis"
doFirst {
configurations.staticAnalysis.resolve()
}
finalizedBy installEslint, installStylelint
}
task staticAnalysisMain {
dependsOn checkstyleMain, pmdMain, findbugsMain
}
task staticAnalysisTest {
dependsOn checkstyleTest, pmdTest, findbugsTest
}
task macker << {
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 staticAnalysisMain, staticAnalysisTest
task staticAnalysis {
description "Runs the entire static analysis tasks."
group "Static analysis"
dependsOn eslint, stylelint, staticAnalysisMain, staticAnalysisTest, 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()})"
}
}
}
def checkConfigFailureClosure = { descriptor, result ->
if (result.exception instanceof org.gradle.messaging.remote.internal.PlaceholderException
&& result.exception.toString().startsWith("org.gradle.api.internal.tasks.testing.TestSuiteExecutionException")) {
throw new GradleException('Detected TestNG configuration failure - check src/test/testng-ci.xml')
}
}
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 "-Duser.timezone=UTC", "-Xss2m", "-Dfile.encoding=UTF-8", "-Djava.io.tmpdir=" + System.getenv("TRAVIS_BUILD_DIR")
} else {
jvmArgs "-Duser.timezone=UTC", "-Xss2m", "-Dfile.encoding=UTF-8"
}
testLogging {
events "passed"
}
if (isLastRetry) {
afterTest afterTestClosure
} else if (isFirstTry) {
afterSuite checkConfigFailureClosure
}
finalizedBy "killFirefox${id}"
dependsOn enhancerRun
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 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."
}
}
task cleanTestOutputDir << {
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 from Eclipse."
}
dependsOn cleanTestOutputDir
}
// COVERAGE TASKS
jacoco {
toolVersion = "0.7.8"
}
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
}