1<?xml version="1.0" encoding="UTF-8"?>
2<project name="phpunit" default="setup">
3    <target name="setup" depends="clean,install-dependencies"/>
4    <target name="validate" depends="php-syntax-check,validate-composer-json,validate-phpunit-xsd"/>
5
6    <target name="clean" unless="clean.done" description="Cleanup build artifacts">
7        <delete dir="${basedir}/bin"/>
8        <delete dir="${basedir}/vendor"/>
9        <delete file="${basedir}/composer.lock"/>
10        <delete dir="${basedir}/build/documentation"/>
11        <delete dir="${basedir}/build/logfiles"/>
12        <delete dir="${basedir}/build/phar"/>
13        <delete>
14            <fileset dir="${basedir}/build">
15                <include name="**/phpunit*.phar"/>
16                <include name="**/phpunit*.phar.asc"/>
17            </fileset>
18        </delete>
19
20        <property name="clean.done" value="true"/>
21    </target>
22
23    <target name="prepare" unless="prepare.done" depends="clean" description="Prepare for build">
24        <mkdir dir="${basedir}/build/documentation"/>
25        <mkdir dir="${basedir}/build/logfiles"/>
26        <property name="prepare.done" value="true"/>
27    </target>
28
29    <target name="validate-composer-json" unless="validate-composer-json.done" description="Validate composer.json">
30        <exec executable="${basedir}/build/tools/composer" failonerror="true" taskname="composer">
31            <arg value="validate"/>
32            <arg value="--no-check-lock"/>
33            <arg value="--strict"/>
34            <arg value="${basedir}/composer.json"/>
35        </exec>
36
37        <property name="validate-composer-json.done" value="true"/>
38    </target>
39
40    <target name="-dependencies-installed">
41        <available file="${basedir}/composer.lock" property="dependencies-installed"/>
42    </target>
43
44    <target name="install-dependencies" unless="dependencies-installed" depends="-dependencies-installed,validate-composer-json" description="Install dependencies with Composer">
45        <exec executable="${basedir}/build/tools/composer" taskname="composer">
46            <arg value="update"/>
47            <arg value="--no-interaction"/>
48            <arg value="--no-progress"/>
49            <arg value="--no-ansi"/>
50            <arg value="--no-suggest"/>
51        </exec>
52    </target>
53
54    <target name="php-syntax-check" unless="php-syntax-check.done" description="Perform syntax check on PHP files">
55        <apply executable="php" failonerror="true" taskname="lint">
56            <arg value="-l"/>
57
58            <fileset dir="${basedir}/src">
59                <include name="**/*.php"/>
60                <modified/>
61            </fileset>
62
63            <fileset dir="${basedir}/tests">
64                <include name="**/*.php"/>
65                <modified/>
66            </fileset>
67        </apply>
68
69        <property name="php-syntax-check.done" value="true"/>
70    </target>
71
72    <target name="validate-phpunit-xsd" unless="validate-phpunit-xsd.done" description="Validate phpunit.xsd">
73        <exec executable="xmllint" failonerror="true" taskname="xmllint">
74            <arg value="--noout"/>
75            <arg path="${basedir}/phpunit.xsd"/>
76        </exec>
77
78        <property name="validate-phpunit-xsd.done" value="true"/>
79    </target>
80
81    <target name="test" depends="validate,install-dependencies" description="Run tests">
82        <exec executable="${basedir}/phpunit" taskname="phpunit"/>
83    </target>
84
85    <target name="signed-phar" depends="phar" description="Create signed PHAR archive of PHPUnit and all its dependencies">
86        <exec executable="gpg" failonerror="true">
87            <arg value="--local-user"/>
88            <arg value="sb@sebastian-bergmann.de"/>
89            <arg value="--armor"/>
90            <arg value="--detach-sign"/>
91            <arg path="${basedir}/build/phpunit-library-${version}.phar"/>
92        </exec>
93
94        <exec executable="gpg" failonerror="true">
95            <arg value="--local-user"/>
96            <arg value="sb@sebastian-bergmann.de"/>
97            <arg value="--armor"/>
98            <arg value="--detach-sign"/>
99            <arg path="${basedir}/build/phpunit-${version}.phar"/>
100        </exec>
101    </target>
102
103    <target name="phar" depends="-phar-determine-version,-phar-prepare" description="Create PHAR archive of PHPUnit and all its dependencies">
104        <antcall target="-phar-build">
105            <param name="type" value="release"/>
106        </antcall>
107    </target>
108
109    <target name="phar-nightly" depends="-phar-prepare" description="Create PHAR archive of PHPUnit and all its dependencies (nightly)">
110        <antcall target="-phar-build">
111            <param name="type" value="nightly"/>
112        </antcall>
113    </target>
114
115    <target name="-phar-prepare" depends="clean,install-dependencies">
116        <mkdir dir="${basedir}/build/phar"/>
117        <copy file="${basedir}/composer.json" tofile="${basedir}/composer.json.bak"/>
118
119        <exec executable="${basedir}/build/tools/composer">
120            <arg value="require"/>
121            <arg value="phpunit/dbunit:~2.0"/>
122            <arg value="phpunit/php-invoker:~1.1"/>
123        </exec>
124
125        <move file="${basedir}/composer.json.bak" tofile="${basedir}/composer.json"/>
126
127        <exec executable="${basedir}/build/phar-manifest.php" output="${basedir}/build/phar/manifest.txt"/>
128        <copy todir="${basedir}/build/phar" file="${basedir}/build/ca.pem" />
129
130        <copy file="${basedir}/vendor/phpunit/php-code-coverage/LICENSE" tofile="${basedir}/build/phar/php-code-coverage/LICENSE"/>
131        <copy todir="${basedir}/build/phar/php-code-coverage">
132            <fileset dir="${basedir}/vendor/phpunit/php-code-coverage/src">
133                <include name="**/*" />
134            </fileset>
135        </copy>
136
137        <copy file="${basedir}/vendor/phpunit/php-file-iterator/LICENSE" tofile="${basedir}/build/phar/php-file-iterator/LICENSE"/>
138        <copy todir="${basedir}/build/phar/php-file-iterator">
139            <fileset dir="${basedir}/vendor/phpunit/php-file-iterator/src">
140                <include name="**/*.php" />
141            </fileset>
142        </copy>
143
144        <copy file="${basedir}/vendor/phpunit/php-text-template/LICENSE" tofile="${basedir}/build/phar/php-text-template/LICENSE"/>
145        <copy todir="${basedir}/build/phar/php-text-template">
146            <fileset dir="${basedir}/vendor/phpunit/php-text-template/src">
147                <include name="**/*.php" />
148            </fileset>
149        </copy>
150
151        <copy file="${basedir}/vendor/phpunit/php-timer/LICENSE" tofile="${basedir}/build/phar/php-timer/LICENSE"/>
152        <copy todir="${basedir}/build/phar/php-timer">
153            <fileset dir="${basedir}/vendor/phpunit/php-timer/src">
154                <include name="**/*.php" />
155            </fileset>
156        </copy>
157
158        <copy file="${basedir}/vendor/phpunit/php-token-stream/LICENSE" tofile="${basedir}/build/phar/php-token-stream/LICENSE"/>
159        <copy todir="${basedir}/build/phar/php-token-stream">
160            <fileset dir="${basedir}/vendor/phpunit/php-token-stream/src">
161                <include name="**/*.php" />
162            </fileset>
163        </copy>
164
165        <copy file="${basedir}/vendor/phpunit/phpunit-mock-objects/LICENSE" tofile="${basedir}/build/phar/phpunit-mock-objects/LICENSE"/>
166        <copy todir="${basedir}/build/phar/phpunit-mock-objects">
167            <fileset dir="${basedir}/vendor/phpunit/phpunit-mock-objects/src">
168                <include name="**/*" />
169            </fileset>
170        </copy>
171
172        <copy file="${basedir}/vendor/sebastian/code-unit-reverse-lookup/LICENSE" tofile="${basedir}/build/phar/sebastian-code-unit-reverse-lookup/LICENSE"/>
173        <copy todir="${basedir}/build/phar/sebastian-code-unit-reverse-lookup">
174            <fileset dir="${basedir}/vendor/sebastian/code-unit-reverse-lookup/src">
175                <include name="**/*.php" />
176            </fileset>
177        </copy>
178
179        <copy file="${basedir}/vendor/sebastian/comparator/LICENSE" tofile="${basedir}/build/phar/sebastian-comparator/LICENSE"/>
180        <copy todir="${basedir}/build/phar/sebastian-comparator">
181            <fileset dir="${basedir}/vendor/sebastian/comparator/src">
182                <include name="**/*.php" />
183            </fileset>
184        </copy>
185
186        <copy file="${basedir}/vendor/sebastian/diff/LICENSE" tofile="${basedir}/build/phar/sebastian-diff/LICENSE"/>
187        <copy todir="${basedir}/build/phar/sebastian-diff">
188            <fileset dir="${basedir}/vendor/sebastian/diff/src">
189                <include name="**/*.php" />
190            </fileset>
191        </copy>
192
193        <copy file="${basedir}/vendor/sebastian/environment/LICENSE" tofile="${basedir}/build/phar/sebastian-environment/LICENSE"/>
194        <copy todir="${basedir}/build/phar/sebastian-environment">
195            <fileset dir="${basedir}/vendor/sebastian/environment/src">
196                <include name="**/*.php" />
197            </fileset>
198        </copy>
199
200        <copy file="${basedir}/vendor/sebastian/exporter/LICENSE" tofile="${basedir}/build/phar/sebastian-exporter/LICENSE"/>
201        <copy todir="${basedir}/build/phar/sebastian-exporter">
202            <fileset dir="${basedir}/vendor/sebastian/exporter/src">
203                <include name="**/*.php" />
204            </fileset>
205        </copy>
206
207        <copy file="${basedir}/vendor/sebastian/recursion-context/LICENSE" tofile="${basedir}/build/phar/sebastian-recursion-context/LICENSE"/>
208        <copy todir="${basedir}/build/phar/sebastian-recursion-context">
209            <fileset dir="${basedir}/vendor/sebastian/recursion-context/src">
210                <include name="**/*.php" />
211            </fileset>
212        </copy>
213
214        <copy file="${basedir}/vendor/sebastian/resource-operations/LICENSE" tofile="${basedir}/build/phar/sebastian-resource-operations/LICENSE"/>
215        <copy todir="${basedir}/build/phar/sebastian-resource-operations">
216            <fileset dir="${basedir}/vendor/sebastian/resource-operations/src">
217                <include name="**/*.php" />
218            </fileset>
219        </copy>
220
221        <copy file="${basedir}/vendor/sebastian/global-state/LICENSE" tofile="${basedir}/build/phar/sebastian-global-state/LICENSE"/>
222        <copy todir="${basedir}/build/phar/sebastian-global-state">
223            <fileset dir="${basedir}/vendor/sebastian/global-state/src">
224                <include name="**/*.php" />
225            </fileset>
226        </copy>
227
228        <copy file="${basedir}/vendor/sebastian/object-enumerator/LICENSE" tofile="${basedir}/build/phar/object-enumerator/LICENSE"/>
229        <copy todir="${basedir}/build/phar/sebastian-object-enumerator">
230            <fileset dir="${basedir}/vendor/sebastian/object-enumerator/src">
231                <include name="**/*.php" />
232            </fileset>
233        </copy>
234
235        <copy file="${basedir}/vendor/sebastian/version/LICENSE" tofile="${basedir}/build/phar/sebastian-version/LICENSE"/>
236        <copy todir="${basedir}/build/phar/sebastian-version">
237            <fileset dir="${basedir}/vendor/sebastian/version/src">
238                <include name="**/*.php" />
239            </fileset>
240        </copy>
241
242        <copy file="${basedir}/vendor/doctrine/instantiator/LICENSE" tofile="${basedir}/build/phar/doctrine-instantiator/LICENSE"/>
243        <copy todir="${basedir}/build/phar/doctrine-instantiator">
244            <fileset dir="${basedir}/vendor/doctrine/instantiator/src">
245                <include name="**/*.php" />
246            </fileset>
247        </copy>
248
249        <copy file="${basedir}/vendor/symfony/yaml/LICENSE" tofile="${basedir}/build/phar/symfony/LICENSE"/>
250        <copy todir="${basedir}/build/phar/symfony">
251            <fileset dir="${basedir}/vendor/symfony">
252                <include name="**/*.php" />
253                <exclude name="**/Command/*.php" />
254                <exclude name="**/Tests/**" />
255            </fileset>
256        </copy>
257
258        <copy todir="${basedir}/build/phar/dbunit">
259            <fileset dir="${basedir}/vendor/phpunit/dbunit/src">
260                <include name="**/*.php" />
261            </fileset>
262        </copy>
263
264        <copy todir="${basedir}/build/phar/php-invoker">
265            <fileset dir="${basedir}/vendor/phpunit/php-invoker/src">
266                <include name="**/*.php" />
267            </fileset>
268        </copy>
269
270        <copy file="${basedir}/vendor/phpdocumentor/reflection-common/LICENSE" tofile="${basedir}/build/phar/phpdocumentor-reflection-common/LICENSE"/>
271        <copy todir="${basedir}/build/phar/phpdocumentor-reflection-common">
272            <fileset dir="${basedir}/vendor/phpdocumentor/reflection-common/src">
273                <include name="**/*.php" />
274            </fileset>
275        </copy>
276
277        <copy file="${basedir}/vendor/phpdocumentor/reflection-docblock/LICENSE" tofile="${basedir}/build/phar/phpdocumentor-reflection-docblock/LICENSE"/>
278        <copy todir="${basedir}/build/phar/phpdocumentor-reflection-docblock">
279            <fileset dir="${basedir}/vendor/phpdocumentor/reflection-docblock/src">
280                <include name="**/*.php" />
281            </fileset>
282        </copy>
283
284        <copy file="${basedir}/vendor/phpdocumentor/type-resolver/LICENSE" tofile="${basedir}/build/phar/phpdocumentor-type-resolver/LICENSE"/>
285        <copy todir="${basedir}/build/phar/phpdocumentor-type-resolver">
286            <fileset dir="${basedir}/vendor/phpdocumentor/type-resolver/src">
287                <include name="**/*.php" />
288            </fileset>
289        </copy>
290
291        <copy file="${basedir}/vendor/phpspec/prophecy/LICENSE" tofile="${basedir}/build/phar/phpspec-prophecy/LICENSE"/>
292        <copy todir="${basedir}/build/phar/phpspec-prophecy">
293            <fileset dir="${basedir}/vendor/phpspec/prophecy/src">
294                <include name="**/*.php" />
295            </fileset>
296        </copy>
297
298        <copy file="${basedir}/vendor/myclabs/deep-copy/LICENSE" tofile="${basedir}/build/phar/myclabs-deep-copy/LICENSE"/>
299        <copy todir="${basedir}/build/phar/myclabs-deep-copy">
300            <fileset dir="${basedir}/vendor/myclabs/deep-copy/src">
301                <include name="**/*.php" />
302            </fileset>
303        </copy>
304
305        <copy file="${basedir}/vendor/webmozart/assert/LICENSE" tofile="${basedir}/build/phar/webmozart-assert/LICENSE"/>
306        <copy todir="${basedir}/build/phar/webmozart-assert">
307            <fileset dir="${basedir}/vendor/webmozart/assert/src">
308                <include name="**/*.php" />
309            </fileset>
310        </copy>
311    </target>
312
313    <target name="-phar-build" depends="-phar-determine-version">
314        <copy todir="${basedir}/build/phar/phpunit">
315            <fileset dir="${basedir}/src">
316                <include name="**/*.php"/>
317                <include name="**/*.tpl*"/>
318            </fileset>
319        </copy>
320
321        <exec executable="${basedir}/build/phar-version.php" outputproperty="_version">
322            <arg value="${version}"/>
323            <arg value="${type}"/>
324        </exec>
325
326        <exec executable="${basedir}/build/tools/phpab" taskname="phpab">
327            <arg value="--all" />
328            <arg value="--static" />
329            <arg value="--once" />
330            <arg value="--phar" />
331            <arg value="--hash" />
332            <arg value="SHA-1" />
333            <arg value="--output" />
334            <arg path="${basedir}/build/phpunit-library-${_version}.phar" />
335            <arg value="--template" />
336            <arg path="${basedir}/build/library-phar-autoload.php.in" />
337            <arg path="${basedir}/build/phar" />
338        </exec>
339
340        <copy file="${basedir}/build/binary-phar-autoload.php.in" tofile="${basedir}/build/binary-phar-autoload.php"/>
341        <replace file="${basedir}/build/binary-phar-autoload.php" token="X.Y.Z" value="${_version}"/>
342
343        <exec executable="${basedir}/build/tools/phpab" taskname="phpab">
344            <arg value="--all" />
345            <arg value="--nolower" />
346            <arg value="--static" />
347            <arg value="--phar" />
348            <arg value="--hash" />
349            <arg value="SHA-1" />
350            <arg value="--output" />
351            <arg path="${basedir}/build/phpunit-${_version}.phar" />
352            <arg value="--template" />
353            <arg path="${basedir}/build/binary-phar-autoload.php" />
354            <arg path="${basedir}/build/phar" />
355        </exec>
356
357        <chmod file="${basedir}/build/phpunit-${_version}.phar" perm="ugo+rx"/>
358
359        <delete dir="${basedir}/build/phar"/>
360        <delete file="${basedir}/build/binary-phar-autoload.php"/>
361    </target>
362
363    <target name="-phar-determine-version">
364        <exec executable="${basedir}/build/version.php" outputproperty="version" />
365    </target>
366
367    <target name="generate-project-documentation" depends="-phploc,-phpcs,-phpmd,-phpunit">
368        <exec executable="${basedir}/build/tools/phpdox" dir="${basedir}/build" taskname="phpdox"/>
369    </target>
370
371    <target name="-phploc" depends="prepare">
372        <exec executable="${basedir}/build/tools/phploc" output="/dev/null" taskname="phploc">
373            <arg value="--count-tests"/>
374            <arg value="--log-xml"/>
375            <arg path="${basedir}/build/logfiles/phploc.xml"/>
376            <arg path="${basedir}/src"/>
377            <arg path="${basedir}/tests"/>
378        </exec>
379    </target>
380
381    <target name="phpcs">
382        <exec executable="${basedir}/build/tools/phpcs" taskname="phpcs">
383            <arg value="--standard=${basedir}/build/phpcs.xml"/>
384            <arg value="--extensions=php"/>
385            <arg value="--cache"/>
386        </exec>
387    </target>
388
389    <target name="-phpcs" depends="prepare">
390        <exec executable="${basedir}/build/tools/phpcs" output="/dev/null" taskname="phpcs">
391            <arg value="--standard=${basedir}/build/phpcs.xml"/>
392            <arg value="--extensions=php"/>
393            <arg value="--cache"/>
394            <arg value="--report=checkstyle"/>
395            <arg value="--report-file=${basedir}/build/logfiles/checkstyle.xml"/>
396        </exec>
397    </target>
398
399    <target name="-phpmd" depends="prepare">
400        <exec executable="${basedir}/build/tools/phpmd" taskname="phpmd">
401            <arg path="${basedir}/src"/>
402            <arg value="xml"/>
403            <arg path="${basedir}/build/phpmd.xml"/>
404            <arg value="--reportfile"/>
405            <arg path="${basedir}/build/logfiles/pmd.xml"/>
406        </exec>
407    </target>
408
409    <target name="-phpunit" depends="setup">
410        <exec executable="${basedir}/phpunit" taskname="phpunit">
411            <arg value="--coverage-xml"/>
412            <arg path="${basedir}/build/logfiles/coverage"/>
413            <arg value="--log-junit"/>
414            <arg path="${basedir}/build/logfiles/junit.xml"/>
415        </exec>
416    </target>
417</project>
418
419