-
Notifications
You must be signed in to change notification settings - Fork 0
/
maverick.sh
78 lines (69 loc) · 1.6 KB
/
maverick.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
#!/bin/bash
UPL=$(tput cuu1)
EL=$(tput el)
overwrite_line() { echo -e "$UPL$EL$@"; }
compile() {
echo "[1/2] compile to xml"
file=$(cat $PWD/pom.pug)
text="mixin dependency(group, artifact, version)
dependency
groupId= group
artifactId= artifact
version= version
doctype xml
$file"
echo "$text" | pug -Ps >pom.xml
}
start_maven() {
status="\033[0m[2/2] run maven"
echo -e "$status"
while read -r line; do
if [[ $line == *"ERROR"* ]]; then
echo -e "$status |\t\033[0;31m$line\r"
elif [[ $line == *"SUCCESS"* ]]; then
echo -e "$status |\t\033[0;32m$line\n"
elif [[ $line == *"Total time"* ]]; then
echo -e "$status |\t\033[0m$line\r"
elif [[ $line == *"Finished at"* ]]; then
echo -e "$status |\t\033[0m$line\n"
else
overwrite_line "$status |\t$line"
fi
done < <(mvn -f $PWD/pom.xml clean install)
}
check_requirements() {
if ! hash pug &>/dev/null; then
echo "please install pug first.."
exit 1
fi
if ! hash mvn &>/dev/null; then
echo "please install maven first.."
exit 1
fi
}
check_requirements
if [[ $1 == "init" ]]; then
if [[ ! -e "$PWD/pom.pug" ]]; then
content="project
modelVersion 4.0.0
groupId com.example
artifactId test
version 0.0.1-SNAPSHOT"
echo "$content" >$PWD/pom.pug
else
echo "pom already exists.."
fi
exit 1
fi
if [[ -e "$PWD/pom.pug" ]]; then
compile
overwrite_line "[1/2] compile to xml\t[ done ]"
else
echo "no pom.pug to compile..."
fi
if [[ -e "$PWD/pom.xml" ]]; then
start_maven
echo -e "[2/2] run maven\t\t[ done ]"
else
echo "need a pom.xml to run maven..."
fi