-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle
138 lines (111 loc) · 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
import static org.gradle.testfixtures.ProjectBuilder.*
import static org.gradle.testkit.runner.TaskOutcome.*
import org.gradle.testfixtures.ProjectBuilder
import groovyx.gpars.GParsPool
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.codehaus.groovy:groovy-all:2.0.5'
classpath "org.codehaus.gpars:gpars:1.1.0"
classpath gradleTestKit()
}
}
plugins { id 'java' }
ext.build_failed = false
ext.gradleVersion = '2.9'
////////////////////////////////////////////////////////////////////////////////
task wrapper(type: Wrapper) {
gradleVersion = gradleVersion
}
// utility task to setup wrapper in top level project and sub projects
task setupWrapper (dependsOn: wrapper) << {
new File("${projectDir}/examples").traverse( maxDepth: 0, type: groovy.io.FileType.DIRECTORIES ){ dir ->
println "Wrapping examples directory ${dir.absolutePath}"
exec {
workingDir dir
commandLine "${projectDir}/gradlew", "wrapper", "--gradle-version", gradleVersion
}
}
}
////////////////////////////////////////////////////////////////////////////////
def buildProject(proj) {
def subTasks = ProjectBuilder.builder()
.withProjectDir(file("./examples/${proj}/"))
.build()
.getTasksByName("Example", false).first()
.getDependsOn()
subTasks.each { subTask ->
def tries = 1
def test_failed = true
// tests may fail due to unavailability of 3rd party service
// so we need to retry a few times in the event of a failure
while (tries <= 3) {
// ensure we have a clean environment for each test
try {
GradleRunner.create()
.withProjectDir(file("./examples/${proj}/"))
.withArguments('clean')
.build()
} catch (Exception e) {
// noop - some projects don't have clean tasks
}
if (!(subTask instanceof org.gradle.api.Task)) {
// if this isn't a task, skip it and continue to next subTask in subTasks.each closure
return false
}
try {
FileWriter writer = new FileWriter("build/test/${proj}-${subTask.name}.txt")
GradleRunner.create()
.withProjectDir(file("./examples/${proj}/"))
.forwardStdError(writer)
.forwardStdOutput(writer)
.withArguments([subTask.name, '-PdebugExample'])
.build()
writer.close()
} catch (Exception e) {
//e.printStackTrace()
// try again
println "Test attempt ${tries} failed for ${proj}::${subTask.name}"
tries++
continue // continue while loop
}
// test was succesfull - exit try loop
test_failed = false
break
}
if (test_failed) {
project.build_failed = true
println "Test failed ${proj}::${subTask.name}"
} else {
println "Test passed ${proj}::${subTask.name}"
}
}
}
task testSetup() {
delete('build')
mkdir('build/test')
}
task baseTest(dependsOn: testSetup) << {
println "Running base tests"
// Elasticsearch account not available
GParsPool.withPool(10) {
[
'Objectstore',
'Cloudant',
'DashDB'
]
.eachParallel() {
proj -> buildProject(proj)
}
}
if (project.build_failed) {
throw new GradleException("One or more tests failed")
}
}
task check(dependsOn: baseTest, type: Test, overwrite: true) << {
println "Finished running tests."
println "*** Test output can be found in '${projectDir}/build/test/' ***"
}
////////////////////////////////////////////////////////////////////////////////