Skip to content

Commit 02927b7

Browse files
authored
[MNG-8141] Aftermath, and tidy up (#1572)
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
1 parent ac5d71a commit 02927b7

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java

-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.util.Collection;
2929
import java.util.Collections;
3030
import java.util.HashMap;
31-
import java.util.HashSet;
3231
import java.util.Iterator;
3332
import java.util.LinkedHashSet;
3433
import java.util.List;
@@ -464,12 +463,7 @@ void performFor(String value, String locationKey, Consumer<String> mutator) {
464463
}
465464
}
466465
}
467-
HashSet<String> profileIds = new HashSet<>();
468466
for (Profile profile : interpolatedActivations) {
469-
if (!profileIds.add(profile.getId())) {
470-
problems.add(new ModelProblemCollectorRequest(Severity.WARNING, ModelProblem.Version.BASE)
471-
.setMessage("Duplicate activation for profile " + profile.getId()));
472-
}
473467
Activation activation = profile.getActivation();
474468
Optional<Activation> a = Optional.ofNullable(activation);
475469
a.map(Activation::getFile).ifPresent(fa -> {

maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public DefaultModelValidator(ModelVersionProcessor versionProcessor) {
9595
this.versionProcessor = versionProcessor;
9696
}
9797

98+
@SuppressWarnings("checkstyle:methodlength")
9899
@Override
99100
public void validateRawModel(Model m, ModelBuildingRequest request, ModelProblemCollector problems) {
100101
Parent parent = m.getParent();
@@ -132,7 +133,22 @@ public void validateRawModel(Model m, ModelBuildingRequest request, ModelProblem
132133
}
133134
}
134135

135-
if (request.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0) {
136+
if (request.getValidationLevel() == ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL) {
137+
// profiles: they are essential for proper model building (may contribute profiles, dependencies...)
138+
HashSet<String> minProfileIds = new HashSet<>();
139+
for (Profile profile : m.getProfiles()) {
140+
if (!minProfileIds.add(profile.getId())) {
141+
addViolation(
142+
problems,
143+
Severity.WARNING,
144+
Version.BASE,
145+
"profiles.profile.id",
146+
null,
147+
"Duplicate activation for profile " + profile.getId(),
148+
profile);
149+
}
150+
}
151+
} else if (request.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0) {
136152
Severity errOn30 = getSeverity(request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0);
137153

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

0 commit comments

Comments
 (0)