forked from Benjol/SE-AutoReviewComments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.xml
409 lines (376 loc) · 17 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
<project name="autoreviewcomments" default="all" basedir=".">
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
<description>
Compiling script to different browsers.
</description>
<!-- Primitive substitutions are defined in this file. -->
<property name="build.prop" value="${basedir}/build.properties"/>
<!-- The sites our script should run on are defined in this file -->
<property name="build.sites" value="${basedir}/build.sites"/>
<property name="build.excludes" value="${basedir}/build.excludes"/>
<property name="encoding" value="UTF-8"/>
<property name="name" value="autoreviewcomments"/>
<!-- The location used during the build process. -->
<property name="build" value="${basedir}/build"/>
<!-- The location that contains our source code. -->
<property name="src" value="${basedir}/src"/>
<!-- The location where we'll place the resulting packages. -->
<property name="dist" value="${basedir}/dist"/>
<!-- The location where we store our signing certificates and keys. -->
<property name="cert" value="${basedir}/.cert"/>
<!-- Sub folder in the build directory for our extension. -->
<property name="buildDir" value="${build}/${name}"/>
<!-- The location where our key for the Chrome extension is located. -->
<property name="cert.chromePath" value="${cert}/chrome"/>
<!-- The key file used to sign the Chrome extension.. -->
<property name="cert.chrome" value="${cert.chromePath}/${name}.pem"/>
<!-- The directory where we store the various icon files. -->
<property name="src.icons" value="${src}/icons"/>
<!-- Location for Chrome-specific source files. -->
<property name="src.chrome" value="${src}/.chrome"/>
<!-- Location for Firefox-specific source files. -->
<property name="src.firefox" value="${src}/.firefox"/>
<!-- The location that contains our templates. -->
<property name="src.templates" value="${src}/.templates"/>
<!-- Location for JS modules that can be merged into the main source file. -->
<property name="src.modules" value="${src}/.modules"/>
<!-- Location of buildcrx. Used to pack the Chrome extension into a CRX.
See: https://github.com/kylehuff/buildcrx
If Arch detection becomes necessaray see https://github.com/twall/jna/blob/master/build.xml#L168
-->
<condition property="sdk.buildcrx" value="${basedir}/SDK/buildcrx.exe">
<os family="windows"/>
</condition>
<condition property="sdk.buildcrx" value="${basedir}/SDK/buildcrx_linux_x86">
<and>
<os family="unix"/>
<not>
<isset property="arch"/>
</not>
</and>
</condition>
<condition property="sdk.buildcrx" value="${basedir}/SDK/buildcrx_linux_x86_64">
<and>
<os family="unix"/>
<equals arg1="${arch}" arg2="64"/>
</and>
</condition>
<property name="sdk.firefox" value="${basedir}/SDK/addon-sdk-1.16"/>
<property name="sdk.cfx" value="${sdk.firefox}/bin/cfx"/>
<!-- Location of Google Closure Compiler. Used to pack userscript.
See: https://developers.google.com/closure/compiler/ -->
<property name="sdk.closurecompiler" value="${basedir}/SDK/compiler.jar"/>
<!-- Location of HTML compressor. Used to compress template HTML.
See: https://code.google.com/p/htmlcompressor/ -->
<property name="sdk.htmlcompressor" value="${basedir}/SDK/htmlcompressor-1.5.3.jar"/>
<!-- Alias target to build all targets. -->
<target name="all" depends="preinit, userscript, chrome, firefox, clean"/>
<!-- Make sure all required directories exist. -->
<target name="preinit">
<mkdir dir="${cert}"/>
<mkdir dir="${dist}"/>
<mkdir dir="${build}"/>
<mkdir dir="${buildDir}"/>
<mkdir dir="${src}"/>
<mkdir dir="${src.icons}"/>
<mkdir dir="${src.chrome}"/>
<mkdir dir="${src.firefox}"/>
<mkdir dir="${src.modules}"/>
<mkdir dir="${src.templates}"/>
<mkdir dir="${cert.chromePath}"/>
</target>
<!-- Copy all generic sources to the build directory. -->
<target name="copy">
<copy todir="${buildDir}">
<fileset dir="${src}">
<include name="*.*"/>
<exclude name=".*"/>
</fileset>
</copy>
</target>
<!-- Perform HTML compression on the template files to make sure their code is reduced to a single line. -->
<target name="compress-templates">
<apply executable="java" parallel="false">
<fileset dir="${src.templates}" includes="*.html"/>
<arg value="-jar"/>
<arg path="${sdk.htmlcompressor}"/>
<arg line="--type html"/>
<arg value="--preserve-comments"/>
<arg value="--compress-css"/>
<srcfile/>
<arg value="-o"/>
<mapper type="glob" from="*" to="${buildDir}/.templates/*"/>
<targetfile/>
</apply>
</target>
<target name="tokenreplace" depends="sites, sites-userscript, excludes-userscript, sites-chrome, sites-firefox, compress-templates">
<!-- Replace templates. -->
<loadfile srcfile="${buildDir}/.templates/css.html" property="ant-templates-css"/>
<replace dir="${buildDir}" token="@ant-templates-css@" value="${ant-templates-css}"/>
<loadfile srcfile="${buildDir}/.templates/message.html" property="ant-templates-message"/>
<replace dir="${buildDir}" token="@ant-templates-message@" value="${ant-templates-message}"/>
<loadfile srcfile="${buildDir}/.templates/option.html" property="ant-templates-option"/>
<replace dir="${buildDir}" token="@ant-templates-option@" value="${ant-templates-option}"/>
<loadfile srcfile="${buildDir}/.templates/popup.html" property="ant-templates-popup"/>
<replace dir="${buildDir}" token="@ant-templates-popup@" value="${ant-templates-popup}"/>
<!-- Clean up the temporary directory where we stored the HTML-compressed templates. -->
<delete dir="${buildDir}/.templates"/>
<delete dir="${buildDir}/.modules"/>
<!-- General token replacing in the rest of the code. -->
<replace dir="${buildDir}" replacefilterfile="${build.prop}" encoding="${encoding}"/>
<replace dir="${buildDir}" token="@ant-sites@" value="${sites}" encoding="${encoding}"/>
<replace dir="${buildDir}" token="// @ant-sites-userscript@" value="${sites-userscript}" encoding="${encoding}"/>
<replace dir="${buildDir}" token="// @ant-excludes-userscript@" value="${excludes-userscript}" encoding="${encoding}"/>
<replace dir="${buildDir}" token=""@ant-sites-chrome-list@"" value="${sites-chrome-list}"
encoding="${encoding}"/>
<replace dir="${buildDir}" token=""@ant-sites-firefox-list@"" value="${sites-firefox-list}"
encoding="${encoding}"/>
</target>
<!-- Tasks to prepare the list of target sites in different formats -->
<target name="sites">
<loadfile property="sites" srcFile="${build.sites}"/>
</target>
<!-- Construct the list of target sites as required by the userscript.
The results have to be regular expressions.
For reference see: http://wiki.greasespot.net/Include_and_exclude_rules -->
<target name="sites-userscript">
<loadfile property="sites-userscript" srcFile="${build.sites}">
<filterchain>
<!-- Replace the possible *. at the start of each line with (*.)*
This allows for options subdomains if the line started with *. -->
<replaceregex pattern="^\*\." replace="(*.)?"/>
<!-- Dots in the line have to be escaped, to match literal dots. -->
<replacestring from="." to="\."/>
<!-- The star has to be replaced by .* to match any amount of characters. -->
<replacestring from="*" to=".*"/>
<!-- Prefix all lines with /^https?:\/\/ to match http and https URLs.
This also opens the regular expression with / -->
<prefixlines prefix="/^https?:\/\/"/>
<!-- Suffix all lines with a /.*$/ to match all pages on the site.
The also closes the regular expression with / -->
<suffixlines suffix="/.*$/"/>
<!-- Prefix all lines with the mandatory @include comment. -->
<prefixlines prefix="// @include "/>
</filterchain>
</loadfile>
</target>
<!-- Construct the list of target sites as required by Chrome.
The results have to be proprietary "match patterns".
For reference see: http://developer.chrome.com/extensions/match_patterns -->
<target name="sites-chrome">
<loadfile property="sites-chrome-list-in" srcFile="${build.sites}">
<filterchain>
<!-- Duplicate each line, prefixing one with http:// and the other with https://,
then wrap each line in quotes and suffix them with a comma. -->
<replaceregex pattern="(.*)" replace=""http://\1/*","https://\1/*","/>
</filterchain>
</loadfile>
<!-- Remove last trailing comma from property. -->
<propertyregex property="sites-chrome-list" input="${sites-chrome-list-in}" regexp=",[\r\n]*$" replace=""/>
</target>
<!-- Construct the list of target sites as required by Firefox.
The results have to be regular expressions.
For reference see: https://developer.mozilla.org/en-US/Add-ons/SDK/Low-Level_APIs/util_match-pattern -->
<target name="sites-firefox">
<loadfile property="sites-firefox-list-in" srcFile="${build.sites}">
<filterchain>
<!-- Replace the possible *. at the start of each line with (*.)*
This allows for options subdomains if the line started with *. -->
<replaceregex pattern="^\*\." replace="(*.)?"/>
<!-- Dots in the line have to be escaped, to match literal dots. -->
<replacestring from="." to="\."/>
<!-- The star has to be replaced by .* to match any amount of characters. -->
<replacestring from="*" to=".*"/>
<!-- Prefix all lines with /^https?:\/\/ to match http and https URLs.
This also opens the regular expression with / -->
<prefixlines prefix="/^https?:\/\/"/>
<!-- Suffix all lines with a /.*$/ to match all pages on the site.
The also closes the regular expression with / -->
<suffixlines suffix="\/.*$/,"/>
</filterchain>
</loadfile>
<!-- Remove last trailing comma from property. -->
<propertyregex property="sites-firefox-list" input="${sites-firefox-list-in}" regexp=",[\r\n]*$" replace=""/>
</target>
<!-- Construct the list of exclude sites as required by the userscript.
For reference see: http://wiki.greasespot.net/Include_and_exclude_rules -->
<target name="excludes-userscript">
<loadfile property="excludes-userscript" srcFile="${build.excludes}">
<filterchain>
<!-- Prefix all lines with the mandatory @exclude comment. -->
<prefixlines prefix="// @exclude "/>
</filterchain>
</loadfile>
</target>
<!-- Build the userscript. -->
<target name="userscript" depends="preinit, copy-userscript">
<!-- Create a fileset that includes only the source userscript. -->
<fileset dir="${buildDir}" id="userscript-path">
<include name="*.user.js"/>
</fileset>
<!-- Add a "min" into the filename for the output filename. -->
<pathconvert property="userscript-path-out" refid="userscript-path">
<mapper>
<regexpmapper from="(.*?)\.user.js$" to="\1.min.user.js"/>
</mapper>
</pathconvert>
<!-- Convert the path to a property. -->
<pathconvert property="userscript-path" refid="userscript-path"/>
<!-- Invoke the Google Closure Compiler with the generated file names. -->
<java jar="${sdk.closurecompiler}" fork="true">
<arg value="--js"/>
<arg value="${userscript-path}"/>
<arg value="--js_output_file"/>
<arg value="${userscript-path-out}"/>
</java>
<!-- Move the compressed and the uncompressed version to the output folder. -->
<move todir="${dist}">
<fileset dir="${buildDir}">
<include name="*.user.js"/>
</fileset>
</move>
<antcall target="clean"/>
</target>
<!-- Copy the data required for the userscript to the build directory. -->
<target name="copy-userscript">
<antcall target="copy"/>
<!-- Replace the autoupdater -->
<loadfile srcfile="${src.modules}/autoupdater.js" property="ant-modules-autoupdater"/>
<replace dir="${buildDir}" token="@ant-modules-autoupdater@" value="${ant-modules-autoupdater}"/>
<!-- Replace pre-defined identifiers. -->
<antcall target="tokenreplace"/>
</target>
<target name="dev" depends="preinit, copy-chrome">
<copy todir="${dist}/chrome-dev">
<fileset dir="${buildDir}"/>
</copy>
<antcall target="clean"/>
</target>
<!-- Build the Chrome extension. -->
<target name="chrome" depends="preinit, copy-chrome, chrome-zip, chrome-crx, clean"/>
<!-- Just places the extension in the build directory so you can load it as an unpacked extension. -->
<target name="chrome-debug" depends="preinit, copy-chrome"/>
<!-- Copy the files required to build the Chrome extension to the build directory. -->
<target name="copy-chrome">
<copy todir="${buildDir}">
<fileset dir="${src.chrome}/"/>
</copy>
<!-- Copy all .js files from the common source directory and replace the "user" part in their name. -->
<copy todir="${buildDir}">
<fileset dir="${src}">
<include name="*.*"/>
<exclude name=".*"/>
</fileset>
<mapper>
<regexpmapper from="(.*?)(\.user)?.js$" to="\1.js"/>
</mapper>
</copy>
<!-- Replace pre-defined identifiers. -->
<antcall target="tokenreplace"/>
<!-- Copy required icons to output directory. -->
<copy todir="${buildDir}/icons">
<fileset dir="${src.icons}">
<include name="icon16.png"/>
<include name="icon48.png"/>
<include name="icon128.png"/>
</fileset>
</copy>
</target>
<!-- Put the Chrome extension files in a ZIP (for Chrome Web Store upload). -->
<target name="chrome-zip" depends="preinit, copy-chrome">
<zip destfile="${buildDir}/chrome.zip" basedir="${buildDir}"/>
<copy file="${buildDir}/chrome.zip" tofile="${dist}/${name}-webstore.zip"/>
</target>
<!-- Build the Chrome CRX package for direct installation. -->
<target name="chrome-crx" depends="chrome-keycheck, build-chrome-key">
<condition property="isMac">
<os family="mac"/>
</condition>
<if>
<os family="mac"/>
<then>
<echo message="Building the Chrome CRX archive is currently not supported on the MacOS operating system family!"/>
</then>
<else>
<exec executable="${sdk.buildcrx}" failonerror="true">
<arg value="${buildDir}/chrome.zip"/>
<arg value="${cert.chrome}"/>
<arg value="${dist}/${name}.crx"/>
</exec>
</else>
</if>
</target>
<!-- Check if the key for signing the Chrome extension exists. -->
<target name="chrome-keycheck">
<condition property="cert.chrome.found">
<available file="${cert.chrome}" type="file"/>
</condition>
</target>
<!-- Generate a private key if none was found. -->
<target name="build-chrome-key" unless="cert.chrome.found">
<exec executable="openssl">
<arg value="genrsa"/>
<arg value="-out"/>
<arg value="${cert.chrome}"/>
<arg value="2048"/>
</exec>
</target>
<!-- Build the Firefox extension. -->
<target name="firefox" depends="preinit, copy-firefox">
<exec executable="${python2}" failonerror="true">
<arg line="${sdk.cfx}"/>
<arg line="--pkgdir"/>
<arg line="${buildDir}"/>
<arg line="--output-file"/>
<arg line="${buildDir}/${name}.xpi"/>
<arg line="xpi"/>
</exec>
<copy file="${buildDir}/${name}.xpi" tofile="${dist}/${name}.xpi"/>
<antcall target="clean"/>
</target>
<!-- Compiles the extension and runs it in an instance of Firefox. -->
<target name="firefox-debug" depends="preinit, copy-firefox">
<exec executable="${python2}" failonerror="true">
<arg line="${sdk.cfx}"/>
<arg line="--pkgdir"/>
<arg line="${buildDir}"/>
<arg line="--output-file"/>
<arg line="${buildDir}/${name}.xpi"/>
<arg line="run"/>
</exec>
</target>
<!-- Copy the files required to build the Firefox extension to the build directory. -->
<target name="copy-firefox">
<!-- Copy all .js files from the common source directory and replace the "user" part in their name. -->
<copy todir="${buildDir}">
<fileset dir="${src}">
<include name="*.*"/>
<exclude name=".*"/>
</fileset>
<mapper>
<regexpmapper from="(.*?)(\.user)?.js$" to="\1.js"/>
</mapper>
</copy>
<!-- Move the files to the content subfolder -->
<move todir="${buildDir}/data">
<fileset dir="${buildDir}"/>
</move>
<copy todir="${buildDir}">
<fileset dir="${src.firefox}/"/>
</copy>
<!-- Replace pre-defined identifiers. -->
<antcall target="tokenreplace"/>
<copy todir="${buildDir}/content/icons">
<fileset dir="${src.icons}">
<include name="icon48.png"/>
<include name="icon64.png"/>
</fileset>
</copy>
</target>
<!-- Clean the build directory. -->
<target name="clean">
<delete dir="${buildDir}"/>
</target>
<!-- Alias to run all clean tasks. -->
<target name="clean-all" depends="clean"/>
</project>