Skip to content

Commit

Permalink
refactor: reanme java_build_utils.sh -> lib/maven_utils.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
oldratlee committed Jul 18, 2023
1 parent 563a7ad commit d53f561
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 32 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- [🗂 Lib](#%F0%9F%97%82-lib)
- [`trap_error_info.sh`](#trap_error_infosh)
- [`common_utils.sh`](#common_utilssh)
- [`java_build_utils.sh`](#java_build_utilssh)
- [`maven_utils.sh`](#java_build_utilssh)
- [`prepare_jdks.sh`](#prepare_jdkssh)
- [⚒️ Tool](#-tool)
- [`gen_source_guard`](#gen_source_guard)
Expand Down Expand Up @@ -76,14 +76,14 @@ api functions:
- `jvu::switch_to_jdk`
- `jvu::java_cmd`

## [`java_build_utils.sh`](lib/java_build_utils.sh)
## [`maven_utils.sh`](lib/maven_utils.sh)

maven util functions for build.

api functions:

- maven operation functions:
- `jvb::mvn_cmd`
- `mvu::mvn_cmd`

## [`prepare_jdks.sh`](lib/prepare_jdks.sh)

Expand Down
52 changes: 24 additions & 28 deletions lib/java_build_utils.sh → lib/maven_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
################################################################################
# api functions:
#
# - java operation functions:
# - jvb::get_java_version
# - jvb::java_cmd
# - maven operation functions:
# - jvb::mvn_cmd
# - mvu::mvn_cmd
################################################################################
#
#_ source guard begin _#
Expand All @@ -27,22 +23,22 @@ source "$__source_guard_364DF1B5_9CA2_44D3_9C62_CDF6C2ECB24F/common_utils.sh"
# maven operation functions
#################################################################################

readonly JVB_DEFAULT_MVN_OPTS=(
readonly MVU_DEFAULT_MVN_OPTS=(
-V --no-transfer-progress
)

jvb::_find_mvn_cmd_path() {
if [ -n "${_JVB_MVN_PATH:-}" ]; then
echo "$_JVB_MVN_PATH"
mvu::_find_mvn_cmd_path() {
if [ -n "${_MVU_MVN_PATH:-}" ]; then
echo "$_MVU_MVN_PATH"
return
fi

local -r maven_wrapper_name="mvnw"

# 1. find the mvnw from project root dir
if [[ -n "${PROJECT_ROOT_DIR:-}" && -e "$PROJECT_ROOT_DIR/$maven_wrapper_name" ]]; then
_JVB_MVN_PATH="$PROJECT_ROOT_DIR/$maven_wrapper_name"
echo "$_JVB_MVN_PATH"
_MVU_MVN_PATH="$PROJECT_ROOT_DIR/$maven_wrapper_name"
echo "$_MVU_MVN_PATH"
return
fi

Expand All @@ -51,8 +47,8 @@ jvb::_find_mvn_cmd_path() {
while true; do
local mvnw_path="$d/$maven_wrapper_name"
[ -x "$mvnw_path" ] && {
_JVB_MVN_PATH="$mvnw_path"
echo "$_JVB_MVN_PATH"
_MVU_MVN_PATH="$mvnw_path"
echo "$_MVU_MVN_PATH"
return
}

Expand All @@ -62,8 +58,8 @@ jvb::_find_mvn_cmd_path() {

# 3. find mvn from $PATH
if command -v mvn &>/dev/null; then
_JVB_MVN_PATH=mvn
echo "$_JVB_MVN_PATH"
_MVU_MVN_PATH=mvn
echo "$_MVU_MVN_PATH"
return
fi

Expand All @@ -76,41 +72,41 @@ jvb::_find_mvn_cmd_path() {
)"
}

jvb::mvn_cmd() {
mvu::mvn_cmd() {
(($# > 0)) || cu::die "${FUNCNAME[0]} requires arguments! But no provided"

# FIXME hard code logic for `DISABLE_GIT_DIRTY_CHECK`
cu::log_then_run "$(jvb::_find_mvn_cmd_path)" \
"${JVB_MVN_OPTS[@]}" \
cu::log_then_run "$(mvu::_find_mvn_cmd_path)" \
"${MVU_MVN_OPTS[@]}" \
${DISABLE_GIT_DIRTY_CHECK+-Dgit.dirty=false} \
"$@"
}

jvb::get_mvn_local_repository_dir() {
mvu::get_mvn_local_repository_dir() {
(($# == 0)) || cu::die "${FUNCNAME[0]} requires no arguments! But provided $#: $*"

if [ -z "${_JVB_MVN_LOCAL_REPOSITORY_DIR:-}" ]; then
echo "$_JVB_MVN_LOCAL_REPOSITORY_DIR"
if [ -z "${_MVU_MVN_LOCAL_REPOSITORY_DIR:-}" ]; then
echo "$_MVU_MVN_LOCAL_REPOSITORY_DIR"
fi

_JVB_MVN_LOCAL_REPOSITORY_DIR="$(
jvb::mvn_cmd --no-transfer-progress help:evaluate -Dexpression=settings.localRepository |
_MVU_MVN_LOCAL_REPOSITORY_DIR="$(
mvu::mvn_cmd --no-transfer-progress help:evaluate -Dexpression=settings.localRepository |
grep '^/'
)"

[ -n "${_JVB_MVN_LOCAL_REPOSITORY_DIR:-}" ] || cu::die "Fail to find maven local repository directory"
[ -n "${_MVU_MVN_LOCAL_REPOSITORY_DIR:-}" ] || cu::die "Fail to find maven local repository directory"
}

################################################################################
# auto run logic when source
################################################################################

jvb::__auto_run_when_source() {
mvu::__auto_run_when_source() {
# set VAR if absent

if [ -z "${JVB_MVN_OPTS[*]:-}" ]; then
JVB_MVN_OPTS=("${JVB_DEFAULT_MVN_OPTS[@]}")
if [ -z "${MVU_MVN_OPTS[*]:-}" ]; then
MVU_MVN_OPTS=("${MVU_DEFAULT_MVN_OPTS[@]}")
fi
}

jvb::__auto_run_when_source
mvu::__auto_run_when_source
2 changes: 1 addition & 1 deletion templates/integration_test.template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ readonly PREPARE_JDKS_INSTALL_BY_SDKMAN=(

source "$BASH_BUDDY_ROOT/lib/prepare_jdks.sh"

source "$BASH_BUDDY_ROOT/lib/java_build_utils.sh"
source "$BASH_BUDDY_ROOT/lib/maven_utils.sh"

################################################################################
# ci build logic
Expand Down

0 comments on commit d53f561

Please sign in to comment.