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

feat: linuxdistro jdk provider #1826

Merged
merged 4 commits into from
Sep 12, 2024

Conversation

maxandersen
Copy link
Collaborator

adds linuxdistro provider which for now searches /usr/lib/jvm for jdks.

It is not enabled by default as it is not possible to safely determine the version and build of the jdk
present or needed to be installed if mising.

Meaning to get it user need to run jbang config set jdkproviders all or jbang config set jdkproviders linuxdistro if only want this.

You can see which providers are finding jdks by running jbang jdk list --show-details

Fixes #1825

@quintesse I see that jbang jdk list --show-details list what looks like all dirs even though javac is not available. is that expected?

adds `linuxdistro` provider which for now searches `/usr/lib/jvm` for jdks.

It is not enabled by default as it is not possible to safely determine the version and build of the jdk
present or needed to be installed if mising.

Meaning to get it user need to select it `--jdk-provider=linuxdistro` or just enable all providers `--jdk-provider=all`
on command line or run `jbang config set jdk-provider linuxdistro` to make it default for all jbang invocations.
@quintesse
Copy link
Contributor

It is not enabled by default as it is not possible to safely determine the version and build of the jdk
present

Why not? Is there no RELEASE file in those JDKs?

or needed to be installed if mising.

Not sure what you mean by this?

is that expected?

It shows what the providers tell it to show. Providers shouldn't return anything without doing sanity checks.

@maxandersen
Copy link
Collaborator Author

Why not? Is there no RELEASE file in those JDKs?

I mean, once these are enabled we no longer have a consistent java version when using jbang by default.

Today its always, honor your configured path, otherwise fallback to .jbang managed or foojay fetched jdks.

if we enable the others like sdkman/linux alternatives you will get whatever order of providers are enabled and used on your system and when jbang perform installs it might not be the one selected next time you run - even in the same shell.

unless jbang managed ones trumph everything else I reckon.

@quintesse
Copy link
Contributor

I mean, once these are enabled we no longer have a consistent java version when using jbang by default.

Ah yes, indeed. Although I'd say that given what you mention next:

Today its always, honor your configured path, otherwise fallback to .jbang managed or foojay fetched jdks.

the fact that we first use what's on the path already means that we can never be sure what JDK we're running.

if we enable the others like sdkman/linux alternatives you will get whatever order of providers are enabled and used on your system and when jbang perform installs it might not be the one selected next time you run - even in the same shell.

unless jbang managed ones trumph everything else I reckon.

jbang managed ones do indeed have priority (after what's on your PATH that is, like mentioned above)

@quintesse
Copy link
Contributor

Btw, talking about native providers... you run MacOS, can't you make a provider for JDKs installed on Macs? :-)

@@ -121,6 +121,8 @@ default Jdk createJdk(@Nonnull String id, @Nullable Path home, @Nonnull String v

default String name() {
String nm = getClass().getSimpleName();
// TODO: this 11 is here assuming it ends in "JdkProvider" - dont make that
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not? It's a reasonable default implementation, isn't it? If your implementation doesn't follow that scheme you can simply override this method and return the value that you desire.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a name called LinxDistroProvider and it showed up as 'linuxdist' which confused me - will update one that is a bit more explicit.

@quintesse
Copy link
Contributor

is that expected?

It shows what the providers tell it to show. Providers shouldn't return anything without doing sanity checks.

I see now what you were trying to do. You're using the BaseFolderJdkProvider which assumes that the only folders that it will encounter are always valid JDKs. But we could add a simple filter for ./RELEASE.

@maxandersen
Copy link
Collaborator Author

Btw, talking about native providers... you run MacOS, can't you make a provider for JDKs installed on Macs? :-)

macs doesn't install native jdks anymore do they ?

@maxandersen
Copy link
Collaborator Author

the fact that we first use what's on the path already means that we can never be sure what JDK we're running.

we can be sure the user gets the JDK that is defined in his terminal/session like any other common cli command.

@maxandersen
Copy link
Collaborator Author

But we could add a simple filter for ./RELEASE.

not sure where to best add it as some of the code already does use it for naming ...but other seems to use filenames. lets do that in another pr.

@quintesse
Copy link
Contributor

the fact that we first use what's on the path already means that we can never be sure what JDK we're running.

we can be sure the user gets the JDK that is defined in his terminal/session like any other common cli command.

What I mean is that we cannot make assumptions about the JDK we're running, either we're running a JBang-managed JDK or ... something else that we know very little about. So what's so different about running another JDK that's available on the system (as long as we can verify it's the correct versions and it's a JDK)? In what way are managed JBang JDKs "better" than what the user has on their system? (I'm of course assuming modern JDKs from any vendor are fully functional)

@quintesse
Copy link
Contributor

macs doesn't install native jdks anymore do they ?

Dunno, I don't use Macs so I have no idea how people install JDKs there :-)

if(nm.endsWith("JdkProvider")) {
return nm.substring(0, nm.length() - 11).toLowerCase();
} else {
return nm;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably do .toLowerCase() here

@quintesse quintesse changed the title feat: liunxdistro jdk provider feat: linuxdistro jdk provider Aug 6, 2024
@maxandersen maxandersen force-pushed the linuxdistroprovider branch 2 times, most recently from 901c620 to 3761694 Compare August 12, 2024 10:33
Copy link
Contributor

@quintesse quintesse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will work as-is. The only thing we could still do is the filtering for the existence of the RELEASE file. But we could also leave that for a future PR if there aren't any real issues.

Copy link
Contributor

@quintesse quintesse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I've just tested this myself and I do see the problem now. There's a whole bunch of duplication going on. I think what we should do is add a protected boolean acceptFolder(Path jdkFolder) { return true; } to the BaseFoldersJdkProvider which subclasses can override. In the case of the LinuxDistro provider I'd then check that the folders are not symlinks, and a bin/javac exists (in my case all folders are JREs)

NB: we could make this test the default implementation as well, because realistically all JDKs should be able to pass these tests.

@maxandersen
Copy link
Collaborator Author

@quintesse is that not done better in separate PR ?

@quintesse
Copy link
Contributor

@quintesse is that not done better in separate PR ?

Well , right now this PR would add a dozen unusable entries on my system. That's not really something we want, right?

@maxandersen
Copy link
Collaborator Author

@quintesse i don't see them so if you can push update to this pr with what you wanna see fixed lets do that.

@quintesse
Copy link
Contributor

Will do, but on PTO now, Have to see when I have a bit of time :-)

@Nullable
@Override
protected String jdkId(String name) {
return name + "-nixdistro";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way you chose a different name here than the name of the provider itself? ("linuxdistro" vs "nixdistro")

@quintesse quintesse force-pushed the linuxdistroprovider branch 2 times, most recently from dab4045 to ba3c08e Compare August 28, 2024 23:43
@maxandersen maxandersen merged commit 8c0f8ef into jbangdev:main Sep 12, 2024
11 checks passed
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.

add /usr/lib/jvm as a optional jdk location to search for preinstalled javass
2 participants