halcyon / asdf-java

A Java plugin for asdf-vm.
MIT License
454 stars 86 forks source link

Set java home reports file name too long (zsh) and does not set java home #139

Closed BFMeenink closed 2 years ago

BFMeenink commented 3 years ago

Description

Using asdf-java, with version adoptopenjdk-8.0.282+8.openj9-0.24.0, in zsh. When I add . ~/.asdf/plugins/java/set-java-home.zsh to ~/.zshrc I get file name too long errors and java_home is not set.

Environment

echo $0 -> zsh echo $SHELL -> /bin/zsh asdf --version -> v0.8.0 asdf plugin list --urls --refs -> java https://github.com/halcyon/asdf-java.git master be57a70 cat ~/.asdfrc -> java_macos_integration_enable = yes

Steps taken

Expected

Actual

dirname: /Users/bremeeni/.asdf/installs/java/adoptopenjdk-8.0.282+8.openj9-0.24.0/bin
total 7512
drwxr-xr-x  44 bremeeni  staff   1.4K Apr 22  2020 ./
drwxr-xr-x  13 bremeeni  staff   416B Mar 22 13:23 ../
-rwxr-xr-x   1 bremeeni  staff    86K Apr 22  2020 appletviewer
...
-rwxr-xr-x   1 bremeeni  staff    86K Apr 22  2020 xjc
/Users/bremeeni/.asdf/installs/java/adoptopenjdk-8.0.282+8.openj9-0.24.0/bin: File name too long

is output; for each and every statement executed from then onwards.

Temporary fix/workaround

Am I missing something?

delgurth commented 3 years ago

Seeing your output it seems you changed the dirname command to a ls -al command.

What happens if you do:

/usr/bin/dirname /Users/bremeeni/.asdf/installs/java/adoptopenjdk-8.0.282+8.openj9-0.24.0/bin. For me that results in:

❯ /usr/bin/dirname /Users/bremeeni/.asdf/installs/java/adoptopenjdk-8.0.282+8.openj9-0.24.0/bin
/Users/bremeeni/.asdf/installs/java/adoptopenjdk-8.0.282+8.openj9-0.24.0

If this makes the output the same for you, you could replace the 2 dirnames in set-java-home.zsh to /usr/bin/dirname.

BFMeenink commented 2 years ago

Sorry for not replying for so long, I somehow did not get a notification and have solved the issue in the mean time.

In my .zshrc there's function chpwd () { pwd && ls -FGlahp }. I've solved the issue by using something very similar to what you suggested and the set-java-home in general:

function asdf_update_java_home {
  asdf current java 2>&1 > /dev/null
  if [[ "$?" -eq 0 ]]
  then
      export JAVA_HOME=$(asdf where java)
  fi
}

autoload -U add-zsh-hook
add-zsh-hook precmd asdf_update_java_home