-
Notifications
You must be signed in to change notification settings - Fork 305
/
build-module.sh
executable file
·77 lines (66 loc) · 2.41 KB
/
build-module.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
#!/bin/bash
# compile specify module and copy to specify directory
version=$(head -n10 pom.xml | awk -F'[<>]' '/<version>/ {print $3; exit}')
mvn_opts="-Dmaven.test.skip=true -Dmaven.javadoc.skip=true -Dmaven.source.skip=true --quiet"
# if build for remote host, then skip all path exists check
SKIP_CHECK=0
function build_base() {
cd $SRC_DIR
mvn package -B $mvn_opts -pl :addax-core,:addax-rdbms,:addax-storage,:addax-transformer -am || exit 1
rsync -a core/target/addax/* ${ADDAX_HOME}
rsync -azv lib/addax-{rdbms,storage,transformer}/target/addax/lib/* ${ADDAX_HOME}/lib/
}
if [ -z "$SRC_DIR" ]; then
SRC_DIR=$HOME/code/personal/Addax
fi
if [ -z "$ADDAX_HOME" ]; then
ADDAX_HOME=/opt/app/addax
fi
if [ -z $1 ]; then
echo "Usage: $0 module_name"
exit 1
fi
if [ -n "${REMOTE_HOST}" ]; then
echo "The building module will upload to ${REMOTE_HOST}"
ADDAX_HOME=${REMOTE_HOST}:${ADDAX_HOME}
SKIP_CHECK=1
fi
if [ $SKIP_CHECK -eq 0 ]; then
[ -d $ADDAX_HOME ] || mkdir -p $ADDAX_HOME || exit 1
[ -d $ADDAX_HOME/bin ] || build_base
fi
MODULE_NAME=$1
cd $SRC_DIR
mvn package -B $mvn_opts -pl :$MODULE_NAME -am || exit 1
if [ "$MODULE_NAME" == "addax-core" ]; then
scp core/target/${MODULE_NAME}-${version}.jar ${ADDAX_HOME}/lib
exit 0
fi
if [ "$MODULE_NAME" == "addax-common" ];then
scp common/target/${MODULE_NAME}-${version}.jar ${ADDAX_HOME}/lib
exit 0
fi
if [ "$MODULE_NAME" == "addax-rdbms" -o "$MODULE_NAME" == "addax-storage" -o "$MODULE_NAME" == "addax-transformer" ]; then
scp lib/${MODULE_NAME}/target/${MODULE_NAME}-${version}.jar ${ADDAX_HOME}/lib
exit 0
fi
# if the module nam ends with reader, then the module base directory is plugin/reader,
# else the directory is plugin/writer
if [[ $MODULE_NAME =~ .*"reader" ]]; then
MODULE_DIR=plugin/reader
elif [[ $MODULE_NAME =~ .*"writer" ]]; then
MODULE_DIR=plugin/writer
else
echo "module name must end with reader or writer"
exit 1
fi
if [ $SKIP_CHECK -eq 0 ]; then
[ -d $ADDAX_HOME/$MODULE_DIR ] || mkdir -p $ADDAX_HOME/$MODULE_DIR || exit 1
fi
if [ -n "$2" -a "$2" = "s" ]; then
rsync -avz $MODULE_DIR/$MODULE_NAME/target/${MODULE_NAME}-${version}/$MODULE_DIR/${MODULE_NAME}/${MODULE_NAME}-${version}.jar \
$ADDAX_HOME/$MODULE_DIR/${MODULE_NAME}
else
rsync -avz $MODULE_DIR/$MODULE_NAME/target/${MODULE_NAME}-${version}/$MODULE_DIR/${MODULE_NAME} \
$ADDAX_HOME/$MODULE_DIR/
fi