Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add architecture to full version on M1 macs only #351

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

marquiswang
Copy link
Contributor

Right now, jenv doesn't differentiate between JDKs for different
architectures. For the vast majority of systems, this is not a problem,
since only one architecture is supported. However, on the new M1 Macs,
two architectures are supported: x86_64 and aarch64.

A user might want to be able to switch between two architectures of
JDKs. Current Jenv refuses to add the second JDK because it detects the
same version.

We need to use lipo -archs to detect the architecture of the JDK.

For M1 Macs only, append the architecture to the full version name. For
example:

$ bin/jenv add /Library/Java/JavaVirtualMachines/zulu-17.0.2-x86_64.jdk/Contents/Home/
zulu64-17.0.2-x86_64 added
17.0.2 added
17.0 added
17 added

$ bin/jenv add /Library/Java/JavaVirtualMachines/zulu-17.0.2-aarch64.jdk/Contents/Home/
zulu64-17.0.2-arm64 added
17.0.2 already present, skip installation
17.0 already present, skip installation
17 already present, skip installation

Marquis Wong added 2 commits May 26, 2022 13:13
Right now, jenv doesn't differentiate between JDKs for different
architectures, except for 32 bit vs 64 bit. For the vast majority of
systems, this is not a problem, since only one architecture is
supported. However, on the new M1 Macs, two 64 bit architectures are
supported: x86_64 and aarch64.

A user might want to be able to switch between two architectures of
JDKs. Current Jenv refuses to add the second JDK because it detects the
same version.

We can read the architecture by reading the `os.arch` system property.

This commit changes the jenv alias format from

  [provider][32|64]-[version]

to

  [provider]-[version]-[architecture]

For example, before, the full alias would be

  oracle64-17.0.2

and how it is

  oracle-17.0.2-x86_64

For M1 builds, it now shows

  orable-17.0.2-aarch64

This is a change to the alias format, so if you run `jenv add` with a
JDK that was already added to jenv, it will get re-added with the new
format.
This commit changes the behavior of `jenv add` and `jenv
global|local|shell [version]`

Previously, jenv add would add "short" aliases of the version. For
example, adding Zulu JDK 11.0.3 would add the following aliases:
* 11
* 11.0
* 11.0.3
* zulu64-11.0.3

This was very convenient in that it prevented you from needing to type
`jenv version zulu64-11.0.3` to change versions, but led to some
confusion among users. See issues jenv#345, jenv#326, jenv#300, jenv#268, etc.

It also made `jenv versions` very verbose if you had a lot of versions.

This commit addresses this by adding "smart" version detection when
running `jenv global|local|shell [version]`, allowing you to run:

$ jenv global 11      # Change to JDK 11
$ jenv global 11.0.2  # Change to JDK 11.0.2
$ jenv local zulu     # Change to Zulu JDK
$ jenv shell x86_64   # Change to x86_64 architecture

With all of these commands, `jenv` will attempt to avoid changing the
other properties. So if the current global version is a Temurin JDK 11,
and you run `jenv global 18`, it will change to a Temurin JDK 18
(assuming you have one installed). If instead you run `jenv global zulu`
it will change to a Zulu JDK 11.

With this change, `jenv add` no longer adds the short version aliases.

The old aliases still work, but users may want to remove those aliases
if they are no longer useful. The aliases take priority over the smart
behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant