-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.xml
393 lines (354 loc) · 11.9 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
<project name="ShockTherapy" default="dist" basedir=".">
<description>
Plasma globe simulator
</description>
<property name="app_name" value="${ant.project.name}"/>
<property name="android_target_id" value="android-29"/>
<property name="android_activity" value="ShockTherapyActivity"/>
<property name="android_package" value="com.googlecode.electroshocktherapy"/>
<property name="android.key.store" location="../keys/ShockTherapy.keystore"/>
<property name="android.key.alias" value="shocktherapy"/>
<property name="android.ant.target" value="debug"/>
<property name="chrome_key" location="../keys/ShockTherapy.pem"/>
<property environment="env" />
<property name="PATH" value="${env.PATH}" />
<property name="output" location="."/>
<property name="build" location="${output}/build"/>
<property name="dist" location="${output}/dist"/>
<property name="android_project_build" location="${build}/android_project"/>
<property name="chrome_build" location="${build}/chrome_app"/>
<property name="sugar_build" location="${build}/ShockTherapy.activity"/>
<property name="exec_search_list">
android
chrome
</property>
<property name="exec_search_android">
android
/opt/android-sdk-update-manager/tools/android
android.bat
C:/Program File/Android/android-sdk/tools/android.bat
C:/Program Files (x86)/Android/android-sdk/tools/android.bat
</property>
<property name="exec_search_chrome">
chromium-browser
google-chrome
chrome
chrome.exe
C:/Program Files/Google/Chrome/Application/chrome.exe
C:/Program Files (x86)/Google/Chrome/Application/chrome.exe
</property>
<script language="javascript"> <![CDATA[
this.importClass || load("nashorn:mozilla_compat.js");
importClass(java.io.File);
importClass(java.lang.System);
var path = new String(project.getProperty("PATH")).split(File.pathSeparator);
var resolvePath = function(filename) {
var f = new File(filename);
if (f.isAbsolute()) {
if (f.exists())
return filename;
return null;
}
for (var i = 0; i < path.length; i++) {
f = new File(path[i], filename);
if (f.exists())
return f.getAbsolutePath();
}
return null;
}
var searchPaths = function(paths) {
var p;
for (var i = 0; i < paths.length; i++) {
p = paths[i];
if (p.length > 0) {
p = resolvePath(p);
if (p !== null)
return p;
}
}
return null;
}
var prop_list = new String(
project.getProperty("exec_search_list")).split("\n")
for (var i = 0; i < prop_list.length; i++) {
var name = prop_list[i];
if (name.length == 0)
continue
var result = searchPaths(new String(
project.getProperty("exec_search_" + name)).split("\n"));
if (result !== null) {
System.out.println("INFO: " + name + " _exec=" + result);
project.setProperty(name + "_exec", result);
}
else
System.err.println(
"ERROR: could not locate " + name + " executable");
}
]]></script>
<target name="clean"
description="clean up" >
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
<target name="init" depends="clean">
<mkdir dir="${build}"/>
<mkdir dir="${dist}"/>
</target>
<target name="build.icons">
<mkdir dir="${build}/util/svg"/>
<javac srcdir="util/svg" destdir="${build}/util/svg" includeantruntime="false"/>
<mkdir dir="${build}/icons"/>
<java classname="CreateIcon" failonerror="true">
<arg file="web/icons/High_voltage_warning.svg"/>
<arg file="${build}/icons"/>
<arg value="512 128 96 72 48 36 16"/>
<arg value="2.0"/>
<arg value="0.5"/>
<arg value="true"/>
<classpath>
<pathelement path="${build}/util/svg"/>
</classpath>
</java>
<java classname="CreateIcon" failonerror="true">
<arg file="web/icons/Overflow_button.svg"/>
<arg file="${build}/icons"/>
<arg value="32"/>
<arg value="0"/>
<arg value="0"/>
<arg value="true"/>
<classpath>
<pathelement path="${build}/util/svg"/>
</classpath>
</java>
<java classname="CreateIcon" failonerror="true">
<arg file="web/icons/Up_button.svg"/>
<arg file="${build}/icons"/>
<arg value="48"/>
<arg value="2.0"/>
<arg value="0.5"/>
<arg value="false"/>
<classpath>
<pathelement path="${build}/util/svg"/>
</classpath>
</java>
</target>
<target name="build.favicon" depends="build.icons">
<exec executable="./node_modules/grunt-cli/bin/grunt">
<arg value="--output=${output}"/>
<arg value="generate-favicon"/>
</exec>
</target>
<target name="build.android" depends="init, build.icons, build.favicon">
<exec executable="${android_exec}" searchpath="true" failonerror="true">
<arg value="create"/>
<arg value="project"/>
<arg value="--target"/>
<arg value="${android_target_id}"/>
<arg value="--name"/>
<arg value="${app_name}"/>
<arg value="--path"/>
<arg value="${android_project_build}"/>
<arg value="--activity"/>
<arg value="${android_activity}"/>
<arg value="--package"/>
<arg value="${android_package}"/>
</exec>
<copy todir="${android_project_build}" overwrite="true">
<fileset dir="android">
</fileset>
</copy>
<copy todir="${android_project_build}/assets" overwrite="true">
<fileset dir="web">
<exclude name="icons/**"/>
<exclude name="layout/demo/**"/>
<exclude name="lib/**"/>
<exclude name="manifest.json"/>
<!-- the android app uses a smaller sound file from res/raw -->
<exclude name="sounds/**"/>
</fileset>
</copy>
<mkdir dir="${android_project_build}/assets/icons"/>
<copy file="${build}/icons/High_voltage_warning_48.png"
tofile="${android_project_build}/assets/icons/High_voltage_warning_48.png">
</copy>
<copy file="${build}/icons/High_voltage_warning_48.ico"
tofile="${android_project_build}/assets/icons/High_voltage_warning_48.ico">
</copy>
<copy file="${build}/icons/Overflow_button_32.png"
tofile="${android_project_build}/assets/icons/Overflow_button_32.png">
</copy>
<copy file="${build}/icons/Up_button_48.png"
tofile="${android_project_build}/assets/icons/Up_button_48.png">
</copy>
<mkdir dir="${android_project_build}/res/drawable-ldpi"/>
<copy file="${build}/icons/High_voltage_warning_36.png"
tofile="${android_project_build}/res/drawable-ldpi/ic_launcher.png"
overwrite="true"></copy>
<mkdir dir="${android_project_build}/res/drawable-mdpi"/>
<copy file="${build}/icons/High_voltage_warning_48.png"
tofile="${android_project_build}/res/drawable-mdpi/ic_launcher.png"
overwrite="true"></copy>
<mkdir dir="${android_project_build}/res/drawable-hdpi"/>
<copy file="${build}/icons/High_voltage_warning_72.png"
tofile="${android_project_build}/res/drawable-hdpi/ic_launcher.png"
overwrite="true"></copy>
<mkdir dir="${android_project_build}/res/drawable-xhdpi"/>
<copy file="${build}/icons/High_voltage_warning_96.png"
tofile="${android_project_build}/res/drawable-xhdpi/ic_launcher.png"
overwrite="true"></copy>
<!-- Generate a longer loop of electric_discharge.wav, since SoundPool
can produce poor results with an extremely short loop. -->
<mkdir dir="${android_project_build}/res/raw"/>
<mkdir dir="${build}/util/audio"/>
<javac srcdir="util/audio" destdir="${build}/util/audio" includeantruntime="false"/>
<java classname="RepeatAudioLoop" failonerror="true">
<arg value="1"/>
<arg file="web/sounds/electric_discharge.wav"/>
<arg file="${android_project_build}/res/raw/electric_discharge.wav"/>
<classpath>
<pathelement path="${build}/util/audio"/>
</classpath>
</java>
<concat destfile="${android_project_build}/ant.properties" append="yes">
<string value="key.store=${android.key.store} "></string>
<string value="key.alias=${android.key.alias} "></string>
</concat>
</target>
<target name="dist.android" depends="build.android">
<subant target="${android.ant.target}">
<fileset file="${android_project_build}/build.xml"/>
</subant>
<move file="${android_project_build}/bin/${app_name}-${android.ant.target}.apk"
tofile="${dist}/${app_name}.apk"/>
</target>
<target name="dist.android.release">
<antcall target="dist.android">
<param name="android.ant.target" value="release"/>
</antcall>
</target>
<target name="dist.chrome" depends="init, build.icons">
<mkdir dir="${chrome_build}"/>
<copy todir="${chrome_build}">
<fileset dir="web">
<exclude name="icons/**"/>
<exclude name="layout/demo/**"/>
<exclude name="lib/**"/>
<!-- chrome only needs the wav file -->
<exclude name="sounds/*.mp3"/>
<exclude name="sounds/*.ogg"/>
</fileset>
</copy>
<copy todir="${chrome_build}" overwrite="true">
<fileset dir="${build}">
<include name="icons/High_voltage_warning_16.png"/>
<include name="icons/High_voltage_warning_48.png"/>
<include name="icons/High_voltage_warning_48.ico"/>
<include name="icons/High_voltage_warning_128.png"/>
<include name="icons/Overflow_button_32.png"/>
<include name="icons/Up_button_48.png"/>
</fileset>
</copy>
<zip destfile="${dist}/ShockTherapy-chrome.zip"
basedir="${chrome_build}"
/>
<script language="javascript"> <![CDATA[
this.importClass || load("nashorn:mozilla_compat.js");
importClass(java.io.File);
importClass(java.lang.System);
var arg, args, exec, chrome_key;
args = [
"--no-message-box",
"--pack-extension=" + project.getProperty("chrome_build")
];
chrome_key = project.getProperty("chrome_key");
if (chrome_key !== null && new File(chrome_key).exists())
args.push("--pack-extension-key=" + chrome_key);
else
System.out.println(
"INFO: file not found: chrome_key=" + chrome_key);
exec = project.createTask("exec");
exec.setExecutable(project.getProperty("chrome_exec"));
exec.setFailonerror(true);
for (var i = 0; i < args.length; i++) {
arg = exec.createArg();
arg.setValue(args[i]);
}
exec.perform();
]]></script>
<move file="${chrome_build}.crx"
tofile="${dist}/${app_name}.crx"/>
</target>
<target name="dist.sugar" depends="init, build.icons">
<property name="sugar_activity_src" location="sugar/ShockTherapy.activity"/>
<copy todir="${sugar_build}">
<fileset dir="${sugar_activity_src}">
<exclude name="MANIFEST"/>
</fileset>
</copy>
<copy todir="${sugar_build}/web">
<fileset dir="web">
<exclude name="icons/**"/>
<exclude name="layout/demo/**"/>
<exclude name="lib/**"/>
<!-- WebKitGTK+ needs the ogg for the HTMLAudioElement, or
wav for the new "Web Audio API" (if supported). -->
<exclude name="sounds/*.mp3"/>
</fileset>
</copy>
<mkdir dir="${sugar_build}/web/icons"/>
<copy file="${build}/icons/High_voltage_warning_48.png"
tofile="${sugar_build}/web/icons/High_voltage_warning_48.png">
</copy>
<copy file="${build}/icons/High_voltage_warning_48.ico"
tofile="${sugar_build}/web/icons/High_voltage_warning_48.ico">
</copy>
<copy file="${build}/icons/Overflow_button_32.png"
tofile="${sugar_build}/web/icons/Overflow_button_32.png">
</copy>
<copy file="${build}/icons/Up_button_48.png"
tofile="${sugar_build}/web/icons/Up_button_48.png">
</copy>
<script language="javascript"> <![CDATA[
this.importClass || load("nashorn:mozilla_compat.js");
importClass(java.io.File);
importClass(java.lang.System);
function recursiveFileList(base_dir) {
var child_f, current, dir_list, f, i, result, stack;
stack = [base_dir]
result = [];
while (stack.length > 0) {
current = stack.pop();
f = new File(current);
dir_list = f.list();
for (i = 0; i < dir_list.length; i++) {
child_f = new File(current, dir_list[i]);
if (child_f.isDirectory())
stack.push(child_f.getAbsolutePath());
else {
child_f = child_f.getAbsolutePath();
child_f = child_f.substring(base_dir.length()+1, child_f.length());
result.push(child_f);
}
}
}
return result;
}
var i, result;
result = recursiveFileList(project.getProperty("sugar_build"));
result.sort();
result.push("");
result = result.join("\n");
project.setProperty("sugar_manifest_content", result);
]]></script>
<concat destfile="${sugar_build}/MANIFEST">
<string value="${sugar_manifest_content}"></string>
</concat>
<zip destfile="${dist}/ShockTherapy.xo"
basedir="${sugar_build}/.."
includes="ShockTherapy.activity/**"
/>
</target>
<target name="dist" depends="dist.android, dist.chrome, dist.sugar"
description="generate the distribution" >
</target>
</project>