/
build.xml
474 lines (416 loc) · 17.5 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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
<?xml version="1.0" encoding="UTF-8"?>
<project name="sockso" default="run" basedir=".">
<description>Builds, runs and packages Sockso</description>
<!--
#############
INIT/PROPS
#############
-->
<property file="sockso.properties" />
<property name="sockso.version" value="1.5.1" />
<property name="dir.build" value="build/app" />
<property name="dir.build.test" value="build/test" />
<property name="dir.dist" value="dist" />
<property name="dir.docs" value="docs" />
<property name="dir.docs.junit" value="${dir.docs}/junit" />
<property name="dir.src" value="src" />
<property name="dir.src.test" value="test" />
<property name="dir.lib" value="lib/std" />
<property name="dir.lib-dev" value="lib/dev" />
<property name="dir.lib-opt" value="lib/opt" />
<property name="dir.temp" value="ant-temp-dir" />
<property name="dir.resources" value="resources" />
<property name="dir.packages" value="packages" />
<property name="dir.scripts" value="scripts" />
<property name="dir.javadocs" value="${dir.docs}/javadocs" />
<property name="dir.www" value="www" />
<!-- set classpaths for jars -->
<fileset id="sockso.jars" dir=".">
<include name="${dir.lib}/*.jar" />
</fileset>
<pathconvert pathsep=":" property="app.classpath" refid="sockso.jars">
<map from="${basedir}/" to=""/>
</pathconvert>
<pathconvert pathsep=" " property="jar.classpath" refid="sockso.jars">
<map from="${basedir}/" to=" "/>
</pathconvert>
<!-- classpath for dev jars -->
<fileset id="sockso-dev.jars" dir=".">
<include name="${dir.lib-dev}/*.jar" />
</fileset>
<pathconvert pathsep=":" property="dev.classpath" refid="sockso-dev.jars">
<map from="${basedir}/" to=""/>
</pathconvert>
<!-- classpath for optional jars -->
<fileset id="sockso-opt.jars" dir=".">
<include name="${dir.lib-opt}/*.jar" />
</fileset>
<pathconvert pathsep=":" property="opt.classpath" refid="sockso-opt.jars">
<map from="${basedir}/" to=""/>
</pathconvert>
<pathconvert pathsep=" " property="jar-opt.classpath" refid="sockso-opt.jars">
<map from="${basedir}/" to=" "/>
</pathconvert>
<property name="junit.classpath" value="${dir.build}:${dir.build.test}:${app.classpath}:${dev.classpath}:${opt.classpath}" />
<taskdef name="jamon"
classname="org.jamon.ant.JamonTask"
classpath="${dir.lib}/jamon-runtime-2.3.1.jar:${dir.lib-dev}/jamon-api-2.3.0.jar:${dir.lib-dev}/jamon-processor-2.3.2.jar:${dir.lib-dev}/jamon-anttask-2.3.1.jar" />
<taskdef name="jarbundler"
classname="net.sourceforge.jarbundler.JarBundler"
classpath="${dir.lib-dev}/jarbundler-2.1.0.jar" />
<taskdef name="testability"
classname="com.google.ant.TestabilityTask"
classpath="${dev.classpath}" />
<taskdef resource="net/sf/antcontrib/antcontrib.properties"
classpath="${dev.classpath}" />
<target name="init">
<mkdir dir="${dir.dist}" />
<mkdir dir="${dir.build}" />
<mkdir dir="${dir.build.test}" />
<mkdir dir="${dir.packages}" />
<if>
<not><available file="sockso.properties" /></not>
<then>
<copy file="sockso.properties-sample" tofile="sockso.properties" />
</then>
</if>
</target>
<!--
################
COMPILE/BUILD
################
-->
<!-- compile jamon source files to java classes -->
<target name="compile-templates" depends="init">
<delete dir="${dir.src}/com/pugh/mymusic/tmpl" />
<jamon destdir="${dir.src}" srcdir="templates" />
</target>
<!-- creates a file with some properties info -->
<target name="create-properties">
<!-- write app properties file -->
<echo file="src/com/pugh/sockso/Sockso.java">
package com.pugh.sockso;
public class Sockso {
public static final String VERSION = "${sockso.version}";
}
</echo>
</target>
<!-- compiles the project to build/ -->
<target name="compile" depends="create-properties,compile-templates">
<!-- then do compile -->
<javac srcdir="${dir.src}"
destdir="${dir.build}"
classpath="${app.classpath}:${opt.classpath}"
target="1.5"
debug="${debug}"
includeantruntime="true">
<compilerarg value="-Xlint:unchecked" />
<compilerarg value="-Xlint:deprecation" />
</javac>
</target>
<!-- builds resources -->
<target name="resources" depends="init">
<!-- compile stub file -->
<javac srcdir="${dir.resources}" destdir="${dir.resources}" includeantruntime="true" />
<!-- remove locale javascript files, we don't want to pack them -->
<delete>
<fileset dir="${dir.resources}/htdocs/js" includes="locale*.js" />
</delete>
<!-- pack javascript -->
<exec executable="${php.exe}">
<arg value="${dir.scripts}/pack-resources.php" />
<arg value="${sockso.version}" />
</exec>
<!-- create locale javascript files -->
<exec executable="${php.exe}">
<arg value="${dir.scripts}/create-locale-javascript.php" />
<arg value="${sockso.version}" />
</exec>
<!-- create locale index file -->
<exec executable="${php.exe}">
<arg value="${dir.scripts}/create-locale-index.php" />
<arg value="${sockso.version}" />
</exec>
<!-- build jar -->
<jar basedir="${dir.resources}" destfile="${dir.dist}/resources.jar">
<fileset dir="${dir.resources}">
<exclude name="**/*.java" />
<!-- TODO: exclude all javascript but the packed javascript file -->
</fileset>
</jar>
<!-- copy files to dist dir -->
<copy todir="${dir.dist}/resources">
<fileset dir="resources" />
</copy>
</target>
<!-- puts the dist together -->
<target name="dist" depends="jars">
<copy todir="${dir.dist}">
<fileset dir="dist-files" />
</copy>
<copy todir="${dir.dist}/lib/std">
<fileset dir="${dir.lib}" />
</copy>
<!-- windows tray icon -->
<mkdir dir="${dir.dist}/icons" />
<copy file="${dir.resources}/icons/tray.ico" todir="${dir.dist}/icons" />
</target>
<!-- creates all the main sockso jar files -->
<target name="jars" depends="jar,resources" />
<!-- cleans any compiles tests -->
<target name="clean-tests">
<delete dir="${dir.build.test}" />
</target>
<!-- cleans the dist build -->
<target name="clean" depends="clean-tests">
<delete dir="${dir.build}" />
<delete dir="${dir.dist}" />
<delete dir="${dir.src}/com/pugh/sockso/templates" />
<delete dir="${dir.packages}" />
</target>
<!-- build the main jar file -->
<target name="jar" depends="compile">
<jar file="${dir.dist}/sockso.jar" basedir="${dir.build}">
<include name="**/*.class" />
<manifest>
<attribute name="Built-By" value="${developer.name}" />
<attribute name="Main-class" value="com.pugh.sockso.Main" />
<attribute name="Class-Path" value="resources.jar ${jar.classpath} ${jar-opt.classpath}" />
</manifest>
</jar>
</target>
<target name="lint-js" description="run jslint on javascript files">
<exec executable="rhino" failonerror="true">
<arg value="scripts/lint.js" />
</exec>
</target>
<!--
#####################
DOCS/PACKAGING
#####################
-->
<target name="javadocs">
<javadoc sourcepath="${dir.src}" destdir="${dir.javadocs}" classpath="${app.classpath}:${dev.classpath}:${opt.classpath}" />
</target>
<!-- make packages from dist -->
<target name="package" depends="clean,dist,website">
<mkdir dir="${dir.temp}" />
<move file="${dir.dist}" tofile="${dir.temp}/sockso-${sockso.version}" />
<!-- OSX.
1. create .app folder -->
<jarbundler dir="${dir.packages}"
name="sockso-${sockso.version}"
shortname="Sockso"
mainclass="com.pugh.sockso.Main"
icon="${dir.resources}/icons/sockso.icns"
version="${sockso.version}"
infostring="Sockso - Personal Music Server"
arguments="--resourcestype=jar"
jvmversion="1.5+">
<jarfileset dir="${dir.temp}">
<include name="**/*.jar" />
</jarfileset>
</jarbundler>
<!-- 2. create dmg's from .app folder -->
<exec executable="hdiutil">
<arg line="create -srcfolder ${dir.packages}/sockso-${sockso.version}.app ${dir.packages}/sockso-${sockso.version}.dmg"/>
</exec>
<copy file="${dir.packages}/sockso-${sockso.version}.dmg" tofile="${dir.packages}/sockso-latest.dmg" />
<copy file="${dir.packages}/sockso-${sockso.version}.dmg" tofile="${dir.packages}/sockso-dev.dmg" />
<!-- 3. remove .app folder -->
<delete dir="${dir.packages}/sockso-${sockso.version}.app" />
<!-- we need the resources.jar files for the mac bundle, but not other packages -->
<delete file="${dir.temp}/sockso-${sockso.version}/resources.jar" />
<delete file="${dir.temp}/sockso-${sockso.version}/resources/ResourcesAnchor.class" />
<delete file="${dir.temp}/sockso-${sockso.version}/resources/ResourcesAnchor.java" />
<!-- make standard packages -->
<zip destfile="${dir.packages}/sockso-dev.zip" basedir="${dir.temp}" />
<zip destfile="${dir.packages}/sockso-latest.zip" basedir="${dir.temp}" />
<zip destfile="${dir.packages}/sockso-${sockso.version}.zip" basedir="${dir.temp}" />
<!-- @todo make 64bit windows archive -->
<!-- done, cleanup! -->
<move file="${dir.temp}/sockso-${sockso.version}" tofile="${dir.dist}" />
<delete dir="${dir.temp}" />
<!-- build optionals package -->
<zip destfile="${dir.packages}/sockso-optionals.zip" basedir="${dir.lib-opt}" />
</target>
<!-- updates the website (if it's configured) with information like current version -->
<target name="website">
<if>
<not><equals arg1="${website.path}" arg2="" /></not>
<then>
<property name="template" value="${website.path}/views/controllers/version/latest.tpl" />
<echo message="Updating website with latest version ${sockso.version}" />
<echo message="Template: ${template}" />
<echo file="${template}">${sockso.version}</echo>
</then>
</if>
</target>
<!-- includes optional components into the distribution -->
<target name="optionals">
<copy todir="${dir.dist}/lib/opt">
<fileset dir="${dir.lib-opt}" />
</copy>
</target>
<!--
##################
RUN/DEBUG
##################
-->
<!-- runs the project -->
<target name="run" depends="dist,optionals">
<java jar="${dir.dist}/sockso.jar" dir="${dir.dist}/" fork="true" jvm="${ant.run.jvm}">
<arg value="--logtype=${run.arg.logtype}" />
<arg value="--resourcestype=${run.arg.resourcestype}" />
<arg value="--dbtype=${run.arg.dbtype}" />
<arg value="--dbhost=${run.arg.dbhost}" />
<arg value="--dbuser=${run.arg.dbuser}" />
<arg value="--dbpass=${run.arg.dbpass}" />
<arg value="--dbname=${run.arg.dbname}" />
</java>
</target>
<!-- starts a project in debug mode -->
<target name="debug" depends="clean,dist,optionals" if="netbeans.home">
<java jar="${dir.dist}/sockso.jar" dir="${dir.dist}/" fork="true" jvm="${ant.run.jvm}">
<arg value="--logtype=${run.arg.logtype}" />
<arg value="--resourcestype=${run.arg.resourcestype}" />
<arg value="--dbtype=${run.arg.dbtype}" />
<arg value="--dbhost=${run.arg.dbhost}" />
<arg value="--dbuser=${run.arg.dbuser}" />
<arg value="--dbpass=${run.arg.dbpass}" />
<arg value="--dbname=${run.arg.dbname}" />
<jvmarg value="-Xdebug" />
<jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,address=8888,suspend=n" />
</java>
</target>
<target name="profile" depends="dist,optionals" if="netbeans.home">
<nbprofiledirect>
</nbprofiledirect>
<java jar="${dir.dist}/sockso.jar" dir="${dir.dist}/" fork="true" jvm="${ant.run.jvm}">
<arg value="--logtype=${run.arg.logtype}" />
<arg value="--resourcestype=${run.arg.resourcestype}" />
<arg value="--dbtype=${run.arg.dbtype}" />
<arg value="--dbhost=${run.arg.dbhost}" />
<arg value="--dbuser=${run.arg.dbuser}" />
<arg value="--dbpass=${run.arg.dbpass}" />
<arg value="--dbname=${run.arg.dbname}" />
<jvmarg value="${profiler.info.jvmargs.agent}" />
</java>
</target>
<!--
##################
TESTING
##################
-->
<!-- compile test cases -->
<target name="compile-tests">
<javac srcdir="${dir.src.test}"
destdir="${dir.build.test}"
classpath="${dir.build}:${app.classpath}:${dev.classpath}"
target="1.5"
debug="on"
includeantruntime="true">
<compilerarg value="-Xlint:unchecked" />
<compilerarg value="-Xlint:deprecation" />
</javac>
</target>
<!-- init before we do tests -->
<target name="init-tests">
<if>
<equals arg1="${mysql.enabled}" arg2="1" />
<then>
<sql driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://${mysql.host}"
userid="${mysql.user}"
password="${mysql.pass}"
classpath="${opt.classpath}"
onerror="continue">
<transaction src="test/data/mysql/drop.sql"/>
<transaction src="test/data/mysql/create.sql"/>
</sql>
</then>
</if>
</target>
<!-- tests a particular class -->
<!-- the class to test needs to be specified on the command line by using:
-Dclass=FULL_CLASSNAME -->
<target name="test-single" depends="compile,compile-tests,init-tests">
<fail unless="class">Must set property 'class'</fail>
<junit haltonfailure="true">
<classpath path="${junit.classpath}" />
<formatter type="plain" usefile="false" />
<test name="${class}" />
</junit>
</target>
<!-- run all tests and generate reports -->
<target name="test" depends="clean,compile,compile-tests,init-tests">
<delete dir="${dir.docs.junit}" />
<mkdir dir="${dir.docs.junit}" />
<mkdir dir="${dir.docs.junit}/html" />
<mkdir dir="${dir.docs.junit}/results" />
<junit haltonfailure="true" dir=".">
<classpath path="${junit.classpath}" />
<formatter type="plain" usefile="false" />
<formatter type="xml" />
<batchtest fork="yes" todir="${dir.docs.junit}/results">
<fileset dir="${dir.build.test}">
<include name="**/*Test.class" />
</fileset>
</batchtest>
</junit>
<junitreport todir="${dir.docs.junit}">
<fileset dir="${dir.docs.junit}/results">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${dir.docs.junit}/html"/>
</junitreport>
</target>
<!-- runs the testability reports -->
<target name="testability" depends="clean,dist">
<testability
filter=""
resultfile="${dir.docs}/testability.result.html"
errorfile="${dir.docs}/testability.err.txt"
printdepth="2"
print="html"
mincost="1"
maxexcellentcost="50"
maxacceptablecost="100"
worstoffendercount="25"
whitelist="com.pugh.sockso."
cyclomatic="1"
global="10"
failproperty="testability.failproperty">
<classpath>
<fileset dir="${dir.dist}">
<include name="sockso.jar"/>
</fileset>
</classpath>
</testability>
</target>
<target name="test-all" depends="test,test-js" />
<!-- starts the js test server -->
<target name="test-js-server">
<java jar="${dir.lib-dev}/JsTestDriver-${jstestdriver.version}.jar" fork="true">
<arg value="--port" />
<arg value="${jstestdriver.port}" />
</java>
</target>
<!-- runs the js tests -->
<target name="test-js">
<waitfor maxwait="1" maxwaitunit="second">
<socket server="localhost" port="${jstestdriver.port}"/>
</waitfor>
<!--
<condition property="tests" value="${tests}" else="all">
<isset property="tests" />
</condition>
-->
<java jar="${dir.lib-dev}/JsTestDriver-${jstestdriver.version}.jar" fork="true">
<arg value="--config" />
<arg value="test/js/jsTestDriver.conf" />
<arg value="--tests" />
<arg value="all" />
</java>
</target>
</project>