-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.errorcheck.xml
345 lines (315 loc) · 14.9 KB
/
build.errorcheck.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
<?xml version="1.0" encoding="UTF-8"?>
<project name="errorcheck" default="" basedir=".">
<description>errorcheck targets</description>
<property name="buildfile.errorcheck.loaded" value="true"/>
<!-- * basic interface * -->
<target name="errorcheck" depends="syntaxcheck, placeholdercheck, pluralcheck, wordcheck, suspectedwordcheck, charcheck"
description="exec syntax/placeholder/plural/word/suspectedword/char error check for l10n files"/>
<target name="commoncheck" depends="syntaxcheck, placeholdercheck, pluralcheck"
description="exec syntax/placeholder/plural error check for l10n files"/>
<!-- * common macro * -->
<macrodef name="errorlog">
<attribute name="file"/>
<attribute name="message" default=""/>
<attribute name="append" default="false"/>
<attribute name="encoding" default="UTF-8"/>
<attribute name="type" default="error"/>
<attribute name="fail" default="false"/>
<text name="text" optional="true"/>
<sequential>
<groovy>
<arg value="@{file}"/>
ant.mkdir(dir:new File(args[0]).getParent())
</groovy>
<echo taskname="@{taskname}" file="@{file}" message="@{message}@{text}" encoding="@{encoding}"/>
<if>
<istrue value="@{fail}"/>
<then>
<fail taskname="@{type}" message="@{message}@{text}"/>
</then>
<else>
<echo taskname="@{type}" message="@{message}@{text}"/>
</else>
</if>
</sequential>
</macrodef>
<!-- * Syntax Check * -->
<target name="syntaxcheck" depends="load-conf" unless="nosyntaxcheck"
description="syntax error check of converted files">
<fail message="${cmsg.noprop.syntaxcheck.dir}" unless="syntaxcheck.dir"/>
<loadmessage pattern="^vmsg\.syntaxcheck\."/>
<fail message="${vmsg.syntaxcheck.no.srcdir}">
<condition><not><available file="${syntaxcheck.dir}" type="dir"/></not></condition>
</fail>
<property name="syntaxcheck.output" value="temp/syntaxerror.txt"/>
<delete file="${syntaxcheck.output}" failonerror="false"/>
<groovy><![CDATA[
errormsg = new StringBuilder()
includes = properties.'syntaxcheck.includes' ?: '**'
excludes = properties.'syntaxcheck.excludes' ?: ''
ant.fileset(dir:properties.'syntaxcheck.dir', includes:includes, excludes:excludes).each { file ->
if (file =~ /\.properties$/) validpattern = /${properties.'RE.properties.validline'}\n/
else if (file =~ /\.dtd$/) validpattern = /${properties.'RE.dtd.validblock'}\n/
else if (file =~ /\.inc$/) validpattern = /${properties.'RE.inc.validline'}\n/
else if (file =~ /\.ini$/) validpattern = /${properties.'RE.ini.validline'}\n/
else return
content = new StringBuilder()
file.getFile().getText('UTF-8').replaceFirst(/^\ufeff/, '').eachLine{ line,n -> content << "@line ${n+1}: $line\n" }
content = content.toString().replaceAll(validpattern, '')
if (content) errormsg << "Syntax error found in $file:\n$content\n"
}
if (errormsg) {
ant.mkdir(dir:new File(properties.'errorsummary.output').getParent())
ant.echo(message: errormsg, file: properties.'errorsummary.output', append: true)
ant.errorlog(type: 'syntaxerror', , fail: properties.'syntaxcheck.failonerror',
file: properties.'syntaxcheck.output', message: "$errormsg${properties.'vmsg.syntaxcheck.found'}")
}
]]></groovy>
</target>
<!-- * Placeholder Check * -->
<target name="placeholdercheck" depends="load-conf" unless="noplaceholdercheck"
description="placeholder usage error check of converted properties files">
<fail message="${cmsg.noprop.placeholdercheck.dir}" unless="placeholdercheck.dir"/>
<loadmessage pattern="^vmsg\.placeholdercheck\."/>
<fail message="${vmsg.placeholdercheck.no.srcdir}">
<condition><not><available file="${placeholdercheck.dir}" type="dir"/></not></condition>
</fail>
<property name="placeholdercheck.output" value="temp/placeholdererror.txt"/>
<delete file="${placeholdercheck.output}" failonerror="false"/>
<groovy><![CDATA[
max = 5
errormsg = new StringBuilder()
includes = properties.'placeholdercheck.includes' ?: '**/*.properties'
excludes = properties.'placeholdercheck.excludes' ?: ''
ant.fileset(dir:properties.'placeholdercheck.dir', includes:includes, excludes:excludes).each {
if (!(it =~ /\.properties$/)) return // check only properties files
errorlines = new StringBuilder()
it.getFile().getText('UTF-8').eachLine { line, n ->
err = false
(2..max).each { i -> // search %2$2, %3$S...
if (!err && line =~ "^[^#].+=.+%$i\\\$S") {
(1..<i).each { j -> // confirm if smaller number placeholders are defined
err = err || (!line.contains("%$j\$S") && !line.contains("%$j\$0.S"))
}
}
}
if (err) errorlines << "@line ${n+1}: $line\n"
}
if (errorlines) errormsg << "Placeholder error found in $it:\n$errorlines\n"
}
if (errormsg) {
ant.mkdir(dir:new File(properties.'errorsummary.output').getParent())
ant.echo(message: errormsg, file: properties.'errorsummary.output', append: true)
ant.errorlog(type: 'placeholdererror', fail: properties.'placeholdererror.failonerror',
file: properties.'placeholdercheck.output', message: "$errormsg${properties.'vmsg.placeholdercheck.found'}")
}
]]></groovy>
</target>
<!-- * Plural Form Usage Check * -->
<target name="pluralcheck" depends="load-conf" unless="nopluralcheck"
description="plural form error check of converted properties files">
<loadmessage pattern="^vmsg\.pluralcheck\."/>
<property name="pluralcheck.output" value="temp/pluralcheck.txt"/>
<delete file="${pluralcheck.output}" failonerror="false"/>
<groovy><![CDATA[
errormsg = new StringBuilder()
includes = properties.'pluralcheck.includes' ?: '**/*.properties'
excludes = properties.'pluralcheck.excludes' ?: ''
ant.fileset(dir:properties.'pluralcheck.dir', includes:includes, excludes:excludes).each {
if (!(it =~ /\.properties$/)) return // check only properties files
errorlines = new StringBuilder()
it.getFile().getText('UTF-8').replaceAll(/(?ms)${properties.'pluralcheck.allow'}/, properties.'pluralcheck.allow.replace').eachLine { line, n ->
if (line =~ /^\s*[-0-9a-zA-Z_.?{@}]+\s*=.+;.+/) {
errorlines << "@line ${n+1}: $line\n"
}
}
if (errorlines) errormsg << "Plural form error may exists in $it:\n$errorlines\n\n"
}
if (errormsg) {
ant.mkdir(dir:new File(properties.'errorsummary.output').getParent())
ant.echo(message: errormsg, file: properties.'errorsummary.output', append: true)
ant.errorlog(type: 'pluralformerror', fail: properties.'pluralcheck.failonerror',
file: properties.'pluralcheck.output', message: "$errormsg${properties.'vmsg.pluralcheck.found'}")
}
]]></groovy>
</target>
<!-- * Contents (Word/Character) Check * -->
<macrodef name="wordchecksuite">
<attribute name="allowpattern" default="${wordcheck.allow}"/>
<attribute name="denypattern" default="${wordcheck.deny}"/>
<attribute name="replacement" default="${wordcheck.deny.replace}"/>
<attribute name="dir" default="${wordcheck.dir}"/>
<attribute name="output" default="${wordcheck.output}"/>
<attribute name="includes" default="${wordcheck.includes}"/>
<attribute name="excludes" default="${wordcheck.excludes}"/>
<attribute name="regexpengine" default=""/>
<sequential>
<groovy>
<!-- pass attributes using args to avoid being interprited as groovy code -->
<arg value="(?m)@{allowpattern}"/>
<arg value="(?m)@{denypattern}"/>
<arg value="@{replacement}"/>
<arg value="@{dir}"/>
<arg value="@{output}"/>
<arg value="@{includes}"/>
<arg value="@{excludes}"/>
<arg value="@{regexpengine}"/>
<![CDATA[
import org.apache.oro.text.regex.*;
allowpattern = args[0]
denypattern = args[1]
denypattern_ = ~denypattern
replacement = args[2]
dir = args[3]
outputfile = new File(args[4])
includes = args[5]
excludes = args[6]
regexpengine = args[7]
xmlcommentpattern = /${properties.'RE.xml.comment'}/
linecommentpattern = /(?m)^(@line [0-9]+: )?\s*#[^\n]*/
errormsg = new StringBuilder()
def wordchecker(file, encoding, allowpattern, denypattern, commentpattern) {
errorlines = new StringBuilder()
content = new StringBuilder()
file.getFile().getText(encoding).eachLine{ line,n -> content << "@line ${n+1}: $line\n" }
content = content.toString()
if (commentpattern) {
content = content.replaceAll(commentpattern, '')
}
if (allowpattern) {
content = content.replaceAll(allowpattern, properties.'wordcheck.allow.replace')
}
if (regexpengine == 'jakartaoro') {
PatternMatcher matcher = new Perl5Matcher();
PatternCompiler compiler = new Perl5Compiler();
Pattern pattern = compiler.compile("($denypattern)");
content.eachLine { line, n ->
if (matcher.contains(line, pattern)) {
errorlines << Util.substitute(matcher, pattern, new Perl5Substitution(replacement, Perl5Substitution.INTERPOLATE_ALL), line, Util.SUBSTITUTE_ALL) + "\n"
}
}
}
else {
content.eachLine { line, n ->
if (line =~ denypattern_) {
errorlines << line.replaceAll("($denypattern)", replacement) + "\n"
}
}
}
if (errorlines) errormsg << "Error Found in $file:\n$errorlines\n\n"
}
ant.fileset(dir:dir, includes:includes, excludes:excludes).each {
if (it =~ /\.(dtd|xml|html?|xhtml|rdf)$/)
wordchecker(it, 'UTF-8', allowpattern, denypattern, xmlcommentpattern)
}
if (properties.'wordcheck.unescape.properties') {
// note: native2ascii task require JDK installed and JAVA_HOME env set properly, or you'll see the error "error starting Sun's native2ascii"
ant.native2ascii(src:dir, includes:'**/*.properties',
dest:'${lot.temp.dir}/wordcheck', reverse:true, encoding:'UTF-8')
ant.fileset(dir: '${lot.temp.dir}/wordcheck', includes:includes, excludes:excludes).each {
if (it =~ /\.properties$/)
wordchecker(it, 'UTF-8', allowpattern, denypattern, linecommentpattern)
}
ant.delete(dir:'${lot.temp.dir}/wordcheck', failonerror:false)
}
else {
ant.fileset(dir:dir, includes:includes, excludes:excludes).each {
if (it =~ /\.properties$/)
wordchecker(it, 'UTF-8', allowpattern, denypattern, linecommentpattern)
}
}
ant.fileset(dir:dir, includes:includes, excludes:excludes).each {
if (it =~ /\.inc$/)
wordchecker(it, 'UTF-8', allowpattern, denypattern, null)
}
if (errormsg) {
ant.mkdir(dir:outputfile.getParent())
outputfile.append(errormsg, 'UTF-8')
}
]]></groovy>
</sequential>
</macrodef>
<target name="wordcheck" depends="load-conf" unless="nowordcheck"
description="word error check of converted files">
<fail message="${cmsg.noprop.wordcheck.dir}" unless="wordcheck.dir"/>
<loadmessage pattern="^vmsg\.wordcheck\."/>
<fail message="${vmsg.wordcheck.no.srcdir}">
<condition><not><available file="${wordcheck.dir}" type="dir"/></not></condition>
</fail>
<property name="wordcheck.output" value="temp/worderror.txt"/>
<delete file="${wordcheck.output}" failonerror="false"/>
<equals property="wordcheck.deny" value="${wordcheck.deny.ja}" arg1="${locale}" arg2="ja"/>
<equals property="wordcheck.deny" value="${wordcheck.deny.ja-JP-mac}" arg1="${locale}" arg2="ja-JP-mac"/>
<property name="wordcheck.deny" value="##NOTHING##"/>
<equals property="wordcheck.allow" value="${wordcheck.allow.ja}" arg1="${locale}" arg2="ja"/>
<equals property="wordcheck.allow" value="${wordcheck.allow.ja-JP-mac}" arg1="${locale}" arg2="ja-JP-mac"/>
<property name="wordcheck.allow" value="##NOTHING##"/>
<wordchecksuite excludes="${l10n.includes.not.common}" denypattern="${wordcheck.deny}"/>
<wordchecksuite includes="${wordcheck.includes}" excludes="${l10n.includes.not.only.fx}"
denypattern="${wordcheck.deny}|${wordcheck.deny.firefox}"/>
<wordchecksuite includes="${wordcheck.includes}" excludes="${l10n.includes.not.only.tb}"
denypattern="${wordcheck.deny}|${wordcheck.deny.thunderbird}"/>
<wordchecksuite includes="${wordcheck.includes}" excludes="${l10n.includes.not.only.fe}"
denypattern="${wordcheck.deny}|${wordcheck.deny.fennec}"/>
<wordchecksuite includes="${wordcheck.includes}" excludes="${l10n.includes.not.only.sb}"
denypattern="${wordcheck.deny}|${wordcheck.deny.sunbird}"/>
<wordchecksuite includes="${wordcheck.includes}" excludes="${l10n.includes.not.only.sm}"
denypattern="${wordcheck.deny}|${wordcheck.deny.seamonkey}"/>
<wordchecksuite includes="${wordcheck.includes}" excludes="${l10n.includes.not.only.fx.tb.sm}"
denypattern="${wordcheck.deny}|${wordcheck.deny.firefox}|${wordcheck.deny.thunderbird}|${wordcheck.deny.seamonkey}"/>
<wordchecksuite includes="${wordcheck.includes}" excludes="${l10n.includes.not.only.fx.sm}"
denypattern="${wordcheck.deny}|${wordcheck.deny.firefox}|${wordcheck.deny.seamonkey}"/>
<wordchecksuite includes="${wordcheck.includes}" excludes="${l10n.includes.not.only.tb.sm}"
denypattern="${wordcheck.deny}|${wordcheck.deny.thunderbird}|${wordcheck.deny.seamonkey}"/>
<if>
<available file="${wordcheck.output}"/>
<then>
<loadfile property="wordcheck.error" srcfile="${wordcheck.output}" encoding="UTF-8"/>
<if>
<istrue value="${wordcheck.failonerror}"/>
<then>
<fail message="${N}${wordcheck.error}${vmsg.wordcheck.found}"/>
</then>
<else>
<echo taskname="wordcheckerror" message="${N}${wordcheck.error}${vmsg.wordcheck.found}"/>
</else>
</if>
</then>
</if>
</target>
<target name="suspectedwordcheck" depends="load-conf" unless="nosuspectedwordcheck" if="dosuspectedwordcheck">
<delete file="${wordcheck.suspected.output}" failonerror="false"/>
<equals property="wordcheck.suspected" value="@{2}|${wordcheck.suspected.ja}" arg1="${locale}" arg2="ja"/>
<equals property="wordcheck.suspected" value="@{2}|${wordcheck.suspected.ja-JP-mac}" arg1="${locale}" arg2="ja-JP-mac"/>
<property name="wordcheck.suspected" value="##NOTHING##"/>
<wordchecksuite dir="${wordcheck.dir}" output="${wordcheck.suspected.output}"
allowpattern="##NOTHING##" denypattern="${wordcheck.suspected}"/>
</target>
<target name="charcheck" depends="load-conf" unless="nocharcheck"
description="character error check of converted files">
<delete file="${charcheck.output}" failonerror="false"/>
<fail message="${cmsg.noprop.charcheck.dir}" unless="charcheck.dir"/>
<loadmessage pattern="^vmsg\.charcheck\."/>
<fail message="${vmsg.charcheck.no.srcdir}">
<condition><not><available file="${charcheck.dir}" type="dir"/></not></condition>
</fail>
<wordchecksuite dir="${charcheck.dir}" output="${charcheck.output}" regexpengine="jakartaoro"
includes="${charcheck.includes}" excludes="${charcheck.excludes}"
allowpattern="${charcheck.allow}" denypattern="${charcheck.deny}" replacement="${charcheck.deny.replace}"/>
<if>
<available file="${charcheck.output}"/>
<then>
<loadfile property="charcheck.error" srcfile="${charcheck.output}" encoding="UTF-8"/>
<if>
<istrue value="${charcheck.failonerror}"/>
<then>
<fail message="${N}${charcheck.error}${vmsg.charcheck.found}"/>
</then>
<else>
<echo taskname="charcheckerror" message="${N}${charcheck.error}${vmsg.charcheck.found}"/>
</else>
</if>
</then>
</if>
</target>
</project>