-
Notifications
You must be signed in to change notification settings - Fork 0
/
phonegapbuild.xml
207 lines (181 loc) · 7.58 KB
/
phonegapbuild.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
<project name="phonegapbuild" default="buildApp">
<property name="appDownloadDir" value="${basedir}/target/phonegap"/>
<property name="appSourceDir" value="${basedir}/target/html5"/>
<property name="buildDir" value="${basedir}/target/phonegap-temp"/>
<target name="initApp">
<delete dir="${buildDir}"/>
<mkdir dir="${buildDir}"/>
<delete dir="${appDownloadDir}"/>
<mkdir dir="${appDownloadDir}"/>
<fail message="Property username (PhoneGap Build Username) is missing" unless="username"/>
<fail message="Property password (PhoneGap Build Password) is missing" unless="password"/>
<fail message="Property signkey (PhoneGap Build Singkey name) is missing" unless="signkey"/>
<fail message="Property debug (PhoneGap Build Debug) is missing" unless="debug"/>
<property name="appTitle" value="${project.name}"/>
<echo>App title: ${appTitle}</echo>
</target>
<macrodef name="curl">
<attribute name="args"/>
<attribute name="dir" default="${basedir}"/>
<sequential>
<echo>curl @{args}</echo>
<exec executable="curl" outputproperty="curlOutput" logError="true" dir="@{dir}">
<arg line="@{args}"/>
</exec>
</sequential>
</macrodef>
<macrodef name="updateAppInfo">
<sequential>
<local name="curlOutput"/>
<curl args="-u ${username}:${password} https://build.phonegap.com/api/v1/apps"/>
<script language="javascript">
// <![CDATA[
var apps = eval("apps="+project.getProperty("curlOutput")).apps;
var foundApp;
for (var i=0; i<apps.length; i++) {
app = apps[i];
if (app.title==appTitle) {
foundApp = app;
break;
}
}
if (foundApp) {
project.setProperty("appId", app.id);
var statusList = [];
for (var platform in app.status) {
var status = app.status[platform];
statusList.push('"'+platform+'":"'+status+'"');
}
project.setProperty("appStatus", statusList.join(","));
} else {
project.setProperty("appStatus", "error");
}
// ]]>
</script>
<echo>App id ${appId} status ${appStatus}</echo>
</sequential>
</macrodef>
<target name="getAppInfo" depends="initApp">
<updateAppInfo/>
</target>
<target name="getUserInfo" depends="initApp">
<local name="curlOutput"/>
<curl args="-u ${username}:${password} https://build.phonegap.com/api/v1/me"/>
<script language="javascript">
// <![CDATA[
var keys = eval("keys="+project.getProperty("curlOutput")).keys;
var result = [];
for (var platform in keys) {
var keyList = keys[platform].all;
if (keyList) {
for (var i=0; i<keyList.length; i++) {
var key = keyList[i];
if (key.title==signkey) {
result.push('"'+platform+'":"'+key.id+'"');
break;
}
}
}
}
project.setProperty("appKeys", "{"+result.join(",")+"}");
// ]]>
</script>
<echo>Found app keys: ${appKeys}</echo>
</target>
<target name="waitForBuild" depends="initApp">
<waitfor maxwait="30" maxwaitunit="second">
<scriptcondition language="javascript">
getAppInfo.execute();
var appStatus = project.getProperty("appStatus");
self.setValue(appStatus.indexOf('pending')==-1);
</scriptcondition>
</waitfor>
</target>
<target name="zipSources" depends="initApp">
<zip destfile="${buildDir}/source.zip">
<fileset dir="${appSourceDir}"/>
</zip>
</target>
<target name="createApp" depends="getAppInfo, getUserInfo, zipSources" unless="appId">
<local name="curlOutput"/>
<curl args="-u ${username}:${password} -F file=@${buildDir}/source.zip -F data='{"create_method":"file", "keys":${appKeys},"title":"${appTitle}","debug":"${debug}"}' https://build.phonegap.com/api/v1/apps"/>
<updateAppInfo/>
<echo>App created</echo>
</target>
<target name="updateApp" depends="getAppInfo, getUserInfo, zipSources" if="appId">
<property name="sourceZip" value="${buildDir}/source.zip"/>
<local name="curlOutput"/>
<curl args="-u ${username}:${password} -X PUT -F file=@${buildDir}/source.zip -F data='{"create_method":"file","keys":${appKeys},"title":"${appTitle}","debug":"${debug}"}' https://build.phonegap.com/api/v1/apps/${appId}"/>
<echo>App updated</echo>
</target>
<macrodef name="downloadForPlatform">
<attribute name="platform"/>
<sequential>
<local name="curlOutput"/>
<local name="downloadLink"/>
<curl args="-u ${username}:${password} https://build.phonegap.com/apps/${appId}/download/@{platform}"/>
<script language="javascript">
project.setProperty("downloadLink", project.getProperty("curlOutput").match(/href="([^"]+)/)[1]);
</script>
<downloadUrl targetDir="${appDownloadDir}/@{platform}" sourceurl="${downloadLink}"/>
<echo file="${appDownloadDir}/@{platform}/sourceUrl" message="${downloadLink}"/>
</sequential>
</macrodef>
<macrodef name="downloadUrl">
<attribute name="targetDir"/>
<attribute name="sourceUrl"/>
<sequential>
<echo>Downloading @{sourceUrl} to @{targetDir}</echo>
<mkdir dir="@{targetDir}"/>
<local name="curlArgs"/>
<script language="javascript">
var curlArgs = '-O '+'@{sourceUrl}'.split(' ').join(' -O ');
project.setProperty('curlArgs', curlArgs);
</script>
<curl args="${curlArgs}" dir="@{targetDir}"/>
</sequential>
</macrodef>
<target name="downloadIos" depends="getAppInfo">
<downloadForPlatform platform="ios"/>
</target>
<target name="downloadAndroid" depends="getAppInfo">
<downloadForPlatform platform="android"/>
</target>
<target name="downloadBlackberry" depends="getAppInfo">
<downloadForPlatform platform="blackberry"/>
<property name="bbDir" value="${appDownloadDir}/blackberry"/>
<local name="jadContent"/>
<loadresource property="jadContent">
<fileset dir="${bbDir}" includes="*.jad"/>
</loadresource>
<local name="downloadLink"/>
<loadfile srcFile="${bbDir}/sourceUrl" property="downloadLink"/>
<script language="javascript">
// <![CDATA[
var jadUrlPath = project.getProperty('downloadLink');
var lastSlash = jadUrlPath.lastIndexOf('/');
jadUrlPath = jadUrlPath.substring(0, lastSlash);
var match;
var jadContent = ''+project.getProperty("jadContent");
var codUrls = [];
var jadRegex = /RIM-COD-URL-\d+: (.*)/g;
while (match = jadRegex.exec(jadContent)) {
codUrls.push(jadUrlPath+'/'+match[1]);
}
project.setProperty("codUrls", codUrls.join(" "));
// ]]>
</script>
<downloadUrl targetDir="${bbDir}" sourceUrl="${codUrls}"/>
</target>
<target name="downloadWebos" depends="getAppInfo">
<downloadForPlatform platform="webos"/>
</target>
<target name="downloadSymbian" depends="getAppInfo">
<downloadForPlatform platform="symbian"/>
</target>
<target name="downloadWinphone" depends="getAppInfo">
<downloadForPlatform platform="winphone"/>
</target>
<target name="downloadApp" depends="downloadAndroid, downloadWinphone, downloadIos, downloadSymbian, downloadWebos, downloadBlackberry"/>
<target name="buildApp" depends="updateApp, createApp, waitForBuild, downloadApp"/>
</project>