-
Notifications
You must be signed in to change notification settings - Fork 0
/
maven.sh
153 lines (124 loc) · 4.19 KB
/
maven.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
#!/bin/bash
#Author: CaoZheng
#Date: 2017/05/25
Script_Path=$(dirname $0)
Temp_Path=/tmp/$(openssl rand -hex 5)
mkdir $Temp_Path
compare_url="$1"
base_url="$2"
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 "================="
echo "Unknow file type!"
echo "================="
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 "================="
echo "Unknow file type!"
echo "================="
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
echo "[INFO] Done."; echo
}
archive_jar() {
mkdir $Temp_Path/jar_war
Project_List=$(cat $Temp_Path/final_list.txt|grep /src/|sed 's#/src.*##'|sort|uniq -c|grep -v pom.xml|awk '{ print $2 }')
for i in $Project_List
do
local 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
echo "[INFO] Compile $BaseName"
cd $BaseName
mvn clean install -DskipTests &> /dev/null
if [ $? != 0 ];then
echo "[ERROR] Compile $(basename $i) failed"
rm -rf $Temp_Path
exit 1
else
echo "[INFO] Done."
fi
cd target
ls|egrep "*.jar|*.war"|xargs -i mv {} $Temp_Path/jar_war
echo
done
echo "[INFO] Last step: archive"
cd $Temp_Path/jar_war
local FILES=$(ls |egrep "*.jar|*.war")
tar czf jar_war.tar.gz $FILES --remove-files
if [ ! -d ~/Deliverable/jar_tar ];then
mkdir -p ~/Deliverable/jar_tar
else
rm -rf ~/Deliverable/jar_tar/*
fi
mv jar_war.tar.gz ~/Deliverable/jar_tar
if [ $? = 0 ];then
echo "[INFO] Done."
echo "[INFO] Target path: /home/ci/Deliverable/jar_tar/jar_war.tar.gz"
fi
}
clean() {
cd; rm -rf $Temp_Path
}
main() {
get_diff_txt
archive_jar
clean
}
main