1<?xml version="1.0" encoding="UTF-8"?>
2<project name="phploc" default="setup">
3    <target name="setup" depends="clean,install-dependencies"/>
4
5    <target name="clean" description="Cleanup build artifacts">
6        <delete dir="${basedir}/build/phar"/>
7        <delete dir="${basedir}/vendor"/>
8        <delete file="${basedir}/composer.lock"/>
9        <delete>
10            <fileset dir="${basedir}/build">
11                <include name="**/phploc*.phar"/>
12                <include name="**/phploc*.phar.asc"/>
13            </fileset>
14        </delete>
15    </target>
16
17    <target name="install-dependencies" unless="dependencies-installed" depends="-dependencies-installed" description="Install dependencies with Composer">
18        <exec executable="composer" taskname="composer">
19            <arg value="update"/>
20            <arg value="--no-interaction"/>
21            <arg value="--no-progress"/>
22            <arg value="--no-ansi"/>
23            <arg value="--no-suggest"/>
24            <arg value="--optimize-autoloader"/>
25            <arg value="--prefer-stable"/>
26        </exec>
27    </target>
28
29    <target name="install-tools" unless="tools-installed" depends="-tools-installed" description="Install tools using phive">
30        <exec executable="phive" taskname="phive">
31            <arg value="install"/>
32        </exec>
33    </target>
34
35    <target name="test" depends="install-dependencies,install-tools" description="Run tests with PHPUnit">
36        <exec executable="${basedir}/tools/phpunit" failonerror="true"/>
37    </target>
38
39    <target name="signed-phar"
40            description="Create signed PHAR archive of PHPUnit and all its dependencies (release)"
41            depends="phar">
42        <exec executable="bash" outputproperty="version">
43            <arg value="-c" />
44            <arg value="${basedir}/phploc --version | awk 'BEGIN { ORS = &quot;&quot;; } {print $2}'" />
45        </exec>
46
47        <exec executable="gpg" failonerror="true">
48            <arg value="--armor" />
49            <arg value="--detach-sign" />
50            <arg path="${basedir}/build/phploc-${version}.phar" />
51        </exec>
52    </target>
53
54    <target name="phar"
55            description="Create PHAR archive of PHPLOC and all its dependencies"
56            depends="setup,phar-build">
57        <mkdir dir="${basedir}/build/phar"/>
58    </target>
59
60    <target name="phar-build">
61        <exec executable="bash" outputproperty="version">
62            <arg value="-c" />
63            <arg value="${basedir}/phploc --version | awk 'BEGIN { ORS = &quot;&quot;; } {print $2}'" />
64        </exec>
65
66        <copy todir="${basedir}/build/phar/src">
67            <fileset dir="${basedir}/src">
68                <include name="**/*.php" />
69            </fileset>
70        </copy>
71
72        <copy todir="${basedir}/build/phar/finder-facade">
73            <fileset dir="${basedir}/vendor/sebastian/finder-facade/src">
74                <include name="**/*.php" />
75                <exclude name="**/autoload.php" />
76            </fileset>
77        </copy>
78
79        <copy todir="${basedir}/build/phar/version">
80            <fileset dir="${basedir}/vendor/sebastian/version/src">
81                <include name="**/*.php" />
82                <exclude name="**/autoload.php" />
83            </fileset>
84        </copy>
85
86        <copy todir="${basedir}/build/phar/symfony">
87            <fileset dir="${basedir}/vendor/symfony">
88                <include name="**/*.php" />
89                <exclude name="**/Tests/**" />
90            </fileset>
91        </copy>
92
93        <copy todir="${basedir}/build/phar/fdomdocument">
94            <fileset dir="${basedir}/vendor/theseer/fdomdocument/src"/>
95        </copy>
96
97        <exec executable="${basedir}/build/phar-manifest.php" output="${basedir}/build/phar/manifest.txt"/>
98
99        <exec executable="${basedir}/tools/phpab">
100            <arg value="--all" />
101            <arg value="--phar" />
102            <arg value="--output" />
103            <arg path="${basedir}/build/phploc-${version}.phar" />
104            <arg value="--template" />
105            <arg path="${basedir}/build/phar-autoload.php.in" />
106            <arg value="--indent" />
107            <arg value="            " />
108            <arg path="${basedir}/build/phar" />
109        </exec>
110
111        <chmod file="${basedir}/build/phploc-${version}.phar" perm="ugo+rx"/>
112    </target>
113
114    <target name="-dependencies-installed">
115        <available file="${basedir}/vendor" property="dependencies-installed" type="dir"/>
116    </target>
117
118    <target name="-tools-installed">
119        <available file="${basedir}/tools" property="tools-installed" type="dir"/>
120    </target>
121</project>
122