File tree Expand file tree Collapse file tree 1 file changed +14
-6
lines changed
Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments