fix: auto-generate non-numeric id when linking JDK with numeric version - #2567
Conversation
|
Important Review skippedAuto reviews are limited based on label configuration. 🏷️ Required labels (at least one) (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
quintesse
left a comment
There was a problem hiding this comment.
It's okay, although personally I wouldn't do the counter thing.
Because now, instead of being backwards compatible, we've introduced a new behaviour.
If before you would have run jbang jdk install 21 /foo/bar twice you would have gotten the message that 21 was already installed and to use --force if you really want to do that. With a counter you might end up installing more and more versions without really noticing. If you really want to install multiple 21s I think it should be an explicit act. (eg. the user explicitly giving it a unique name)
|
Good point. what prefix would you use for the one default ? |
I'm okay with the one you chose in the PR: "user" 👍 |
When a user runs 'jbang jdk install 21 /path/to/jdk', instead of
rejecting the numeric id, automatically generate a non-numeric id
using the pattern '<version>-user' (e.g. '21-user'). If that id
already exists, append an incrementing suffix ('21-user-1', etc.).
This fixes the catch-22 where 'jdk install' required a non-numeric id
but '--java' only accepted numeric versions, making it impossible to
link an existing JDK and then use it.
Fixes jbangdev#2557
Problem
When a user tries to link an existing JDK using a numeric version, they hit a catch-22:
jbang jdk install 21 $JDK_PATHjbang jdk install java-21 $JDK_PATHthenjbang --java java-21The correct workaround (
jdk install java-21+--java 21) was not discoverable.Fix
Instead of rejecting numeric IDs, auto-generate a non-numeric id using the pattern
<version>-user:If
21-user-linkedalready exists, it increments:21-user-1,21-user-2, etc.The linked JDK is then found by
--java 21via the version-based lookup inLinkedJdkProvider.Tests
testJdkInstallWithLinkingAndIntegerId→ verifies numeric id generates11-user-linkedtestJdkInstallWithLinkingAndIntegerIdGeneratesIncrementedUserId→ verifies counter suffixtestJdkInstallWithLinkingToExistingJdkPathWithDifferentVersion→ verifies13-user-linkedFixes #2557