FelixSelter / JEnv-for-Windows

Change your current Java version with one line
Apache License 2.0
676 stars 87 forks source link

Option to download and install java versions #35

Open rcsilva83 opened 2 years ago

rcsilva83 commented 2 years ago

Would be super convenient if jenv could not only switch Java versions, but also had the ability to go ahead and install the configured version. It's also desirable the ability do configure a "dist URL" to be able to download from a local mirror when the user is behind a corporate firewall.

FelixSelter commented 2 years ago

Im not sure if this should really be a jenv feature. If this feature would be implemented the only thing it would do is downloading the installer from the java website and running the exe. This would save the user 1 google query and 3 clicks. However by manipulating the jenv script or hosts.txt security vulnerabilities could be introduced easily. It might even trigger some anti virus applications when an application downloads code from the internet and executes it.

What I could imagine is that jenv automatically opens the website of the desired version.

But what do you think? You may still convince me of this feature

rcsilva83 commented 2 years ago

This is a feature provided by SDKman and it seems to work fine.

I think you can see the real benefit from this feature when you think on a scale of hundreds of developers on an organization. Better yet, if we had a .jenv file with the JDK version on the project, it would be possible to git clone and type some kind of jenv config command that would download and set the JDK for it.

FelixSelter commented 2 years ago

Yea I start liking the idea. This can easily be integrated with #36 See my comment on the linked pull request for further details.

The only question remaining is how to find out where the user installed the java version. May #32 can be implemented efficiently.

I also remember that you could pass a command line argument to the java installer to run silently in the background and install to a specific location. But I doubt it would be a good idea to take that much control from the user. What if he wants to but it at another drive?

Further investigation is needed

ebresie commented 2 years ago

Not sure if this helps, but Disco API may provide an interface with a catalog of available openjdk distributions.

FelixSelter commented 2 years ago

Wow thank you. That makes it a lot easier. Will need to see if they work with silent installation. But in theory I only have to call https://api.foojay.io/disco/v3.0/packages?version=<version>&operating_system=windows&directly_downloadable=true&archive_type=msi now

FelixSelter commented 2 years ago

To retrieve the architecture for disco api we could use the following:

$architecture = Get-CimInstance -ClassName Win32_Processor | Select-Object -ExpandProperty Architecture

$architecture can then be the following:

x86 (0) MIPS (1) Alpha (2) PowerPC (3) ARM (5) ia64 (6) x64 (9) ARM64 (12)

[System.Environment]::Is64BitOperatingSystem

FelixSelter commented 2 years ago

@rcsilva83 Would your distro url look something like this: `https://example.com/%version%/download/installer.msi
If not could you provide an example?

dibog commented 1 year ago

Similiar tools like 'pyenv' and 'nvm' also list of available versions and do the actual download of the tools. It would be great if jenv could do the same.