-
Notifications
You must be signed in to change notification settings - Fork 0
/
changeVersion
executable file
·86 lines (75 loc) · 2.01 KB
/
changeVersion
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
#!/bin/sh
# Copyright (C) 2011 GeoSolutions - http://geo-solutions.it
#
# Author: Carlo Cancellieri
#
#This library is free software; you can redistribute it and/or
#modify it under the terms of the GNU Lesser General Public
#License as published by the Free Software Foundation; either
#version 2.1 of the License, or (at your option) any later version.
#
#This library is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#Lesser General Public License for more details.
#
#You should have received a copy of the GNU Lesser General Public
#License along with this library; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
usage(){
echo "USAGE: $0 {-n|-b|-c} <BASE_DIR> <NEW_VERSION> \n\
\t -n dry run\n\
\t -b run (perform backup)\n\
\t -c run (no backup)\n\
RETURN:\n\
\t0 if success\n\
\t1 if fails"
}
if [ $# -lt 3 ]; then
echo "No arguments!"
usage;
exit 1;
fi
if [ -d $2 ]; then
BASE_DIR=$2;
else
echo "2nd argument is wrong (shoould be an existing dir): $3"
usage;
exit 1;
fi
NEW_VERSION=$3;
XML_COMMAND=xmlstarlet
XML_COMMAND_ARGS="ed -N x=http://maven.apache.org/POM/4.0.0 \
-u \"/x:project/x:version | /x:project/x:parent/x:version\" \
-v \"$NEW_VERSION\"";
if [ $1 = "-n" ]; then
for pom in `find $BASE_DIR -name pom.xml`; do
echo $XML_COMMAND_ARGS $pom|xargs $XML_COMMAND;
if [ $? -ne 0 ]; then
exit 1;
fi
done
elif [ $1 = "-b" ]; then
for pom in `find $BASE_DIR -name pom.xml`; do
cp -fp $pom $pom".old";
echo $XML_COMMAND_ARGS $pom".old"|xargs $XML_COMMAND > $pom;
if [ $? -ne 0 ]; then
exit 1;
fi
done
elif [ $1 = "-c" ]; then
for pom in `find $BASE_DIR -name pom.xml`; do
cp -fp $pom $pom".old";
echo $XML_COMMAND_ARGS $pom".old"|xargs $XML_COMMAND > $pom;
if [ $? -ne 0 ]; then
exit 1;
fi
rm $pom".old";
done
else
echo "1st argument is wrong: $1"
usage
exit 1;
fi
return 0;