-
Notifications
You must be signed in to change notification settings - Fork 3
/
build_schematron-validation.xml
281 lines (262 loc) · 12.9 KB
/
build_schematron-validation.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
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2023 Stefan Jung. All rights reserved.
See the accompanying LICENSE file for applicable license.
-->
<project basedir="." name="build_dita2schematron" xmlns:if="ant:if" xmlns:unless="ant:unless">
<import file="build_taskdef_ph-schematron.xml"/>
<!-- Default properties -->
<property unless:set="schematron.fail"
name="schematron.fail"
value="false"
/>
<property unless:set="schematron.failon.fatal"
name="schematron.failon.fatal"
value="true"
/>
<property unless:set="schematron.failon.error"
name="schematron.failon.error"
value="true"
/>
<property unless:set="schematron.failon.warning"
name="schematron.failon.warning"
value="false"
/>
<property unless:set="schematron.failon.info"
name="schematron.failon.info"
value="false"
/>
<property unless:set="schematron.processing.engine"
name="schematron.processing.engine"
value="pure"
/>
<basename unless:set="dita.input.filename" file="${args.input}" property="dita.input.filename" suffix=".ditamap"/>
<property name="schematron.logfile"
value="${output.dir}/${dita.input.filename}.schematron.log"
/>
<target name="schematron-validation">
<condition property="schematron-validation-active">
<or>
<isset property="schematron.map.validation.files"/>
<isset property="schematron.topic.validation.files"/>
</or>
</condition>
<echo if:set="schematron-validation-active" level="info">*******************************************************************</echo>
<echo if:set="schematron-validation-active" level="info">schematron.fail = ${schematron.fail}</echo>
<echo if:set="schematron-validation-active" level="info">schematron.failon.fatal = ${schematron.failon.fatal}</echo>
<echo if:set="schematron-validation-active" level="info">schematron.failon.error = ${schematron.failon.error}</echo>
<echo if:set="schematron-validation-active" level="info">schematron.failon.warning = ${schematron.failon.warning}</echo>
<echo if:set="schematron-validation-active" level="info">schematron.failon.info = ${schematron.failon.info}</echo>
<echo if:set="schematron.svrl.dir" level="info">schematron.svrl.dir = ${schematron.svrl.dir}</echo>
<echo if:set="schematron-validation-active" level="info">*******************************************************************</echo>
<condition property="old.schematron.log">
<available file="${schematron.logfile}" type="file"/>
</condition>
<delete if:set="old.schematron.log" file="${schematron.logfile}" failonerror="false" quiet="true" verbose="false"/>
<echo unless:set="schematron.map.validation.files" level="info">Skip Schematron DITA Map validation</echo>
<echo if:set="schematron.map.validation.files" level="info">Validate DITA Maps with Schematron</echo>
<schematron-validate if:set="schematron.map.validation.files"
target="-schematron-validate-maps"
files="${schematron.map.validation.files}"
/>
<echo unless:set="schematron.topic.validation.files" level="info">Skip Schematron DITA Topic validation</echo>
<echo if:set="schematron.map.validation.files" level="info">Validate DITA Topics with Schematron</echo>
<schematron-validate if:set="schematron.topic.validation.files"
target="-schematron-validate-topics"
files="${schematron.topic.validation.files}"
/>
<!-- Strip debugging information -->
<condition property="schematron.logfile.exists" value="true">
<available file="${schematron.logfile}"/>
</condition>
<move if:set="schematron.logfile.exists"
file="${schematron.logfile}"
tofile="${schematron.logfile}.temp"
quiet="true" verbose="false"
overwrite="true"
/>
<copy if:set="schematron.logfile.exists"
file="${schematron.logfile}.temp"
tofile="${schematron.logfile}"
quiet="true"
verbose="false"
overwrite="true">
<filterchain>
<linecontainsregexp negate="true">
<regexp pattern="com.helger"/>
</linecontainsregexp>
</filterchain>
</copy>
<delete file="${schematron.logfile}.temp" verbose="false" quiet="true" failonerror="false"/>
<!-- Break the build, if logfile contains errors -->
<condition if:set="schematron.logfile.exists" property="fail.fatal">
<and>
<istrue value="${schematron.fail}"/>
<istrue value="${schematron.failon.fatal}"/>
</and>
</condition>
<dita-ot-fail if:set="fail.fatal" id="DTSS001F">
<condition>
<resourcecontains resource="${schematron.logfile}" substring="[fatal]" casesensitive="false"/>
</condition>
</dita-ot-fail>
<condition if:set="schematron.logfile.exists" property="fail.error">
<and>
<istrue value="${schematron.fail}"/>
<istrue value="${schematron.failon.error}"/>
</and>
</condition>
<dita-ot-fail if:set="fail.error" id="DTSS002E">
<condition>
<resourcecontains resource="${schematron.logfile}" substring="[error]" casesensitive="false"/>
</condition>
</dita-ot-fail>
<condition if:set="schematron.logfile.exists" property="fail.warning">
<and>
<istrue value="${schematron.fail}"/>
<istrue value="${schematron.failon.warning}"/>
</and>
</condition>
<dita-ot-fail if:set="fail.warning" id="DTSS003W">
<condition>
<resourcecontains resource="${schematron.logfile}" substring="[warn]" casesensitive="false"/>
</condition>
</dita-ot-fail>
<condition if:set="schematron.logfile.exists" property="fail.info">
<and>
<istrue value="${schematron.fail}"/>
<istrue value="${schematron.failon.info}"/>
</and>
</condition>
<dita-ot-fail if:set="fail.info" id="DTSS004I">
<condition>
<resourcecontains resource="${schematron.logfile}" substring="[info]" casesensitive="false"/>
</condition>
</dita-ot-fail>
<fail if:set="fail.fatal">
<condition>
<resourcecontains resource="${schematron.logfile}" substring="[fatal]" casesensitive="false"/>
</condition>
</fail>
<fail if:set="fail.error">
<condition>
<resourcecontains resource="${schematron.logfile}" substring="[error]" casesensitive="false"/>
</condition>
</fail>
<fail if:set="fail.warning">
<condition>
<resourcecontains resource="${schematron.logfile}" substring="[warn]" casesensitive="false"/>
</condition>
</fail>
<fail if:set="fail.info">
<condition>
<resourcecontains resource="${schematron.logfile}" substring="[info]" casesensitive="false"/>
</condition>
</fail>
</target>
<target name="-schematron-validate-maps">
<echo level="info">Validate '@{map.file}' with '${schematron.files}' using the processing engine '${schematron.processing.engine}'</echo>
<record name="${schematron.logfile}" action="start" append="true"/>
<!--
If the property svrlDirectory is set, task generates SVRL files in the specified directory.
-->
<schematron if:set="schematron.svrl.dir"
schematronFile="${schematron.files}"
expectSuccess="true"
svrlDirectory="${schematron.svrl.dir}"
schematronProcessingEngine="${schematron.processing.engine}"
failOnError="false">
<xmlcatalog refid="dita.catalog" />
<ditafileset format="ditamap" />
<errorRole if:true="schematron.failon.fatal" role="fatal" />
<errorRole if:true="schematron.failon.error" role="error" />
<errorRole if:true="schematron.failon.warning" role="warning" />
<errorRole if:true="schematron.failon.info" role="info" />
</schematron>
<schematron unless:set="schematron.svrl.dir"
schematronFile="${schematron.files}"
expectSuccess="true"
schematronProcessingEngine="${schematron.processing.engine}"
failOnError="false">
<xmlcatalog refid="dita.catalog" />
<ditafileset format="ditamap" />
<errorRole if:true="schematron.failon.fatal" role="fatal" />
<errorRole if:true="schematron.failon.error" role="error" />
<errorRole if:true="schematron.failon.warning" role="warning" />
<errorRole if:true="schematron.failon.info" role="info" />
</schematron>
<record name="${schematron.logfile}" action="stop"/>
</target>
<target name="-schematron-validate-topics">
<echo level="info">Validate topics with '${schematron.files}' using the processing engine '${schematron.processing.engine}'</echo>
<record name="${schematron.logfile}" action="start" append="true"/>
<!--
If the property svrlDirectory is set, task generates SVRL files in the specified directory.
-->
<schematron if:set="schematron.svrl.dir"
schematronFile="${schematron.files}"
expectSuccess="true"
svrlDirectory="${schematron.svrl.dir}"
schematronProcessingEngine="${schematron.processing.engine}"
failOnError="false">
<xmlcatalog refid="dita.catalog" />
<ditafileset format="dita" />
<errorRole if:true="schematron.failon.fatal" role="fatal" />
<errorRole if:true="schematron.failon.error" role="error" />
<errorRole if:true="schematron.failon.warning" role="warning" />
<errorRole if:true="schematron.failon.info" role="info" />
</schematron>
<schematron unless:set="schematron.svrl.dir"
schematronFile="${schematron.files}"
expectSuccess="true"
schematronProcessingEngine="${schematron.processing.engine}"
failOnError="false">
<xmlcatalog refid="dita.catalog" />
<ditafileset format="dita" />
<errorRole if:true="schematron.failon.fatal" role="fatal" />
<errorRole if:true="schematron.failon.error" role="error" />
<errorRole if:true="schematron.failon.warning" role="warning" />
<errorRole if:true="schematron.failon.info" role="info" />
</schematron>
<record name="${schematron.logfile}" action="stop"/>
<!-- Clean up whitespace and linebreaks in SVRL files -->
<replaceregexp match="\s*&#xa;\s*" replace="" flags="g">
<fileset dir="${output.dir}" includes="**/*.svrl"/>
</replaceregexp>
<!-- Clean up log file -->
<replaceregexp match="\[schematron\]\s*" replace="" file="${schematron.logfile}" flags="g"/>
<copy file="${schematron.logfile}" tofile="${schematron.logfile}.temp">
<filterchain>
<linecontainsregexp negate="true">
<regexp pattern="Validating XML file"/>
</linecontainsregexp>
<linecontainsregexp negate="true">
<regexp pattern="Found no hashCode implementation"/>
</linecontainsregexp>
<linecontainsregexp negate="true">
<regexp pattern="Binding pure Schematron"/>
</linecontainsregexp>
<linecontainsregexp negate="true">
<regexp pattern="Successfully parsed Schematron file"/>
</linecontainsregexp>
<linecontainsregexp negate="true">
<regexp pattern="The expectations were not fullfilled"/>
</linecontainsregexp>
<linecontainsregexp negate="true">
<regexp pattern="JAXP"/>
</linecontainsregexp>
<linecontainsregexp negate="true">
<regexp pattern="Schematron error for XML file"/>
</linecontainsregexp>
<linecontainsregexp negate="true">
<regexp pattern="was validated against Schematron"/>
</linecontainsregexp>
<deletecharacters chars="\t"/>
<trim/>
<ignoreblank/>
</filterchain>
</copy>
<delete file="${schematron.logfile}"/>
<move file="${schematron.logfile}.temp" tofile="${schematron.logfile}"/>
</target>
</project>