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 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Regex update
  • Loading branch information
aparnajyothi-y committed Mar 21, 2025
commit cb386ac736070eed0ab3ad0e944d3b96095cbcc0
2 changes: 1 addition & 1 deletion dist/cleanup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97075,7 +97075,7 @@ function getVersionFromFileContent(content, distributionName, versionFile) {
const versionFileName = getFileName(versionFile);
if (versionFileName == '.tool-versions') {
javaVersionRegExp =
/^(java\s+)(?:\S*-)?v?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(\.\d+)?(-ea(\.\d+)?)?(\.LTS)?)$/m;
/^(java\s+)(?:\S*-)?v?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\S+)?(\.\d+)?(-ea(\.\d+)?)?(\.LTS)?)$/m;
}
else {
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
Expand Down
2 changes: 1 addition & 1 deletion dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135080,7 +135080,7 @@ function getVersionFromFileContent(content, distributionName, versionFile) {
const versionFileName = getFileName(versionFile);
if (versionFileName == '.tool-versions') {
javaVersionRegExp =
/^(java\s+)(?:\S*-)?v?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(\.\d+)?(-ea(\.\d+)?)?(\.LTS)?)$/m;
/^(java\s+)(?:\S*-)?v?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\S+)?(\.\d+)?(-ea(\.\d+)?)?(\.LTS)?)$/m;
}
else {
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export function getVersionFromFileContent(
const versionFileName = getFileName(versionFile);
if (versionFileName == '.tool-versions') {
javaVersionRegExp =
Copy link
Preview

Copilot AI Jul 28, 2025

Choose a reason for hiding this comment

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

The complex regex pattern lacks documentation explaining its purpose and the various parts it matches. Add comments describing what each component captures.

Suggested change
javaVersionRegExp =
javaVersionRegExp =
/**
* Matches Java version strings in `.tool-versions` files.
* - ^java\s+: Matches lines starting with "java" followed by whitespace.
* - (?:\S*-)?: Optionally matches a non-whitespace string followed by a hyphen (e.g., "adopt-").
* - (?<version>\d+(?:\.\d+)*...): Captures the version number, which:
* - Starts with one or more digits (\d+).
* - May include additional dot-separated numeric components (e.g., "11.0.2").
* - May be followed by a suffix (e.g., "+", "_", ".", or "-") and:
* - openj9[-._]?\d[\w.-]*: Matches OpenJ9-specific versions (e.g., "openj9-0.24.0").
* - java\d+: Matches Java-specific identifiers (e.g., "java11").
* - jre[-_\w]*: Matches JRE-specific identifiers (e.g., "jre8").
* - OpenJDK\d+[\w_.-]*: Matches OpenJDK-specific identifiers (e.g., "OpenJDK11").
* - [a-z0-9]+: Matches other alphanumeric identifiers.
* - Flags:
* - i: Case-insensitive matching.
* - m: Multiline matching.
*/

Copilot uses AI. Check for mistakes.

/^(java\s+)(?:\S*-)?v?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(\.\d+)?(-ea(\.\d+)?)?(\.LTS)?)$/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"))|
        .[]'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello @annettejanewilson, Thank you again for your thorough analysis and the detailed feedback.

We’ve updated the pattern to correctly match all of the Java versions in your test suite, with a few clearly documented exceptions:

  • semeru-openj9-11.0.15+10_openj9-0.32.0: The previous regex mistakenly extracted _0.32.0 instead of the intended 11.0.15+10. We’ve revised the pattern to capture the correct version segment reliably. To avoid ambiguity in such cases, we recommend relying on the first captured version or applying lightweight post-processing to clean up trailing components.

  • jetbrains-21b212.1: This format isn’t semver-compliant and doesn't align well with regex-based parsing. We've documented it as a known limitation and suggest handling these rare formats through manual fallback logic when needed.

Rather than overfitting the regex to cover every edge case, we’ve prioritized maintainable support for standard and semver-like formats while explicitly documenting exceptions for transparency.

Thanks again for your valuable input and please don’t hesitate to share more insights or suggestions!

} else {
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
}
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy