Skip to content

Commit

Permalink
Do not hardcode min and max versions
Browse files Browse the repository at this point in the history
Instead of increasing the range more and more, look for minimum and
maximum version of all installed Java versions.
  • Loading branch information
michaellass committed Jan 3, 2025
1 parent c234411 commit 87c1442
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions archlinux-java-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@
# This script uses `exec` on purpose to launch a suitable JRE before the end of
# the script.
# shellcheck disable=SC2093

# Default boundaries for Java versions
min=6
max=30

VERSION=10
JAVADIR=###JAVADIR###

Expand Down Expand Up @@ -117,6 +112,27 @@ function normalize_name {
fi
}

available=$(archlinux-java status | tail -n+2 | cut -d' ' -f3 | sort -rV -t- -k2 | xargs)
default=$(archlinux-java get)

if [ -z "$default" ]; then
echo_stderr "Your Java installation is not set up correctly. Try archlinux-java fix."
exit 1
fi

# Default boundaries for Java versions
min=-1
max=-1
for ver in $available; do
major=$(normalize_name "$ver" | cut -d- -f2)
if [ "$major" -gt "$max" ]; then
max="$major"
fi
if [ "$major" -lt "$min" ] || [ "$min" -eq -1 ]; then
min="$major"
fi
done

function generate_candiates {
local list
local pref_package
Expand Down Expand Up @@ -307,14 +323,6 @@ while :; do
shift
done

available=$(archlinux-java status | tail -n+2 | cut -d' ' -f3 | sort -rV -t- -k2 | xargs)
default=$(archlinux-java get)

if [ -z "$default" ]; then
echo_stderr "Your Java installation is not set up correctly. Try archlinux-java fix."
exit 1
fi

candidates=$(generate_candiates)

for ver in $candidates; do
Expand Down

0 comments on commit 87c1442

Please sign in to comment.