Skip to content

Commit d6d9d88

Browse files
committed
refactor - deduplicate code
1 parent 3e8fa1c commit d6d9d88

23 files changed

+16
-1422
lines changed

src/main/bash/sdkman-use.sh

+16-23
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,7 @@ function __sdk_use() {
4242
elif [[ ${count} -eq 1 ]]
4343
then
4444
version=$(basename $(ls -d "${SDKMAN_CANDIDATES_DIR}/${candidate}/${major_version}"*))
45-
if [[ $PATH =~ ${SDKMAN_CANDIDATES_DIR}/${candidate}/([^/]+) ]]; then
46-
local matched_version
47-
48-
if [[ "$zsh_shell" == "true" ]]; then
49-
matched_version=${match[1]}
50-
else
51-
matched_version=${BASH_REMATCH[1]}
52-
fi
53-
54-
export PATH=${PATH//${SDKMAN_CANDIDATES_DIR}\/${candidate}\/${matched_version}/${SDKMAN_CANDIDATES_DIR}\/${candidate}\/${version}}
55-
fi
45+
__sdkman_change_candidate_in_path "$candidate"
5646
__sdkman_echo_green "Using ${candidate} version ${version} in this shell."
5747
else
5848
echo ""
@@ -74,18 +64,7 @@ function __sdk_use() {
7464
# Just update the *_HOME and PATH for this shell.
7565
__sdkman_set_candidate_home "$candidate" "$version"
7666

77-
if [[ $PATH =~ ${SDKMAN_CANDIDATES_DIR}/${candidate}/([^/]+) ]]; then
78-
local matched_version
79-
80-
if [[ "$zsh_shell" == "true" ]]; then
81-
matched_version=${match[1]}
82-
else
83-
matched_version=${BASH_REMATCH[1]}
84-
fi
85-
86-
export PATH=${PATH//${SDKMAN_CANDIDATES_DIR}\/${candidate}\/${matched_version}/${SDKMAN_CANDIDATES_DIR}\/${candidate}\/${version}}
87-
fi
88-
67+
__sdkman_change_candidate_in_path "$candidate"
8968
if [[ ! (-L "${SDKMAN_CANDIDATES_DIR}/${candidate}/current" || -d "${SDKMAN_CANDIDATES_DIR}/${candidate}/current") ]]; then
9069
__sdkman_echo_green "Setting ${candidate} version ${version} as default."
9170
__sdkman_link_candidate_version "$candidate" "$version"
@@ -95,3 +74,17 @@ function __sdk_use() {
9574
__sdkman_echo_green "Using ${candidate} version ${version} in this shell."
9675
fi
9776
}
77+
78+
function __sdkman_change_candidate_in_path() {
79+
if [[ $PATH =~ ${SDKMAN_CANDIDATES_DIR}/${1}/([^/]+) ]]; then
80+
local matched_version
81+
82+
if [[ "$zsh_shell" == "true" ]]; then
83+
matched_version=${match[1]}
84+
else
85+
matched_version=${BASH_REMATCH[1]}
86+
fi
87+
88+
export PATH=${PATH//${SDKMAN_CANDIDATES_DIR}\/${candidate}\/${matched_version}/${SDKMAN_CANDIDATES_DIR}\/${candidate}\/${version}}
89+
fi
90+
}

src/test/resources/features/checksum_verification.feature

-82
This file was deleted.

src/test/resources/features/command_line_interop.feature

-24
This file was deleted.

src/test/resources/features/current_candidate.feature

-39
This file was deleted.

src/test/resources/features/default_version.feature

-35
This file was deleted.

src/test/resources/features/flush.feature

-33
This file was deleted.

src/test/resources/features/home.feature

-45
This file was deleted.

src/test/resources/features/hooks.feature

-25
This file was deleted.

0 commit comments

Comments
 (0)