forked from itplr-kosit/xrechnung-schematron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.xml
415 lines (361 loc) · 16.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
<project name="xrechnung-schematron" default="compile-schematron-rules"
basedir=".">
<description>Build XRechnung Schematron Rules</description>
<!-- set global default properties for this build -->
<!-- main build directories -->
<property name="src.dir" location="${basedir}/src" />
<property name="validation.dir" location="${src.dir}/validation" />
<property name="lib.dir" location="${basedir}/lib" />
<property name="build.dir" location="${basedir}/build" />
<property name="download.dir" location="${build.dir}/download" />
<property name="dist.dir" location="${basedir}/dist" />
<property name="tools.dir" location="${basedir}/tools" />
<property name="test.src.dir" location="${basedir}/test/instances" />
<property name="test.build.dir" location="${build.dir}/test" />
<property name="bis.build.dir" location="${basedir}/build/bis" />
<property name="xr-schematron.build.dir" location="${build.dir}/schematron" />
<!-- Naming -->
<property name="xr-schematron.version.full" value="2.2.0" />
<property name="xrechnung.version" value="3.0.2" />
<property name="dist.name"
value="xrechnung-${xrechnung.version}-schematron-${xr-schematron.version.full}" />
<property name="saxon.jar" value="saxon9he.jar" />
<property name="xmute.version.full" value="0.5" />
<property name="xmute.jar" value="xml-mutate.jar" />
<property name="bis.version" value="3.0.17" />
<property name="bis.zip" value="${bis.version}.zip" />
<property name="bis.download.url"
value="https://github.com/OpenPEPPOL/peppol-bis-invoice-3/archive/refs/tags/${bis.zip}" />
<property name="xr-schematron.zip" value="${dist.name}.zip" />
<macrodef name="schematron-compile"
description="Compiles Schematron to XSLT using Saxon">
<attribute name="schematron" description="Schematron file to compile." />
<attribute name="workdir"
description="Base directory in which to download Schematron Skeleton and keep intermediaries." />
<attribute name="outdir" />
<attribute name="overwrite" default="false" />
<attribute name="insuffix" default="sch" />
<attribute name="saxon.jar" default="${lib.dir}/${saxon.jar}"
description="Location of Saxon jar." />
<attribute name="deleteonexit" default="true"
description="Whether to delete intermediate XSLT files on exit. Note if not deleting, then subsequent runs of macro produce wrong results!" />
<attribute name="schematronbinding" default="xslt2"
description="Which XSLT version to build for." />
<sequential>
<local name="schematron.basename" />
<basename file="@{schematron}" suffix="@{insuffix}"
property="schematron.basename" />
<echo
message="Compiling '@{schematron}' Schematron with basename='${schematron.basename}'" />
<mkdir dir="@{workdir}" />
<tempfile property="expanded.sch" prefix="expanded" suffix=".sch"
destdir="@{workdir}" deleteonexit="@{deleteonexit}" />
<tempfile property="unabstract.sch" prefix="unabstract" suffix=".sch"
destdir="@{workdir}" deleteonexit="@{deleteonexit}" />
<tempfile property="schematron.xsl" prefix="schematron" suffix=".xsl"
destdir="@{workdir}" deleteonexit="@{deleteonexit}" />
<tempfile property="check-schematron.xsl" prefix="check-schematron"
suffix=".xsl" destdir="@{workdir}" deleteonexit="@{deleteonexit}" />
<!-- Download schematron skeletons -->
<property name="schematron.skeleton.url"
value="https://raw.githubusercontent.com/Schematron/schematron/master/trunk/schematron/code" />
<get src="${schematron.skeleton.url}/iso_dsdl_include.xsl"
dest="@{workdir}" verbose="true" skipexisting="true" usetimestamp="true"
httpusecaches="true" />
<get src="${schematron.skeleton.url}/iso_abstract_expand.xsl"
dest="@{workdir}" verbose="true" skipexisting="true" usetimestamp="true"
httpusecaches="true" />
<get
src="${schematron.skeleton.url}/iso_svrl_for_@{schematronbinding}.xsl"
dest="@{workdir}" verbose="true" skipexisting="true" usetimestamp="true"
httpusecaches="true" />
<get
src="${schematron.skeleton.url}/iso_schematron_skeleton_for_saxon.xsl"
dest="@{workdir}" verbose="true" skipexisting="true" usetimestamp="true"
httpusecaches="true" />
<!-- expand inclusions -->
<xslt style="@{workdir}/iso_dsdl_include.xsl" in="@{schematron}"
out="@{workdir}/${schematron.basename}-expanded.sch"
classpath="@{saxon.jar}" force="@{overwrite}">
<factory name="net.sf.saxon.TransformerFactoryImpl" />
</xslt>
<!-- expand abstract patterns -->
<xslt style="@{workdir}/iso_abstract_expand.xsl"
in="@{workdir}/${schematron.basename}-expanded.sch"
out="@{workdir}/${schematron.basename}-unabstract.sch"
classpath="@{saxon.jar}" force="@{overwrite}">
<factory name="net.sf.saxon.TransformerFactoryImpl" />
</xslt>
<!-- svrl it -->
<xslt style="@{workdir}/iso_svrl_for_@{schematronbinding}.xsl"
in="@{workdir}/${schematron.basename}-unabstract.sch"
out="@{outdir}/${schematron.basename}.xsl" classpath="@{saxon.jar}"
force="@{overwrite}">
<factory name="net.sf.saxon.TransformerFactoryImpl" />
<param name="generate-fired-rule" expression="true" />
<param name="full-path-notation" expression="3" />
</xslt>
<echo
message="finished schematron compile output to @{outdir}/${schematron.basename}.xsl"
/>
</sequential>
</macrodef>
<target name="init"
description="Initializes build directory structure and ISO timestamp">
<!-- Create timestamps -->
<tstamp>
<format property="build.date" pattern="yyyy-MM-dd" />
</tstamp>
<echo>Build date: ${build.date}</echo>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build.dir}" />
<mkdir dir="${download.dir}" />
<mkdir dir="${lib.dir}" />
<mkdir dir="${dist.dir}" />
<mkdir dir="${build.dir}/generated" />
<mkdir dir="${build.dir}/bis" />
</target>
<target name="retrieve-xmute" depends="init">
<fail unless="xmute.download.url.prefix"
message="Property xmute.download.url.prefix must exist for this target to work" />
<get src="${xmute.download.url.prefix}/xml-mutate-${xmute.version.full}.jar"
dest="${lib.dir}/${xmute.jar}" verbose="true" skipexisting="false"
usetimestamp="true" />
</target>
<target name="prepare-saxon" depends="init"
description="Download Saxon-HE and add jar to library directory">
<get
src="https://sourceforge.net/projects/saxon/files/Saxon-HE/9.9/SaxonHE9-9-1-8J.zip/download"
dest="${download.dir}/SaxonHE9-9-1-8J.zip" verbose="true"
skipexisting="true" usetimestamp="true" />
<unzip src="${download.dir}/SaxonHE9-9-1-8J.zip" dest="${lib.dir}">
<patternset>
<include name="**/${saxon.jar}" />
</patternset>
<flattenmapper />
</unzip>
</target>
<target name="prepare-build-dir" depends="init"
description="Works for zip from master and release zips">
<filter token="xr-schematron.version.full"
value="${xr-schematron.version.full}" />
<filter token="xrechnung.version" value="${xrechnung.version}" />
<copy todir="${build.dir}/schematron"
file="${validation.dir}/schematron/common.sch" />
<copy todir="${build.dir}" filtering="true">
<fileset dir="${basedir}">
<include name="README.md" />
<include name="CHANGELOG.md" />
<include name="LICENSE" />
</fileset>
</copy>
</target>
<target name="retrieve-peppol-bis-billing-rules" depends="init"
description="Download and prepare Peppol BIS Billing 3.0 rules">
<echo
message="Loading Peppol BIS Billing ${bis.version} from ${bis.download.url}" />
<get src="${bis.download.url}" dest="${download.dir}" verbose="true"
skipexisting="true" usetimestamp="false" httpusecaches="false" />
<fail message="No Peppol BIS Billing zip file available">
<condition>
<not>
<resourceexists>
<file file="${download.dir}/${bis.zip}" />
</resourceexists>
</not>
</condition>
</fail>
<echo message="Unpacking Peppol BIS Billing ${bis.version} from ${bis.zip}" />
<unzip src="${download.dir}/${bis.zip}" dest="${build.dir}/bis"
failonemptyarchive="true">
<patternset>
<include name="**/PEPPOL-EN16931-*.sch" />
</patternset>
<flattenmapper />
</unzip>
<path id="schematron-path">
<fileset dir="${build.dir}/bis" includes="**.sch" />
</path>
<fail message="Could not extract PEPPOL BIS Billing rules">
<condition>
<or>
<not>
<available file="PEPPOL-EN16931-UBL.sch">
<filepath refid="schematron-path" />
</available>
</not>
<not>
<available file="PEPPOL-EN16931-CII.sch">
<filepath refid="schematron-path" />
</available>
</not>
</or>
</condition>
</fail>
</target>
<target name="merge-peppol-rules-with-xr-rules"
depends="retrieve-peppol-bis-billing-rules">
<!-- merge ubl -->
<xslt in="${validation.dir}/schematron/ubl/XRechnung-UBL-validation.sch"
out="${xr-schematron.build.dir}/ubl/XRechnung-UBL-validation.sch"
style="${src.dir}/xsl/peppol-into-xr.xsl">
<param name="syntax" expression="UBL" />
<classpath>
<pathelement location="${lib.dir}/${saxon.jar}" />
</classpath>
<factory name="net.sf.saxon.TransformerFactoryImpl" />
</xslt>
<!-- merge cii -->
<xslt in="${validation.dir}/schematron/cii/XRechnung-CII-validation.sch"
out="${xr-schematron.build.dir}/cii/XRechnung-CII-validation.sch"
style="${src.dir}/xsl/peppol-into-xr.xsl">
<param name="syntax" expression="CII" />
<classpath>
<pathelement location="${lib.dir}/${saxon.jar}" />
</classpath>
<factory name="net.sf.saxon.TransformerFactoryImpl" />
</xslt>
</target>
<target name="check-merge-peppol-rules-with-xr-rules"
depends="merge-peppol-rules-with-xr-rules">
<mkdir dir="${xr-schematron.build.dir}/tmp"/>
<!-- failonerror must be yes -->
<!-- check ubl -->
<xslt in="${xr-schematron.build.dir}/ubl/XRechnung-UBL-validation.sch"
out="${xr-schematron.build.dir}/tmp/ubl.out"
style="${src.dir}/xsl/check-schematron-asserts.xsl" failonerror="yes">
<classpath>
<pathelement location="${lib.dir}/${saxon.jar}" />
</classpath>
<factory name="net.sf.saxon.TransformerFactoryImpl" />
</xslt>
<!-- check cii -->
<xslt in="${xr-schematron.build.dir}/cii/XRechnung-CII-validation.sch"
out="${xr-schematron.build.dir}/tmp/cii.out"
style="${src.dir}/xsl/check-schematron-asserts.xsl" failonerror="yes">
<classpath>
<pathelement location="${lib.dir}/${saxon.jar}" />
</classpath>
<factory name="net.sf.saxon.TransformerFactoryImpl" />
</xslt>
</target>
<target name="merge-peppol-xr-rules"
depends="retrieve-peppol-bis-billing-rules, merge-peppol-rules-with-xr-rules, check-merge-peppol-rules-with-xr-rules">
<echo>Retrieving, merging and checking Peppol with XR Rules</echo>
</target>
<target name="compile-schematron-rules"
depends="prepare-saxon, prepare-build-dir, merge-peppol-xr-rules"
description="Compiling schematron rules">
<schematron-compile
schematron="${build.dir}/schematron/cii/XRechnung-CII-validation.sch"
insuffix="sch" workdir="${download.dir}"
outdir="${build.dir}/schematron/cii" deleteonexit="false" overwrite="true" />
<schematron-compile
schematron="${build.dir}/schematron/ubl/XRechnung-UBL-validation.sch"
insuffix="sch" workdir="${download.dir}"
outdir="${build.dir}/schematron/ubl" deleteonexit="false" overwrite="true"
/>
</target>
<target name="transform-xr-rules-to-peppol-nrs"
depends="prepare-saxon, prepare-build-dir">
<xslt in="${validation.dir}/schematron/ubl/XRechnung-UBL-validation.sch"
out="${build.dir}/national-rules/XRechnung-UBL-NRS.sch"
style="${tools.dir}/xr-2-peppol-bis-billing-nrs.xsl">
<classpath>
<pathelement location="${lib.dir}/${saxon.jar}" />
</classpath>
<factory name="net.sf.saxon.TransformerFactoryImpl" />
</xslt>
</target>
<target name="compile" depends="compile-schematron-rules"
description="Compiling Schematron rules from sources"> </target>
<target name="check-xmute-available" depends="retrieve-xmute">
<fail message="You must have xml-mutate installed in ${lib.dir}">
<condition>
<not>
<available file="${lib.dir}/${xmute.jar}" />
</not>
</condition>
</fail>
</target>
<target name="test-single-file" depends="compile-schematron-rules"
description="Unit testing Schematron Rules with XML-Mutate">
<echo>Unit testing Schematron rules ...</echo>
<java jar="${lib.dir}/${xmute.jar}" failonerror="yes" fork="yes"
dir="${basedir}">
<arg value="--target" />
<arg value="${build.dir}/generated" />
<!-- Has no impact -->
<arg value="--fail-fast" />
<arg value="--schematron" />
<arg
value="xrubl=${build.dir}/schematron/ubl/XRechnung-UBL-validation.xsl" />
<arg value="--schematron" />
<arg
value="xrcii=${build.dir}/schematron/cii/XRechnung-CII-validation.xsl" />
<arg value="test/instances/${test.file.name}" />
</java>
</target>
<target name="test-only"
description="Unit testing Schematron Rules wit XML-Mutate">
<echo>Unit testing Schematron rules ...</echo>
<java jar="${lib.dir}/${xmute.jar}" failonerror="yes" fork="yes"
dir="${basedir}">
<arg value="--target" />
<arg value="${build.dir}/generated" />
<!-- Has no impact -->
<arg value="--fail-fast" />
<arg value="--schematron" />
<arg
value="xrubl=${build.dir}/schematron/ubl/XRechnung-UBL-validation.xsl" />
<arg value="--schematron" />
<arg
value="xrcii=${build.dir}/schematron/cii/XRechnung-CII-validation.xsl" />
<arg value="test/instances/ubl-inv/" />
<arg value="test/instances/ubl-cn/" />
<arg value="test/instances/cii/" />
</java>
</target>
<target name="update-spec-id"
description="Updating Specification IDs for tests">
<echo>Checking Specification IDs</echo>
<!-- get fileset -->
<mkdir dir="${test.build.dir}/tmp" />
<xslt basedir="${test.src.dir}" destdir="${test.build.dir}/tmp"
style="${src.dir}/xsl/normalization.xsl"
classpath="${lib.dir}/${saxon.jar}" extension=".xml">
<factory name="net.sf.saxon.TransformerFactoryImpl" />
<param name="xr-version" expression="_3.0" />
</xslt>
<copy todir="test/instances" overwrite="true">
<fileset dir="${test.build.dir}/tmp" />
</copy>
<delete dir="${test.build.dir}/tmp" />
</target>
<target name="remove-xsi-schema-location"
description="Removing xsi namespace declarations and schemaLocations">
<mkdir dir="${build.dir}/tmp" />
<xslt basedir="${test.src.dir}" destdir="${build.dir}/tmp"
style="${src.dir}/xsl/normalization.xsl"
classpath="${lib.dir}/${saxon.jar}" extension=".xml">
<factory name="net.sf.saxon.TransformerFactoryImpl" />
</xslt>
</target>
<target name="test"
depends="retrieve-xmute, check-xmute-available, compile, transform-xr-rules-to-peppol-nrs, test-only"
description="Unit testing Schematron Rules wit XML-Mutate" />
<target name="dist-only" depends="compile"
description="Generate the distribution">
<zip destfile="${dist.dir}/${xr-schematron.zip}" basedir="${build.dir}"
excludes="download/**,schematron/tmp/**,bis/**,generated/**,national-rules/**"
/>
</target>
<target name="dist" depends="test,dist-only"
description="Generate the distribution">
</target>
<target name="clean" description="clean up">
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build.dir}" verbose="true" includeEmptyDirs="true" />
<delete dir="${dist.dir}" verbose="true" includeEmptyDirs="true" />
</target>
</project>