-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.xml
More file actions
331 lines (286 loc) · 12.4 KB
/
build.xml
File metadata and controls
331 lines (286 loc) · 12.4 KB
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
<?xml version="1.0" encoding="UTF-8"?>
<project name="Project" default="help">
<!-- ++++++++++++++++++++++++++++++++++++++++++ -->
<!-- | Init -->
<!-- ++++++++++++++++++++++++++++++++++++++++++ -->
<!-- Vars -->
<property name="basedir" value="."/>
<property environment="env"/>
<!-- Command help -->
<target name="help">
<echo message=""/>
<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="|"/>
<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="|-- coverage (Show code coverage metric)"/>
<echo message="|-- phploc (Show lines of code metric)"/>
<echo message="|-- qa (Run quality assurance tools)"/>
<echo message="|-- |-- phpcpd (Show copy paste metric)"/>
<echo message="|-- |-- phpcs (Show code sniffer metric)"/>
<echo message="|-- |-- phpmd (Show mess detector metric)"/>
<echo message="|"/>
<echo message="| +++ Metric Reports +++"/>
<echo message="|-- phploc-report (Generate lines of code metric report)"/>
<echo message="|-- phpcpd-report (Generate copy paste metric report)"/>
<echo message="|-- phpcs-report (Generate code sniffer metric report)"/>
<echo message="|-- phpmd-report (Generate mess detector metric report)"/>
<echo message="|"/>
<echo message="| +++ Tools +++"/>
<echo message="|-- lint (Lint all php files)"/>
<echo message="|-- phpcbf (Run PHP Code Beautifier)"/>
<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-report"/>
<antcall target="phpcpd-report"/>
<antcall target="phpcs-report"/>
<antcall target="phpmd-report"/>
</target>
<!-- cleanup -->
<target name="cleanup">
<delete dir="${basedir}/build"/>
</target>
<!-- prepare -->
<target name="prepare">
<mkdir dir="${basedir}/build"/>
</target>
<!-- ++++++++++++++++++++++++++++++++++++++++++ -->
<!-- | Quality Assurance -->
<!-- ++++++++++++++++++++++++++++++++++++++++++ -->
<!-- run qa tools -->
<target name="qa">
<antcall target="phpcpd"/>
<antcall target="phpcs"/>
<antcall target="phpmd"/>
</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>
<!-- 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/Test" 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/Test" 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="--coverage-clover='${basedir}/build/coverage/clover.xml'"/>
<arg line="."/>
</exec>
</target>
<!-- show code coverage metric -->
<target name="coverage" depends="phpunit-prepare">
<exec dir="${basedir}/src/Test" executable="${basedir}/vendor/bin/phpunit" failonerror="true">
<arg line="--coverage-text='${basedir}/build/coverage/coverage.txt'"/>
<arg line="."/>
</exec>
<exec dir="${basedir}/build/coverage" executable="cat">
<arg line="coverage.txt"/>
</exec>
</target>
<!-- ++++++++++++++++++++++++++++++++++++++++++ -->
<!-- | PHP Lines of Code -->
<!-- ++++++++++++++++++++++++++++++++++++++++++ -->
<!-- create necessary directories -->
<target name="phploc-prepare">
<mkdir dir="${basedir}/build/phploc"/>
</target>
<!-- show lines of code metric -->
<target name="phploc">
<exec dir="${basedir}" executable="${basedir}/vendor/bin/phploc">
<arg path="${basedir}/src"/>
</exec>
</target>
<!-- generate lines of code metric report -->
<target name="phploc-report" 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>
<!-- show copy paste metric -->
<target name="phpcpd">
<exec dir="${basedir}" executable="${basedir}/vendor/bin/phpcpd">
<arg path="${basedir}/src"/>
</exec>
</target>
<!-- generate copy paste metric report -->
<target name="phpcpd-report" 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>
<!-- show code sniffer metric -->
<target name="phpcs">
<exec dir="${basedir}" executable="${basedir}/vendor/bin/phpcs">
<arg value="--standard=PSR2"/>
<arg value="--extensions=php"/>
<arg value="-n"/>
<arg path="${basedir}/src"/>
</exec>
</target>
<!-- generate code sniffer metric report -->
<target name="phpcs-report" 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>
<!-- show mess detector metric -->
<target name="phpmd">
<exec dir="${basedir}" executable="${basedir}/vendor/bin/phpmd">
<arg path="${basedir}/src"/>
<arg value="text"/>
<arg value="cleancode,codesize,controversial,design,naming,unusedcode"/>
</exec>
</target>
<!-- generate mess detector metric report -->
<target name="phpmd-report" 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>
<!-- ++++++++++++++++++++++++++++++++++++++++++ -->
<!-- | PHP Code Beautifier -->
<!-- ++++++++++++++++++++++++++++++++++++++++++ -->
<!-- run php code beautifier -->
<target name="phpcbf">
<exec dir="${basedir}" executable="${basedir}/vendor/bin/phpcbf">
<arg value="--standard=PSR2"/>
<arg value="--extensions=php"/>
<arg value="-n"/>
<arg path="${basedir}/src"/>
</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/**"/>
<exclude name="sandbox/**"/>
</fileset>
</apply>
</target>
</project>