forked from heremaps/com.here.validate.svrl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_dita2svrl_template.xml
419 lines (403 loc) · 13 KB
/
build_dita2svrl_template.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
<?xml version="1.0" encoding="UTF-8"?>
<!--ant-->
<!--
This file is part of the DITA Validator project.
See the accompanying LICENSE file for applicable licenses.
-->
<project
xmlns:dita="http://dita-ot.sourceforge.net"
name="com.here.validate.svrl"
>
<!--
Setting up schematron processing. Sets up ant variable defaults
-->
<target
dita:extension="depends org.dita.dost.platform.InsertDependsAction"
description="Preprocess"
dita:depends="{depend.preprocess.pre},
build-init,
{depend.preprocess.post}"
name="svrl.init"
>
<!-- This defines the output file -->
<dita-ot-fail id="DOTA069F">
<condition>
<not>
<available file="${args.input}" type="file"/>
</not>
</condition>
<param name="1" value="${args.input}"/>
</dita-ot-fail>
<!-- This defines the output file -->
<basename file="${args.input}" property="svrl.filename.root" suffix=".ditamap"/>
<dirname property="args.input.dir" file="${args.input}"/>
<path id="svrl.classpath">
<fileset dir="${dita.plugin.com.here.validate.svrl.dir}/lib">
<include name="*.jar"/>
<exclude name="ant*.jar"/>
<exclude name="validate-1.0.jar"/>
</fileset>
<pathelement location="${dita.dir}/lib/ant-launcher.jar"/>
<pathelement location="${dita.dir}/lib/ant.jar"/>
</path>
<taskdef resource="com/here/validate/antlib.xml"/>
<taskdef classname="com.oopsconsultancy.xmltask.ant.XmlTask" name="xmltask">
<classpath>
<pathelement location="${dita.plugin.com.here.validate.svrl.dir}/lib/xmltask.jar"/>
</classpath>
</taskdef>
<!-- Use the default location for the schematron customization if this is not set -->
<property
name="svrl.customization.dir"
value="${dita.plugin.com.here.validate.svrl.dir}/xsl"
/>
<property
name="svrl.filter.file"
value="${dita.plugin.com.here.validate.svrl.dir}/xsl/schematron-output.xsl"
/>
<property
name="svrl.result.file"
value="${dita.plugin.com.here.validate.svrl.dir}/xsl/schematron-result.xsl"
/>
<!-- Create a dummy cache file to use if cache parameter is not set -->
<tempfile
deleteonexit="true"
destdir="${dita.temp.dir}"
property="svrl.cache.file"
/>
<property name="args.validate.cachefile" value="${svrl.cache.file}"/>
<!--
Use the default severity for each rule unless an override has been set.
-->
<property
name="svrl.ruleset.file"
value="${dita.plugin.com.here.validate.svrl.dir}/cfg/ruleset/default.xml"
/>
<property
name="svrl.fixable.file"
value="${dita.plugin.com.here.validate.svrl.dir}/cfg/ruleset/fix-macros.xml"
/>
<!--
The property args.input.dir should hold the folder for the document e.g
de_guide, release_notes etc. This will allow the validator to scan all *.dita
files belonging to a document.
-->
<property name="args.validate.ignore.rules" value=""/>
<property
name="args.validate.blacklist"
value="(kilo)?metre|colour|teh|seperate"
/>
<property
name="args.validate.check.case"
value="Bluetooth|HTTP|HTTPS|IoT|JSON|Java|Javadoc|JavaScript|XML|HTML"
/>
<!-- Default value if no value is passed is 'true' -->
<condition property="com.here.validate.svrl.output.rule-id" value="true">
<or>
<not>
<isset property="args.validate.output.rule-id"/>
</not>
<istrue value="${args.validate.output.rule-id}"/>
</or>
</condition>
<condition property="com.here.validate.svrl.output.rule-id" value="false">
<isfalse value="${args.validate.output.rule-id}"/>
</condition>
<property name="args.validate.mode" value="default"/>
<!-- Output to Std Out if not running a report -->
<condition property="svrl.echo.output">
<or>
<equals arg1="${args.validate.mode}" arg2="strict"/>
<equals arg1="${args.validate.mode}" arg2="default"/>
<equals arg1="${args.validate.mode}" arg2="lax"/>
</or>
</condition>
<condition property="svrl.fix.output">
<equals arg1="${args.validate.mode}" arg2="fix-dita"/>
</condition>
<!-- Create SVRL report file if requested -->
<condition
property="svrl.report.file"
value="${output.dir}/${svrl.filename.root}.svrl"
>
<not>
<isset property="svrl.echo.output"/>
</not>
</condition>
<tempfile
deleteonexit="true"
destdir="${dita.temp.dir}"
property="svrl.report.file"
/>
<property name="com.here.validate.svrl.mode" value="${args.validate.mode}"/>
<condition property="is_windows">
<os family="windows"/>
</condition>
<copy todir="${dita.temp.dir}/dita">
<fileset dir="${args.input.dir}"/>
</copy>
</target>
<target if="is_windows" name="strip-doctype">
<!-- Windows only -->
<replaceregexp flags="g" match=".*(<!ENTITY).+" replace="">
<fileset dir="${dita.temp.dir}/dita">
<include name="**/*.dita"/>
<include name="**/*.ditamap"/>
</fileset>
</replaceregexp>
<replaceregexp match="(<!DOCTYPE).+\n*\]?>" replace="">
<fileset dir="${dita.temp.dir}/dita">
<include name="**/*.dita"/>
<include name="**/*.ditamap"/>
</fileset>
</replaceregexp>
<replaceregexp match="(<!DOCTYPE).+\n*.*.dtd".*>" replace="">
<fileset dir="${dita.temp.dir}/dita">
<include name="**/*.dita"/>
<include name="**/*.ditamap"/>
</fileset>
</replaceregexp>
</target>
<!--
Ensure that all *.dita files found within the ${args.input.dir} are valid XML
For efficiency, run DTD Validation against modified files only, if requested.
Do not update the cache yet.
-->
<target name="validate-against-doctype" unless="is_windows">
<dita-ot-echo id="SVRL002I">
<param name="1" value="Running DTD validation"/>
</dita-ot-echo>
<xmlvalidate
taskname="validate-files"
failonerror="true"
lenient="no"
warn="yes"
>
<xmlcatalog refid="dita.catalog"/>
<fileset dir="${args.input.dir}">
<include name="**/*.dita"/>
<modified update="false">
<param name="cache.cachefile" value="${args.validate.cachefile}"/>
</modified>
</fileset>
</xmlvalidate>
</target>
<!--
Runs a simple find and replace regex over errors that have been discovered.
-->
<target if="svrl.fix.output" name="svrl.fix-dita">
<dita-ot-echo id="SVRL002I">
<param name="1" value="Correcting markup of DITA Files"/>
</dita-ot-echo>
<tempfile
destdir="${dita.temp.dir}"
property="auto-correct.xml"
suffix=".xml"
deleteonexit="true"
/>
<get-fixable-rules file="${svrl.fixable.file}" fixable="fixable.rules"/>
<xslt
taskname="gen-ant"
basedir="${svrl.dir}"
style="${dita.plugin.com.here.validate.svrl.dir}/xsl/auto-correct-output.xsl"
in="${svrl.report.file}"
out="${auto-correct.xml}"
>
<param expression="${dita.dir}" name="DITA_DIR"/>
<param expression="${args.input.dir}" name="SOURCE"/>
<param expression="${fixable.rules}" name="FIXABLE_RULESET"/>
</xslt>
<ant antfile="${auto-correct.xml}">
<property name="dir" value="${args.input.dir}"/>
</ant>
<!-- Fix Markdown and DITA files -->
<dita-ot-echo id="SVRL002I">
<param name="1" value="Correcting markup of Markdown and MDITA Files"/>
</dita-ot-echo>
<fix-markdown dir="${args.input.dir}" todir="${args.input.dir}">
<fileset dir="${dita.temp.dir}/dita" casesensitive="yes">
<include name="**/*.md"/>
<include name="**/*.mdita"/>
</fileset>
</fix-markdown>
</target>
<!--
Creates a set of SVRL files based on the rule set.
-->
<target
depends="svrl.init, strip-doctype, validate-against-doctype"
name="svrl"
>
<dita-ot-echo id="SVRL002I">
<param name="1" value="Running Schematron Ruleset"/>
</dita-ot-echo>
<get-validation-rulesets
error="ruleset.error"
fatal="ruleset.fatal"
file="${svrl.ruleset.file}"
warning="ruleset.warning"
/>
<java
taskname="gen-svrl"
classname="org.apache.tools.ant.launch.Launcher"
classpathref="svrl.classpath"
failonerror="false"
fork="true"
outputproperty="svrl.output"
resultproperty="svrl.result"
>
<arg value="-Ddita.dir=${dita.dir}"/>
<arg value="-Ddita.plugin.org.dita.base.dir=${dita.plugin.org.dita.base.dir}"/>
<arg value="-buildfile"/>
<arg value="${dita.plugin.com.here.validate.svrl.dir}/run-svrl.xml"/>
<arg
value="-Ddita.plugin.com.here.validate.svrl.dir=${dita.plugin.com.here.validate.svrl.dir}"
/>
<arg value="-Ddita.temp.dir=${dita.temp.dir}"/>
<arg value="-Ddefault.language=${default.language}"/>
<arg value="-Dsvrl.customization.dir=${svrl.customization.dir}"/>
<!-- Parameters for the textual-rules template from the base plug-in -->
<arg value="-Dargs.validate.blacklist=${args.validate.blacklist}"/>
<arg value="-Dargs.validate.check.case=${args.validate.check.case}"/>
<!-- Common parameters for the schematron template from the base plug-in -->
<arg
value="-Dcom.here.validate.svrl.output.rule-id=${com.here.validate.svrl.output.rule-id}"
/>
<arg value="-Dargs.validate.ignore.rules=${args.validate.ignore.rules}"/>
<arg value="-Druleset.fatal=${ruleset.fatal}"/>
<arg value="-Druleset.error=${ruleset.error}"/>
<arg value="-Druleset.warning=${ruleset.warning}"/>
<arg value="-Dargs.validate.cachefile=${args.validate.cachefile}"/>
<arg value="-v"/>
</java>
<dita-ot-fail id="SVRL001F">
<condition>
<not>
<equals arg1="${svrl.result}" arg2="0"/>
</not>
</condition>
<param name="1" value="${svrl.output}"/>
</dita-ot-fail>
<echo level="verbose" message="${svrl.output}" taskname="gen-svrl"/>
<validate-markdown
dir="${dita.temp.dir}/dita"
todir="${dita.temp.dir}/svrl/dita"
>
<fileset dir="${dita.temp.dir}/dita" casesensitive="yes">
<include name="**/*.md"/>
<include name="**/*.mdita"/>
</fileset>
</validate-markdown>
</target>
<!--
Merge validation artifacts e.g. SVRL per DITA file from the previous transformation
into one SVRL file
-->
<target name="svrl-merge">
<dita-ot-echo id="SVRL002I">
<param name="1" value="Merging Schematron Results"/>
</dita-ot-echo>
<xslt
taskname="merge-svrl"
force="true"
in="${svrl.customization.dir}/dita2svrl.xsl"
out="${svrl.report.file}"
style="${dita.plugin.com.here.validate.svrl.dir}/xsl/schematron-merge.xsl"
>
<xmlcatalog refid="dita.catalog"/>
<param expression="${dita.temp.dir}/svrl/" name="in"/>
<param expression="svrl.xml" name="extension"/>
<factory name="net.sf.saxon.TransformerFactoryImpl"/>
</xslt>
<!-- Clean up temporary files -->
<delete failonerror="false" includeemptydirs="true">
<fileset dir="${dita.temp.dir}/svrl" includes="**/*"/>
</delete>
</target>
<!--
Runs a filter XSLT transform on a merged SVRL file to retrieve human-readable results
-->
<target if="svrl.echo.output" name="run-filter">
<dita-ot-echo id="SVRL002I">
<param name="1" value="Processing Schematron Results"/>
</dita-ot-echo>
<!--
Create two temporary files used for recording all validation results
and a count of the number of errors/warnings found.
-->
<tempfile
deleteonexit="true"
destdir="${dita.temp.dir}"
property="output.txt"
suffix=".txt"
/>
<tempfile
deleteonexit="true"
destdir="${dita.temp.dir}"
property="result.txt"
suffix=".txt"
/>
<xslt
taskname="filter-svrl"
basedir="${svrl.dir}"
in="${svrl.report.file}"
out="${output.txt}"
style="${svrl.filter.file}"
>
<factory name="net.sf.saxon.TransformerFactoryImpl"/>
<param expression="${com.here.validate.svrl.mode}" name="MODE"/>
</xslt>
<xslt
taskname="result-svrl"
basedir="${svrl.dir}"
in="${svrl.report.file}"
out="${result.txt}"
style="${svrl.result.file}"
>
<factory name="net.sf.saxon.TransformerFactoryImpl"/>
<param expression="${com.here.validate.svrl.mode}" name="MODE"/>
</xslt>
</target>
<!--
Parse results.svrl and print failed assertions and reports to the console.
Aanalyze file ${svrl.errors.count},and fail set the flag if necessary.
-->
<target if="svrl.echo.output" name="svrl.echo">
<loadfile
failonerror="true"
property="svrl.console.output"
srcfile="${output.txt}"
/>
<loadfile
failonerror="true"
property="svrl.errors.count"
srcfile="${result.txt}"
/>
<svrl-result-echo message="${svrl.console.output}"/>
<condition property="svrl.errors.detected">
<not>
<equals arg1="${svrl.errors.count}" arg2="0"/>
</not>
</condition>
</target>
<!--
Bust the cache file and fail the build.
-->
<target if="svrl.errors.detected" name="svrl.report">
<delete file="${args.validate.cachefile}"/>
<dita-ot-fail id="SVRL001F">
<param name="1" value="Errors detected during validation"/>
</dita-ot-fail>
</target>
<!--
Runs a filter XSLT transform on a merged SVRL file to retrieve human-readable results
-->
<target
depends="run-filter, svrl.fix-dita, svrl.echo,svrl.report"
name="svrl-filter"
/>
<!--
Ant target executed to create an SVRL file
-->
<target depends="svrl, svrl-merge, svrl-filter" name="dita2svrl"/>
</project>