forked from xspec/xspec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.xml
441 lines (369 loc) · 19.1 KB
/
build.xml
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
<?xml version="1.0" encoding="UTF-8"?>
<!-- ===================================================================== -->
<!-- File: build.xml -->
<!-- Author: Jeni Tennison -->
<!-- Tags: -->
<!-- Copyright (c) 2008, 2010 Jeni Tennison (see end of file.) -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<project name="xspec" default="xspec" xmlns:if="ant:if" xmlns:unless="ant:unless">
<description><![CDATA[
Usage (command-line):
See https://github.com/xspec/xspec/wiki/Running-with-Ant
---
Usage (Oxygen XSLT transformation scenario):
This file can be used in place of Oxygen's ${frameworksDir}/xspec/build.xml
Setup:
- Duplicate Oxygen's default XSpec scenario
- Under Options tab:
- Build file: [this file]
- Under Parameters tab:
- "xspec.project.dir" parameter value: "C:\Git\xspec" for example
- If "catalog" parameter uses ${pdu}, replace it with ${pd}
- New parameters if required (See https://github.com/xspec/xspec/wiki/Running-with-Ant):
- test.type
- xspec.phase
- xspec.fail
]]></description>
<!-- "xspec.project.dir" property: Documented in Wiki. DO NOT RENAME.
Directory where XSpec repository is cloned. -->
<dirname property="xspec.project.dir" file="${ant.file.xspec}" />
<!-- "xspec.properties" property: Documented. DO NOT RENAME.
Absolute or relative path of Ant properties file -->
<property name="xspec.properties" location="${xspec.project.dir}/xspec.properties" />
<property file="${xspec.properties}" />
<!-- "xspec.xml" property: Documented in Wiki. DO NOT RENAME.
No default value. This property is always provided by the user.
This property name is vague. Use the alias property "xspec.xspecfile.original" for internal use. -->
<!-- "saxon.custom.options" property: Documented in Wiki. DO NOT RENAME.
Optional command-line arguments passed to Saxon when running the tests.
For example, -warnings:recover -strip:none -opt:10 -dtd:off -l:off -versionmsg:off -expand:on
-outval:fatal -val:lax
No default value. This property is occasionally provided by the user. -->
<!-- "catalog" property: Documented in Wiki. DO NOT RENAME.
File path (not URL) of XML catalog file -->
<!-- File path of the original XSpec file specified by the user -->
<property name="xspec.xspecfile.original" value="${xspec.xml}" />
<!-- Directory of the original XSpec file -->
<dirname property="xspec.xspecfile.dir" file="${xspec.xspecfile.original}" />
<!-- File name (with extension) of the original XSpec file -->
<basename property="xspec.xspecfile.name" file="${xspec.xspecfile.original}" />
<!-- File name (without extension) of the original XSpec file -->
<basename property="xspec.xspecfile.name.without.xml"
file="${xspec.xspecfile.name}"
suffix=".xml" />
<basename property="xspec.xspecfile.name.without.ext"
file="${xspec.xspecfile.name.without.xml}"
suffix=".xspec" />
<!-- "xspec.dir" property: Documented in Wiki. DO NOT RENAME.
This property name is vague. Use the alias property "xspec.output.dir" for internal use. -->
<property name="xspec.dir" value="${xspec.xspecfile.dir}/xspec" />
<!-- Directory where various output files are created -->
<property name="xspec.output.dir" value="${xspec.dir}" />
<!-- File path of the XML report file -->
<property name="xspec.result.xml"
value="${xspec.output.dir}/${xspec.xspecfile.name.without.ext}-result.xml" />
<!-- "xspec.result.html" property: Used by Oxygen default transformation. DO NOT RENAME.
File path of the HTML report file -->
<property name="xspec.result.html"
value="${xspec.output.dir}/${xspec.xspecfile.name.without.ext}-result.html" />
<!-- "clean.output.dir" property: Documented in Wiki. DO NOT RENAME.
Controls whether to delete the output files -->
<property name="clean.output.dir" value="false" />
<!-- File path of XSLT file for formatting the HTML report file. -->
<property name="xspec.reporter.xsl"
value="${xspec.project.dir}/src/reporter/format-xspec-report.xsl" />
<!-- "test.type" property: Documented in Wiki. DO NOT RENAME.
Specifies XSLT, XQuery or Schematron -->
<property name="test.type" value="t" />
<!-- Properties indicating whether the test type is a specific type -->
<condition property="xspec.is.schematron" else="false">
<equals arg1="${test.type}" arg2="s" />
</condition>
<condition property="xspec.is.xquery" else="false">
<equals arg1="${test.type}" arg2="q" />
</condition>
<condition property="xspec.is.xslt" else="false">
<equals arg1="${test.type}" arg2="t" />
</condition>
<!-- "xspec.fail" property: Documented in Wiki. DO NOT RENAME.
Controls whether to make the build fail when one or more tests failed -->
<property name="xspec.fail" value="true" />
<!-- File path of the XSpec file after preprocessing.
XSLT and XQuery: This property is just the alias of the original XSpec file.
Schematron: This file is created while preprocessing at "STEP 4" and deleted by cleanup. -->
<condition property="xspec.xspecfile.preprocessed"
value="${xspec.xspecfile.original}-compiled.xspec"
else="${xspec.xspecfile.original}">
<istrue value="${xspec.is.schematron}" />
</condition>
<!-- Catalog URL.
To work around a Saxon bug, it must be URL: https://saxonica.plan.io/issues/3025#note-8
To debug catalog resolution, -Dsaxon.custom.options=-t would help.
Oxygen 20 default transformation scenario sets catalog even when file does not exist. Hence
validate=false. -->
<makeurl property="xspec.catalog.url" file="${catalog}" validate="false" if:set="catalog" />
<!-- File path of the compiled XSLT/XQuery file that finally runs the tests -->
<property name="xspec.compiled.runner.without.ext"
value="${xspec.output.dir}/${xspec.xspecfile.name.without.ext}" />
<condition property="xspec.compiled.runner"
value="${xspec.compiled.runner.without.ext}.xq"
else="${xspec.compiled.runner.without.ext}.xsl">
<istrue value="${xspec.is.xquery}" />
</condition>
<!-- Converts URL to file path -->
<scriptdef name="makepath" language="javascript" src="${xspec.project.dir}/src/ant/make-path.js">
<attribute name="url" />
<attribute name="property" />
</scriptdef>
<!-- Performs XSLT using Saxon with common parameters including catalog -->
<macrodef name="saxon-xslt">
<attribute name="in" />
<attribute name="out" />
<attribute name="style" />
<element name="factory-elements" optional="true" />
<element name="xslt-elements" optional="true" />
<sequential>
<xslt in="@{in}" out="@{out}" style="@{style}" force="true">
<factory name="net.sf.saxon.TransformerFactoryImpl">
<factory-elements />
<!-- For debugging -->
<!--<attribute name="http://saxon.sf.net/feature/timing"
value="true"/>-->
</factory>
<xmlcatalog if:set="catalog">
<catalogpath>
<pathelement location="${catalog}" />
</catalogpath>
</xmlcatalog>
<xslt-elements />
</xslt>
</sequential>
</macrodef>
<!-- Transforms the input XML using the given XSLT and loads the output XML as Ant properties -->
<macrodef name="xml-to-properties">
<attribute name="in" />
<attribute name="style" />
<sequential>
<!-- <tempfile deleteonexit=false> accumulates temp files. <tempfile deleteonexit=true> makes
debugging a bit harder. Hence a fixed path. -->
<property name="xspec.xml-to-properties.temp"
value="${xspec.output.dir}/${xspec.xspecfile.name.without.ext}_xml-to-properties.xml" />
<saxon-xslt in="@{in}"
out="${xspec.xml-to-properties.temp}"
style="${xspec.project.dir}/src/ant/@{style}" />
<xmlproperty file="${xspec.xml-to-properties.temp}" />
</sequential>
</macrodef>
<!-- Prepares the environment before compilation -->
<target name="init">
<echo message="Testing ${xspec.xspecfile.name} [${test.type}]" />
<!-- Verify "test.type" -->
<fail message="Invalid test.type: '${test.type}'">
<condition>
<and>
<isfalse value="${xspec.is.schematron}" />
<isfalse value="${xspec.is.xquery}" />
<isfalse value="${xspec.is.xslt}" />
</and>
</condition>
</fail>
<!-- Verify .xspec file existence, to avoid creating a useless output directory -->
<available property="xspec.xspecfile.is.available"
file="${xspec.xspecfile.original}" type="file" />
<fail message="XSpec file not found: '${xspec.xspecfile.original}'"
unless="xspec.xspecfile.is.available" />
<!-- Create the output directory.
Need to retry, for the creation may fail temporarily while running the build repeatedly
with clean.output.dir=true. -->
<retry retrycount="2" retrydelay="1000">
<mkdir dir="${xspec.output.dir}" />
</retry>
</target>
<!-- Gets the file path (not URL) of the Schematron file -->
<target name="locate-schematron-file" if="${xspec.is.schematron}">
<xml-to-properties in="${xspec.xspecfile.original}" style="locate-schematron.xsl" />
<makepath property="xspec.schematron.file" url="${xspec.schematron.uri}" />
<echo message="Path of Schematron file: ${xspec.schematron.file}"
level="info" />
</target>
<!-- Gets the Schematron phase defined in the XSpec file, if no phase was specified by the user.
Gets a zero-length string when the phase is not defined in the XSpec file. -->
<target name="get-schematron-phase" if="${xspec.is.schematron}" unless="xspec.phase">
<xml-to-properties in="${xspec.xspecfile.original}" style="get-schematron-phase.xsl" />
<echo message="Schematron phase set in XSpec: '${xspec.phase}'"
level="info"
unless:blank="${xspec.phase}" />
</target>
<!-- Preprocesses the XSpec file for Schematron -->
<target name="preprocess-schematron"
depends="locate-schematron-file, get-schematron-phase"
if="${xspec.is.schematron}">
<!-- Location of the temporary files -->
<property name="xspec.schematron.preprocessed.step1"
value="${xspec.output.dir}/${xspec.xspecfile.name.without.ext}-sch-temp1.xml" />
<property name="xspec.schematron.preprocessed.step2"
value="${xspec.output.dir}/${xspec.xspecfile.name.without.ext}-sch-temp2.xml" />
<!-- Location of the preprocessed Schematron XSL file.
Since the original Schematron file may reference other files at relative paths,
the preprocessed XSL file needs to go in the same folder as the original Schematron file.
This file is created at "STEP 3" and deleted by cleanup. -->
<property name="xspec.schematron.preprocessed.xsl.file"
value="${xspec.schematron.file}-compiled.xsl" />
<echo message="STEP 1: Include modules"
level="info" />
<saxon-xslt in="${xspec.schematron.file}"
out="${xspec.schematron.preprocessed.step1}"
style="${xspec.project.dir}/src/schematron/iso-schematron/iso_dsdl_include.xsl" />
<echo message="STEP 2: Expand abstracts"
level="info" />
<saxon-xslt in="${xspec.schematron.preprocessed.step1}"
out="${xspec.schematron.preprocessed.step2}"
style="${xspec.project.dir}/src/schematron/iso-schematron/iso_abstract_expand.xsl" />
<echo message="STEP 3: Convert Schematron to XSLT"
level="info" />
<echo message="phase=${xspec.phase}"
level="info"
unless:blank="${xspec.phase}" />
<saxon-xslt in="${xspec.schematron.preprocessed.step2}"
out="${xspec.schematron.preprocessed.xsl.file}"
style="${xspec.project.dir}/src/schematron/iso-schematron/iso_svrl_for_xslt2.xsl">
<xslt-elements>
<!-- TODO: Parameters should be gathered from .xspec file -->
<param name="allow-foreign" expression="true" />
<param name="phase" expression="${xspec.phase}" unless:blank="${xspec.phase}" />
</xslt-elements>
</saxon-xslt>
<makeurl property="xspec.schematron.preprocessed.xsl.url"
file="${xspec.schematron.preprocessed.xsl.file}" />
<makeurl property="xspec.output.dir.url"
file="${xspec.output.dir}" />
<echo message="STEP 4: Convert XSpec into another XSpec that references the generated XSLT"
level="info" />
<saxon-xslt in="${xspec.xspecfile.original}"
out="${xspec.xspecfile.preprocessed}"
style="${xspec.project.dir}/src/schematron/schut-to-xspec.xsl">
<xslt-elements>
<param name="stylesheet" expression="${xspec.schematron.preprocessed.xsl.url}" />
<param name="test_dir" expression="${xspec.output.dir.url}" />
</xslt-elements>
</saxon-xslt>
</target>
<!-- Compiles the XSpec file into the test runner file written in XSLT or XQuery -->
<target name="compile" depends="init, preprocess-schematron">
<condition property="xspec.compiler.xsl"
value="generate-query-tests.xsl"
else="generate-xspec-tests.xsl">
<istrue value="${xspec.is.xquery}" />
</condition>
<echo message="Compiling Tests..."
level="info" />
<saxon-xslt in="${xspec.xspecfile.preprocessed}"
out="${xspec.compiled.runner}"
style="${xspec.project.dir}/src/compiler/${xspec.compiler.xsl}" />
</target>
<!-- Runs the compiled XSpec for XQuery -->
<target name="run-xquery-test" depends="compile" if="${xspec.is.xquery}">
<echo message="Running XQuery Tests..."
level="info" />
<!-- Can't specify saxon.custom.options with <xslt> task so have to
fall back to running Saxon as Java app. -->
<java classname="net.sf.saxon.Query" fork="true" failonerror="true">
<!-- Saxon should be included in the classpath -->
<classpath>
<pathelement path="${java.class.path}" />
</classpath>
<arg line="${saxon.custom.options}" if:set="saxon.custom.options" />
<arg value="-catalog:${xspec.catalog.url}" if:set="catalog" />
<arg value="-o:${xspec.result.xml}" />
<arg value="-s:${xspec.xspecfile.preprocessed}" />
<arg value="-q:${xspec.compiled.runner}" />
</java>
</target>
<!-- Runs the compiled XSpec for XSLT -->
<target name="run-xslt-test" depends="compile" unless="${xspec.is.xquery}">
<echo message="Running XSLT Tests..."
level="info" />
<!-- Can't specify saxon.custom.options with <xslt> task so have to
fall back to running Saxon as Java app. -->
<java classname="net.sf.saxon.Transform" fork="true" failonerror="true">
<!-- Saxon should be included in the classpath -->
<classpath>
<pathelement path="${java.class.path}" />
</classpath>
<arg line="${saxon.custom.options}" if:set="saxon.custom.options" />
<arg value="-catalog:${xspec.catalog.url}" if:set="catalog" />
<arg value="-it:{http://www.jenitennison.com/xslt/xspec}main" />
<arg value="-ext:on" />
<arg value="-o:${xspec.result.xml}" />
<arg value="-s:${xspec.xspecfile.preprocessed}" />
<arg value="-xsl:${xspec.compiled.runner}" />
</java>
</target>
<!-- Main target -->
<target name="xspec"
description="Generates the result of XSpec tests"
depends="run-xquery-test, run-xslt-test">
<saxon-xslt in="${xspec.result.xml}"
out="${xspec.result.html}"
style="${xspec.reporter.xsl}">
<factory-elements>
<attribute name="http://saxon.sf.net/feature/allow-external-functions"
value="true"/>
</factory-elements>
<xslt-elements>
<param name="inline-css" expression="true" />
</xslt-elements>
</saxon-xslt>
<antcall target="fail" />
<antcall target="cleanup" />
</target>
<!-- Makes the build fail, unless otherwise specified -->
<target name="fail" if="${xspec.fail}">
<xml-to-properties in="${xspec.result.xml}" style="find-test-failure.xsl" />
<fail message="XSpec tests failed. See ${xspec.result.html} for a report.">
<condition>
<not>
<istrue value="${xspec.passed}" />
</not>
</condition>
</fail>
</target>
<!-- Cleans up the output files, if required-->
<target name="cleanup" if="${clean.output.dir}">
<echo message="Clean up"
level="info" />
<!-- Need to retry, for someone may still hold a file, which tends to happen on AppVeyor. -->
<retry retrycount="1" retrydelay="1000">
<delete dir="${xspec.output.dir}" />
</retry>
<delete file="${xspec.xspecfile.preprocessed}" if:true="${xspec.is.schematron}" />
<delete file="${xspec.schematron.preprocessed.xsl.file}" />
</target>
</project>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS COMMENT. -->
<!-- -->
<!-- Copyright (c) 2008, 2010 Jeni Tennison -->
<!-- -->
<!-- The contents of this file are subject to the MIT License (see the URI -->
<!-- http://www.opensource.org/licenses/mit-license.php for details). -->
<!-- -->
<!-- Permission is hereby granted, free of charge, to any person obtaining -->
<!-- a copy of this software and associated documentation files (the -->
<!-- "Software"), to deal in the Software without restriction, including -->
<!-- without limitation the rights to use, copy, modify, merge, publish, -->
<!-- distribute, sublicense, and/or sell copies of the Software, and to -->
<!-- permit persons to whom the Software is furnished to do so, subject to -->
<!-- the following conditions: -->
<!-- -->
<!-- The above copyright notice and this permission notice shall be -->
<!-- included in all copies or substantial portions of the Software. -->
<!-- -->
<!-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -->
<!-- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -->
<!-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.-->
<!-- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -->
<!-- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -->
<!-- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -->
<!-- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->