gnodet-bot commented on code in PR #13897:
URL: https://github.com/apache/maven/pull/13897#discussion_r4521313406
##########
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) {
Review Comment:
💡 **Duplicated `getGroupId`/`getArtifactId` helpers** — these two static
methods (lines 189–210) are byte-for-byte identical to the ones added in
`DefaultModelBuilder` (lines 3269–3290). If the parsing logic ever needs an
edge-case fix and only one copy gets updated, importer deduplication and model
builder inclusion matching will silently diverge. Consider extracting to a
package-private utility (e.g., `InclusionHelper`) or adding
`groupId()`/`artifactId()` convenience methods on the `Inclusion` model class
so both call sites stay in sync automatically.
##########
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:
💡 **`id=":"` (bare colon) passes as valid but should be an ERROR.** When
`id` is `":"`, `colonIdx == 0` produces `parsedGroupId = ""` and
`parsedArtifactId = ""`, which falls through to the bare-wildcard WARNING
("must specify at least groupId or artifactId"). A bare colon is a malformed
identifier — it should be rejected with an ERROR, consistent with how
`id="no-colon"` (no colon at all) is handled. Consider adding a check for empty
segments:
```suggestion
} else {
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 empty groupId and
artifactId; expected 'groupId:artifactId' format.",
inclusion);
} else {
if (groupId == null || groupId.isEmpty()) {
groupId = parsedGroupId;
}
if (artifactId == null || artifactId.isEmpty()) {
artifactId = parsedArtifactId;
}
}
```
--
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]