forked from linagora/linshare-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_distrib.sh
More file actions
executable file
·224 lines (186 loc) · 5.24 KB
/
build_distrib.sh
File metadata and controls
executable file
·224 lines (186 loc) · 5.24 KB
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
#!/bin/bash
set -e
#set -x
#if [ $# -ne 1 ] ; then
# echo "ERROR: the first an unique argument is the linshare version number, ex 0.9.3"
# exit 1
#fi
############################################################
# GLOBAL VARIABLES
############################################################
# Argument : optional : build function name, ex: build_sso
g_main_function=$1
g_set_current_revision=0
#[ -z "${2}" ] && g_set_current_revision=1
g_branch_or_tag="$(git rev-parse --abbrev-ref HEAD)"
g_version=`grep -E "<version>(.*)</version>" pom.xml -o|head -n1|sed -r 's/<version>(.*)<\/version>/\1/g'`
g_logfile=linshare.build.$$.log
g_mvn_opts=""
g_mvn_opts="-Dmaven.test.skip"
g_output_dir="./target"
g_distribution_dir="./distrib"
g_ressources="./src/main/resources"
g_revision=""
############################################################
# FUNCTIONS
############################################################
function echo_linshare ()
{
local l_args=$@
echo "[INFO] ${l_args}"
echo "[BUILD-LINSHARE-SCRIPT][INFO] ${l_args}" >> $g_logfile
}
function maven ()
{
echo "> mvn $@ ${g_mvn_opts}"
mvn $@ ${g_mvn_opts} >> $g_logfile
}
function maven_clean ()
{
echo_linshare "Cleaning maven compiled files..."
echo "> mvn clean"
mvn clean >> $g_logfile
}
function distribute_jar ()
{
local l_version=${g_version}
local l_extension="jar"
local l_root_name="linshare-${l_version}"
local l_ouput_name="linshare-${l_version}"
mv ${g_output_dir}/${l_root_name}.${l_extension} ${g_distribution_dir}/${l_ouput_name}.${l_extension}
echo_linshare "Done."
}
function distribute_war ()
{
local l_suffix=$1
local l_version=${g_version}
local l_extension="war"
local l_root_name="linshare"
local l_ouput_name="linshare-${l_version}"
if [ ${g_set_current_revision} -eq 1 ] ; then
if [ ! -z "${g_revision}" ] ; then
l_ouput_name="${l_ouput_name}-r${g_revision}"
fi
fi
if [ "${l_suffix}" != "" ] ; then
l_ouput_name="${l_ouput_name}${l_suffix}"
fi
mv ${g_output_dir}/${l_root_name}.${l_extension} ${g_distribution_dir}/${l_ouput_name}.${l_extension}
echo_linshare "Done."
}
function init_context ()
{
g_revision=$(git log -n 1 |grep ^commit| cut -d' ' -f2)
g_version=`grep -E "<version>(.*)</version>" pom.xml -o|head -n1|sed -r 's/<version>(.*)<\/version>/\1/g'`
### Initialisation du workspace.
echo_linshare "Log file : ${g_logfile}"
echo_linshare "Current revision : ${g_revision}"
echo_linshare "Pom version ${g_version}"
echo_linshare "Building LinShare ${g_version} distribution"
echo_linshare "Creating distrib dir..."
#cd $(dirname $0)
rm -rf ${g_distribution_dir}/
mkdir -p ${g_distribution_dir}
}
function end_context ()
{
# Clean du workspace.
maven_clean
echo_linshare "END."
}
function build_installer ()
{
# Creation de la version avec installeur.
maven_clean
echo_linshare "Building jar installer..."
maven package -Dtarget=distribution
distribute_jar
}
function build_classic ()
{
# Creation de la version sans SSO
maven_clean
echo_linshare "Building war without SSO..."
maven package
distribute_war "-without-SSO"
}
function build_cas ()
{
# Creation de la version avec CAS
maven_clean
echo_linshare "Building war for CAS..."
mv ${g_ressources}/{,DISABLED}springContext-security.xml
mv ${g_ressources}/{DISABLED,}springContext-securityCAS.xml
maven package
distribute_war "-CAS"
mv ${g_ressources}/{DISABLED,}springContext-security.xml
mv ${g_ressources}/{,DISABLED}springContext-securityCAS.xml
}
function build_sso ()
{
# Creation de la version avec SSO
maven_clean
echo_linshare "Building war for HTTP-Header based SSO..."
mv ${g_ressources}/{,DISABLED}springContext-security.xml
mv ${g_ressources}/{DISABLED,}springContext-securityLLNG.xml
maven package
distribute_war "-SSO"
mv ${g_ressources}/{DISABLED,}springContext-security.xml
mv ${g_ressources}/{,DISABLED}springContext-securityLLNG.xml
}
function build_source ()
{
local linshare_soure=linshare-src
local linshare_archive=linshare-${g_version}-src.tar
echo_linshare "Archive creation in progress : ${linshare_archive}"
git archive --format=tar ${g_branch_or_tag} -o ${g_distribution_dir}/${linshare_archive}
bzip2 ${g_distribution_dir}/${linshare_archive}
echo_linshare "Done."
}
function test_linshare ()
{
# Creation de la version avec SSO
maven_clean
echo_linshare "Testing LinShare"
echo "> mvn test"
mvn test >> $g_logfile
}
usage()
{
echo
echo "Usage : $g_main_function is not a valid function : possible choices are : classic , installer , cas , sso , source, all"
echo " command target"
exit 0
}
############################################################
# MAIN
############################################################
if [ -z "$g_main_function" ] ; then
usage
fi
if [ "${g_main_function}" == "all" ] ; then
# Initialisation du workspace.
init_context
# Testing LinShare
test_linshare
# Creation de la version avec installeur.
build_installer
# Creation de la version sans SSO
build_classic
# Creation de la version avec CAS
#build_cas
# Creation de la version avec SSO
build_sso
# Creation de l'archive des sources
build_source
else
if [ `declare -F "build_${g_main_function}"|wc -l` -eq 1 ] ; then
# Initialisation du workspace.
init_context
"build_${g_main_function}"
else
usage
fi
fi
# Clean du workspace.
end_context