Skip to content

Commit

Permalink
[MNG-8141] Aftermath, and tidy up (#1572)
Browse files Browse the repository at this point in the history
No (logic) change, merely moved the new code to proper place (validation) to not piggy back onto processing: this is much cleaner.

---

https://issues.apache.org/jira/browse/MNG-8141

Inspired by suggestions in master PR #1569
  • Loading branch information
cstamas committed Jun 10, 2024
1 parent ac5d71a commit 02927b7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
Expand Down Expand Up @@ -464,12 +463,7 @@ void performFor(String value, String locationKey, Consumer<String> mutator) {
}
}
}
HashSet<String> profileIds = new HashSet<>();
for (Profile profile : interpolatedActivations) {
if (!profileIds.add(profile.getId())) {
problems.add(new ModelProblemCollectorRequest(Severity.WARNING, ModelProblem.Version.BASE)
.setMessage("Duplicate activation for profile " + profile.getId()));
}
Activation activation = profile.getActivation();
Optional<Activation> a = Optional.ofNullable(activation);
a.map(Activation::getFile).ifPresent(fa -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public DefaultModelValidator(ModelVersionProcessor versionProcessor) {
this.versionProcessor = versionProcessor;
}

@SuppressWarnings("checkstyle:methodlength")
@Override
public void validateRawModel(Model m, ModelBuildingRequest request, ModelProblemCollector problems) {
Parent parent = m.getParent();
Expand Down Expand Up @@ -132,7 +133,22 @@ public void validateRawModel(Model m, ModelBuildingRequest request, ModelProblem
}
}

if (request.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0) {
if (request.getValidationLevel() == ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL) {
// profiles: they are essential for proper model building (may contribute profiles, dependencies...)
HashSet<String> minProfileIds = new HashSet<>();
for (Profile profile : m.getProfiles()) {
if (!minProfileIds.add(profile.getId())) {
addViolation(
problems,
Severity.WARNING,
Version.BASE,
"profiles.profile.id",
null,
"Duplicate activation for profile " + profile.getId(),
profile);
}
}
} else if (request.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0) {
Severity errOn30 = getSeverity(request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0);

// [MNG-6074] Maven should produce an error if no model version has been set in a POM file used to build an
Expand Down

0 comments on commit 02927b7

Please sign in to comment.