cstamas commented on code in PR #11786:
URL: https://github.com/apache/maven/pull/11786#discussion_r2920582287
##########
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:
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.
--
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]