-
Notifications
You must be signed in to change notification settings - Fork 4
/
preflightcheck.sh
212 lines (193 loc) · 4.75 KB
/
preflightcheck.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/bin/bash
# set source and test locations
src="src/main/kotlin/net/thauvin/erik/gradle/semver/"
test="src/main/kotlin/net/thauvin/erik/gradle/semver/"
# e.g: .java, .kt, etc.
ext=".kt"
java8=true
# e.g: <example directory> <gradle args...>
declare -a examples=(
"examples/java incrementBuildMeta run"
"examples/kotlin incrementBuildMeta run"
"examples/annotation-processor/java incrementMinor run"
"examples/annotation-processor/kotlin incrementMinor run")
# e.g: empty or javadoc, etc.
gradle_doc=""
# e.g. empty or sonarqube
gradle_sonar="sonarqube"
# gradle options for examples
gradle_opts="--console=plain --no-build-cache --no-daemon"
# maven arguments for examples
maven_args="compile exec:java"
#
# Version: 1.1.3
#
if [ "$java8" = true ]
then
export JAVA_HOME="$JAVA8_HOME"
export PATH="$(cygpath "$JAVA_HOME")/bin:$PATH"
fi
pwd=$PWD
red=$(tput setaf 1)
cyan=$(tput setaf 6)
std=$(tput sgr0)
date=$(date +%Y)
pause() {
read -p "Press [Enter] key to continue..."
}
checkCopyright() {
if [ "$(grep -c "$date" "$1")" -eq 0 ]
then
echo -e " Invalid: ${red}$f${std}"
else
echo -e " Checked: $1"
fi
}
runGradle() {
cd "$1" || exit 1
clear
reset
echo -e "> Project: ${cyan}${1}${std} [Gradle]"
shift
./gradlew $@ || exit 1
pause
cd "$pwd"
}
runKobalt() {
cd "$1" || exit 1
if [ -f kobalt/src/Build.kt ]
then
clear
reset
echo -e "> Project: ${cyan}${1}${std} [Kobalt]"
shift
./kobaltw $@ || exit 1
pause
fi
cd "$pwd"
}
runMaven() {
cd "$1" || exit 1
if [ -f pom.xml ]
then
clear
reset
echo -e "> Project: ${cyan}${1}${std} [Maven]"
shift
mvn $@ || exit 1
pause
fi
cd "$pwd"
}
updateWrappers() {
clear
./updatewrappers.sh
pause
}
checkDeps() {
clear
echo -e "${cyan}Checking depencencies...${std}"
gradle --console=plain dU || exit 1
read -p "Check Examples depencencies? [y/n] " cont
clear
case $cont in
[Nn] ) return ;;
* ) for ex in "${!examples[@]}"
do
runGradle $(echo "${examples[ex]}" | cut -d " " -f 1) dU
runKobalt $(echo "${examples[ex]}" | cut -d " " -f 1) checkVersions
runMaven $(echo "${examples[ex]}" | cut -d " " -f 1) versions:display-dependency-updates
if [ "$ex" -eq "${#examples}" ]
then
read -p "Continue? [y/n]: " cont
clear
case $cont in
* ) continue ;;
[Nn] ) return ;;
esac
fi
done ;;
esac
}
gradleCheck() {
clear
echo -e "${cyan}Checking Gradle build....${std}"
gradle $gradle_opts clean check $gradle_doc $gradle_sonar || exit 1
pause
}
runExamples() {
for ex in "${!examples[@]}"
do
runGradle ${examples[ex]} clean $gradle_opts
runKobalt ${examples[ex]} clean
runMaven $(echo "${examples[ex]}" | cut -d " " -f 1) clean $maven_args
done
}
examplesMenu() {
clear
echo -e "${cyan}Examples${std}"
for ex in "${!examples[@]}"
do
printf ' %d. %s\n' $(($ex + 1)) $(echo "${examples[ex]}" | cut -d " " -f 1)
done
echo " $((${#examples[@]} + 1)). Run All Examples"
read -p "Enter choice [1-${#examples[@]}]: " choice
clear
case $choice in
[0-9] ) if [ "$choice" -gt "${#examples[@]}" ]
then
runExamples
examplesMenu
else
runGradle ${examples[$(($choice - 1))]}
runKobalt ${examples[$(($choice - 1))]}
runMaven $(echo "${examples[$(($choice - 1))]}" | cut -d " " -f 1) $maven_args
examplesMenu
fi ;;
* ) return ;;
esac
}
validateCopyrights() {
clear
echo -e "${cyan}Validating copyrights...${std}"
for f in LICENSE.TXT ${src}/*${ext} ${test}/*${ext}
do
checkCopyright "$f"
done
pause
}
everything() {
updateWrappers
checkDeps
gradleCheck
runExamples
validateCopyrights
}
showMenu() {
clear
echo "${cyan}Preflight Check${std}"
echo " 1. Update Wrappers"
echo " 2. Check Dependencies"
echo " 3. Check Gradle Build"
echo " 4. Run Examples"
echo " 5. Validate Copyrights"
echo " 6. Check Everything"
}
readOptions() {
local choice
read -p "Enter choice [1-6]: " choice
case $choice in
1) updateWrappers ;;
2) checkDeps ;;
3) gradleCheck ;;
4) examplesMenu ;;
5) validateCopyrights ;;
6) everything ;;
*) exit 0 ;;
esac
}
while true
do
showMenu
readOptions
done