forked from corimf/build-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
corimf-build-android
executable file
·263 lines (226 loc) · 7.54 KB
/
corimf-build-android
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
#!/bin/sh -e
#
# 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.
#
###############################################################################
# Use the -e option so the script will fail on the first non-zero return code.
# This is a script to automate building a 2.3.0 thru 3.1.0 snapshot of Android
# Cordova for delivery to a product team to integrate. The manual process for
# this is described in our wiki. It is assumed that the platform/plugman/plugin
# repos have already been tagged with NEW_TAG. If you are just doing a test
# build and not creating a snapshot for product integration, you can get around
# the NEW_TAG check by setting it to "HEAD" in your corimf-settings file.
if [ "$1" = "" ]
then
echo "Loading the settings from corimf-settings..."
source corimf-settings
else
echo "Loading the settings from $1"
source "$1"
fi
echo "PLATFORM_REPO=$PLATFORM_REPO"
echo "REMOTE_ORIGIN=$REMOTE_ORIGIN"
echo "BRANCH=$BRANCH"
echo "NEW_TAG=$NEW_TAG"
echo "SKIP_PLUGIN=$SKIP_PLUGIN"
/bin/echo -n "Hit ENTER to continue: "
read ANSWER
# Shouldn't need to change anything below here.
check_rc() {
SAVE_RC=$?
if [ $SAVE_RC != 0 ]
then
echo "Failed."
exit $RC
elif [ "$DONE" = 1 ]
then
echo "Success."
else
echo "Incomplete."
exit 1
fi
}
trap check_rc EXIT
echo "Running Android Cordova build of corimf:"
echo " Date:" `date`
echo " Remote origin: $REMOTE_ORIGIN"
echo " Branch: $BRANCH"
echo " New Tag: $NEW_TAG"
echo " Skip Plugin: $SKIP_PLUGIN"
echo
echo "Checking that we are one dir above the git repo..."
test -d $PLATFORM_REPO
echo "Checking major version number..."
MAJOR=`echo $BRANCH | cut -f1 -d.`
test "$MAJOR" -ge 2 -a "$MAJOR" -le 3
if [ "$MAJOR" -ge 3 ]
then
echo "Checking that the plugin count is $PLUGIN_COUNT..."
COUNT=0
for PLUGIN in $PLUGINS
do
COUNT=`expr $COUNT + 1`
done
test "$COUNT" == "$PLUGIN_COUNT"
else
echo "Skipping all plugins since version is $MAJOR"
PLUGINS=
PLUGMAN_REPO=
fi
echo "Checking that each plugin repo exists..."
for PLUGIN in $PLUGINS
do
test -d $PLUGIN
done
echo "Checking that we are on the expected ESR branch $BRANCH for platform and plugins..."
for DIR in $PLATFORM_REPO $PLUGMAN_REPO $PLUGINS
do
/bin/echo -n "$DIR: "
cd $DIR
git status --porcelain -b | grep '^##' | grep "## $BRANCH"
cd ..
done
echo "Doing a git pull and tags fetch on platform and plugins to make sure we are up-to-date..."
for DIR in $PLATFORM_REPO $PLUGMAN_REPO $PLUGINS
do
/bin/echo -n "$DIR: "
cd $DIR
git pull $REMOTE_ORIGIN $BRANCH
git fetch --tags $REMOTE_ORIGIN
cd ..
done
echo "Checking that the platform and plugins have the tag $NEW_TAG..."
for DIR in $PLATFORM_REPO $PLUGMAN_REPO $PLUGINS
do
/bin/echo -n "$DIR: "
cd $DIR
git rev-parse $NEW_TAG
cd ..
done
echo "Checking that the platform and plugins are checked out at the tag $NEW_TAG..."
for DIR in $PLATFORM_REPO $PLUGMAN_REPO $PLUGINS
do
/bin/echo -n "$DIR: "
cd $DIR
ACTUAL=`git log -1 --format=oneline | cut -f1 -d' '`
DESIRED=`git rev-parse $NEW_TAG`
test "$ACTUAL" == "$DESIRED"
cd ..
done
echo "Checking that we are using compiler for Java 5 or 6, not 7..."
VERSION=`javac -version 2>&1 | cut -f2 -d.`
test "$VERSION" -ge 5 -a "$VERSION" -le 6
if [ $BRANCH = "2.6.0esr" ]
then
echo "Updating platform to use API 17..."
android update project -p $PLATFORM_REPO/framework -t android-17
# Work around annoying bug in the bin/build script that assumes API 17
# is the latest you have installed.
echo "Checking that API 17 is the most recent SDK installed..."
API_LEVEL=`android list targets | grep "API level:" | tail -n1 | cut -f2 -d: | tr -d ' '`
if [ "$API_LEVEL" != "17" ]
then
echo "Sorry, you need to uninstall the SDK for API $API_LEVEL"
echo " or temporarily disable it by moving it to another directory, because it is"
echo " preventing API 17 from being the most recent API installed."
echo " This is a requirement for older Cordova versions."
echo " (i.e., \"mv \$SDK_HOME/sdk/platforms/android-$API_LEVEL \$SDK_HOME/sdk/disabled-platforms/android-$API_LEVEL\" and make sure you have \"Android SDK Build Tools\" for v17 installed."
exit 1
fi
fi
if [ $MAJOR -eq 2 ]
then
# you need to mkdir cordova-android/framework/libs and add commons-codec.jar
test -d cordova-android/framework/libs
test -f cordova-android/framework/libs/commons-codec-1.7.jar
fi
echo "Rebuilding the cordova.jar..."
cd cordova-android
cd framework
ant clean
ant jar
cd ..
cd ..
PROJECT_DIR=example-android-$NEW_TAG
SNAPSHOT_DIR=forgsa-android-$NEW_TAG
echo "Checking that project $PROJECT_DIR does not exist yet..."
test ! -e $PROJECT_DIR
echo "Checking that snapshot dir $SNAPSHOT_DIR does not exist yet..."
test ! -f $SNAPSHOT_DIR
echo "Creating a new Android project..."
cordova-android/bin/create $PROJECT_DIR com.example Example
if [ ! -z "$PLUGINS" ]
then
echo "Load pre-reqs for plugman..."
cd $PLUGMAN_REPO
if [ -d node_modules ]
then
rm -r node_modules
fi
npm install
cd ..
fi
echo "Installing plugins into project..."
for PLUGIN in $PLUGINS
do
if [ "$PLUGIN" = "$SKIP_PLUGIN" ]
then
echo "Warning: Skipping $PLUGIN"
continue
fi
node $PLUGMAN_REPO/main.js --debug install -platform android -project $PROJECT_DIR --plugin ./$PLUGIN
done
echo "Building the project (apk)..."
cd $PROJECT_DIR
cordova/build
if [ $MAJOR -ge 3 ]
then
# capture the plugins in a jar for Worklight as a convenience for 3.x
jar cvf cordova_plugins.jar -C ant-build/classes org/apache/cordova
fi
cd ..
echo "Creating snapshot content in $SNAPSHOT_DIR..."
mkdir $SNAPSHOT_DIR
# get the original platform project. Not really needed perhaps.
cp -rp cordova-android/framework $SNAPSHOT_DIR/framework
if [ -d $SNAPSHOT_DIR/framework/test ]
then
# don't need test artifacts
rm -r $SNAPSHOT_DIR/framework/test
fi
# get the example project, which includes cordova.jar and cordova.js.
cp -rp $PROJECT_DIR $SNAPSHOT_DIR/example
if [ -d $SNAPSHOT_DIR/example/assets/www/spec ]
then
# don't need test artifacts
rm -r $SNAPSHOT_DIR/example/assets/www/spec
fi
# get the IBM-MODIFICATIONS.txt files, just to be nice.
mkdir $SNAPSHOT_DIR/modifications
for REPO in $PLATFORM_REPO $PLUGMAN_REPO $PLUGINS
do
test -f $REPO/IBM-MODIFICATIONS.txt && cp $REPO/IBM-MODIFICATIONS.txt $SNAPSHOT_DIR/modifications/$REPO.IBM-MODIFICATIONS.txt
done
# remove metadata files created by OSX Finder
find $SNAPSHOT_DIR -name .DS_Store -delete
echo "Zipping snapshot content as $SNAPSHOT_DIR.zip..."
zip -r $SNAPSHOT_DIR.zip $SNAPSHOT_DIR
# TODO: echo "Checking that each plugin repo is present..."
# TODO: echo "Checking that each plugin is checked out at the correct tag"
echo "All building complete."
DONE=1