-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbuild.xml
447 lines (376 loc) · 15.6 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
<project name="zaproxy-test" default="test" basedir=".">
<description>Run the ZAP JUnit tests.</description>
<!-- set global properties for this build -->
<property name="build" location="build" />
<property name="build.src" location="src-build" />
<property name="helpertasks.jar.name" value="helpertasks.jar" />
<property name="lib.dir" location="lib" />
<property name="src" location="src" />
<property name="src.version" value="1.7" />
<property name="zaproxy" location="../zaproxy" />
<property name="zaproxy-2.2" location="../zaproxy-2.2" />
<property name="zaproxy-extensions" location="../zap-extensions" />
<property name="zaproxy-extensions-beta" location="../zap-extensions-beta" />
<property name="zaproxy-extensions-alpha" location="../zap-extensions-alpha" />
<path id="build.helpertasks.classpath">
<fileset dir="${lib.dir}" includes="${helpertasks.jar.name}"/>
<fileset dir="${zaproxy}/build/zap" includes="zap.jar"/>
</path>
<!-- Requires ZAP's clientapi at runtime (built with zaproxy project and included with zap.jar) -->
<typedef name="stopzapwithtimeout" classname="org.zaproxy.ant.zap.taskdefs.StopZapTimeout" classpathref="build.helpertasks.classpath" />
<!-- Detect Operating system -->
<condition property="isMac">
<os family="mac" />
</condition>
<condition property="isUnix">
<os family="unix" />
</condition>
<condition property="isWindows">
<os family="windows" />
</condition>
<target name="init">
<delete dir="${build}" includeEmptyDirs="true" />
<mkdir dir="${build}" />
</target>
<target name="build-helpertasks-jar" depends="init">
<local name="build.classes.dir" />
<property name="build.classes.dir" location="${build}/classes" />
<delete dir="${build.classes.dir}" includeEmptyDirs="true" />
<mkdir dir="${build.classes.dir}"/>
<javac srcdir="${build.src}" destdir="${build.classes.dir}" source="${src.version}"
target="${src.version}" includeantruntime="false" encoding="UTF-8">
<!-- Include required ZAP's clientapi -->
<classpath>
<fileset dir="${zaproxy}/build/zap">
<include name="zap.jar" />
</fileset>
</classpath>
</javac>
<jar jarfile="${lib.dir}/${helpertasks.jar.name}" update="true" compress="false" basedir="${build.classes.dir}" />
<delete dir="${build.classes.dir}" includeEmptyDirs="true" />
</target>
<macrodef name="compile-extensions-unittests">
<attribute name="basedir"/>
<attribute name="destdir" />
<sequential>
<javac srcdir="@{basedir}/test" destdir="@{destdir}" source="${src.version}" target="${src.version}" includeantruntime="false" debug="${debug}">
<classpath>
<fileset dir="@{basedir}/testlib">
<include name="*.jar" />
</fileset>
<fileset dir="@{basedir}/lib">
<include name="*.jar" />
</fileset>
<pathelement location="@{basedir}/build/build"/>
</classpath>
</javac>
</sequential>
</macrodef>
<target name="compile" depends="init" description="compile the source ">
<echo message="Compiling the source..." />
<!-- Compile with debug information if the property "javac.debug" is set to true -->
<local name="debug" />
<condition property="debug" value="true" else="false">
<istrue value="${javac.debug}" />
</condition>
<compile-extensions-unittests basedir="${zaproxy-extensions}" destdir="${build}" />
<compile-extensions-unittests basedir="${zaproxy-extensions-beta}" destdir="${build}" />
<compile-extensions-unittests basedir="${zaproxy-extensions-alpha}" destdir="${build}" />
<!-- Compile the java code from ${src} into ${build} -->
<!--javac srcdir="${src}" destdir="${build}" classpath="zap.jar"/-->
<javac srcdir="${src}" destdir="${build}" source="${src.version}" target="${src.version}" includeantruntime="false" debug="${debug}">
<classpath>
<fileset dir="lib">
<include name="*.jar" />
</fileset>
<fileset dir="${zaproxy}/lib">
<include name="*.jar" />
<exclude name="ant.jar" />
</fileset>
<fileset dir="${zaproxy}/build/zap">
<include name="zap.jar" />
</fileset>
<pathelement location="${build}"/>
<pathelement location="${zaproxy-extensions}/build/build"/>
<pathelement location="${zaproxy-extensions-beta}/build/build"/>
<pathelement location="${zaproxy-extensions-alpha}/build/build"/>
</classpath>
</javac>
<javac srcdir="${zaproxy}/test" destdir="${build}" source="${src.version}" target="${src.version}" includeantruntime="false" debug="${debug}">
<classpath>
<fileset dir="${zaproxy}/testlib">
<include name="*.jar" />
</fileset>
<fileset dir="${zaproxy}/lib">
<include name="*.jar" />
<exclude name="ant.jar" />
</fileset>
<fileset dir="${zaproxy}/build/zap">
<include name="zap.jar" />
</fileset>
</classpath>
</javac>
</target>
<target name="test" depends="compile">
<!-- Run the JUnit tests -->
<junit printsummary="yes" haltonerror="on">
<classpath>
<fileset dir="lib">
<include name="*.jar" />
<exclude name="ant*.jar" />
</fileset>
<fileset dir="${zaproxy}/lib">
<include name="*.jar" />
<exclude name="ant*.jar" />
<exclude name="junit*.jar" />
</fileset>
<fileset dir="${zaproxy}/build/zap">
<include name="zap.jar" />
<exclude name="ant*.jar" />
</fileset>
<pathelement location="${zaproxy-extensions}/bin"/> <!-- When running in Eclipse -->
<pathelement location="${zaproxy-extensions}/build/build"/> <!-- When running on build server -->
<pathelement location="${zaproxy-extensions-beta}/bin"/>
<pathelement location="${zaproxy-extensions-beta}/build/build"/>
<pathelement location="${zaproxy-extensions-alpha}/bin"/>
<pathelement location="${zaproxy-extensions-alpha}/build/build"/>
<pathelement location="bin"/> <!-- When running in Eclipse -->
<pathelement location="build"/> <!-- When running on build server -->
</classpath>
<formatter type="plain"/>
<formatter type="xml"/>
<batchtest fork="yes" todir="results">
<fileset dir="${build}">
<include name="**/*UnitTest.class"/>
<exclude name="**/Abstract*Test.class"/>
</fileset>
</batchtest>
</junit>
<!-- Run the quick unit tests -->
<antcall target="unit-test-start-stop"/>
<!-- The 2.2 tests will fail as the add-ons are not backwards compatible
<antcall target="unit-test-2.2-start-stop"/>
-->
</target>
<target name="check-for-errors">
<!-- Sanity check - there should always be some INFO messages -->
<copy file="${test-dir}/test/zap.log" tofile="${test-dir}/test/zap.info">
<filterchain>
<linecontains>
<contains value="INFO"/>
</linecontains>
</filterchain>
</copy>
<fail message="No INFO messages in ${test-dir}/test/zap.log'">
<condition>
<length file="${test-dir}/test/zap.info" when="eq" length="0" />
</condition>
</fail>
<!-- Now check for errors -->
<copy file="${test-dir}/test/zap.log" tofile="${test-dir}/test/zap.errors">
<filterchain>
<linecontains>
<contains value="ERROR"/>
</linecontains>
</filterchain>
</copy>
<!-- Echo any found to the console - cant use loadfile as it fails on empty files -->
<concat>
<fileset file="${test-dir}/test/zap.errors"/>
</concat>
<fail message="Found ERROR messages in ${test-dir}/test/zap.log">
<condition>
<!-- Error check - there shouldnt be any ERROR messages -->
<length file="${test-dir}/test/zap.errors" when="gt" length="0" />
</condition>
</fail>
</target>
<target name="deploy-addons">
<!-- Deploy all release add-ons -->
<copy todir="${test-dir}/plugin" overwrite="true">
<fileset dir="${zaproxy-extensions}/build/zap-exts" includes="*.zap" excludes="example*"/>
</copy>
<!-- Deploy all beta add-ons -->
<copy todir="${test-dir}/plugin" overwrite="true">
<fileset dir="${zaproxy-extensions-beta}/build/zap-exts" includes="*.zap"/>
</copy>
<!-- Deploy all alpha add-ons -->
<!-- Hold off doing this for now - too many errors
<copy todir="${test-dir}/plugin" overwrite="true">
<fileset dir="${zaproxy-extensions-alpha}/build/zap-exts" includes="*.zap"/>
</copy>
-->
</target>
<target name="deploy-to">
<!-- Deploy ZAP -->
<copy todir="${test-dir}">
<fileset dir="${zaproxy}/build/zap" />
</copy>
<chmod file="${test-dir}/zap.sh" perm="u+x"/>
<antcall target="deploy-addons">
<param name="test-dir" location="${test-dir}"/>
</antcall>
</target>
<target name="deploy-2.2-to">
<!-- Deploy ZAP -->
<copy todir="${test-dir}">
<fileset dir="${zaproxy-2.2}/build/zap" />
</copy>
<chmod file="${test-dir}/zap.sh" perm="u+x"/>
<antcall target="deploy-addons">
<param name="test-dir" location="${test-dir}"/>
</antcall>
</target>
<target name="unit-test-start-stop">
<!-- Start and stop ZAP as a daemon and check if any errors logged -->
<property name="test-dir" value="start-stop-dir" />
<delete dir="${test-dir}" includeEmptyDirs="true" />
<mkdir dir="${test-dir}" />
<antcall target="deploy-to">
<param name="test-dir" location="${test-dir}"/>
</antcall>
<condition property="script" value="zap.bat" else="./zap.sh">
<istrue value="${isWindows}" />
</condition>
<local name="zapport" />
<property name="zapport" value="8090" />
<exec dir="${test-dir}" executable="${script}" spawn="true">
<arg value="-daemon"/>
<arg line="-dir test"/>
<arg value="-port"/>
<arg value="${zapport}"/>
</exec>
<stopzapwithtimeout zapaddress="localhost" zapport="${zapport}" timeout="60" pollinginterval="1" />
<!-- Give time to shut down -->
<sleep seconds="5"/>
<antcall target="check-for-errors">
<param name="test-dir" location="${test-dir}"/>
</antcall>
</target>
<target name="unit-test-2.2-start-stop">
<!-- Start and stop ZAP 2.2 as a daemon and check if any errors logged -->
<property name="test-dir" value="start-stop-2.2-dir" />
<delete dir="${test-dir}" includeEmptyDirs="true" />
<mkdir dir="${test-dir}" />
<antcall target="deploy-2.2-to">
<param name="test-dir" location="${test-dir}"/>
</antcall>
<condition property="script" value="zap.bat" else="./zap.sh">
<istrue value="${isWindows}" />
</condition>
<local name="zapport" />
<property name="zapport" value="8090" />
<exec dir="${test-dir}" executable="${script}" spawn="true">
<arg value="-daemon"/>
<arg line="-dir test"/>
<arg value="-port"/>
<arg value="${zapport}"/>
</exec>
<stopzapwithtimeout zapaddress="localhost" zapport="${zapport}" timeout="60" pollinginterval="1" />
<!-- Give time to shut down -->
<sleep seconds="5"/>
<antcall target="check-for-errors">
<param name="test-dir" location="${test-dir}"/>
</antcall>
</target>
<target name="unit-test">
<!--
A parameterized task for running command line scans of urls.
Do not call directly.
You should typicaly have built zaproxy zaproxy-extensions and zaproxy-extensions-beta prior to this,
but might well not want to do that every time, which is why its not automated.
-->
<delete dir="${test-dir}" includeEmptyDirs="true" />
<mkdir dir="${test-dir}" />
<antcall target="deploy-to">
<param name="test-dir" location="${test-dir}"/>
</antcall>
<condition property="script" value="zap.bat" else="./zap.sh">
<istrue value="${isWindows}" />
</condition>
<exec dir="${test-dir}" executable="${script}">
<arg value="-cmd"/>
<arg line="-dir test"/>
<arg value="-quickurl"/>
<arg value="${test-url}"/>
<arg line="-quickout scan-result.xml"/>
<arg line="-port 8090"/>
</exec>
<antcall target="check-for-errors">
<param name="test-dir" location="test-bodgeit"/>
</antcall>
<!-- TODO
compare results!
-->
</target>
<target name="unit-test-bodgeit">
<antcall target="unit-test">
<param name="test-dir" location="test-bodgeit"/>
<param name="test-url" value="http://localhost:8080/bodgeit/"/>
</antcall>
</target>
<target name="bodgeittest" depends="compile">
<!-- Start ZAP -->
<antcall target="startZapDaemon" />
<!--
<antcall target="startZapDaemon" />
-->
<!-- Run the Bodgeit JUnit tests -->
<junit printsummary="yes" haltonerror="on">
<classpath>
<fileset dir="lib">
<include name="*.jar" />
<exclude name="ant*.jar" />
</fileset>
<fileset dir="${zaproxy}/lib">
<include name="*.jar" />
<exclude name="junit*.jar" />
<exclude name="mockito*.jar" />
</fileset>
<fileset dir="${zaproxy}/build/zap">
<include name="zap.jar" />
</fileset>
<pathelement location="bin"/> <!-- When running in Eclipse -->
<pathelement location="build"/> <!-- When running on build server -->
</classpath>
<formatter type="plain"/>
<formatter type="xml"/>
<batchtest fork="yes" todir="results">
<fileset dir="src">
<include name="org/zaproxy/zap/BodgeItIntegrationTest.java"/>
</fileset>
</batchtest>
</junit>
<!-- Stop ZAP -->
<!--stopZapTask zapAddress="${zapaddr}" zapPort="${zapport}"/-->
</target>
<property name="zapaddr" value="localhost" />
<property name="zapport" value="8090" />
<property name="zapdir" value="/home/simon/tools/zap" />
<target name="startZap">
<java classname="org.zaproxy.zap.ZAP" fork="true" spawn="true" dir="${zapdir}">
<arg value="-port"/>
<arg value="${zapport}"/>
<classpath>
<pathelement location="${zapdir}/zap.jar"/>
</classpath>
</java>
<!-- Give ZAP a chance to start -->
<sleep seconds="20"/>
</target>
<target name="startZapDaemon">
<java classname="org.zaproxy.zap.ZAP" fork="true" spawn="true" dir="${zapdir}">
<arg value="-daemon"/>
<arg value="-port"/>
<arg value="${zapport}"/>
<classpath>
<pathelement location="${zapdir}/zap.jar"/>
</classpath>
</java>
<!-- Give ZAP a chance to start -->
<sleep seconds="20"/>
</target>
<target name="stopZap">
<stopZapTask zapAddress="${zapaddr}" zapPort="${zapport}" debug="true"/>
</target>
</project>