forked from gdubw/gdub
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mw
executable file
·82 lines (70 loc) · 1.81 KB
/
mw
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
#!/usr/bin/env bash
# DEFAULTS may be overridden by calling environment.
MVN="${MVN:-mvn}"
MVNW="${MVNW:-mvnw}"
MVN_POMFILE="${MVN_POMFILE:-pom.xml}"
err() {
echo -e "${@}" >&2
}
lookup() {
local file="${1}"
local curr_path="${2}"
[[ -z "${curr_path}" ]] && curr_path="${PWD}"
# Search recursively upwards for file.
until [[ "${curr_path}" == "/" ]]; do
if [[ -e "${curr_path}/${file}" ]]; then
echo "${curr_path}/${file}"
break
else
curr_path=$(dirname "${curr_path}")
fi
done
}
select_mvn() {
local dir="${1}"
# Use project's mvnw if found.
local mvnw=$(lookup "${MVNW}" "${dir}")
if [[ -z "${mvnw}" ]]; then
err "No ${MVNW} set up for this project; consider setting one up:"
err "https://github.com/takari/takari-maven-plugin\n"
else
echo "${mvnw}"
return 0
fi
# Deal with a missing wrapper by defaulting to system mvn.
local mvn=$(which "${MVN}" 2>/dev/null)
if [[ -z ${mvn} ]]; then
err "'${MVN}' not installed or not available in your PATH:"
err "${PATH}"
else
echo "${mvn}"
return 0
fi
return 1
}
execute_mvn() {
local pom_xml=$(lookup "${MVN_POMFILE}")
local mvn=$(select_mvn "${working_dir}")
local build_args=( ${BUILD_ARG} "$@" )
if [[ -n "${pom_xml}" ]]; then
# We got a good build file, start mvnw there.
cd "$(dirname "${pom_xml}")"
else
err "Unable to find a mvn build file named ${MVN_POMFILE}."
fi
# Say what we are gonna do, then do it.
err "Using mvn at '${mvn}' to run POM '${pom_xml}':\n"
if [[ -n "build_args[@]" ]]; then
"${mvn}" "${build_args[@]}"
else
"${mvn}"
fi
}
# gw may be sourced from other scripts as a library to select / run mvn(w).
if [[ ${BASH_SOURCE[0]} != $0 ]]; then
export -f execute_mvn select_mvn lookup err
else
set -e
execute_mvn "$@"
exit $?
fi