forked from loye168/tddl5
-
Notifications
You must be signed in to change notification settings - Fork 1
/
saveVersion.sh
57 lines (52 loc) · 2.08 KB
/
saveVersion.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
#!/bin/sh
# This file is used to generate the package-info.java class that
# records the version, revision, branch, user, timestamp, and url
unset LANG
unset LC_CTYPE
unset LC_TIME
user=`whoami`
date=`date +'%F %T'`
current_path=`pwd`
bin_abs_path=$(readlink -f $(dirname $0))
project_path=$(readlink -f $(dirname $bin_abs_path))
echo "run saveVersion.sh script"
echo "cd to $bin_abs_path for workaround relative path"
cd $bin_abs_path
if [ -d .svn ]; then
revision=`svn info | sed -n -e 's/Last Changed Rev: \(.*\)/\1/p'`
url=`svn info node | sed -n -e 's/URL: \(.*\)/\1/p'`
# Get canonical branch (branches/X, tags/X, or trunk)
branch=`echo $url | sed -n -e 's,.*\(branches/.*\)$,\1,p' \
-e 's,.*\(tags/.*\)$,\1,p' \
-e 's,.*/trunk$,trunk,p'`
version=`echo $url | sed -n -e 's,.*branches/\(.*\)$,\1,p' \
-e 's,.*tags/\(.*\)$,\1,p' \
-e 's,.*/trunk$,trunk,p'`
elif [ -d .git ]; then
revision=`git log -1 --pretty=format:"%H"`
hostname=`hostname`
url=`git remote -v | grep origin | grep fetch | awk '{print $2}'`
version=`cat pom.xml | head -n 10 | grep -oP '<version>5\.\d+\.\d+(-SNAPSHOT)?' | cut -c 10-`
branch=`git branch --no-color | grep '*' | awk '{print $2}'`
else
revision="Unknown"
branch="Unknown"
version="Unknown"
url="file://$bin_abs_path"
fi
srcChecksum=`find ./ -maxdepth 1 -name '*.sh' | LC_ALL=C sort | xargs md5sum | md5sum | cut -d ' ' -f 1`
cat << EOF | \
sed -e "s/VERSION/$version/" -e "s/USER/$user/" -e "s/DATE/$date/" \
-e "s|URL|$url|" -e "s/REV/$revision/" \
-e "s|BRANCH|$branch|" -e "s/SRCCHECKSUM/$srcChecksum/" \
> tddl-common/src/main/java/com/taobao/tddl/common/utils/version/package-info.java
/*
* Generated by saveVersion.sh
*/
@VersionAnnotation(version="VERSION", revision="REV", branch="BRANCH",
user="USER", date="DATE", url="URL",
srcChecksum="SRCCHECKSUM")
package com.taobao.tddl.common.utils.version;
EOF
echo "cd to $current_path for continue"
cd $current_path