-
Notifications
You must be signed in to change notification settings - Fork 0
/
ant.sh
199 lines (162 loc) · 5.56 KB
/
ant.sh
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
#!/bin/bash
#Author: CaoZheng
Script_Path=$(dirname $0)
Temp_Path=/tmp/$(openssl rand -hex 5)
mkdir $Temp_Path
mkdir $Temp_Path/class_tar
compare_url="$1"
base_url="$2"
build_files="$3"
get_diff_txt() {
echo "[INFO] Get difference list... "
svn diff --summarize $compare_url $base_url > $Temp_Path/svn.txt
awk '$1=="A" { print $2 }' $Temp_Path/svn.txt|egrep -v "\/\." > $Temp_Path/A.list
awk '$1=="M" { print $2 }' $Temp_Path/svn.txt|egrep -v "\/\." > $Temp_Path/M.list
awk '$1=="MM" { print $2 }' $Temp_Path/svn.txt|egrep -v "\/\." >> $Temp_Path/M.list
awk '$1=="D" { print $2 }' $Temp_Path/svn.txt|egrep -v "\/\." > $Temp_Path/D.list
cat $Temp_Path/M.list|while read i
do
FileType=$(svn info "$i"|grep 'Node Kind'|awk '{ print $3 }')
if [ "$FileType" = "file" ];then
echo $i >> $Temp_Path/final_list.txt
fi
done
cat $Temp_Path/D.list|while read i
do
FileType=$(svn info "$i"|grep 'Node Kind'|awk '{ print $3 }')
if [ "$FileType" = "file" ];then
echo $i >> $Temp_Path/final_list.txt
elif [ "$FileType" = "directory" ]; then
echo $i >> $Temp_Path/D.dir.txt
else
echo "[ERROR] Unknow file type!"
rm -rf $Temp_Path
exit 1
fi
done
sed s#$compare_url#$base_url# $Temp_Path/A.list > $Temp_Path/A.list.tmp
cat $Temp_Path/A.list.tmp|while read i
do
FileType=$(svn info "$i"|grep 'Node Kind'|awk '{ print $3 }')
if [ "$FileType" = "file" ];then
origin_url=$(echo $i|sed s#$base_url#$compare_url#)
echo $origin_url >> $Temp_Path/final_list.txt
elif [ "$FileType" = "directory" ]; then
origin_url=$(echo $i|sed s#$base_url#$compare_url#)
echo $origin_url >> $Temp_Path/A.dir.txt
else
echo "[ERROR] Unknow file type!"
rm -rf $Temp_Path
exit 1
fi
done
if [ -f "$Temp_Path/D.dir.txt" ];then
cat $Temp_Path/D.dir.txt|while read i
do
grep $i $Temp_Path/final_list.txt &> /dev/null
if [ $? != 0 ];then
svn ls --recursive $i|grep -v '.*/$'|sed "s#^#${i}\/#"|egrep -v "\/\." >> $Temp_Path/final_list.txt
fi
done
fi
if [ -f "$Temp_Path/A.dir.txt" ];then
cat $Temp_Path/A.dir.txt|while read i
do
grep $i $Temp_Path/final_list.txt &> /dev/null
if [ $? != 0 ];then
trunk_url=$(echo $i|sed s#$compare_url#$base_url#)
svn ls --recursive $trunk_url|grep -v '.*/$'|sed "s#^#${compare_url}\/#"|egrep -v "\/\." >> $Temp_Path/final_list.txt
fi
done
fi
[ $? = 0 ] && echo "[INFO] Done."; echo
}
archive() {
cat $Temp_Path/final_list.txt|egrep ".*\.java" > $Temp_Path/Java_File_List.txt
cat $Temp_Path/final_list.txt|egrep -v ".*\.java" > $Temp_Path/Other_File_List.txt
#Java_File_List.txt process
Project_List=$(cat $Temp_Path/Java_File_List.txt|grep /src/|sed 's#/src.*##'|sort|uniq -c|grep -v pom.xml|awk '{ print $2 }')
for i in $Project_List
do
BaseName=$(basename $i)
cd $Temp_Path
echo "[INFO] Checkout $i"
svn checkout $i &> /dev/null
if [ $? != 0 ];then
echo "[ERROR] Checkout $BaseName failed"
rm -rf $Temp_Path
exit 1
fi
cd $BaseName
if [ ! -f $build_file ];then
echo "[ERROR] Please input exact ant build filename(s), $build_file does not exist"
rm -rf $Temp_Path
exit 1
fi
build_file_list=$(echo $build_files|tr ',' ' ')
for build_file in $build_file_list
do
if [ ! -f $build_file ];then
echo "[ERROR] $build_file does not exist"
rm -rf $Temp_Path
exit 1
fi
echo "[INFO] Build file: $build_file"
echo "[INFO] Building..."
ant -buildfile $build_file &> /dev/null
if [ $? != 0 ];then
echo "[ERROR] Compile failed"
rm -rf $Temp_Path
exit 1
else
echo "[INFO] Done."; echo
fi
done
done
cd $Temp_Path
java_file_list=$(cat Java_File_List.txt)
for i in $java_file_list;
do
Class_File=$(basename $i|sed 's/java/class/')
find -type f -name $Class_File|xargs -i cp {} $Temp_Path/class_tar
done
#Other_File_List.txt process
cd $Temp_Path/class_tar
cat $Temp_Path/Other_File_List.txt|while read i
do
echo "[INFO] wget $i --user=liuchenwei --password=liuchenwei"
wget $i --user=liuchenwei --password=liuchenwei &>/dev/null
if [ $? != 0 ];then
echo "[ERROR] $i cannot download from svn server"
rm -rf $Temp_Path
exit 1
elif [ -f $(basename $i) ];then
echo "[INFO] Done."
echo
fi
done
#Archive
echo "[INFO] Last step: archive"
cd $Temp_Path/class_tar
FILES=$(ls)
tar czf class.tar.gz $FILES --remove-files
if [ ! -d ~/Deliverable/class_tar ];then
mkdir -p ~/Deliverable/class_tar
else
rm -rf ~/Deliverable/class_tar/*
fi
mv class.tar.gz ~/Deliverable/class_tar
if [ $? = 0 ];then
echo "[INFO] Done."
echo "[INFO] Target path: /home/ci/Deliverable/class_tar/class.tar.gz"
fi
}
clean() {
cd; rm -rf $Temp_Path
}
main() {
get_diff_txt
archive
clean
}
main