forked from TEAMMATES/teammates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
547 lines (483 loc) · 18.1 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
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.4.1"
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.3.13",
"com.google.appengine:appengine-api-labs:${appengineVersion}",
"com.google.code.gson:gson:2.2.2",
"com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:r239",
"com.mailjet:mailjet-client:4.0.1",
"com.sendgrid:sendgrid-java:2.2.2",
"com.sun.jersey:jersey-client:1.19",
"com.sun.jersey:jersey-core:1.19",
"com.sun.jersey.contribs:jersey-multipart:1.19",
"joda-time:joda-time:2.9.4",
"org.apache.taglibs:taglibs-standard-impl:1.2.5",
"org.jsoup:jsoup:1.9.2"
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.9.1"
runtime configurations.exclude
enhancer "javax.jdo:jdo2-api:2.3-eb",
"joda-time:joda-time:2.9.4",
"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.5",
"org.apache.commons:commons-lang3:3.4",
"org.seleniumhq.selenium:selenium-java:2.53.0",
"org.testng:testng:6.8.7"
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
def nonMailEntries = cp.entries.findAll{ entry ->
!entry.path.contains("mail-1.4.5")
}
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/Travis 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", "src/test/javascript"]
def configFile = ["-c", "static-analysis/teammates-eslint.yml"]
def ignore = ["--ignore-pattern", "lib/"]
commandLine = (isWindows ? ["cmd", "/c"] : []) + command + jsDirs + configFile + ignore
}
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", "[email protected]"
}
task downloadStaticAnalysisTools {
description "Downloads all static analysis tools."
group "Static analysis"
doFirst {
configurations.staticAnalysis.resolve()
}
finalizedBy installEslint
}
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, staticAnalysisMain, staticAnalysisTest, macker
}
// TEST TASKS
def numOfTestRetries = 3
def isTravis = System.getenv("TRAVIS") != null
def failedXmlPath = "test-output/testng-failed.xml"
def failedXmlUrl = "https://gist.githubusercontent.com/anonymous/gist_id/raw/"
(1..numOfTestRetries + 1).each { 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 }
}
}
def afterTestClosure = { descriptor, result ->
if (result.resultType == TestResult.ResultType.FAILURE && result.exception != null && result.exception.getMessage() != null) {
def msg = result.exception.getMessage()
def shouldDiff = msg.indexOf("<<[expected>\n") != -1
if (shouldDiff) {
file("expected").text = msg[(msg.indexOf("<<[expected>\n") + 13)..(msg.indexOf("\n</expected]>>") - 1)]
file("actual").text = msg[(msg.indexOf("<<[actual>\n") + 11)..(msg.indexOf("\n</actual]>>") - 1)]
if (isWindows) {
def process = "FC expected actual".execute()
println "Diff for " + descriptor.getClassName() + "." + descriptor.getName() + ":\n"
println process.getText()
process.waitFor()
} else {
def process = "diff expected actual".execute()
println "Diff for " + descriptor.getClassName() + "." + descriptor.getName() + ":\n"
println process.getText()
process.waitFor()
}
}
}
}
test {
useTestNG()
options.suites "src/test/testng-travis.xml"
options.useDefaultListeners = true
options.outputDirectory = file("build/reports/test-try-1")
ignoreFailures = numOfTestRetries != 0 ? true : false
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"
}
afterTest afterTestClosure
finalizedBy "killFirefox1"
dependsOn "enhancerRun"
}
task travisTests {
description "Runs the full test suite and retries failed test up to ${numOfTestRetries} times."
group "Test"
dependsOn "test"
}
(1..numOfTestRetries).each { id ->
def isLastRetry = id == numOfTestRetries ? true : false
task "testRetry${id}"(type: Test) {
useTestNG()
options.suites("build/reports/test-try-${id}/testng-failed.xml")
options.outputDirectory = file("build/reports/test-try-${id+1}")
options.useDefaultListeners = true
testClassesDir = sourceSets.test.output.classesDir
classpath = sourceSets.test.runtimeClasspath
testSrcDirs = sourceSets.test.java.srcDirs as List
ignoreFailures = isLastRetry ? false : true
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) {
exceptionFormat = "full"
}
}
if (!isLastRetry) {
afterTest afterTestClosure
}
finalizedBy "killFirefox${id+1}"
dependsOn test, enhancerRun
onlyIf {
file("build/reports/test-try-${id}/testng-failed.xml").exists()
}
}
travisTests.dependsOn "testRetry${id}"
}
task generateFailedCmd(type: Exec) {
onlyIf {
file("build/reports/test-try-${numOfTestRetries}/testng-failed.xml").exists()
}
def os = new ByteArrayOutputStream()
doFirst {
commandLine "gist", "-p", "build/reports/test-try-${numOfTestRetries}/testng-failed.xml"
standardOutput = os
}
doLast {
def gistUrl = os.toString()
def gistHash = gistUrl.substring(gistUrl.lastIndexOf("/") + 1).replaceAll("\\s", "")
logger.lifecycle("Run failed tests locally using the gradle task")
logger.lifecycle("./gradlew -Pgist=${gistHash} downloadFailedXml")
logger.lifecycle("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."
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 {
logger.lifecycle("The failed xml has been downloaded successfully.")
logger.lifecycle("You can now run the failed tests from Eclipse.")
}
dependsOn cleanTestOutputDir
}
// COVERAGE TASKS
jacoco {
toolVersion = "0.7.6.201602180812"
}
jacocoTestReport {
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)
reports {
xml.enabled false
html.enabled true
}
afterEvaluate {
classDirectories = files(classDirectories.files.collect {
fileTree(dir: it, exclude: ["**/*.jar", "teammates/client/**/*", "**/*Filter.class", "**/*Servlet.class"])
})
}
}