-
Notifications
You must be signed in to change notification settings - Fork 31
Take BUILD_NUMBER into consideration for Version sorting #45
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
Conversation
b095ef0 to
4771a4d
Compare
| } | ||
|
|
||
| static Regex VersionExtractor = new Regex (@"(?<version>[\d]+(\.\d+)+)(_(?<patch>\d+))?", RegexOptions.Compiled); | ||
| static Regex NonDigitMatcher = new Regex (@"[^\d]"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this still use RegexOptions.Compiled, or is it better to not do that for shorter Regex strings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. For years Mono didn't support them, so I didn't use them...
Certainly wouldn't hurt to use them.
| } | ||
| else if (GetJavaSettingsPropertyValue ("java.version", out version) && !string.IsNullOrEmpty (version)) { | ||
| version = GetParsableVersion (version); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we do the !string.IsNullOrEmpty check when constructing ReleaseProperties?
Then wouldn't have to do this check so much here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe? However, consider:
If we did as you suggest, JUST_A_KEY wouldn't be present in jdk.ReleaseProperties.
Is that desirable? I don't know.
Fixes: http://work.devdiv.io/661401 The version numbers which the Microsoft OpenJDK packages provide was not consistent with what `JdkInfo` expected: the `release` file would have a `JAVA_VERSION` value which was a three-tuple, and didn't include the `BUILD_NUMBER` value. For example: JAVA_VERSION="1.8.0" BUILD_NUMBER=7 Unfortunately, `JdkInfo.GetJavaVersion()` was only taking `JAVA_VERSION` into consideration, so when multiple different OpenJDK packages were processed which all had the *same* `JAVA_VERSION` value but *different* `BUILD_NUMBER` values, `JdkInfo.GetMacOSMicrosoftJdks()` returned the "wrong" one first. (In actuality, the one it returned first was not knowable, and was probably whatever `Directory.EnumerateDirectories()` returned first.) Simple enough, we just need to take `BUILD_NUMBER` into consideration as part of constructing `JdkInfo.Version`, right? Not so fast. Turns Out™ that the version value held within `JAVA_VERSION` or the `java.version` property -- which need not be identical! -- can also contain `-`, not just `_`. A "Java Version" is *really" (at least) 4 optional parts: JAVA_VERSION : VERSION ('_' UPDATE)? ('-' MILESTONE)? ('-' SUFFIX)? Which means Java version values such as `1.8.0_1-9-microsoft-b00` are possible, from various different locations, e.g. the `version` value vs. the `build` value in `java -version` output: $ bin/java -version openjdk version "1.8.0-9" OpenJDK Runtime Environment (build 1.8.0-9-microsoft-b00) OpenJDK 64-Bit Server VM (build 25.71-b00, mixed mode) Instead of trying to top-down parse a version number, go for a "bottom-up" parsing: 1. Replace all *non-digit* characters with `.` 2. Split the value on (1) on `.`, creating an array, and remove all empty values. 3. Separately parse the values in (2) as part of `System.Version` construction. This allows at least a sane-ish, plausible, `Version` construction. `1.8.0_161-b12` will be parsed as `new Version(1, 8, 0, 161)` (as we'll just grab up to the first four values), and we'll gracefully ignore any other non-digit characters in the string. This allows us to better construct a `Version` value for Microsoft OpenJDK packages, allowing us in turn to *sort* the packages, which allows `JdkInfo>GetMacOSMicrosoftJdks()` to return the highest version *first*, as is desired.
4771a4d to
a4b61e0
Compare
Fixes: http://work.devdiv.io/661401 The version numbers which the Microsoft OpenJDK packages provide was not consistent with what `JdkInfo` expected: the `release` file would have a `JAVA_VERSION` value which was a three-tuple, and didn't include the `BUILD_NUMBER` value. For example: JAVA_VERSION="1.8.0" BUILD_NUMBER=7 Unfortunately, `JdkInfo.GetJavaVersion()` was only taking `JAVA_VERSION` into consideration, so when multiple different OpenJDK packages were processed which all had the *same* `JAVA_VERSION` value but *different* `BUILD_NUMBER` values, `JdkInfo.GetMacOSMicrosoftJdks()` returned the "wrong" one first. (In actuality, the one it returned first was not knowable, and was probably whatever `Directory.EnumerateDirectories()` returned first.) Simple enough, we just need to take `BUILD_NUMBER` into consideration as part of constructing `JdkInfo.Version`, right? Not so fast. Turns Out™ that the version value held within `JAVA_VERSION` or the `java.version` property -- which need not be identical! -- can also contain `-`, not just `_`. A "Java Version" is *really" (at least) 4 optional parts: JAVA_VERSION : VERSION ('_' UPDATE)? ('-' MILESTONE)? ('-' SUFFIX)? Which means Java version values such as `1.8.0_1-9-microsoft-b00` are possible, from various different locations, e.g. the `version` value vs. the `build` value in `java -version` output: $ bin/java -version openjdk version "1.8.0-9" OpenJDK Runtime Environment (build 1.8.0-9-microsoft-b00) OpenJDK 64-Bit Server VM (build 25.71-b00, mixed mode) Instead of trying to top-down parse a version number, go for a "bottom-up" parsing: 1. Replace all *non-digit* characters with `.` 2. Split the value on (1) on `.`, creating an array, and remove all empty values. 3. Separately parse the values in (2) as part of `System.Version` construction. This allows at least a sane-ish, plausible, `Version` construction. `1.8.0_161-b12` will be parsed as `new Version(1, 8, 0, 161)` (as we'll just grab up to the first four values), and we'll gracefully ignore any other non-digit characters in the string. This allows us to better construct a `Version` value for Microsoft OpenJDK packages, allowing us in turn to *sort* the packages, which allows `JdkInfo>GetMacOSMicrosoftJdks()` to return the highest version *first*, as is desired.
Context; dotnet/android-tools@917d3b3...9e78d6e Fixes for OpenJDK: dotnet/android-tools#43 dotnet/android-tools#45 Better logging: dotnet/android-tools#46 Fix for missing JDKs on MacOS: dotnet/android-tools#48 Tests now pass on Windows: dotnet/android-tools#47
Context; dotnet/android-tools@917d3b3...9e78d6e Fixes for OpenJDK: dotnet/android-tools#43 dotnet/android-tools#45 Better logging: dotnet/android-tools#46 Fix for missing JDKs on MacOS: dotnet/android-tools#48 Tests now pass on Windows: dotnet/android-tools#47
Fixes: http://work.devdiv.io/661401
The version numbers which the Microsoft OpenJDK packages provide was
not consistent with what
JdkInfoexpected: thereleasefile wouldhave a
JAVA_VERSIONvalue which was a three-tuple, and didn'tinclude the
BUILD_NUMBERvalue. For example:Unfortunately,
JdkInfo.GetJavaVersion()was only takingJAVA_VERSIONinto consideration, so when multiple different OpenJDKpackages were processed which all had the same
JAVA_VERSIONvaluebut different
BUILD_NUMBERvalues,JdkInfo.GetMacOSMicrosoftJdks()returned the "wrong" one first.(In actuality, the one it returned first was not knowable, and was
probably whatever
Directory.EnumerateDirectories()returned first.)Simple enough, we just need to take
BUILD_NUMBERinto considerationas part of constructing
JdkInfo.Version, right?Not so fast. Turns Out™ that the version value held within
JAVA_VERSIONor thejava.versionproperty -- which need not beidentical! -- can also contain
-, not just_. A "Java Version" is*really" (at least) 4 optional parts:
Which means Java version values such as
1.8.0_1-9-microsoft-b00arepossible, from various different locations, e.g. the
versionvaluevs. the
buildvalue injava -versionoutput:Instead of trying to top-down parse a version number, go for a
"bottom-up" parsing:
.., creating an array, and remove allempty values.
System.Versionconstruction.
This allows at least a sane-ish, plausible,
Versionconstruction.1.8.0_161-b12will be parsed asnew Version(1, 8, 0, 161)(aswe'll just grab up to the first four values), and we'll gracefully
ignore any other non-digit characters in the string.
This allows us to better construct a
Versionvalue for MicrosoftOpenJDK packages, allowing us in turn to sort the packages, which
allows
JdkInfo>GetMacOSMicrosoftJdks()to return the highest versionfirst, as is desired.