-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.xml
340 lines (340 loc) · 19.1 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
<?xml version="1.0"?>
<project name="TDProject_Channel" default="deploy" basedir=".">
<property file="${basedir}/build.properties"/>
<property file="${basedir}/build.default.properties"/>
<property file="${basedir}/build.${os.family}.properties"/>
<property environment="env" />
<property name="namespace" value="TDProject" />
<property name="module" value="Channel"/>
<property name="codepool" value="core"/>
<property name="unique.name" value="${codepool}/${namespace}/${module}" />
<property name="php-src.dir" value="${basedir}/src" />
<property name="php-test.dir" value="${basedir}/tests" />
<property name="php-target.dir" value="${basedir}/target"/>
<!-- ==================================================================== -->
<!-- Cleans the directories with the generated source files -->
<!-- ==================================================================== -->
<target name="clean" description="Cleans almost everything, so use carefully.">
<delete dir="${php-target.dir}" includeemptydirs="true" quiet="false" verbose="true" failonerror="true"/>
</target>
<!-- ==================================================================== -->
<!-- Prepares all the required directories -->
<!-- ==================================================================== -->
<target name="prepare" depends="clean" description="Prepares all the required directories.">
<mkdir dir="${php-target.dir}" />
<mkdir dir="${php-target.dir}/reports" />
<mkdir dir="${php-target.dir}/reports/coverage" />
</target>
<!-- =================================================================== -->
<!-- Generates the source files -->
<!-- =================================================================== -->
<target name="generate" description="Generates the sources.">
<copy todir="${php-target.dir}" preservelastmodified="true" overwrite="true">
<fileset dir="${php-src.dir}" includes="**/generator.xml"/>
<filterchain>
<expandproperties/>
</filterchain>
</copy>
<mkdir dir="${php-target.dir}/app/code/${unique.name}/Block/Abstract" />
<mkdir dir="${php-target.dir}/app/code/${unique.name}/Common" />
<mkdir dir="${php-target.dir}/app/code/${unique.name}/Common/Delegates" />
<mkdir dir="${php-target.dir}/app/code/${unique.name}/Common/Delegates/Interfaces" />
<mkdir dir="${php-target.dir}/app/code/${unique.name}/Common/ValueObjects" />
<mkdir dir="${php-target.dir}/app/code/${unique.name}/Model" />
<mkdir dir="${php-target.dir}/app/code/${unique.name}/Model/Exceptions" />
<mkdir dir="${php-target.dir}/app/code/${unique.name}/Model/Homes" />
<mkdir dir="${php-target.dir}/app/code/${unique.name}/Model/Assembler" />
<mkdir dir="${php-target.dir}/app/code/${unique.name}/Model/Entities" />
<mkdir dir="${php-target.dir}/app/code/${unique.name}/Model/Services" />
<mkdir dir="${php-target.dir}/app/code/${unique.name}/Model/Sql" />
<mkdir dir="${php-target.dir}/app/code/${unique.name}/Model/Sql/System" />
<mkdir dir="${php-target.dir}/app/code/${unique.name}/Model/Utils" />
<mkdir dir="${php-target.dir}/app/code/${unique.name}/Model/Mappings" />
<exec executable="${pear.bin.dir}/generator">
<arg line="-p ${pear.lib.dir} -f ${php-target.dir}/app/code/${unique.name}/META-INF/generator.xml"/>
</exec>
</target>
<!-- ==================================================================== -->
<!-- Copies the sources to the target directory -->
<!-- ==================================================================== -->
<target name="copy" depends="generate" description="Copies the sources to the target directory.">
<copy todir="${php-target.dir}" preservelastmodified="true" overwrite="true">
<fileset dir="${php-src.dir}">
<include name="**/*" />
<exclude name="**/generator.xml"/>
</fileset>
</copy>
</target>
<!-- ==================================================================== -->
<!-- Copies the sources to the deploy directory -->
<!-- ==================================================================== -->
<target name="deploy" description="Copies the sources to the deploy directory.">
<antcall target="prepare"/>
<antcall target="copy"/>
<copy todir="${dir.www}/${instance.dir}" preservelastmodified="true" overwrite="true">
<fileset dir="${php-target.dir}">
<include name="**"/>
</fileset>
</copy>
<copy todir="${dir.www}/${deploy.dir}" preservelastmodified="true" overwrite="true">
<fileset dir="${php-target.dir}">
<include name="**/*"/>
</fileset>
</copy>
</target>
<!-- ==================================================================== -->
<!-- Generates the PEAR package -->
<!-- ==================================================================== -->
<target name="create-package" description="Generates the PEAR package.">
<antcall target="prepare"/>
<antcall target="copy"/>
<tstamp>
<format property="actual.date" pattern="yyyy-MM-dd" locale="en" />
</tstamp>
<tstamp>
<format property="actual.time" pattern="hh:mm:ss" locale="en" />
</tstamp>
<copy tofile="${php-target.dir}/package2.xml" file="${basedir}/pear/package2.xml">
<filterchain>
<expandproperties/>
</filterchain>
</copy>
<exec dir="${php-target.dir}" executable="${pear.bin}">
<arg value="contents"/>
<arg value="-T"/>
<arg value="${php-target.dir}/package2.xml"/>
<arg value="-S"/>
<arg value="${php-target.dir}"/>
<arg value="-D"/>
<arg value="${php-target.dir}"/>
</exec>
<exec dir="${php-target.dir}" executable="${pear.bin}">
<arg value="package"/>
<arg value="package.xml"/>
</exec>
</target>
<!-- ==================================================================== -->
<!-- Generates the API documentation -->
<!-- ==================================================================== -->
<target name="apidoc" description="Generates the API documentation.">
<exec executable="${pear.bin.dir}/phpdoc">
<arg line="-ct type -ue on -s on -t ${php-target.dir}/docs -o HTML:frames:earthli -d ${php-src.dir}"/>
</exec>
</target>
<!-- ==================================================================== -->
<!-- Runs the code sniffer and generates a report -->
<!-- ==================================================================== -->
<target name="phpcs" depends="apidoc" description="Runs the code sniffer and generates a report.">
<exec executable="${pear.bin.dir}/phpcs">
<arg line="--extensions=php,phtml --standard=Zend --report=checkstyle --report-file=${php-target.dir}/reports/checkstyle.xml ${php-src.dir}"/>
</exec>
</target>
<!-- ==================================================================== -->
<!-- Runs the copy and paste detection -->
<!-- ==================================================================== -->
<target name="phpcpd" depends="phpcs" description="Runs the copy and paste detection.">
<exec executable="${pear.bin.dir}/phpcpd">
<arg line="--log-pmd ${php-target.dir}/reports/pmd-cpd.xml ${php-src.dir}"/>
</exec>
</target>
<!-- ==================================================================== -->
<!-- Generate phploc.csv -->
<!-- ==================================================================== -->
<target name="phploc" depends="phpcpd" description="Generate phploc.csv">
<exec executable="${pear.bin.dir}/phploc">
<arg line="--log-xml ${php-target.dir}/reports/phploc.xml ${php-src.dir}"/>
</exec>
</target>
<!-- ==================================================================== -->
<!-- Runs the PHPDepend tool and generats a graphs -->
<!-- ==================================================================== -->
<target name="pdepend" depends="phploc" description="Runs the PHPDepend tool and generats a graphs.">
<exec executable="${pear.bin.dir}/pdepend">
<arg line="--summary-xml=${php-target.dir}/reports/pdepend.xml --jdepend-xml=${php-target.dir}/reports/jdepend.xml --jdepend-chart=${php-target.dir}/reports/jdepend.svg --overview-pyramid=${php-target.dir}/reports/pdepend-pyramid.svg ${php-src.dir}" />
</exec>
</target>
<!-- ==================================================================== -->
<!-- Runs the PHP mess detector tool -->
<!-- ==================================================================== -->
<target name="phpmd" depends="pdepend" description="Runs the PHP Mess detector tool.">
<exec executable="${pear.bin.dir}/phpmd">
<arg line="${php-src.dir} xml codesize,unusedcode --reportfile ${php-target.dir}/reports/pmd.xml" />
</exec>
</target>
<!-- ==================================================================== -->
<!-- Copies the test sources to the target directory -->
<!-- ==================================================================== -->
<target name="copy-tests" description="Copies the test sources to the target directory.">
<antcall target="prepare"/>
<echo message="Preparing TDProject source..."/>
<antcall target="get-tdproject-src" />
<exec dir="${dir.www}/${instance.base.dir.tmp}" executable="${bin.extract}">
<arg line="${bin.extract.args}"/>
<arg line="${dir.www}/${instance.base.dir.tmp}/${instance.download.file}"/>
</exec>
<move todir="${php-target.dir}">
<fileset dir="${dir.www}/${instance.base.dir.tmp}/tdproject-${tdproject.version}"/>
</move>
<echo message="Installing instance ${php-target.dir}..." />
<chmod perm="+x" file="${php-target.dir}/bin/webapp"/>
<exec dir="${php-target.dir}" executable="bin/webapp">
<arg value="setup"/>
</exec>
<antcall target="copy"/>
<copy todir="${php-target.dir}">
<fileset dir="${php-test.dir}">
<include name="**/*" />
</fileset>
<filterchain>
<expandproperties/>
</filterchain>
</copy>
</target>
<!-- ==================================================================== -->
<!-- Runs the PHPUnit tests and generates a report -->
<!-- ==================================================================== -->
<target name="run-tests" depends="copy-tests" description="Runs the PHPUnit tests and generates a report.">
<exec executable="${pear.bin.dir}/phpunit" dir="${php-target.dir}">
<arg line="--log-junit ${php-target.dir}/reports/phpunit.xml --coverage-clover ${php-target.dir}/reports/coverage/clover.xml --coverage-html ${php-target.dir}/reports/coverage/ app/code/${codepool}/${namespace}/${module}/AllTests" />
</exec>
</target>
<!-- ==================================================================== -->
<!-- Runs the PHPUnit tests and generates a report -->
<!-- ==================================================================== -->
<target name="build" description="Runs the PHPUnit tests and generates a report.">
<antcall target="phpmd"/>
<antcall target="run-tests"/>
</target>
<!-- ==================================================================== -->
<!-- Upload current release version to PEAR Channel -->
<!-- ==================================================================== -->
<target name="upload-release" >
<echo message="Releasing ${namespace}_${module}-${release.version}.tgz on ${pear.channel}..."/>
<exec executable="${curl.bin}" outputproperty="exec.response">
<arg line='-F hash="${pear.api.hash}" -F qqfile=@"${php-target.dir}/${namespace}_${module}-${release.version}.tgz" -s http://${pear.channel}/upload'></arg>
</exec>
<echo>${exec.response}</echo>
</target>
<!-- ==================================================================== -->
<!-- Release new patch version -->
<!-- ==================================================================== -->
<target name="version-release" >
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask"/>
<echo message="Preparing new version release" />
<exec executable="awk" output="${basedir}/build.default.properties">
<arg line="'BEGIN{FS="."} {if ($1 ~ /release/ && $2 ~ /version/) print $1 "." $2 "." $3 "." ++$4;else print}' ${basedir}/build.default.properties" />
</exec>
<property file="${basedir}/build.default.properties" prefix="new"/>
<var name="release.version" unset="true"/>
<propertycopy name="release.version" from="new.release.version" />
<input message="Please enter changelog for release version ${release.version}:" addproperty="release.changelog" defaultvalue="- New release version"/>
<tstamp>
<format property="actual.date" pattern="yyyy-MM-dd" locale="en" />
<format property="actual.time" pattern="hh:mm:ss" locale="en" />
</tstamp>
<xmltask source="${basedir}/pear/package2.xml" dest="${basedir}/pear/package2.xml">
<replace path="/:package/:notes/text()" withXml="${release.changelog}"/>
<insert path="/*[local-name()='package']/*[local-name()='changelog']/*[local-name()='release'][1]" position="before">
<![CDATA[<release>
<version>
<release>${release.version}</release>
<api>${api.version}</api>
</version>
<stability>
<release>${release.stability}</release>
<api>${api.stability}</api>
</stability>
<date>${actual.date}</date>
<license uri="http://www.gnu.org/licenses/gpl-2.0.html">GPL, version 2.0</license>
<notes>
${release.changelog}
</notes>
</release>]]>
</insert>
</xmltask>
<propertyregex property="tag.release.version" input="${release.version}" regexp="\." replace="-" casesensitive="true"/>
<exec executable="${git.bin}" dir="${basedir}">
<arg line="commit -a -m '${release.changelog}'" />
</exec>
<exec executable="${git.bin}" dir="${basedir}">
<arg line="push" />
</exec>
<exec executable="${git.bin}" dir="${basedir}">
<arg line="tag -a -m '${release.changelog}' release-${tag.release.version}" />
</exec>
<exec executable="${git.bin}" dir="${basedir}">
<arg line="push ${github.url} tag release-${tag.release.version}" />
</exec>
<antcall target="create-package"/>
<antcall target="upload-release"/>
<echo message="${namespace} Version ${release.version} released." />
</target>
<!-- ==================================================================== -->
<!-- Enables repository export for GIT daemon -->
<!-- ==================================================================== -->
<target name="git-daemon-export-ok" description="Enables GIT repository export">
<touch file="${basedir}/.git/git-daemon-export-ok"/>
</target>
<!-- ==================================================================== -->
<!-- Disables repository export for GIT daemon -->
<!-- ==================================================================== -->
<target name="git-daemon-export-remove" description="Disables GIT repository export">
<delete file="${basedir}/.git/git-daemon-export-ok"/>
</target>
<!-- ==================================================================== -->
<!-- Initializing a TDProject instance for testing purpose -->
<!-- ==================================================================== -->
<target name="init-instance" description="Creates a TDProject instance for testing purpose">
<echo message="Preparing TDProject source..."/>
<antcall target="get-tdproject-src" />
<delete dir="${basedir}/instance-src" includeemptydirs="true" quiet="false" verbose="false" failonerror="true"/>
<delete dir="${dir.www}/${instance.dir}" includeemptydirs="true" quiet="false" verbose="false" failonerror="true"/>
<exec dir="${dir.www}/${instance.base.dir.tmp}" executable="${bin.extract}">
<arg line="${bin.extract.args}"/>
<arg line="${dir.www}/${instance.base.dir.tmp}/${instance.download.file}"/>
</exec>
<exec dir="${dir.www}/${instance.dir}" executable="${php.bin}">
<arg line="-f install.php --
--method install
--db_host ${mysql.host}
--db_name ${mysql.database}
--db_user ${mysql.username}
--db_pass ${mysql.password}
"/>
</exec>
<move todir="${dir.www}/${instance.dir}">
<fileset dir="${dir.www}/${instance.base.dir.tmp}/tdproject-${tdproject.version}"/>
</move>
<antcall target="finalize-instance-installation"/>
</target>
<!-- ==================================================================== -->
<!-- Finalize installation of TDProject instance -->
<!-- ==================================================================== -->
<target name="finalize-instance-installation">
<echo message="Installing instance ${instance.url}..." />
<chmod perm="+x" file="${dir.www}/${instance.dir}/bin/webapp"/>
<exec dir="${dir.www}/${instance.dir}" executable="bin/webapp">
<arg value="setup"/>
</exec>
<exec executable="/bin/ln" >
<arg value="-s"/>
<arg value="${dir.www}/${instance.dir}"/>
<arg value="${basedir}/instance-src"/>
</exec>
</target>
<!-- ==================================================================== -->
<!-- Check if TDProject Source Package has been downloaded yet -->
<!-- ==================================================================== -->
<target name="check-tdproject-exists">
<available file="${dir.www}/${instance.base.dir.tmp}/${instance.download.file}" property="tdproject-src.present"/>
</target>
<!-- ==================================================================== -->
<!-- Get TDProject Source Package by given version number -->
<!-- ==================================================================== -->
<target name="get-tdproject-src" depends="check-tdproject-exists" unless="tdproject-src.present">
<echo message="Downloading TDProject v${tdproject.version}..."/>
<mkdir dir="${dir.www}/${instance.base.dir.tmp}" />
<get src="${instance.download.url}/${instance.download.file}" dest="${dir.www}/${instance.base.dir.tmp}/${instance.download.file}"/>
</target>
</project>