-
Notifications
You must be signed in to change notification settings - Fork 22
/
build.gradle
307 lines (261 loc) · 9.55 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
/*******************************************************************************
* Copyright (c) 2015 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
apply plugin: 'base'
apply plugin: 'eclipse'
if (hasProperty('versionFile')) {
apply from: versionFile
} else {
apply from: 'LARS_versions.gradle'
}
boolean haveAnyTestsFailed = false;
loadProperties("${rootProject.rootDir}/test-utils/src/main/resources/config.properties");
// General configuration for all projects
// Set up support for fatTests which rely on a running test server
subprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'findbugs'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
tasks.withType(JavaCompile) {
options.compilerArgs << '-Xlint:unchecked'
options.deprecation = true
}
repositories {
mavenCentral()
}
dependencies {
findbugs 'com.google.code.findbugs:findbugs:3.0.0'
}
sourceSets {
fat {
compileClasspath += sourceSets.main.output
runtimeClasspath += sourceSets.main.output
}
}
findbugs {
sourceSets = [sourceSets.main]
def excludeFile = file("findbugs.exclude.xml")
if (excludeFile.exists()) {
excludeFilter = excludeFile
}
}
findbugsMain {
reports {
xml.enabled = false
html.enabled = true
}
}
configurations {
fatCompile.extendsFrom testCompile
}
check {
dependsOn 'testFat'
}
test {
reports.html.enabled = false
filter.includeTestsMatching '*Test'
ignoreFailures = true
afterTest { desc, result ->
if (result.resultType == TestResult.ResultType.FAILURE) {
haveAnyTestsFailed = true
}
}
}
task testFat(type: Test) {
group 'verification'
description 'Start test server and run the fat tests'
testClassesDir = sourceSets.fat.output.classesDir
classpath = sourceSets.fat.runtimeClasspath
dependsOn fatClasses
dependsOn 'prepareTestWorkingDir'
dependsOn ':server:createTestUsrDir'
dependsOn ':server:startTestMongod'
finalizedBy ':server:stopTestMongod'
dependsOn ':server:startTestServer'
finalizedBy ':server:stopTestServer'
shouldRunAfter 'test'
inputs.files({tasks.prepareTestResources})
reports.html.enabled = false;
ignoreFailures = true
afterTest { desc, result ->
if (result.resultType == TestResult.ResultType.FAILURE) {
haveAnyTestsFailed = true
}
}
if (project.hasProperty('fatFilter')) {
systemProperty 'fatFilter', fatFilter
}
workingDir file('build/test-working')
}
task prepareTestWorkingDir {
dependsOn 'prepareTestResources'
doLast {
mkdir('build/test-working')
}
}
task prepareTestResources (type:Copy) {
from 'src/fat/testResources'
into 'build/test-working/resources'
exclude '**/*.zip'
exclude '**/*.jar'
exclude '**/*.esa'
}
File testResourcesDir = file('src/fat/testResources')
def subProj = delegate
if (testResourcesDir.exists()) {
testResourcesDir.eachDirRecurse({ dir ->
if (dir.name.endsWith('.esa') || dir.name.endsWith('.jar') || dir.name.endsWith('.zip')) {
String relativeTargetPath = dir.parentFile.absolutePath.minus(testResourcesDir.absolutePath)
Task task = task "create-${relativeTargetPath}-${dir.name}" (type: Zip) {
archiveName = dir.name
from dir
destinationDir = subProj.file('build/test-working/resources' + relativeTargetPath)
}
prepareTestResources.dependsOn task
prepareTestResources.outputs.files(task)
}
})
}
task testReport(type: TestReport) {
tasks.withType(Test).each({
reportOn it.binResultsDir
it.finalizedBy testReport
})
destinationDir testReportDir
}
// We have the JDT prefs checked in so disable the tasks which write it
eclipseJdt.enabled = false
cleanEclipseJdt.enabled = false
}
task dist(type: Sync) {
description 'Produce distribution archives, and copy them to the build/distributions directory'
group 'distribution'
into 'build/distributions'
from subprojects*.getTasksByName('dist', false)
}
/**
* If the zip file doesn't contain the all the files in the toCheck
* list, throws an exception.
*/
boolean checkZipContents(zipFileName, toCheck) {
FileTree tree = zipTree(zipFileName)
tree.visit { FileVisitDetails details ->
def foundFiles = []
toCheck.each {
if (details.getPath().equals(it)) {
foundFiles << it
}
}
foundFiles.each {
toCheck.remove(it)
}
}
if (toCheck) {
throw new GradleException("Couldn't find files '${toCheck}' in the zip file '${zipFileName}'")
}
}
task globalTestReport(type: TestReport) {
description 'Produce a test report for all projects and fail the build if any tests failed'
subprojects.each { subproj ->
subproj.tasks.withType(Test).each {
reportOn it.binResultsDir
it.finalizedBy globalTestReport
shouldRunAfter it
}
}
destinationDir file('build/reports/test')
doLast {
if (haveAnyTestsFailed) {
URI reportUri = new File(destinationDir, "index.html").toURI();
reportUri = new URI(reportUri.scheme, "", reportUri.path, null);
throw new Exception("Tests have failed. For more information, see the test report: ${reportUri}. The testServer logs are available at /server/build/usr/servers/testServer/logs.")
}
}
}
// Make the gradle eclipse tools play nicely with this non-java project
task afterEclipseImport << {
Node node = new XmlParser().parse(file('.project'));
node.depthFirst().each {
if (it.name() == "nature" && it.value() == ["org.eclipse.jdt.core.javanature"]) {
it.parent().remove(it)
}
if (it.name() == "buildSpec") {
it.parent().remove(it)
}
}
XmlNodePrinter printer = new XmlNodePrinter(new PrintWriter(file('.project')))
printer.preserveWhitespace = true
printer.print(node)
}
// Function to load configuration properties from a normal
// java properties file. This seems to be necessary to allow
// properties that are visible to both gradle script and java
// testcases
void loadProperties(String fileName) {
Properties properties = new Properties();
File propertiesFile = new File(fileName);
propertiesFile.withInputStream {
properties.load(it);
}
properties.propertyNames().each {
project.ext.set(it, properties.get(it));
}
}
// If a Java 8 VM is available, set up the bootclasspath and path to java.exe for
// other projects to use.
if(hasProperty("java8Home")) {
def java_lib_dir = java8Home + File.separator + "jre" + File.separator + "lib"
def java_bin_dir = java8Home + File.separator + "jre" + File.separator + "bin"
def java_executable = java_bin_dir + File.separator + "java.exe"
File java_exe_file = new File(java_executable)
if (!java_exe_file.exists()) {
java_executable = java_bin_dir + File.separator + "java"
java_exe_file = new File(java_executable)
if (!java_exe_file.exists()) {
throw new GradleException("java8Home property was specified but no exectuable could be found. java8Home was "
+ java8Home + " and " + java_executable + " couldn't be found")
}
}
// The set of jars needed for the bootclasspath varies depending on which JVM is being used
// so this code has to search for them.
def jars = [];
try {
new File(java_lib_dir).eachFileRecurse {
if (it.path =~/\.jar$/) {
jars.add(it.path)
}
}
new File(java_bin_dir).eachFileRecurse {
if (it.path =~/\.jar$/) {
jars.add(it.path)
}
}
} catch (FileNotFoundException e) {
// do nothing. The check below will fail the build
}
if (jars.size() == 0) {
throw new GradleException("the java8Home property was specified but no jar files were found in the expected JRE lib directory. java8Home was "
+ java8Home + " and no jars were found in " + java_lib_dir)
}
ext.java8BootClasspath = jars.iterator().join(File.pathSeparator)
ext.java8Executable = java_executable
logger.warn("Will execute client-lib-tests with JVM at " + java8Executable)
logger.debug("bootstrapclasspath for Java 7 projects set to:\n" + java8BootClasspath)
} else {
logger.warn("java8Home property was not set, so the bootstrapclasspath for client-lib will not be set,"
+" and client-lib-tests will be executed on the current JVM")
}