-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.xml
336 lines (280 loc) · 12 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
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2012 Keita Kita
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project name="andorid.logmatcher.build" default="test">
<!-- Path of main codes. -->
<property name="main.code.directory" location="src/main" />
<!-- Path of unit test codes. -->
<property name="unit.test.code.directory" location="src/unit-test" />
<!-- Path of integration test codes. -->
<property name="integration.test.code.directory"
location="src/integration-test" />
<!-- Path of output files directory. -->
<property name="output.files.directory" location="out" />
<!-- Path-like structure for PYTHONPATH -->
<path id="pythonpath">
<pathelement location="${main.code.directory}" />
<pathelement location="${unit.test.code.directory}" />
<pathelement location="${integration.test.code.directory}" />
<pathelement location="externals/test" />
</path>
<!-- Property for PYTHONPATH -->
<property name="pythonpath" refid="pythonpath" />
<!-- Script for unit test suite. -->
<property name="unit.test.script"
location="${unit.test.code.directory}/unittest_suite.py" />
<!-- Script for unit test suite for a CI server. -->
<property name="ci.unit.test.script"
location="${unit.test.code.directory}/ci_unittest.py" />
<!-- Script for integration test suite on monkeyrunner. -->
<property name="integration.monkeyrunner.test.script"
location="${integration.test.code.directory}/monkeyrunner_test_suite.py" />
<!-- Script for integration test suite on monkeyrunner. -->
<property name="integration.python.test.script"
location="${integration.test.code.directory}/python_test_suite.py" />
<!-- Directory of android application for integration test. -->
<property name="integration.test.android.application.directory"
location="tools/integration-test-android-application" />
<!--
Properties for executables.
-->
<condition property="bat" value=".bat" else="">
<os family="windows" />
</condition>
<property name="python" value="python" />
<property name="coverage" value="coverage" />
<property name="android" value="android${bat}" />
<property name="monkeyrunner" value="monkeyrunner${bat}" />
<!--
Properties for reports.
-->
<!-- Directory for reports. -->
<property name="reports.directory" location="reports" />
<!-- Directory for HTML coverage of unit test report. -->
<property name="reports.unit.test.coverage.directory"
location="${reports.directory}/coverage" />
<!-- File of XML reports.unit.test.result test report. -->
<property name="reports.unit.test.result"
location="${reports.directory}/test_result.xml" />
<!-- File of XML coverage of unit test report. -->
<property name="reports.unit.test.coverage.xml"
location="${reports.directory}/coverage.xml" />
<!--
Properties for release.
-->
<!-- Directory of documentations for distribution. -->
<property name="docs.for.distribution.directory"
location="docs/for_distribution" />
<!-- File of archive for release. release.version property is set
from command line argument. -->
<property name="release.archive"
location="${output.files.directory}/AndroidLogMatcher-${release.version}.zip" />
<!--
Macros and targets for test.
-->
<macrodef name="exec.with.pythonpath"
description="Exec task with PYTHONPATH.">
<attribute name="executable" description="Executable name." />
<element name="arguments" description="Arguments of executable." />
<sequential>
<exec executable="@{executable}"
searchpath="true" failonerror="true">
<env key="PYTHONPATH" value="${pythonpath}" />
<arguments />
</exec>
</sequential>
</macrodef>
<macrodef name="python" description="Execute python.">
<element name="args" description="Arguments of python." />
<sequential>
<exec.with.pythonpath executable="${python}">
<arguments>
<args />
</arguments>
</exec.with.pythonpath>
</sequential>
</macrodef>
<macrodef name="monkeyrunner" description="Execute monkeyrunner.">
<element name="args" description="Arguments of monkeyrunner." />
<sequential>
<exec executable="${monkeyrunner}"
searchpath="true" failonerror="true">
<env key="PYTHONPATH" value="${pythonpath}" />
<args />
</exec>
</sequential>
</macrodef>
<!-- Prepare for reports. -->
<target name="-prepare-reports">
<mkdir dir="${reports.directory}" />
</target>
<target name="test" description="Run unit tests.">
<python>
<args>
<arg file="${unit.test.script}" />
</args>
</python>
</target>
<target name="-check-local-properties-of-integration-test-android-application">
<condition
property="local.properties.of.integration.test.android.application.exists">
<available
file="${integration.test.android.application.directory}/local.properties" />
</condition>
</target>
<target name="-create-local-properties-of-integration-test-android-application"
depends="-check-local-properties-of-integration-test-android-application"
unless="local.properties.of.integration.test.android.application.exists">
<exec executable="${android}" searchpath="true" failonerror="true"
taskname="create local.properties">
<arg line="update project"/>
<arg value="--name" />
<arg value="IntegrationTestAndroidApplication" />
<arg value="--path" />
<arg value="${integration.test.android.application.directory}" />
</exec>
</target>
<target name="install-integration-test-android-application"
depends="-create-local-properties-of-integration-test-android-application"
description="Install an Android application for integration test.">
<ant dir="${integration.test.android.application.directory}"
useNativeBasedir="true" inheritAll="false"
taskname="build and install">
<target name="debug" />
<target name="install" />
</ant>
</target>
<target name="uninstall-integration-test-android-application"
depends="-create-local-properties-of-integration-test-android-application"
description="Uninstall the Android application for integration test.">
<ant dir="${integration.test.android.application.directory}"
useNativeBasedir="true" inheritAll="false"
taskname="uninstall">
<target name="uninstall" />
</ant>
</target>
<target name="integration-monkeyrunner-test"
depends="install-integration-test-android-application"
description="Run integration tests on monkeyrunner. Require Android emulator or device.">
<monkeyrunner>
<args>
<arg file="${integration.monkeyrunner.test.script}" />
</args>
</monkeyrunner>
</target>
<target name="integration-python-test"
depends="install-integration-test-android-application"
description="Run integration tests on Python. Require Android emulator or device.">
<python>
<args>
<arg file="${integration.python.test.script}" />
</args>
</python>
</target>
<target name="integration-all-test"
depends="integration-monkeyrunner-test, integration-python-test"
description="Run all integration tests." />
<target name="clean" description="Clean generated files.">
<delete dir="${output.files.directory}" />
<delete dir="${reports.directory}" />
<delete file=".coverage" />
<ant dir="${integration.test.android.application.directory}"
target="clean" useNativeBasedir="true" inheritAll="false" />
</target>
<!--
Macros and targets for coverage.
-->
<macrodef name="coverage" description="Execute coverage.py.">
<element name="args" description="Arguments of coverage." />
<sequential>
<exec.with.pythonpath executable="${coverage}">
<arguments>
<args />
</arguments>
</exec.with.pythonpath>
</sequential>
</macrodef>
<macrodef name="coverage-run"
description="Run a script and measure coverage.">
<attribute name="script" description="Location of the script." />
<element name="script-exec-arguments" optional="true"
description="Arguments of exec for the script." />
<sequential>
<coverage>
<args>
<arg value="run" />
<arg value="--source=${main.code.directory}" />
<arg value="@{script}" />
<script-exec-arguments />
</args>
</coverage>
</sequential>
</macrodef>
<target name="test-coverage" depends="-prepare-reports"
description="Run unit tests and measure coverage, report as HTML.">
<coverage-run script="${unit.test.script}" />
<echo message="${line.separator}" />
<coverage>
<args>
<arg value="report" />
</args>
</coverage>
<coverage>
<args>
<arg value="html" />
<arg value="--directory" />
<arg file="${reports.unit.test.coverage.directory}" />
</args>
</coverage>
<echo message="${line.separator}" />
<echo
message="HTML coverage of unit test report is ${reports.unit.test.coverage.directory}" />
</target>
<!--
Target for CI.
-->
<target name="ci-test-coverage" depends="-prepare-reports"
description="Run unit tests and measure coverage, report as XML.">
<coverage-run script="${ci.unit.test.script}">
<script-exec-arguments>
<redirector output="${reports.unit.test.result}" />
</script-exec-arguments>
</coverage-run>
<echo message="XML unit test report is ${reports.unit.test.result}" />
<coverage>
<args>
<arg value="xml" />
<arg value="-o" />
<arg file="${reports.unit.test.coverage.xml}" />
</args>
</coverage>
<echo message="XML coverage of unit test report is ${reports.unit.test.coverage.xml}" />
</target>
<!--
Target for release.
-->
<target name="release" description="Create a zip archive for release. Require release.version property.">
<fail unless="release.version"
message="Specify release.version property."/>
<zip destfile="${release.archive}">
<fileset dir="${docs.for.distribution.directory}" />
<fileset dir="${main.code.directory}">
<include name="**/*.py" />
</fileset>
<fileset dir=".">
<include name="README*.txt" />
</fileset>
</zip>
<echo message="The archive is created to ${release.archive}" />
</target>
</project>