-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_executable.sh
executable file
·69 lines (51 loc) · 1.74 KB
/
make_executable.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
#!/bin/bash
NC='\033[0m'
RED='\033[1;31m'
GREEN='\033[1;32m'
BLUE='\033[1;34m'
GRAY='\033[0;37m'
echo -ne "Building executable jar: "
# maven install to local repo
mvn clean install -q
# exit if mvn clean install failed
if [ $? -ne 0 ];
then
printf "${RED}Fail${NC}, exiting"
exit $?
fi
printf "${GREEN}Success${NC}\n"
# extract info to where the executable jar was installed
localRepository=$(mvn help:evaluate -Dexpression=settings.localRepository -q -DforceStdout)
printf "${GRAY}Found local maven repository: ${localRepository}${NC}\n"
groupId=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.groupId}' --non-recursive exec:exec 2>/dev/null)
printf "${GRAY}Found groupId: ${groupId}${NC}\n"
artifactId=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.artifactId}' --non-recursive exec:exec 2>/dev/null)
printf "${GRAY}Found artifactId: ${artifactId}${NC}\n"
version=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec 2>/dev/null)
printf "${GRAY}Found version: ${version}${NC}\n"
# location of the jar
jar="$localRepository"
# add group id as path
IFS='.' read -r -a array <<< "$groupId"
for element in "${array[@]}"
do
jar+="/$element"
done
# add artifact id, version and jar name
jar+="/$artifactId/$version/$artifactId-$version-jar-with-dependencies.jar"
echo -ne "Building executable script: "
# create executable which runs "java -jar $jar" with the appropriate parameters
cat <<EOF >git-analyzer
#!/bin/bash
java -jar $jar \$@
EOF
# exit if cat failed
if [ $? -ne 0 ];
then
printf "${RED}Fail${NC}, exiting"
exit $?
fi
printf "${GREEN}Success${NC}\n"
# make the executable actually executable
chmod +x git-analyzer
printf "Created executable, with jar at: ${BLUE}${jar}${NC}\n"