-
Notifications
You must be signed in to change notification settings - Fork 53
/
create_stroom_module.sh
executable file
·173 lines (134 loc) · 4.23 KB
/
create_stroom_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
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
#!/bin/bash
##################################################################
# Script to create one or more sub-module directory structures #
##################################################################
set -e
setup_echo_colours() {
# Exit the script on any error
set -e
# shellcheck disable=SC2034
if [ "${MONOCHROME}" = true ]; then
RED=''
GREEN=''
YELLOW=''
BLUE=''
BLUE2=''
DGREY=''
NC='' # No Colour
else
RED='\033[1;31m'
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
BLUE='\033[1;34m'
BLUE2='\033[1;34m'
DGREY='\e[90m'
NC='\033[0m' # No Colour
fi
}
error() {
echo "${RED}ERROR${NC}: $*" >&2
echo
}
error_exit() {
error "$@"
exit 1
}
determine_repo_root() {
if ! git rev-parse --show-toplevel > /dev/null 2>&1; then
error_exit "You are not in a git repository."
fi
repo_root_dir="$(git rev-parse --show-toplevel)"
}
add_logback_test_config() {
local logback_config_file="${sub_module_dir}/src/test/resources/logback-test.xml"
if [ ! -f "${logback_config_file}" ]; then
echo -e " Creating logback test config ${logback_config_file}"
# No indenting to support heredoc
cat << EOF > "${logback_config_file}"
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="stroom" level="debug" />
<root level="error">
<appender-ref ref="STDOUT" />
</root>
</configuration>
EOF
fi
}
add_gradle_settings_entry() {
local settings_line="include '${module_name}:${sub_module_name}'"
local settings_file="${repo_root_dir}/settings.gradle"
echo -e " Checking for presence of \"${settings_line}\" in ${settings_file}"
#grep -F "${settings_line}" "${settings_file}"
if grep -qF "${settings_line}" "${settings_file}"; then
echo -e " Already exists"
else
echo -e " Adding \"${settings_line}\" to the end of ${settings_file}"
echo "${settings_line}" >> "${settings_file}"
fi
}
main() {
setup_echo_colours
if [ "$#" -lt 2 ]; then
echo -e "${RED}Error${NC}: Invalid arguments"
echo -e "Usage: ${BLUE}create_stroom_module.sh module_name suffix1 [suffix2 ... suffixN]${NC}"
echo -e "e.g: ${BLUE}create_stroom_module.sh stroom-processor api impl impl-db${NC}"
exit 1
fi
local module_name="$1"; shift
# All remaining args are the required suffixes
local suffixes=( "$@" )
# replace all - with .
local repo_root_dir=""
determine_repo_root
local module_dir="${repo_root_dir}/${module_name}"
mkdir -p "${module_dir}"
for suffix in "${suffixes[@]}"; do
local sub_module_name="${module_name}-${suffix}"
local sub_module_dir="${module_dir}/${sub_module_name}"
if [ -d "${sub_module_dir}" ]; then
echo -e "Sub-module ${sub_module_name} already exists"
fi
echo
echo -e "Building sub-module ${sub_module_name}"
echo -e " Creating directories"
#shellcheck disable=SC2086
mkdir -p ${sub_module_dir}/src/{main,test}/{java,resources}
echo -e " Creating .gitkeep files"
#shellcheck disable=SC2086
touch ${sub_module_dir}/src/{main,test}/{java,resources}/.gitkeep
local readme_file="${module_dir}/README.md"
if [ ! -f "${readme_file}" ] ;then
echo -e " Creating module README"
echo -e "# ${module_name}" > "${readme_file}"
else
echo -e " README file already exists"
fi
# Replace - with .
local gradle_module_name="${sub_module_name//-/.}"
local gradle_build_file="${sub_module_dir}/build.gradle"
if [ ! -f "${gradle_build_file}" ]; then
echo -e " Creating gradle build file ${gradle_build_file} for module ${gradle_module_name}"
{
echo -e "ext.moduleName = '${gradle_module_name}'"
echo -e ""
echo -e "dependencies {"
echo -e ""
echo -e "}"
} > "${gradle_build_file}"
else
echo " Gradle build file ${gradle_build_file} already exists"
fi
add_gradle_settings_entry
add_logback_test_config
done
echo -e
echo -e "Done"
}
main "$@"