Skip to content

Commit aef096d

Browse files
committed
reading /usr/libexec/java_home JVM list in XML format (--xml) instead of parsing the CLI output (-V) // fixes tofi86#91
this refactoring fixes issues with macOS 11.0 Big Sur
1 parent ed8c848 commit aef096d

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/universalJavaApplicationStub

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -567,14 +567,22 @@ if [ -z "${JAVACMD}" ] || [ ! -x "${JAVACMD}" ] ; then
567567

568568
# find installed JavaVirtualMachines (JDK + JRE)
569569
allJVMs=()
570-
# read JDK's from '/usr/libexec/java_home -V' command
571-
while read -r line; do
572-
version=$(echo $line | awk -F $',' '{print $1;}')
573-
path=$(echo $line | awk -F $'" ' '{print $2;}')
570+
571+
# read JDK's from '/usr/libexec/java_home --xml' command with PlistBuddy and a custom Dict iterator
572+
# idea: https://stackoverflow.com/a/14085460/1128689 and https://scriptingosx.com/2018/07/parsing-dscl-output-in-scripts/
573+
javaXml=$(/usr/libexec/java_home --xml)
574+
javaCounter=$(/usr/libexec/PlistBuddy -c "Print" /dev/stdin <<< $javaXml | grep "Dict" | wc -l | tr -d ' ')
575+
stub_logger "[JavaSearch] ... found $javaCounter JVM's"
576+
577+
# iterate over all Dict entries
578+
for idx in $(seq 0 $((javaCounter - 1)))
579+
do
580+
version=$(/usr/libexec/PlistBuddy -c "print :$idx:JVMVersion" /dev/stdin <<< $javaXml)
581+
path=$(/usr/libexec/PlistBuddy -c "print :$idx:JVMHomePath" /dev/stdin <<< $javaXml)
574582
path+="/bin/java"
575583
allJVMs+=("$version:$path")
576-
done < <(/usr/libexec/java_home -V 2>&1 | grep '^[[:space:]]')
577-
# unset while loop variables
584+
done
585+
# unset for loop variables
578586
unset version path
579587

580588
# add Apple JRE if available

0 commit comments

Comments
 (0)