Support for integrating with macOS /usr/libexec/java_home (#112)

Support for integrating with macOS /usr/libexec/java_home
This commit is contained in:
Fernando Crespo 2020-11-16 13:40:25 -03:00 committed by GitHub
parent 29527e0934
commit 825b63d076
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 2 deletions

View File

@ -47,3 +47,14 @@ For zsh shell, instead use:
For fish shell, instead use:
`. ~/.asdf/plugins/java/set-java-home.fish`
## macOS Integration
Some applications in macOS use `/usr/libexec/java_home` to set java home.
Setting java_macos_integration_enable to yes on `.asdfrc` file enables this integration.
```
java_macos_integration_enable = yes
```
_Note: Not all distributions of Java JDK packages offer this integration (eg. liberica). This option only works for packages that **do offer** that integration._

View File

@ -1,4 +1,6 @@
#!/usr/bin/env bash
# shellcheck source=/dev/null
source "$ASDF_DIR/lib/utils.bash"
CACHE_DIR="${TMPDIR:-/tmp}/asdf-java.cache"
if [ ! -d "${CACHE_DIR}" ]
@ -108,14 +110,57 @@ function install {
case ${OS} in
macosx)
case ${ASDF_INSTALL_VERSION} in
zulu*) mv ./* "${ASDF_INSTALL_PATH}" ;;
zulu*)
mv ./* "${ASDF_INSTALL_PATH}"
if [ "$(get_asdf_config_value "java_macos_integration_enable")" = "yes" ]; then
local macOS_integration_path
macOS_integration_path="$(dirname "$(dirname "$(dirname "$(realpath "${ASDF_INSTALL_PATH}/release")")")")"
java_macos_integration_install "$macOS_integration_path"
fi
;;
liberica*) mv ./* "${ASDF_INSTALL_PATH}" ;;
*) mv Contents/Home/* "${ASDF_INSTALL_PATH}" ;;
*)
mv Contents/Home/* "${ASDF_INSTALL_PATH}"
if [ "$(get_asdf_config_value "java_macos_integration_enable")" = "yes" ]; then
local macOS_integration_path
macOS_integration_path="$(realpath .)"
java_macos_integration_install "$macOS_integration_path"
fi
;;
esac ;;
*) mv ./* "${ASDF_INSTALL_PATH}" ;;
esac
}
function uninstall {
case ${OS} in
macosx)
if [ -z "${ASDF_INSTALL_VERSION}" ]; then
true
else
if [ "$(get_asdf_config_value "java_macos_integration_enable")" = "yes" ]; then
java_macos_integration_remove
fi
fi
esac
rm -rf "${ASDF_INSTALL_PATH}"
}
function java_macos_integration_remove {
printf "Removing the integration with /usr/libexec/java_home needs root permission to delete the folder at /Library/Java/JavaVirtualMachines/%s\n" "${ASDF_INSTALL_VERSION}"
sudo rm -rf "/Library/Java/JavaVirtualMachines/${ASDF_INSTALL_VERSION}"
}
function java_macos_integration_install {
local macOS_files_path
macOS_files_path="$1"
printf "Integrating with /usr/libexec/java_home needs root permission for it to create folders under /Library/Java/JavaVirtualMachines\n"
sudo mkdir -p "/Library/Java/JavaVirtualMachines/${ASDF_INSTALL_VERSION}/Contents"
sudo cp -R "${macOS_files_path}/Contents/MacOS" "/Library/Java/JavaVirtualMachines/${ASDF_INSTALL_VERSION}/Contents/"
sudo cp -R "${macOS_files_path}/Contents/Info.plist" "/Library/Java/JavaVirtualMachines/${ASDF_INSTALL_VERSION}/Contents/"
sudo ln -s "${ASDF_INSTALL_PATH}" "/Library/Java/JavaVirtualMachines/${ASDF_INSTALL_VERSION}/Contents/Home"
}
case "$(basename "${0}")" in
list-all) list-all
;;
@ -123,4 +168,5 @@ case "$(basename "${0}")" in
;;
install) install
;;
uninstall) uninstall ;;
esac

1
bin/uninstall Symbolic link
View File

@ -0,0 +1 @@
functions