-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcar.sh
154 lines (133 loc) · 4.04 KB
/
car.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
#!/bin/bash
MVN="$(which mvn)"
export JAVA_HOME="$(java -XshowSettings:properties -version 2>&1 >/dev/null | egrep 'java.home' | sed -E 's/.* = //g')"
CMD=help
if [ -z "$MVN" ]; then
echo "[ERROR]: Maven is not installed."
exit 1
fi
if [ ! $# -eq 0 ]; then
CMD=$1
shift 1
fi
case $CMD in
help)
echo "Build and run simple JAVA project"
echo "Commands:"
echo " -> init - initialize project in current directory
-n <project_name> => name of the project (default is 'demo')
-a <artifact_id> => id of the artifact (default is 'demo')
-g <group_id> => id of the group (default is 'com.example')"
echo " -> build - cleans target and resolves dependencies"
echo " -> run - builds and runs project in current directory
-f <main_class> => marks the main class (default is 'com.example.demo.DemoApplication')
-a <args...> => command line args"
echo " -> test - builds and tests project in current directory
-f <test_class...> "
echo " -> help - outputs this text"
;;
init)
projName=demo
artifactId=demo
groupId=com.example
while [ ! -z $1 ]; do
case $1 in
-n)
shift 1
projName=$([ -z $1 ] && echo $projName || echo $1)
;;
-a)
shift 1
artifactId=$([ -z $1 ] && echo $artifactId || echo $1)
;;
-g)
shift 1
groupId=$([ -z $1 ] && echo $groupId || echo $1)
;;
*)
echo "Invalid args"
exit 1
;;
esac
shift 1
done
curl -qq https://start.spring.io/starter.zip \
-d type=maven-project \
-d language=java \
-d bootVersion=2.6.7 \
-d baseDir=$projName \
-d name=$projName \
-d artifactId=$artifactId \
-d groupId=$groupId \
-d description= \
-d packageName=$groupId.$artifactId \
-d packaging=jar \
-d javaVersion=11 \
-o "$artifactId.zip"
unzip -q "$artifactId.zip"
rm "$artifactId.zip"
echo "Project $artifactId created"
;;
run)
XLINT=$(which xmllint)
if [ -z $XLINT ]; then
echo "[ERROR]: Make sure that xmllint is installed"
exit 1
fi
if [ ! -f pom.xml ]; then
echo "[ERROR]: Make sure the project 'pom.xml' is present"
exit 1
fi
GRP=$(xmllint --xpath "/*[local-name()='project']/*[local-name()='groupId']/text()" pom.xml)
ARCT=$(xmllint --xpath "/*[local-name()='project']/*[local-name()='artifactId']/text()" pom.xml)
MAIN=DemoApplication
ARGS=
while [ ! -z $1 ]; do
case $1 in
-f)
shift 1
MAIN=$1
;;
-a)
shift 1
while [[ ! $1 =~ (^-|^$) ]]; do
ARGS+=" $1"
shift 1
done
;;
*)
echo "Invalid args"
exit 1
;;
esac
shift 1
done
MAINPATH="${GRP}.${ARCT}.${MAIN}"
"$MVN" exec:java -Dexec.mainClass="$MAINPATH" -Dexec.args="$ARGS"
;;
test)
TEST=
while [ ! -z $1 ]; do
case $1 in
-f)
shift 1
TEST=$1
;;
*)
echo "Invalid args"
exit 1
;;
esac
shift 1
done
"$MVN" test -Dtest="$TEST"
;;
build)
"$MVN" clean install -U
;;
*)
echo "Invalid command $1"
exit 2
;;
esac
exit 0