-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.gradle
281 lines (245 loc) · 7.75 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
buildscript {
repositories {
mavenCentral()
mavenLocal()
maven { url "https://maven.saxonica.com/maven" }
}
dependencies {
classpath group: 'net.sf.saxon', name: 'Saxon-HE', version: '12.4'
}
}
plugins {
id 'com.nwalsh.gradle.saxon.saxon-gradle' version '0.10.7'
id 'com.nwalsh.gradle.docker.container' version '0.0.5'
}
import com.nwalsh.gradle.saxon.SaxonXsltTask
import com.nwalsh.gradle.docker.DockerContainer
repositories {
mavenLocal()
mavenCentral()
maven { url = "https://maven.apache.org" }
maven { url "https://dev.saxonica.com/maven" }
}
ext {
c_csrestest = "csrestest"
}
// Find dotnet
def dotnetex = null
// Laboriously construct a search path that includes some default locations
// plus the users actual path.
def spath = ["/usr/local/share/dotnet"]
System.getenv("PATH").split(System.getProperty("path.separator")).each { dir ->
spath += [dir]
}
spath.each { dir ->
if (dotnetex == null) {
def fn = new File(dir + "/dotnet")
if (fn.exists() && fn.canExecute()) {
dotnetex = fn.toString()
} else {
fn = new File(dir + "/dotnet.exe")
if (fn.exists() && fn.canExecute()) {
dotnetex = fn.toString()
}
}
}
}
if (dotnetex == null) {
println("WARNING: Failed to find dotnet[.exe]!")
}
// You must specify the key and source externally in order to push the
// nuget package. For example, they can be read from
// ~/.gradle/gradle.properties. They must not be committed to the
// repository!
if (!hasProperty("nugetApiKey")) {
ext.nugetApiKey = "KEYREQUIREDTOPUSH"
}
if (!hasProperty("nugetSource")) {
ext.nugetSource = "SOURCEREQUIREDTOPUSH"
}
tasks.register('clean') {
doLast {
['XmlResolver', 'XmlResolverData',
'Tests', 'DataTests'].each { proj ->
['bin', 'obj'].each { dir ->
delete "${projectDir}/${proj}/${dir}"
}
}
delete "${projectDir}/XmlResolverData/Data"
delete "${projectDir}/XmlResolverData/XmlResolverData.csproj"
delete "${projectDir}/DataTests/DataTest.cs"
}
}
// ============================================================
tasks.register('copy_data', Copy) {
into "${projectDir}/XmlResolverData/Data"
from ("${projectDir}/data/src/data") {
exclude "manifest.xml"
}
}
tasks.register('make_data_catalog', SaxonXsltTask) {
dependsOn = ['copy_data']
input "${projectDir}/data/src/data/manifest.xml"
output "${projectDir}/XmlResolverData/Data/catalog.xml"
stylesheet "${projectDir}/tools/make-catalog.xsl"
}
tasks.register('make_data_tests', SaxonXsltTask) {
dependsOn = ['copy_data']
outputs.file "${projectDir}/DataTests/DataTest.cs"
input "${projectDir}/data/src/data/manifest.xml"
output "${projectDir}/XmlResolverData/Data/catalog.xml"
stylesheet "${projectDir}/tools/make-catalog.xsl"
parameters (
'generate-tests': "${projectDir}/DataTests/DataTest.cs"
)
}
tasks.register('make_data_csproj', SaxonXsltTask) {
dependsOn = ['copy_data', 'make_data_catalog']
input "${projectDir}/data/src/data/manifest.xml"
output "${projectDir}/XmlResolverData/XmlResolverData.csproj"
stylesheet "${projectDir}/tools/make-csproj.xsl"
}
// ============================================================
tasks.register('dotnetBuild') {
dependsOn = ['dotnetBuildXmlResolver', 'dotnetBuildXmlResolverData']
}
tasks.register("dotnetBuildXmlResolver") {
dependsOn = ['make_data_csproj']
inputs.files fileTree(dir: "${projectDir}/XmlResolver")
outputs.file "${projectDir}/XmlResolver/bin/Release/net6.0/XmlResolver.dll"
outputs.file "${projectDir}/XmlResolver/bin/Release/XmlResolver.${resolverVersion}.nupkg"
doLast {
exec {
workingDir = projectDir
commandLine dotnetex, 'restore', 'XmlResolver.sln', '--verbosity', 'Normal'
}
}
doLast {
exec {
workingDir = projectDir
commandLine dotnetex, 'build', 'XmlResolver.sln', '--verbosity', 'Normal',
'--configuration', 'Release', '/nodereuse:false', '--no-restore',
"-p:Version=${resolverVersion}", "-p:PackageVersion=${resolverVersion}"
}
}
}
tasks.register("dotnetBuildXmlResolverData") {
dependsOn = ['make_data_csproj', 'make_data_tests']
inputs.files fileTree(dir: "${projectDir}/XmlResolverData")
outputs.file "${projectDir}/XmlResolverData/bin/Release/net6.0/XmlResolver.dll"
outputs.file "${projectDir}/XmlResolverData/bin/Release/XmlResolver.${resolverVersion}.nupkg"
doLast {
exec {
workingDir = projectDir
commandLine dotnetex, 'restore', 'XmlResolverData.sln', '--verbosity', 'Normal'
}
}
doLast {
exec {
workingDir = projectDir
commandLine dotnetex, 'build', 'XmlResolverData.sln', '--verbosity', 'Normal',
'--configuration', 'Release', '/nodereuse:false', '--no-restore',
"-p:Version=${resolverVersion}", "-p:PackageVersion=${resolverVersion}"
}
}
}
tasks.register('dotnetTest') {
dependsOn = ['dockerup', 'dotnetTestXmlResolver']
}
tasks.register("dotnetTestXmlResolver") {
dependsOn = ['dockerup', 'dotnetBuildXmlResolverData', 'dotnetBuildXmlResolver']
doLast {
exec {
workingDir = projectDir
environment "CSHARP_XMLRESOLVER_PATH", projectDir
commandLine dotnetex, 'test', 'XmlResolver.sln',
'--verbosity', 'Normal', '--configuration', 'Release',
'--no-build',
'/p:CollectCoverage=true',
'/p:CoverletOutputFormat=opencover',
"/p:CoverletOutput=${buildDir}/reports/coverlet/",
'--',
"NUnit.TestOutputXml=${buildDir}/reports/nunit"
}
}
}
tasks.register("dotnetNugetPush") {
dependsOn "dotnetBuild", "dotnetTest"
inputs.files "${projectDir}/XmlResolver/bin/Release/XmlResolver.${resolverVersion}.nupkg"
inputs.files "${projectDir}/XmlResolverData/bin/Release/XmlResolverData.${resolverVersion}.nupkg"
doLast {
exec {
workingDir = projectDir
commandLine dotnetex, "restore", "XmlResolver.sln", "--verbosity", "Normal"
}
}
doLast {
exec {
workingDir = projectDir
commandLine dotnetex, "nuget", "push",
"${projectDir}/XmlResolver/bin/Release/XmlResolver.${resolverVersion}.nupkg",
"--api-key", nugetApiKey, "--source", nugetSource
}
}
doLast {
exec {
workingDir = projectDir
commandLine dotnetex, "restore", "XmlResolverData.sln", "--verbosity", "Normal"
}
}
doLast {
exec {
workingDir = projectDir
commandLine dotnetex, "nuget", "push",
"${projectDir}/XmlResolverData/bin/Release/XmlResolverData.${resolverVersion}.nupkg",
"--api-key", nugetApiKey, "--source", nugetSource
}
}
}
// ======================================================================
docker_container.configure {
workingDir = "docker"
}
tasks.register("dockerup") {
description "Make sure the Docker container is running."
doLast {
if (!DockerContainer.running(c_csrestest)) {
DockerContainer.compose {
command = "up"
options = ["-p", "xmlres"]
args = "-d"
}
}
}
finalizedBy "dockerstatus"
}
tasks.register("dockerdown") {
description "Make sure the Docker container is not running."
doLast {
if (DockerContainer.running(c_csrestest)) {
DockerContainer.compose {
command = "down"
options = ["-p", "xmlres"]
}
}
}
finalizedBy "dockerstatus"
}
tasks.register("dockerstatus") {
description "Print a short summary of running containers"
doLast {
if (DockerContainer.containers().isEmpty()) {
println("There are no docker containers running.")
} else {
DockerContainer.docker( {
command = "ps"
args = ["-a", "--format={{.ID}} {{.Names}} {{.Status}}"]
})
}
}
}
// ======================================================================
task dist(dependsOn: ["dockerup", "dotnetBuild"]) {
// nop, just a place to hang dependencies
}
dist.finalizedBy "dotnetTest"