forked from apache/royale-asjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cordova-build.xml
244 lines (196 loc) · 8.89 KB
/
cordova-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
<?xml version="1.0"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You 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="cordova-app" default="main">
<!-- this ANT script assumes you are in the following directory structure:
. /* run ANT here */
./src/<APP>.mxml /* The main application MXML tag */
./bin/js-debug /* The result of building APP.mxml via mxmlc, or
./target/javascript/bin/js-debug /* The result of building APP.mxml via maven
./app/<APP> /* The Cordova application directory
1. This ANT script will build the template Cordova app/APP if it does not
already exist.
2. This ANT script will compile the APP.mxml into bin/js-debug
3. This ANT script will remove ./app/<APP>/www contents are replace it with
the contents of bin/js-debug.
Optionally, you can run the Cordova application using ant run
-->
<target name="main" depends="find.cordova.mac,create,copyfiles" description="Creates the Cordova app if needed, compiles the Royale app, copies the results to Cordova app">
</target>
<!-- Set up properties and conditions -->
<property environment="env"/>
<condition property="isWindows" value="windows">
<os family="windows" />
</condition>
<condition property="projectdir" value="${user.dir}">
<not>
<isset property="projectdir" />
</not>
</condition>
<condition property="target" value="target/javascript">
<available file="${projectdir}/target/javascript/bin/js-debug" type="dir" />
</condition>
<property name="target" value="." />
<condition property="platform.android" value="android">
<not>
<isset property="platform.android" />
</not>
</condition>
<condition property="platform.ios" value="ios">
<not>
<isset property="platform.ios" />
</not>
</condition>
<!-- override with -Dappname=other-app-name -->
<basename property="directory.name" file="${projectdir}" />
<condition property="appname" value="${directory.name}">
<not>
<isset property="appname" />
</not>
</condition>
<condition property="cordova.executable" value="cordova.cmd">
<isset property="isWindows" />
</condition>
<condition property="cordova.path" value="${env.APPDATA}\npm">
<isset property="isWindows" />
</condition>
<property name="cordova.target.dir" value="${projectdir}/app/${appname}" />
<available file="${cordova.target.dir}" type="dir" property="app.dir.exists"/>
<target name="find.cordova.mac" unless="isWindows">
<condition property="cordova.executable" value="/usr/local/bin/cordova">
<available file="/usr/local/bin/cordova" type="file"/>
</condition>
<condition property="cordova.path" value="/usr/local/bin">
<available file="/usr/local/bin/cordova" type="file"/>
</condition>
</target>
<condition property="app.path" value="${env.Path}">
<isset property="env.Path" />
</condition>
<property name="app.path" value="${env.PATH}" />
<!-- Create the Cordova template project unless it already exists -->
<target name="makedir" unless="app.dir.exists">
<mkdir dir="${projectdir}/app" />
</target>
<target name="create" unless="app.dir.exists" depends="makedir" description="Creates the Cordova application template">
<!-- create the project -->
<exec executable="${cordova.executable}" dir="${projectdir}/app">
<env key="PATH" path="${app.path}:${cordova.path}"/>
<arg value="create" />
<arg value="${appname}" />
<arg value="org.apache.royale.examples.${appname}" />
<arg value="${appname}" />
</exec>
</target>
<!-- Clean www directory -->
<target name="purge">
<delete includeEmptyDirs="true">
<fileset dir="${cordova.target.dir}/www" includes="**/*" />
</delete>
</target>
<!-- Copy files from step above -->
<target name="copyfiles" depends="purge">
<echo message="Copying files from project" />
<copy todir="${cordova.target.dir}/www">
<fileset dir="${projectdir}/${target}/bin/js-debug" />
</copy>
</target>
<!--
Check to see if the Android platform needs to be loaded.
-->
<target name="check-platform.android">
<property name="android.platform" value="${projectdir}/app/${appname}/platforms/android" />
<available file="${android.platform}" type="dir" property="platform.loaded" />
</target>
<target name="load-platform.android" depends="find.cordova.mac,check-platform.android" unless="platform.loaded">
<exec executable="${cordova.executable}" dir="${cordova.target.dir}">
<env key="PATH" path="${app.path}:${cordova.path}"/>
<arg value="platform" />
<arg value="add" />
<arg value="${platform.android}" />
</exec>
</target>
<!--
Check to see if the iOS platform needs to be loaded.
-->
<target name="check-platform.ios">
<property name="android.ios" value="${projectdir}/app/${appname}/platforms/ios" />
<available file="${ios.platform}" type="dir" property="platform.loaded" />
</target>
<target name="load-platform.ios" depends="find.cordova.mac,check-platform.ios" unless="platform.loaded">
<exec executable="${cordova.executable}" dir="${cordova.target.dir}">
<env key="PATH" path="${app.path}:${cordova.path}"/>
<arg value="platform" />
<arg value="add" />
<arg value="${platform.ios}" />
</exec>
</target>
<!--
Check to see if the Cordova File Plugin is needed and if so, load it.
-->
<target name="check-fileplugin">
<property name="storage.file" value="${projectdir}/${target}/bin/js-debug/org/apache.royale/storage/IPermanentStorage.js" />
<available file="${storage.file}" type="file" property="file.plugin.needed" />
</target>
<target name="load-fileplugin" depends="find.cordova.mac,check-fileplugin" if="file.plugin.needed">
<echo message="Loading cordova file-plugin" />
<exec executable="${cordova.executable}" dir="${cordova.target.dir}">
<env key="PATH" path="${app.path}:${cordova.path}"/>
<arg value="plugin" />
<arg value="add" />
<arg value="cordova-plugin-file" />
</exec>
</target>
<target name="load-plugin" depends="find.cordova.mac">
<echo message="Loading cordova plugin ${plugin}" />
<echo message="target dir = ${cordova.target.dir}" />
<exec executable="${cordova.executable}" dir="${cordova.target.dir}">
<env key="PATH" path="${app.path}:${cordova.path}"/>
<arg value="plugin" />
<arg value="add" />
<arg value="${plugin}" />
</exec>
</target>
<!--
Running the app on the platform
-->
<target name="run.android" depends="find.cordova.mac,load-platform.android,load-fileplugin" description="Runs the Cordova application on the specified platform">
<echo message="Launching ${appname} on platform ${platform.android}" />
<exec executable="${cordova.executable}" dir="${cordova.target.dir}">
<env key="PATH" path="${app.path}:${cordova.path}"/>
<arg value="run" />
<arg value="${platform.android}" />
</exec>
</target>
<target name="run.ios" depends="find.cordova.mac,load-platform.ios,load-fileplugin" description="Runs the Cordova application on the specified platform">
<echo message="Launching ${appname} on platform ${platform.ios}" />
<exec executable="${cordova.executable}" dir="${cordova.target.dir}">
<env key="PATH" path="${app.path}:${cordova.path}"/>
<arg value="run" />
<arg value="${platform.ios}" />
</exec>
</target>
<!--
Cleaning Tasks
-->
<target name="clean" depends="purge" description="Removes files created during the build and copy">
<delete dir="${projectdir}/bin-debug" failonerror="false" />
<delete dir="${projectdir}/bin-release" failonerror="false" />
</target>
<target name="super-clean" depends="clean" description="Removes all files and directories except src and its contents">
<delete dir="${projectdir}/bin" />
<delete dir="${projectdir}/app" />
</target>
</project>