gnodet-bot commented on code in PR #13897:
URL: https://github.com/apache/maven/pull/13897#discussion_r4551299038


##########
impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelValidator.java:
##########
@@ -1571,49 +1602,139 @@ private void validateEffectiveDependency(
         }
 
         if (validationLevel >= ModelValidator.VALIDATION_LEVEL_MAVEN_2_0) {
-            for (Exclusion exclusion : dependency.getExclusions()) {
-                if (validationLevel < 
ModelValidator.VALIDATION_LEVEL_MAVEN_3_0) {
-                    validateCoordinatesId(
-                            prefix,
-                            "exclusions.exclusion.groupId",
-                            problems,
-                            Severity.WARNING,
-                            Version.V20,
-                            exclusion.getGroupId(),
-                            SourceHint.dependencyManagementKey(dependency),
-                            exclusion);
+            validateDependencyExclusions(problems, dependency, prefix, 
validationLevel);
+            validateDependencyInclusions(problems, dependency, prefix);
+        }
+    }
 
-                    validateCoordinatesId(
-                            prefix,
-                            "exclusions.exclusion.artifactId",
+    private void validateDependencyExclusions(
+            ModelProblemCollector problems, Dependency dependency, String 
prefix, int validationLevel) {
+        for (Exclusion exclusion : dependency.getExclusions()) {
+            if (validationLevel < ModelValidator.VALIDATION_LEVEL_MAVEN_3_0) {
+                validateCoordinatesId(
+                        prefix,
+                        "exclusions.exclusion.groupId",
+                        problems,
+                        Severity.WARNING,
+                        Version.V20,
+                        exclusion.getGroupId(),
+                        SourceHint.dependencyManagementKey(dependency),
+                        exclusion);
+
+                validateCoordinatesId(
+                        prefix,
+                        "exclusions.exclusion.artifactId",
+                        problems,
+                        Severity.WARNING,
+                        Version.V20,
+                        exclusion.getArtifactId(),
+                        SourceHint.dependencyManagementKey(dependency),
+                        exclusion);
+            } else {
+                validateCoordinatesIdWithWildcards(
+                        prefix,
+                        "exclusions.exclusion.groupId",
+                        problems,
+                        Severity.WARNING,
+                        Version.V30,
+                        exclusion.getGroupId(),
+                        SourceHint.dependencyManagementKey(dependency),
+                        exclusion);
+
+                validateCoordinatesIdWithWildcards(
+                        prefix,
+                        "exclusions.exclusion.artifactId",
+                        problems,
+                        Severity.WARNING,
+                        Version.V30,
+                        exclusion.getArtifactId(),
+                        SourceHint.dependencyManagementKey(dependency),
+                        exclusion);
+            }
+        }
+    }
+
+    private void validateDependencyInclusions(ModelProblemCollector problems, 
Dependency dependency, String prefix) {
+        for (Inclusion inclusion : dependency.getIncludes()) {
+            String groupId = inclusion.getGroupId();
+            String artifactId = inclusion.getArtifactId();
+            String id = inclusion.getId();
+
+            boolean validId = true;
+            if (id != null && !id.isEmpty()) {
+                int colonIdx = id.indexOf(':');
+                if (colonIdx < 0) {
+                    validId = false;
+                    addViolation(
                             problems,
-                            Severity.WARNING,
-                            Version.V20,
-                            exclusion.getArtifactId(),
+                            Severity.ERROR,
+                            Version.V42,
+                            prefix + "includes.include.id",
                             SourceHint.dependencyManagementKey(dependency),
-                            exclusion);
-                } else {
-                    validateCoordinatesIdWithWildcards(
-                            prefix,
-                            "exclusions.exclusion.groupId",
+                            "with value '" + id + "' does not match the 
expected 'groupId:artifactId' format.",
+                            inclusion);
+                } else if (id.indexOf(':', colonIdx + 1) >= 0) {
+                    validId = false;
+                    addViolation(
                             problems,
-                            Severity.WARNING,
-                            Version.V30,
-                            exclusion.getGroupId(),
+                            Severity.ERROR,
+                            Version.V42,
+                            prefix + "includes.include.id",
                             SourceHint.dependencyManagementKey(dependency),
-                            exclusion);
+                            "with value '" + id
+                                    + "' contains more than one colon; 
expected 'groupId:artifactId' format.",
+                            inclusion);
+                } else {
+                    String parsedGroupId = id.substring(0, colonIdx);
+                    String parsedArtifactId = id.substring(colonIdx + 1);
 
-                    validateCoordinatesIdWithWildcards(
-                            prefix,
-                            "exclusions.exclusion.artifactId",
-                            problems,
-                            Severity.WARNING,
-                            Version.V30,
-                            exclusion.getArtifactId(),
-                            SourceHint.dependencyManagementKey(dependency),
-                            exclusion);
+                    if (groupId == null || groupId.isEmpty()) {
+                        groupId = parsedGroupId;
+                    }
+                    if (artifactId == null || artifactId.isEmpty()) {
+                        artifactId = parsedArtifactId;
+                    }

Review Comment:
   ⚠️ **Empty segment in `id` is not rejected as an ERROR.** When `id` is 
`":"`, `colonIdx == 0`, so `parsedGroupId = id.substring(0, 0) = ""` and 
`parsedArtifactId = id.substring(1) = ""`. Neither the `colonIdx < 0` branch 
nor the double-colon branch fires, `validId` stays `true`, and both empty 
strings fall into the bare-wildcard WARNING path. Same flaw applies to 
`":artifactId"` and `"groupId:"` — one empty segment is not caught.
   
   A colon-separated id with an empty segment is malformed and should be 
rejected with `Severity.ERROR`:
   
   ```suggestion
                       String parsedGroupId = id.substring(0, colonIdx);
                       String parsedArtifactId = id.substring(colonIdx + 1);
   
                       if (parsedGroupId.isEmpty() || 
parsedArtifactId.isEmpty()) {
                           validId = false;
                           addViolation(
                                   problems,
                                   Severity.ERROR,
                                   Version.V42,
                                   prefix + "includes.include.id",
                                   
SourceHint.dependencyManagementKey(dependency),
                                   "with value '" + id
                                           + "' has an empty groupId or 
artifactId segment; expected 'groupId:artifactId' format.",
                                   inclusion);
                       } else {
                           if (groupId == null || groupId.isEmpty()) {
                               groupId = parsedGroupId;
                           }
                           if (artifactId == null || artifactId.isEmpty()) {
                               artifactId = parsedArtifactId;
                           }
                       }
   ```



##########
impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultDependencyManagementImporter.java:
##########
@@ -163,6 +168,48 @@ private boolean equals(Exclusion e1, Exclusion e2) {
                 && Objects.equals(e1.getArtifactId(), e2.getArtifactId());
     }
 
+    private boolean equalsInclusions(Collection<Inclusion> ci1, 
Collection<Inclusion> ci2) {
+        if (ci1.size() == ci2.size()) {
+            Iterator<Inclusion> i1 = ci1.iterator();
+            Iterator<Inclusion> i2 = ci2.iterator();
+            while (i1.hasNext() && i2.hasNext()) {
+                if (!equals(i1.next(), i2.next())) {
+                    return false;
+                }
+            }
+            return !i1.hasNext() && !i2.hasNext();
+        }
+        return false;
+    }
+
+    private boolean equals(Inclusion i1, Inclusion i2) {
+        return Objects.equals(getGroupId(i1), getGroupId(i2)) && 
Objects.equals(getArtifactId(i1), getArtifactId(i2));
+    }
+
+    private static String getGroupId(Inclusion inclusion) {
+        if (inclusion.getGroupId() != null && 
!inclusion.getGroupId().isEmpty()) {
+            return inclusion.getGroupId();
+        }
+        if (inclusion.getId() != null) {
+            int idx = inclusion.getId().indexOf(':');
+            return idx >= 0 ? inclusion.getId().substring(0, idx) : 
inclusion.getId();
+        }
+        return null;
+    }
+
+    private static String getArtifactId(Inclusion inclusion) {

Review Comment:
   ⚠️ **Duplicate helper — still not deduplicated.** `getGroupId(Inclusion)` 
(lines 189–199) and `getArtifactId(Inclusion)` (lines 200–210) are 
byte-for-byte identical to the same methods added in `DefaultModelBuilder` 
(lines 3292 and 3303 of this PR). If the parsing logic ever needs an edge-case 
fix and only one copy gets updated, importer deduplication and builder 
inclusion matching will silently diverge.
   
   Consider extracting to a package-private `InclusionCoordinates` utility, or 
adding `groupId()`/`artifactId()` convenience methods on the `Inclusion` model 
class so both call sites share one implementation.



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