Last active
November 25, 2024 08:49
-
-
Save jedvardsson/5ec22c872a73edda55b248354fc8ca4c to your computer and use it in GitHub Desktop.
Convert output from MacOS /usr/libexec/java_home to json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -o errexit | |
set -o nounset | |
set -o pipefail | |
unset JAVA_VERSION | |
unset JAVA_ARCH | |
require_command() { | |
if ! type $1 1>/dev/null 2>&1; then | |
echo "Missing command: $1" >&2 | |
shift | |
for arg in "${@}"; do | |
echo "--> $arg" | |
done | |
return 1 | |
fi | |
} | |
require_command "jq" "https://jqlang.github.io/jq/" "brew install jq" | |
java_home --xml | | |
plutil -convert json - -o - | | |
jq 'map(. | {"name": .JVMName, "platform_version": .JVMPlatformVersion, "path" : .JVMHomePath, "bundle_id": .JVMBundleID, "version": .JVMVersion, "vendor" : .JVMVendor, "enabled": .JVMEnabled, "arch": .JVMArch})' |
Author
jedvardsson
commented
Nov 22, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment