forked from Flowdalic/asmack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.bash
executable file
·240 lines (218 loc) · 5.33 KB
/
build.bash
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
#!/bin/bash
#set -x
fetch() {
echo "Fetching from ${1} to ${2}"
cd $SRC_DIR
if ! [ -f "${2}/.svn/entries" ]; then
mkdir "${2}"
cd "${2}"
svn co --non-interactive --trust-server-cert "${1}" "."
else
cd "${2}"
svn cleanup
svn up
fi
}
gitfetch() {
echo "Fetching ${2} branch from ${1} to ${3} via git"
cd $SRC_DIR
if ! [ -f "${3}/.git/config" ]; then
git clone "${1}" "${3}"
cd "${3}"
git checkout origin/"${2}"
else
cd "${3}"
git fetch
git checkout origin/"${2}"
fi
if [ $? -ne 0 ]; then
exit
fi
}
testsmackgit() {
cd $SRC_DIR
if [ -f .used-smack-git-repo ] && [ $(cat .used-smack-git-repo) != $SMACK_REPO ] ; then
echo "Used smack repository has changed!"
echo "Old: $(cat .used-smack-git-repo) New: ${SMACK_REPO}."
echo "Deleting old local copy"
rm -rf smack
fi
echo "${SMACK_REPO}" > .used-smack-git-repo
}
fetchall() {
if $SMACK_LOCAL ; then
# always clean the local copy first
rm -rf ${SRC_DIR}/smack
mkdir ${SRC_DIR}/smack
cd $SMACK_REPO
git archive $SMACK_BRANCH | tar -x -C ${SRC_DIR}/smack
if [ $? -ne 0 ]; then
exit
fi
else
gitfetch "$SMACK_REPO" "$SMACK_BRANCH" "smack"
fi
if ! $UPDATE_REMOTE ; then
echo "Won't update or fetch third party resources"
return
fi
fetch "http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/management/common/src/main/" "qpid"
fetch "http://svn.apache.org/repos/asf/harmony/enhanced/java/trunk/classlib/modules/auth/src/main/java/common/" "harmony"
fetch "https://dnsjava.svn.sourceforge.net/svnroot/dnsjava/trunk" "dnsjava"
gitfetch "git://kenai.com/jbosh~origin" "master" "jbosh"
# jldap doesn't compile with the latest version (missing deps?), therefore it's a fixed version for now
# gitfetch "git://git.openldap.org/openldap-jldap.git" "master" "novell-openldap-jldap"
}
copyfolder() {
(
cd ${WD}
(
cd "${1}"
tar -cSsp --exclude-vcs "${3}"
) | (
cd "${2}"
tar -xSsp
)
)
}
buildsrc() {
echo "## Step 20: creating build/src"
cd "${WD}"
rm -rf build/src
mkdir -p build/src/trunk
copyfolder "src/smack/source/" "build/src/trunk" "."
copyfolder "src/qpid/java" "build/src/trunk" "org/apache/qpid/management/common/sasl"
copyfolder "src/novell-openldap-jldap" "build/src/trunk" "."
copyfolder "src/dnsjava" "build/src/trunk" "org"
copyfolder "src/harmony" "build/src/trunk" "."
copyfolder "src/custom" "build/src/trunk" "."
copyfolder "src/jbosh/src/main/java" "build/src/trunk" "."
if $BUILD_JINGLE ; then
copyfolder "src/smack/jingle/extension/source/" "build/src/trunk" "."
fi
}
patchsrc() {
echo "## Step 21: patch build/src"
cd "${WD}"
(
cd build/src/trunk/
for PATCH in `(cd "../../../${1}" ; find -maxdepth 1 -type f)|sort` ; do
if echo $PATCH | grep '\.sh$'; then
if [ -f "../../../${1}/$PATCH" ]; then "../../../${1}/$PATCH" || exit 1 ; fi
fi
if echo $PATCH | grep '\.patch$'; then
if [ -f "../../../${1}/$PATCH" ]; then patch -p0 < "../../../${1}/$PATCH" || exit 1 ; fi
fi
done
)
}
build() {
echo "## Step 30: compile"
ant -Dbuild.all=true $JINGLE_ARGS
if [ $? -ne 0 ]; then
exit
fi
}
buildcustom() {
for dir in `find patch -maxdepth 1 -mindepth 1 -type d`; do
buildsrc
patchsrc "patch"
if $BUILD_JINGLE ; then
patchsrc "jingle"
JINGLE_ARGS="-Djingle=lib/jstun.jar"
fi
patchsrc "${dir}"
ant -Djar.suffix=`echo ${dir}|sed 's:patch/:-:'` $JINGLE_ARGS
done
}
parseopts() {
while getopts r:b:duchj OPTION "$@"; do
case $OPTION in
r)
SMACK_REPO="${OPTARG}"
;;
b)
SMACK_BRANCH="${OPTARG}"
;;
d)
set -x
;;
j)
BUILD_JINGLE=true
;;
u)
UPDATE_REMOTE=false
;;
c)
BUILD_CUSTOM=true
;;
h)
echo "$0 -d -c -u -j -r <repo> -b <branch>"
echo "-d: Enable debug"
echo "-j: Build jingle code"
echo "-c: Apply custom patchs from patch directory"
echo "-u: DON'T update remote third party resources"
echo "-r <repo>: Git repository (can be local or remote) for underlying smack repository"
echo "-b <branch>: Git branch used to build aSmack from underlying smack repository"
exit
;;
esac
done
if islocalrepo $SMACK_REPO ; then
SMACK_LOCAL=true
SMACK_REPO=`readlink -f $SMACK_REPO`
fi
}
islocalrepo() {
local R="^(git|ssh)"
if [[ $1 =~ $R ]]; then
return 1
else
return 0
fi
}
initialize() {
echo "## Step 00: initialize"
if ! [ -d build/src/trunk ]; then
mkdir -p build/src/trunk
fi
if [ ! -d src/ ]; then
mkdir src
fi
rm build/*.jar
rm build/*.zip
}
copystaticsrc() {
cp -ur static-src/* src/
}
# Default configuration
SMACK_REPO=git://github.com/Flowdalic/smack.git
SMACK_BRANCH=master
SMACK_LOCAL=false
UPDATE_REMOTE=true
BUILD_CUSTOM=false
BUILD_JINGLE=false
JINGLE_ARGS=""
SRC_DIR=$(pwd)/src
WD=$(pwd)
parseopts $@
echo "Using Smack git repository $SMACK_REPO with branch $SMACK_BRANCH"
echo "SMACK_LOCAL: $SMACK_LOCAL UPDATE_REMOTE: $UPDATE_REMOTE BUILD_CUSTOM: $BUILD_CUSTOM BUILD_JINGLE: $BUILD_JINGLE"
initialize
copystaticsrc
testsmackgit
fetchall
buildsrc
patchsrc "patch"
if $BUILD_JINGLE ; then
patchsrc "jingle"
JINGLE_ARGS="-Djingle=lib/jstun.jar"
fi
build
if $BUILD_CUSTOM ; then
buildcustom
fi
if which advzip; then
find build/*.jar -exec advzip -z4 '{}' ';'
find build/*.zip -exec advzip -z4 '{}' ';'
fi