Feat: Improve matching of Toolchains versions#11786
Feat: Improve matching of Toolchains versions#11786cstamas wants to merge 3 commits intoapache:maven-3.9.xfrom
Conversation
This feature was totally off from what it was documented.
|
I say
|
|
I think I captured both: the latter "11+" is becoming "[11,)", and former is again same (but implemented as "starts with 11. -- DOT appended, so matches 11, 11.0, 11.999 but not 12.0) -- oohh "11" is not matched. Edit: right, "11" is NOT matched. |
| // if requirement is not a version range itself | ||
| if (!req.contains("[") && !req.contains("(") && !req.contains(",")) { | ||
| if (!interval) { | ||
| return version.startsWith(req + "."); // "11" -> "11.xxx" |
There was a problem hiding this comment.
I was about to propose that logic as well for #11770, i.e. when one just specifies a version requirement that the actual version should just start with the requirement to handle cases like
- 11
- 11.1
- 11.1.1
Of course one has to handle the Java-8 and older versions. But maybe this can be done by removing a leading 1. to 'norm' the versions to all start with their, what's now called, feature version of the JDK.
In this case I wonder how it works if one requires 1.5.2 and has a version 1.5.2 since a trailing dot is added? But I see this case covered in tests.
Just in case that still has slipped, one could test for equals or starts with dot suffix, i.e. the current code.
There was a problem hiding this comment.
Before this call the normalized strings are tested for equality. This is what I missed in my comment above as well. So "1.5.2".equalsIgnoreCase("1.5.2") will yield true
There was a problem hiding this comment.
Re 1.8 support (or older): IMHO, user must write versions as reported by JDK, especially as toolchains XML may be generated today. And if user consistently writes 1.8 there is no problem. The only problem would be 8+ that does not include Java 1.8... unsure about this.
There was a problem hiding this comment.
For possible 1.8 support, see this similar case: c2e4be2
There was a problem hiding this comment.
Legacy code for sure wrote "1.4", "1.6" or "1.8"... and given toolchain does not have "feature version" to match against (nor could?) I'd say we are fine IF users use versions "as reported by Java".
There was a problem hiding this comment.
Before this call the normalized strings are tested for equality.
Oversaw that, thanks.
I'd say we are fine IF users use versions "as reported by Java".
Sounds good. I would try to keep it simple and as long as there is a way to handle it, it's fine.
Also given that the number of users at <=1.8 is hopefully declining, this should also become less of a problem.
| boolean interval = false; | ||
| boolean included = false; | ||
| if (requirement.endsWith("+")) { | ||
| interval = true; | ||
| included = true; | ||
| requirement = requirement.substring(0, requirement.length() - 1); | ||
| } else if (requirement.endsWith("-")) { | ||
| interval = true; | ||
| requirement = requirement.substring(0, requirement.length() - 1); | ||
| } |
There was a problem hiding this comment.
Can't this code be moved into the if block that has checked that the requirement isn't a version-range? In case of the latter this seems to be ignored any-ways.
I have to admit that I wasn't aware this notation is possible and maybe for others it's the same. But then then this is close to #11770, isn't it? |
I was primarily reacting to this line
The 'starts with 11' is not the same as |
I have only seen this notation in the invoker plugin where you can use this for the invoker.properties to specify a need for a specific java version to be active to run a specific integration test. I hit my head around this a week ago because this syntax is bot supported for the requested toolchain in the same file regarding the same kind of requirement. From my perspective I would
|
Well, not quite. This PR is about Toolchains, so about key But alas, invoker does behave as documented for keys like So we will end up with two ways to control/select/match "java version"? This was the crux and motivation for this PR, to align the two (hopefully all). |
This feature was totally off from what it was documented. Have to note, that in this case versions (and hence, their matching) reflect exactly the version that Toolchains discovered (ie there is no "automatic" handling of
1.8vs8, JDK reported version is used as is).Doco: https://maven.apache.org/plugins/maven-invoker-plugin/examples/selector-conditions.html
Expressions and changes:
11." (as per doco, as range[1.5,)is equivalent of this)[11,)" (as per doco)(,11)" (as per doco)