forked from WASdev/tool.lars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
253 lines (213 loc) · 7.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
/*******************************************************************************
* 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'
repositories {
mavenCentral()
}
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
}
}
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'
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) {
// When you create a zip tree, the jar gets unpacked. So the paths 'inside' the jar
// end up looking a bit like this:
// /tmp/expandedArchives/larsServerPackage.jar_1vjjzyok4kl5hstxnvin6rjqx/wlp/usr/servers/larsServer/LICENSE
// so the matching logic is a bit ick.
FileTree tree = zipTree(zipFileName)
boolean found = tree.find { File file ->
def foundFiles = []
toCheck.each {
if (file.getPath().endsWith(it)) {
foundFiles << it
}
}
foundFiles.each {
toCheck.remove(it)
}
if (toCheck) {
return false
}
// toCheck is empty, so all files were found
return true;
}
if (!found) {
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}")
}
}
}
// 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));
}
}