-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathbuild.xml
372 lines (342 loc) · 16.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
<?xml version="1.0" encoding="UTF-8"?>
<project name="iPeer" basedir="." default="build">
<target name="load-db-config">
<loadfile property="dbfile" file="app/config/database.php">
<filterchain>
<stripphpcomments />
<linecontainsregexp>
<regexp pattern="^((?!\?php).)*$" />
</linecontainsregexp>
</filterchain>
</loadfile>
<php expression="${dbfile}"/>
<php expression="DATABASE_CONFIG::getInstance()->default['driver']" returnProperty="db.driver"/>
<php expression="DATABASE_CONFIG::getInstance()->default['host']" returnProperty="db.host"/>
<php expression="DATABASE_CONFIG::getInstance()->default['login']" returnProperty="db.username"/>
<php expression="DATABASE_CONFIG::getInstance()->default['password']" returnProperty="db.password"/>
<php expression="DATABASE_CONFIG::getInstance()->default['database']" returnProperty="db.name"/>
<if>
<!-- we need to override default database to run tests to avoid wiping out development data-->
<not><isset property="env.IPEER_DB_NAME"/></not>
<then>
<property name="db.name" value="ipeer_test" override="true"/>
</then>
</if>
</target>
<target name="build"
depends="prepare,lint,phploc,pdepend,phpmd,phpcs,phpcpd,phpdoc,test,phpcb"/>
<!-- remove phpdoc dependency for now. phpdoc 2.9 is not working with php7 -->
<target name="build-ci"
depends="prepare,lint,phploc,pdepend,phpmd-ci,phpcs-ci,phpcpd,test-ci,phpcb"/>
<target name="clean" description="Cleanup build artifacts">
<delete dir="${project.basedir}/build/api"/>
<delete dir="${project.basedir}/build/code-browser"/>
<delete dir="${project.basedir}/build/coverage"/>
<delete dir="${project.basedir}/build/logs"/>
<delete dir="${project.basedir}/build/pdepend"/>
<delete dir="${project.basedir}/dist"/>
</target>
<target name="prepare" depends="clean"
description="Prepare for build">
<mkdir dir="${project.basedir}/build/api"/>
<mkdir dir="${project.basedir}/build/code-browser"/>
<mkdir dir="${project.basedir}/build/coverage"/>
<mkdir dir="${project.basedir}/build/logs"/>
<mkdir dir="${project.basedir}/build/pdepend"/>
<!-- let Apache write to cache -->
<exec command="chmod -R 777 ${project.basedir}/app/tmp"/>
</target>
<target name="init-test-db" depends="load-db-config">
<pdosqlexec url="mysql:host=${db.host};dbname=${db.name}" userid="${db.username}" password="${db.password}">
<transaction src="app/config/sql/ipeer_samples_data.sql"/>
</pdosqlexec>
<!--<exec command="cake/console/cake schema_ci create DbAcl" passthru="true"/>-->
</target>
<target name="lint">
<phplint haltonfailure="true" cachefile="${project.basedir}/build/lint.cache">
<fileset dir="${project.basedir}/app">
<include name="**/*.php" />
</fileset>
</phplint>
</target>
<target name="phploc" description="Measure project size using PHPLOC">
<exec executable="phploc">
<arg value="--log-csv" />
<arg value="${project.basedir}/build/logs/phploc.csv" />
<arg path="${project.basedir}/app" />
</exec>
</target>
<target name="pdepend"
description="Calculate software metrics using PHP_Depend">
<phpdepend>
<fileset dir="${project.basedir}/app">
<include name="**/*.php" />
<exclude name="tests/**" />
<exclude name="vendors/**" />
<exclude name="plugins/**" />
<exclude name="config/**" />
<exclude name="webroot/**" />
</fileset>
<logger type="jdepend-xml" outfile="${project.basedir}/build/logs/jdepend.xml" />
<logger type="jdepend-chart" outfile="${project.basedir}/build/pdepend/dependencies.svg" />
<logger type="overview-pyramid" outfile="${project.basedir}/build/pdepend/overview-pyramid.svg" />
</phpdepend>
</target>
<target name="phpmd"
description="Perform project mess detection using PHPMD and print human readable output. Intended for usage on the command line before committing.">
<phpmd rulesets="codesize,unusedcode">
<fileset dir="${project.basedir}/app">
<include name="**/*.php" />
<exclude name="tests/**" />
<exclude name="vendors/**" />
<exclude name="plugins/**" />
<exclude name="config/**" />
<exclude name="webroot/**" />
</fileset>
</phpmd>
</target>
<target name="phpmd-ci"
description="Perform project mess detection using PHPMD creating a log file for the continuous integration server">
<phpmd rulesets="codesize,unusedcode">
<fileset dir="${project.basedir}/app">
<include name="**/*.php" />
<exclude name="tests/**" />
<exclude name="vendors/**" />
<exclude name="plugins/**" />
<exclude name="config/**" />
<exclude name="webroot/**" />
</fileset>
<formatter type="xml" outfile="${project.basedir}/build/logs/pmd.xml"/>
</phpmd>
</target>
<target name="phpcs"
description="Find coding standard violations using PHP_CodeSniffer and print human readable output. Intended for usage on the command line before committing.">
<phpcodesniffer standard="PSR2">
<fileset dir="${project.basedir}/app">
<include name="**/*.php" />
<exclude name="tests/**" />
<exclude name="vendors/**" />
<exclude name="plugins/**" />
<exclude name="config/**" />
<exclude name="webroot/**" />
</fileset>
</phpcodesniffer>
</target>
<target name="phpcs-ci"
description="Find coding standard violations using PHP_CodeSniffer creating a log file for the continuous integration server">
<phpcodesniffer standard="PSR2">
<fileset dir="${project.basedir}/app">
<include name="**/*.php" />
<exclude name="tests/**" />
<exclude name="vendors/**" />
<exclude name="plugins/**" />
<exclude name="config/**" />
<exclude name="webroot/**" />
</fileset>
<formatter type="checkstyle" outfile="${project.basedir}/build/logs/checkstyle.xml" />
</phpcodesniffer>
</target>
<target name="phpcpd" description="Find duplicate code using PHPCPD">
<phpcpd>
<fileset dir="${project.basedir}/app">
<include name="**/*.php" />
<exclude name="tests/**" />
<exclude name="vendors/**" />
<exclude name="plugins/**" />
<exclude name="config/**" />
<exclude name="webroot/**" />
</fileset>
<formatter type="pmd" outfile="${project.basedir}/build/logs/pmd-cpd.xml" />
</phpcpd>
</target>
<target name="phpdoc"
description="Generate API documentation using PHPDocumentor">
<phpdoc2 destdir="${project.basedir}/build/api" template="responsive-twig">
<fileset dir="${project.basedir}/app">
<include name="**/*.php" />
<exclude name="tests/**" />
<exclude name="vendors/**" />
<exclude name="plugins/**" />
<exclude name="config/**" />
<exclude name="webroot/**" />
</fileset>
</phpdoc2>
</target>
<target name="post-test" description="clean up after running tests">
<chmod file="app/tmp" mode="0777"/>
</target>
<target name="test" description="Run unit tests" depends="init-test-db">
<exec command="IPEER_DB_NAME=${db.name} sh cake/console/cake -app app testsuite app group component" passthru="true" returnProperty="result.component"/>
<exec command="IPEER_DB_NAME=${db.name} sh cake/console/cake -app app testsuite app group model" passthru="true" returnProperty="result.model"/>
<exec command="IPEER_DB_NAME=${db.name} sh cake/console/cake -app app testsuite app group caliper" passthru="true" returnProperty="result.caliper"/>
<exec command="IPEER_DB_NAME=${db.name} sh cake/console/cake -app app testsuite app group controller" passthru="true" returnProperty="result.controller"/>
<!-- v1_controller test must be last one as it will change the database -->
<!--<exec command="sh cake/console/cake testsuite app case controllers/V1Controller" passthru="true"/>-->
<phingcall target="post-test"/>
<fail message="Component test cases failed">
<condition>
<not>
<equals arg1="${result.component}" arg2="0"/>
</not>
</condition>
</fail>
<fail message="Model test cases failed">
<condition>
<not>
<equals arg1="${result.model}" arg2="0"/>
</not>
</condition>
</fail>
<fail message="Caliper test cases failed">
<condition>
<not>
<equals arg1="${result.caliper}" arg2="0"/>
</not>
</condition>
</fail>
<fail message="Controller test cases failed">
<condition>
<not>
<equals arg1="${result.controller}" arg2="0"/>
</not>
</condition>
</fail>
</target>
<target name="test-win" description="Run unit tests" depends="prepare,init-test-db">
<exec command="IPEER_DB_NAME=${db.name} cake\console\cake.bat -app app testsuite app group component" passthru="true" returnProperty="result.component"/>
<exec command="IPEER_DB_NAME=${db.name} cake\console\cake.bat -app app testsuite app group model" passthru="true" returnProperty="result.model"/>
<exec command="IPEER_DB_NAME=${db.name} cake\console\cake.bat -app app testsuite app group caliper" passthru="true" returnProperty="result.caliper"/>
<exec command="IPEER_DB_NAME=${db.name} cake\console\cake.bat -app app testsuite app group controller" passthru="true" returnProperty="result.controller"/>
<!-- v1_controller test must be last one as it will change the database -->
<phingcall target="post-test"/>
<fail message="Component test cases failed">
<condition>
<not>
<equals arg1="${result.component}" arg2="0"/>
</not>
</condition>
</fail>
<fail message="Model test cases failed">
<condition>
<not>
<equals arg1="${result.model}" arg2="0"/>
</not>
</condition>
</fail>
<fail message="Caliper test cases failed">
<condition>
<not>
<equals arg1="${result.caliper}" arg2="0"/>
</not>
</condition>
</fail>
<fail message="Controller test cases failed">
<condition>
<not>
<equals arg1="${result.controller}" arg2="0"/>
</not>
</condition>
</fail>
</target>
<target name="test-ci" description="Run unit tests for continuous integration" depends="init-test-db">
<exec command="IPEER_DB_NAME=${db.name} cake/console/cake -app app testsuite app group component" passthru="true" returnProperty="result.component"/>
<exec command="IPEER_DB_NAME=${db.name} cake/console/cake -app app testsuite app group model" passthru="true" returnProperty="result.model"/>
<exec command="IPEER_DB_NAME=${db.name} cake/console/cake -app app testsuite app group caliper" passthru="true" returnProperty="result.caliper"/>
<exec command="IPEER_DB_NAME=${db.name} cake/console/cake -app app testsuite app group controller" passthru="true" returnProperty="result.controller"/>
<!-- <exec command="cake/console/cake testreport app group system" passthru="true"/> -->
<!-- v1_controller test must be last one as it will change the database -->
<phingcall target="post-test"/>
<fail message="Component test cases failed">
<condition>
<not>
<equals arg1="${result.component}" arg2="0"/>
</not>
</condition>
</fail>
<fail message="Model test cases failed">
<condition>
<not>
<equals arg1="${result.model}" arg2="0"/>
</not>
</condition>
</fail>
<fail message="Caliper test cases failed">
<condition>
<not>
<equals arg1="${result.caliper}" arg2="0"/>
</not>
</condition>
</fail>
<fail message="Controller test cases failed">
<condition>
<not>
<equals arg1="${result.controller}" arg2="0"/>
</not>
</condition>
</fail>
</target>
<target name="test-ci-integration" description="Run integration tests for continuous integration(output as xml)" depends="prepare,init-test-db">
<exec command="IPEER_DB_NAME=${db.name} cake/console/cake testreport app group system" passthru="true"/>
<phingcall target="post-test"/>
</target>
<target name="upgrade" description="Upgrade iPeer">
<exec command="cake/console/cake upgrade" passthru="true"/>
</target>
<target name="phpcb"
description="Aggregate tool output with PHP_CodeBrowser">
<exec executable="phpcb">
<arg value="--log" />
<arg path="${project.basedir}/build/logs" />
<arg value="--source" />
<arg path="${project.basedir}/app" />
<arg value="--output" />
<arg path="${project.basedir}/build/code-browser" />
</exec>
</target>
<target name="bump" description="bump a version">
<input propertyname="release_option" defaultValue="Minor" validargs="Major,Minor,BugFix" promptChar=":">
Please choose a release type
</input>
<version releasetype="${release_option}" file="version.txt" property="version.number" />
<reflexive file="app/config/core.php">
<filterchain>
<replaceregexp>
<regexp pattern="'IPEER_VERSION', '\d.\d.\d'" replace="'IPEER_VERSION', '${version.number}'"/>
</replaceregexp>
</filterchain>
</reflexive>
</target>
<target name="release" description="Prepare the release" depends="packaging" />
<target name="packaging" description="Packaging the release">
<delete dir="${project.basedir}/dist"/>
<mkdir dir="${project.basedir}/dist"/>
<loadfile property="version.number" file="version.txt"/>
<php function="trim" returnProperty="version.number">
<param value="${version.number}" />
</php>
<echo msg="IPEER_VERSION=${version.number}" file="dist/version_for_jenkins.properties" />
<tar destfile="dist/${phing.project.name}-${version.number}.tar.gz" compression="gzip">
<fileset dir=".">
<exclude name="**/.git/" />
<exclude name="build/" />
<exclude name="dist/" />
</fileset>
</tar>
<filehash file="dist/${phing.project.name}-${version.number}.tar.gz" hashtype="0" />
<echo msg="${filehashvalue}" file="dist/${phing.project.name}-${version.number}.tar.gz.md5" />
<zip destfile="dist/${phing.project.name}-${version.number}.zip">
<fileset dir=".">
<exclude name="**/.git/" />
<exclude name="build/" />
<exclude name="dist/" />
</fileset>
</zip>
<filehash file="dist/${phing.project.name}-${version.number}.zip" hashtype="0" />
<echo msg="${filehashvalue}" file="dist/${phing.project.name}-${version.number}.zip.md5" />
<copy file="readme.md" todir="dist/" />
</target>
<target name="extract" description="Extract i18n strings for translation">
<delete file="app/locale/default.pot" quiet='true'/>
<exec command="cake/console/cake i18n extract -app app -merge yes -output app/locale/ -paths app/controllers,app/models,app/views" passthru="true"/>
</target>
</project>