HannesWell commented on code in PR #11786:
URL: https://github.com/apache/maven/pull/11786#discussion_r2922657855
##########
maven-core/src/main/java/org/apache/maven/toolchain/RequirementMatcherFactory.java:
##########
@@ -57,31 +61,78 @@ public String toString() {
}
private static final class VersionMatcher implements RequirementMatcher {
- DefaultArtifactVersion version;
+ private final String version;
private VersionMatcher(String version) {
- this.version = new DefaultArtifactVersion(version);
+ this.version = version;
}
@Override
public boolean matches(String requirement) {
- try {
- VersionRange range =
VersionRange.createFromVersionSpec(requirement);
- if (range.hasRestrictions()) {
- return range.containsVersion(version);
+ String r = requirement != null ?
requirement.toLowerCase(Locale.ENGLISH) : null;
+ String v = version != null ? version.toLowerCase(Locale.ENGLISH) :
null;
+ if (v == null && r == null) {
+ return true; // null == null
+ }
+ if (v == null || r == null) {
+ return false; // null != non-null
+ }
+ if (v.equals(r)) {
+ return true; // str == str (ignoring case)
+ }
+ return matchesRequirement(v, r);
+ }
+
+ private static final VersionScheme VERSION_SCHEME = new
GenericVersionScheme();
+
+ private static boolean matchesRequirement(String version, String
requirement) {
+ 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);
+ }
+ final String req = requirement;
+
+ // if requirement is not a version range itself
+ if (!req.contains("[") && !req.contains("(") &&
!req.contains(",")) {
+ if (!interval) {
+ return version.startsWith(req + "."); // "11" -> "11.xxx"
Review 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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]