Skip to content

Update Regex to Support All ASDF Versions for the supported distributions in tool-versions File #767

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

aparnajyothi-y
Copy link
Contributor

Description:
This Pull request improves the regex pattern used in the tool-versions file to ensure compatibility with all ASDF versions across the supported distributions. The goal is to provide better flexibility and robustness when parsing tool version entries, handling variations in version formats more effectively.

Related issue:
#719

Check list:

  • [ ✔️] Mark if documentation changes are required.

@aparnajyothi-y aparnajyothi-y requested a review from a team as a code owner March 18, 2025 08:40
const crypto = __nccwpck_require__(6005)
random = (max) => crypto.randomInt(0, max)
} catch {
random = (max) => Math.floor(Math.random(max))

Choose a reason for hiding this comment

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

I don't think Math.random takes a parameter, does it? I think this produces random numbers between 0 and 1 and then floors them to 0.

Choose a reason for hiding this comment

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

Never mind, this is autogenerated, isn't it?

Choose a reason for hiding this comment

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

For reference, I think this is from updating to undici 5.28.5. It looks like it has been fixed but only released in 6.21.2 and 7.4.0.

@@ -133,7 +133,7 @@ export function getVersionFromFileContent(
const versionFileName = getFileName(versionFile);
if (versionFileName == '.tool-versions') {
javaVersionRegExp =
/^(java\s+)(?:\S*-)?v?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(-ea(\.\d+)?)?)$/m;
/^(java\s+)(?:\S*-)?v?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\S+)?(\.\d+)?(-ea(\.\d+)?)?(\.LTS)?)$/m;

Choose a reason for hiding this comment

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

Is the .LTS functional here? As far as I can tell, for the Java versions that have .LTS in them, it always gets consumed by the (\+\S+)? part, since it matches all non-spaces after a +, leaving the rest of the regular expression vestigial. Perhaps that part wasn't expected to match so much?

I tested this regex against the output of asdf list all java. I deduplicated those versions that only differ by their numbers.

Already matched, still match

adoptopenjdk-11.0.15+10
adoptopenjdk-jre-11.0.15+10
graalvm-community-17.0.7
liberica-16+36
liberica-11.0.10+9
liberica-javafx-16+36
liberica-javafx-11.0.10+9
liberica-jre-16+36
liberica-jre-11.0.10+9
liberica-jre-javafx-16+36
liberica-jre-javafx-11.0.10+9
liberica-lite-16+36
liberica-lite-11.0.10+9
microsoft-11.0.15
openjdk-17
openjdk-17.0.1
oracle-17
oracle-17.0.1
oracle-graalvm-21
oracle-graalvm-17.0.7
sapmachine-17
sapmachine-0.0.0
sapmachine-jre-17
sapmachine-jre-0.0.0
semeru-jre-openj9-23+37_openj9-0.47.0
semeru-jre-openj9-11.0.15+10_openj9-0.32.0
semeru-jre-openj9-11.0.16.1+1_openj9-0.33.1
semeru-openj9-23+37_openj9-0.47.0
semeru-openj9-11.0.15+10_openj9-0.32.0
semeru-openj9-11.0.16.1+1_openj9-0.33.1
temurin-11.0.15+10
temurin-jre-11.0.15+10
zulu-11.43.1017
zulu-javafx-11.45.27
zulu-jre-11.45.27
zulu-jre-javafx-11.45.27

Newly matched

adoptopenjdk-21.0.0+35.0.LTS
adoptopenjdk-jre-21.0.0+35.0.LTS
corretto-8.322.06.4
graalvm-22.1.0+java11
microsoft-11.0.16.1
openjdk-18.0.1.1
oracle-17.0.3.1
sapmachine-11.0.16.1
sapmachine-jre-11.0.16.1
semeru-jre-openj9-23.0.1+11_openj9-0.49.0-m2
semeru-openj9-23.0.1+11_openj9-0.49.0-m2
temurin-21.0.0+35.0.LTS
temurin-jre-21.0.0+35.0.LTS
zulu-8.52.0.23
zulu-javafx-8.52.0.23
zulu-jre-8.52.0.23
zulu-jre-javafx-8.52.0.23

Still not matched

adoptopenjdk-19.0.0-beta+36.0.202208190932
adoptopenjdk-jre-19.0.0-beta+36.0.202208190932
corretto-11.0.15.9.1
jetbrains-17.0.4.1b646.8
jetbrains-11.0.16b2043.64
jetbrains-21b212.1
jetbrains-jre-17.0.4.1b646.8
jetbrains-jre-11.0.16b2043.64
jetbrains-jre-21b212.1
kona-8.0.12.b1
liberica-11.0.14.1+1
liberica-8u282+8
liberica-javafx-11.0.14.1+1
liberica-javafx-8u282+8
liberica-jre-11.0.14.1+1
liberica-jre-8u282+8
liberica-jre-javafx-11.0.14.1+1
liberica-jre-javafx-8u282+8
liberica-lite-11.0.14.1+1
liberica-lite-8u302+8
mandrel-23.1.3.1-Final+java21
microsoft-11.0.14.9.1
sapmachine-18-internal.0
sapmachine-19-snapshot
sapmachine-20-snapshot.35
sapmachine-11.0.19-snapshot.1
sapmachine-17.0.3.0.1
sapmachine-jre-18-internal.0
sapmachine-jre-19-snapshot
sapmachine-jre-20-snapshot.35
sapmachine-jre-11.0.19-snapshot.1
sapmachine-jre-17.0.3.0.1
temurin-19.0.0-beta+36.0.202208190932
temurin-jre-19.0.0-beta+36.0.202208190932
zulu-8.62.0.19_1
zulu-11.66.15_1
zulu-javafx-11.66.15_1
zulu-jre-11.66.15_1
zulu-jre-javafx-11.66.15_1

Notable causes of remaining misses are:

  • having 5 number segments in the version in the case of corretto, microsoft and sapmachine
  • having 4 number segments in the version and a + separated build metadata section, in the case of liberica
  • having a suffix like _1 for patch versions in the case of zulu
  • having a - separated pre-release segment like "beta", "snapshot" or "internal" in the case of adoptopenjdk and sapmachine
  • having a b or u separated build number, which seems to be the case for jetbrains and some versions of liberica

I hope that's helpful.

Choose a reason for hiding this comment

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

Oh, in case you want to repeat the analysis, I used jq. The regex engine is close enough for one like this.

asdf list all java |
    sed 's/^/java /' |
    jq -cRn \
        --arg oldregex '^(java\s+)(?:\S*-)?v?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(-ea(\.\d+)?)?)$' \
        --arg newregex '^(java\s+)(?:\S*-)?v?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\S+)?(\.\d+)?(-ea(\.\d+)?)?(\.LTS)?)$' \
        '[
            inputs|
            {
                version:.,
                matches_new:test($newregex),
                matches_old:test($oldregex)
            }
        ]|
        unique_by(.version|=gsub("[0-9]+";"0"))|
        .[]'

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.

2 participants