forked from andreaskweber/php-junit-merge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.xml
268 lines (229 loc) · 9.95 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
<?xml version="1.0" encoding="UTF-8"?>
<project name="Project" default="help">
<!-- ++++++++++++++++++++++++++++++++++++++++++ -->
<!-- | Init -->
<!-- ++++++++++++++++++++++++++++++++++++++++++ -->
<!-- Vars -->
<property name="basedir" value="."/>
<!-- Command help -->
<target name="help">
<echo message="Error: No command passed"/>
<echo message="The following commands are available:"/>
<echo message="|"/>
<echo message="| +++ Build +++"/>
<echo message="|-- build (Run the build)"/>
<echo message="| |-- dependencies (Install dependencies)"/>
<echo message="| |-- tests (Lint all files and run tests)"/>
<echo message="| |-- metrics (Generate quality metrics)"/>
<echo message="|-- cleanup (Cleanup the build directory)"/>
<echo message="|"/>
<echo message="| +++ Composer +++"/>
<echo message="|-- composer -> composer-download, composer-install"/>
<echo message="|-- composer-download (Downloads composer.phar to project)"/>
<echo message="|-- composer-install (Install all dependencies)"/>
<echo message="|-- composer-update (Update dependencies and generate new lockfile)"/>
<echo message="|"/>
<echo message="| +++ Testing +++"/>
<echo message="|-- phpunit -> phpunit-full"/>
<echo message="|-- phpunit-tests (Run unit tests)"/>
<echo message="|-- phpunit-full (Run unit tests and generate code coverage report / logs)"/>
<echo message="|"/>
<echo message="| +++ Metrics +++"/>
<echo message="|-- phploc (Generate lines of code metric)"/>
<echo message="|-- phpcpd (Generate copy paste metric)"/>
<echo message="|-- phpcs (Generate code sniffer metric)"/>
<echo message="|-- phpmd (Generate mess detector metric)"/>
<echo message="|"/>
<echo message="| +++ Tools +++"/>
<echo message="|-- lint (Lint all php files)"/>
<echo message=""/>
</target>
<!-- ++++++++++++++++++++++++++++++++++++++++++ -->
<!-- | Build -->
<!-- ++++++++++++++++++++++++++++++++++++++++++ -->
<!-- run the build -->
<target name="build" depends="cleanup, prepare">
<!-- get all the dependencies necessary for the build -->
<antcall target="dependencies"/>
<!-- ok, looks good - now run all the tests -->
<antcall target="tests"/>
<!-- great, no errors - now we should generate some cool quality metrics -->
<antcall target="metrics"/>
</target>
<!-- fetch dependencies -->
<target name="dependencies">
<antcall target="composer"/>
</target>
<!-- run tests -->
<target name="tests">
<!-- when there is a syntax error we're failing right at the beginning -->
<antcall target="lint"/>
<!-- ahh boy, the unit tests -->
<antcall target="phpunit-full"/>
</target>
<!-- generate metrics -->
<target name="metrics">
<antcall target="phploc"/>
<antcall target="phpcpd"/>
<antcall target="phpcs"/>
<antcall target="phpmd"/>
</target>
<!-- cleanup -->
<target name="cleanup">
<delete dir="${basedir}/build"/>
</target>
<!-- prepare -->
<target name="prepare">
<mkdir dir="${basedir}/build"/>
</target>
<!-- ++++++++++++++++++++++++++++++++++++++++++ -->
<!-- | Composer -->
<!-- ++++++++++++++++++++++++++++++++++++++++++ -->
<!-- main target -->
<target name="composer" depends="composer-download, composer-install"/>
<!-- preconditions -->
<target name="composer-preconditions">
<available file="${basedir}/composer.phar" property="binary.present"/>
<available file="${basedir}/vendor" property="vendor.present"/>
</target>
<!-- download the latest composer release -->
<target name="composer-download" depends="composer-preconditions" unless="binary.present">
<exec dir="${basedir}" executable="wget">
<arg value="https://getcomposer.org/installer"/>
</exec>
<exec dir="${basedir}" executable="php">
<arg value="installer"/>
</exec>
<delete file="${basedir}/installer"/>
</target>
<!-- install dependencies -->
<target name="composer-install" depends="composer-preconditions"> <!-- unless="vendor.present" -->
<exec dir="${basedir}" executable="php">
<arg value="composer.phar"/>
<arg value="install"/>
</exec>
</target>
<!-- update dependencies and generate new lockfile-->
<target name="composer-update" depends="composer-preconditions">
<exec dir="${basedir}" executable="php">
<arg value="composer.phar"/>
<arg value="update"/>
</exec>
</target>
<!-- cleanup -->
<target name="composer-cleanup">
<delete dir="${basedir}/vendor"/>
<delete file="${basedir}/composer.phar"/>
</target>
<!-- ++++++++++++++++++++++++++++++++++++++++++ -->
<!-- | PHP-Unit -->
<!-- ++++++++++++++++++++++++++++++++++++++++++ -->
<!-- main target -->
<target name="phpunit" depends="phpunit-full"/>
<!-- create necessary directories -->
<target name="phpunit-prepare">
<mkdir dir="${basedir}/build/phpunit"/>
<mkdir dir="${basedir}/build/coverage"/>
</target>
<!-- run all tests -->
<target name="phpunit-tests">
<exec dir="${basedir}/src/Tests" executable="${basedir}/vendor/bin/phpunit" failonerror="true">
<arg line="--verbose --stderr"/>
<arg line="."/>
</exec>
</target>
<!-- run all tests and generate logs / code coverage -->
<target name="phpunit-full" depends="phpunit-prepare">
<exec dir="${basedir}/src/Tests" executable="${basedir}/vendor/bin/phpunit" failonerror="true">
<arg line="--verbose --stderr"/>
<arg line="--log-junit ${basedir}/build/phpunit/phpunit.xml"/>
<arg line="--coverage-html ${basedir}/build/coverage"/>
<arg line="."/>
</exec>
</target>
<!-- ++++++++++++++++++++++++++++++++++++++++++ -->
<!-- | PHP Lines of Code -->
<!-- ++++++++++++++++++++++++++++++++++++++++++ -->
<!-- create necessary directories -->
<target name="phploc-prepare">
<mkdir dir="${basedir}/build/phploc"/>
</target>
<!-- generate lines of code metric -->
<target name="phploc" depends="phploc-prepare">
<exec dir="${basedir}" executable="${basedir}/vendor/bin/phploc">
<arg value="--log-xml"/>
<arg value="${basedir}/build/phploc/phploc.xml"/>
<arg path="${basedir}/src"/>
</exec>
</target>
<!-- ++++++++++++++++++++++++++++++++++++++++++ -->
<!-- | PHP Copy-Paste-Detector -->
<!-- ++++++++++++++++++++++++++++++++++++++++++ -->
<!-- create necessary directories -->
<target name="phpcpd-prepare">
<mkdir dir="${basedir}/build/phpcpd"/>
</target>
<!-- run copy paste detector -->
<target name="phpcpd" depends="phpcpd-prepare">
<exec dir="${basedir}" executable="${basedir}/vendor/bin/phpcpd">
<arg value="--log-pmd"/>
<arg path="${basedir}/build/phpcpd/phpcpd.xml"/>
<arg path="${basedir}/src"/>
</exec>
</target>
<!-- ++++++++++++++++++++++++++++++++++++++++++ -->
<!-- | PHP Code-Sniffer -->
<!-- ++++++++++++++++++++++++++++++++++++++++++ -->
<!-- create necessary directories -->
<target name="phpcs-prepare">
<mkdir dir="${basedir}/build/phpcs"/>
</target>
<!-- generate code sniffer metric -->
<target name="phpcs" depends="phpcs-prepare">
<exec dir="${basedir}" executable="${basedir}/vendor/bin/phpcs">
<arg value="--standard=PSR2"/>
<arg value="--extensions=php"/>
<arg value="-n"/>
<arg value="--report=checkstyle"/>
<arg value="--report-file=${basedir}/build/phpcs/phpcs-checkstyle.xml"/>
<arg path="${basedir}/src"/>
</exec>
</target>
<!-- ++++++++++++++++++++++++++++++++++++++++++ -->
<!-- | PHP Mess-Detector -->
<!-- ++++++++++++++++++++++++++++++++++++++++++ -->
<!-- create necessary directories -->
<target name="phpmd-prepare">
<mkdir dir="${basedir}/build/phpmd"/>
</target>
<!-- generate mess detector metric -->
<target name="phpmd" depends="phpmd-prepare">
<exec dir="${basedir}" executable="${basedir}/vendor/bin/phpmd">
<arg path="${basedir}/src"/>
<arg value="xml"/>
<arg value="cleancode,codesize,controversial,design,naming,unusedcode"/>
<arg value="--reportfile"/>
<arg value="${basedir}/build/phpmd/phpmd.xml"/>
</exec>
</target>
<!-- ++++++++++++++++++++++++++++++++++++++++++ -->
<!-- | Lint -->
<!-- ++++++++++++++++++++++++++++++++++++++++++ -->
<!-- check syntax of all php files in src/ directory -->
<target name="lint">
<apply executable="php" failonerror="true">
<arg value="-l"/>
<fileset dir="${basedir}">
<include name="**/*.php"/>
<exclude name="**/vendor/**"/>
</fileset>
</apply>
</target>
<!-- ++++++++++++++++++++++++++++++++++++++++++ -->
<!-- | PHP-Doc -->
<!-- ++++++++++++++++++++++++++++++++++++++++++ -->
<!-- create necessary directories -->
<target name="phpdoc-prepare">
<mkdir dir="${basedir}/build/phpdoc"/>
</target>
</project>