-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathaddTestResource.sh
101 lines (78 loc) · 3.01 KB
/
addTestResource.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
#!/bin/bash
####################################################
# Shell to apply after project generation.
# Distribute additional test files.
#
# The parameters of this script are as follows.
# $1:Generated blank project path
####################################################
set -e
cd `dirname $0`
WORK_DIR=$1
PROJECT_NAME=$(basename "${WORK_DIR}")
echo ">>>>> ARGS CHECK"
if [ ! -n "${WORK_DIR}" ]; then
echo "[Error] Destination directory not specified."
exit -100
fi
if [ ! -d "${WORK_DIR}" ]; then
echo "[Error] Destination directory does not exist."
exit -101
fi
if [ ! -d "${WORK_DIR}/src" ]; then
echo "[Error] It's not a single-project configuration."
exit -102
fi
if [ -e "${WORK_DIR}/src/main/resources/META-INF/spring/applicationContext.xml" ]; then
CONFIG_TYPE="XMLConfig"
else
CONFIG_TYPE="JavaConfig"
fi
if [ -e "${WORK_DIR}/src/main/webapp/WEB-INF/views/welcome/home.jsp" ]; then
VIEW_TYPE="JSP"
else
VIEW_TYPE="Thymeleaf"
fi
APP_PATH=$(find "${WORK_DIR}" -name HelloController.java)
PACKAGE_DIR=$(dirname "$APP_PATH")
PACKAGE_DIR=${PACKAGE_DIR#*/java/}
PACKAGE_DIR=${PACKAGE_DIR%/app/*}
PACKAGE_NAME=${PACKAGE_DIR//\//.}
echo "#####<Parameter>#####"
echo "WORK_DIR=${WORK_DIR}"
echo "CONFIG_TYPE=${CONFIG_TYPE}"
echo "VIEW_TYPE=${VIEW_TYPE}"
echo "PROJECT_NAME=${PROJECT_NAME}"
echo "PACKAGE_NAME=${PACKAGE_NAME}"
echo "#####################"
echo ">>>>> CREATE TMP"
rm -fr ./tmp
mkdir -p ./tmp/${PROJECT_NAME}
echo ">>>>> COPY PARTS"
cp -fr ./parts/base/projectName-*/src ./tmp/${PROJECT_NAME}
cp -fr ./parts/${CONFIG_TYPE}/projectName-*/src ./tmp/${PROJECT_NAME}
cp -fr ./parts/${VIEW_TYPE}/projectName-*/src ./tmp/${PROJECT_NAME}
echo ">>>>> CHANGE PACKAGE"
mkdir -p ./tmp/${PROJECT_NAME}/src/main/java/${PACKAGE_DIR}
mkdir -p ./tmp/${PROJECT_NAME}/src/test/java/${PACKAGE_DIR}
mv ./tmp/${PROJECT_NAME}/src/main/java/xxxxxx/yyyyyy/zzzzzz/* ./tmp/${PROJECT_NAME}/src/main/java/${PACKAGE_DIR}/
mv ./tmp/${PROJECT_NAME}/src/test/java/xxxxxx/yyyyyy/zzzzzz/* ./tmp/${PROJECT_NAME}/src/test/java/${PACKAGE_DIR}/
rm -fr ./tmp/${PROJECT_NAME}/src/*/java/xxxxxx
find ./tmp/${PROJECT_NAME} -type f | xargs sed -i -e "s/xxxxxx\.yyyyyy\.zzzzzz/${PACKAGE_NAME}/g"
echo ">>>>> RENAME PROJECT NAME"
find ./tmp/${PROJECT_NAME} -type f | xargs sed -i -e "s/projectName-web/${PROJECT_NAME}/g"
echo ">>>>> ADD DEPENDENCIES"
cp -f ${WORK_DIR}/pom.xml ./tmp/${PROJECT_NAME}
LF=$(printf '\\\012_')
LF=${LF%_}
DEPENDENCIES_TAG="<dependency>${LF}"
DEPENDENCIES_TAG="${DEPENDENCIES_TAG} <groupId>org.springframework.security<\/groupId>${LF}"
DEPENDENCIES_TAG="${DEPENDENCIES_TAG} <artifactId>spring-security-test<\/artifactId>${LF}"
DEPENDENCIES_TAG="${DEPENDENCIES_TAG} <scope>test<\/scope>${LF}"
DEPENDENCIES_TAG="${DEPENDENCIES_TAG} <\/dependency>${LF}"
DEPENDENCIES_TAG="${DEPENDENCIES_TAG} <!-- == End Unit Test == -->"
sed -i -e "s/<!-- == End Unit Test == -->/${DEPENDENCIES_TAG}/" ./tmp/${PROJECT_NAME}/pom.xml
echo ">>>>> COPY TMP"
cp -fr ./tmp/${PROJECT_NAME}/* ${WORK_DIR}
echo ">>>>> END"
exit 0