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

improved JDK detection startup tasks #5637

Merged
merged 1 commit into from
Apr 17, 2023

Conversation

mbien
Copy link
Member

@mbien mbien commented Mar 9, 2023

  • repurposed debian task to support more distributions
  • registered JDK names will now receive the (System) or (SDKMAN) postfixes
  • only register a JDK if it wasn't registered yet since registering JDKs seems to be expensive (and we don't want to overwrite anything)

platform-detector

@mbien mbien added Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) labels Mar 9, 2023
@mbien mbien added this to the NB18 milestone Mar 9, 2023
@mbien mbien requested a review from lkishalmi March 9, 2023 02:12
@lkishalmi
Copy link
Contributor

I thought that property is used as a platform ID. It is unfortunate that the Platform API does not have an ID. So internally we use that property value as an unofficial ID.

That is being saved in projects metadata if you select the non-default Java platform (in Ant, Maven and Gradle) projects.

Once I was thinking about adding a getId() to the platform, making that official, but then decided not to.

Anyway just felt odd making decisions on Display name.

@lkishalmi
Copy link
Contributor

Next JDK-s to be detected the ones in $HOME/NetBeansJDKs/ and the ones in $HOME/.gradle/jdks...

@mbien

This comment was marked as outdated.

@mbien mbien force-pushed the jdk-detector-improvements branch from eb385a6 to ce9977f Compare April 2, 2023 22:39
@mbien
Copy link
Member Author

mbien commented Apr 3, 2023

update: it is now checking installation paths too, in addition to the registered platform name, to not register duplicates or overwrite existing ones.

@mbien
Copy link
Member Author

mbien commented Apr 12, 2023

@lkishalmi what do you think? Should we get this in? It checks now paths + names for conflicts.

for (Path jdk : jdks) {
try {
String jdkName = namer.apply(jdk);
// don't register if something with the same name or same path exists
Copy link
Member

@neilcsmith-net neilcsmith-net Apr 12, 2023

Choose a reason for hiding this comment

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

The namer should really only be applied if that path doesn't already have the file attribute for the name? Otherwise it should be the value of that attribute.

We could do with a better way of linking path and chosen name - the idea was to allow re-registered JDK's to get the previously set user name by default.

It's probably a minor concern now you're checking for path rather than name to determine registration, but could still be worth considering?

Copy link
Member Author

@mbien mbien Apr 12, 2023

Choose a reason for hiding this comment

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

The namer should really only be applied if that path doesn't already have the file attribute for the name? Otherwise it should be the value of that attribute.

my thinking was to not mess with already registered JDKs at all if there is a conflict in name or path. If the user changed something, the user should remove it first before the automation kicks in again. Being too smart here by updating things quietly during restarts could cause issues.

Keep in mind the version before that registered JDKs without any checks :)

Copy link
Member Author

@mbien mbien Apr 12, 2023

Choose a reason for hiding this comment

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

actually you are probably right. What if SDKMAN is updating JDKs in place. The old version would have simply overwritten the registered platforms. This PR would keep the old ones until they are manually removed.

probably better to think about this more (and I gonna have to install SDKMAN somewhere)

Copy link
Contributor

Choose a reason for hiding this comment

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

SDK man does not update JDK in place as far as I know. It downloads the new one and sets the current symlink to the one used.

Copy link
Member Author

Choose a reason for hiding this comment

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

@neilcsmith-net i tested this:

                        String jdkName = null;
                        FileObject fo = FileUtil.toFileObject(jdk);
                        if (fo != null) {
                            Object value = fo.getAttribute("J2SEPlatform.displayName"); // NOI18N
                            if (value instanceof String) {
                                jdkName = (String) value;
                            }
                        }
                        if (jdkName == null) {
                            jdkName = namer.apply(jdk);
                        }

and I believe this is worse since it can lead to very weird behavior. If you add a JDK with a custom name, then remove it again, it will be added with the same name again on next start which looks for the user as if removal didn't work.

Having automated JDK detection use a fixed naming pattern is better IMO, since it automatically communicates where this is from.

@lkishalmi thanks for checking!

Copy link
Member Author

@mbien mbien Apr 16, 2023

Choose a reason for hiding this comment

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

interesting idea.

                    FileObject fo = FileUtil.toFileObject(jdk);
                    if (fo != null) {
                        Object value = fo.getAttribute("J2SEPlatform.displayName"); // NOI18N
                        if (value instanceof String) {
                            break; // skip, this indicates that it was added (and potentially removed) by the user
                        }
                    }

i think this has potential but there is one big issue: there is no reset button. We would have to be prepared to tell users to remove nb_userdir/var/attributes.xml

Copy link
Member Author

Choose a reason for hiding this comment

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

however :)

having to remove this check later is probably the better option than not having it -> going to change it

Copy link
Member

Choose a reason for hiding this comment

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

Why is the lack of a reset button an issue? If a JDK registration has been manually removed, shouldn't it need to be manually re-added?

That attribute was added primarily to try and maintain the names given to Disco downloaded JDKs incidentally. So they could be removed and then re-added under same name. I've had doubts since about that way to do it, but somewhere I think we should store metadata like names, removal status, etc. of manually unregistered JDKs.

Copy link
Member Author

@mbien mbien Apr 17, 2023

Choose a reason for hiding this comment

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

Why is the lack of a reset button an issue? If a JDK registration has been manually removed, shouldn't it need to be manually re-added?

the longer I thought about it the more I liked the idea of skipping those folders. I think it is the safest option to get auto detection in.

step 1: don't ever override already registered JDKs
step 2: don't annoy the user by registering stuff the user potentially just removed

having a growing "block list" without reset button sounded intuitively wrong to me, but it is probably completely fine in this particular case - and the better option to not having it.

Copy link
Member

Choose a reason for hiding this comment

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

It'll also reset on IDE upgrade - those attributes don't get imported (one of the issues with using them for this IMO). I think it would be good to get this in for NB18, then possibly rethink how we store info in NB19, and whether we need a reset.

@mbien mbien removed this from the NB18 milestone Apr 12, 2023
@lkishalmi
Copy link
Contributor

Just some insights on SDKMAN:

lkishalmi@desktop-su4jobc:~/NetBeansProjects/netbeans$ ls -l ~/.sdkman/candidates/java/
total 19
drwxr-xr-x  9 lkishalmi lkishalmi 11 Jan 18 02:13 17.0.6-tem
drwxr-xr-x 10 lkishalmi lkishalmi 14 Mar  7 00:53 20-zulu
lrwxrwxrwx  1 lkishalmi lkishalmi 10 Apr 15 10:53 current -> 17.0.6-tem

@mbien mbien marked this pull request as draft April 15, 2023 19:11
 - repurposed debian task to support more distributions
 - registered JDK names will now receive the (System) or (SDKMAN)
   postfixes
 - only register a JDK if it hasn't been registered yet
@mbien mbien force-pushed the jdk-detector-improvements branch from ce9977f to e181301 Compare April 17, 2023 14:26
@mbien mbien marked this pull request as ready for review April 17, 2023 14:27
@mbien mbien added this to the NB18 milestone Apr 17, 2023
@mbien mbien merged commit ac3b904 into apache:master Apr 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants