HannesWell commented on code in PR #11786:
URL: https://github.com/apache/maven/pull/11786#discussion_r2920537694


##########
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:
   I was about to propose that logic as well for 
https://github.com/apache/maven/pull/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.
   



-- 
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]

Reply via email to