Skip to content

Commit 758e054

Browse files
committed
Revert "[MNG-8141] Model builder should report problems it finds during build (#1556)"
This reverts commit 7fcd8c5.
1 parent 7fcd8c5 commit 758e054

File tree

3 files changed

+6
-131
lines changed

3 files changed

+6
-131
lines changed

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

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -97,30 +97,6 @@
9797
@Named
9898
@Singleton
9999
public class DefaultModelBuilder implements ModelBuilder {
100-
/**
101-
* Key for "fail on invalid model" property.
102-
* <p>
103-
* Visible for testing.
104-
*/
105-
static final String FAIL_ON_INVALID_MODEL = "maven.modelBuilder.failOnInvalidModel";
106-
107-
/**
108-
* Checks user and system properties (in this order) for value of {@link #FAIL_ON_INVALID_MODEL} property key, if
109-
* set and returns it. If not set, defaults to {@code true}.
110-
* <p>
111-
* This is only meant to provide "escape hatch" for those builds, that are for some reason stuck with invalid models.
112-
*/
113-
private static boolean isFailOnInvalidModel(ModelBuildingRequest request) {
114-
String val = request.getUserProperties().getProperty(FAIL_ON_INVALID_MODEL);
115-
if (val == null) {
116-
val = request.getSystemProperties().getProperty(FAIL_ON_INVALID_MODEL);
117-
}
118-
if (val != null) {
119-
return Boolean.parseBoolean(val);
120-
}
121-
return true;
122-
}
123-
124100
@Inject
125101
private ModelProcessor modelProcessor;
126102

@@ -277,7 +253,6 @@ public ModelBuildingResult build(ModelBuildingRequest request) throws ModelBuild
277253
protected ModelBuildingResult build(ModelBuildingRequest request, Collection<String> importIds)
278254
throws ModelBuildingException {
279255
// phase 1
280-
boolean failOnInvalidModel = isFailOnInvalidModel(request);
281256
DefaultModelBuildingResult result = new DefaultModelBuildingResult();
282257

283258
DefaultModelProblemCollector problems = new DefaultModelProblemCollector(result);
@@ -331,7 +306,7 @@ protected ModelBuildingResult build(ModelBuildingRequest request, Collection<Str
331306
profileActivationContext.setProjectProperties(tmpModel.getProperties());
332307

333308
Map<String, Activation> interpolatedActivations =
334-
getInterpolatedActivations(rawModel, profileActivationContext, failOnInvalidModel, problems);
309+
getInterpolatedActivations(rawModel, profileActivationContext, problems);
335310
injectProfileActivations(tmpModel, interpolatedActivations);
336311

337312
List<Profile> activePomProfiles =
@@ -455,12 +430,8 @@ private interface InterpolateString {
455430
}
456431

457432
private Map<String, Activation> getInterpolatedActivations(
458-
Model rawModel,
459-
DefaultProfileActivationContext context,
460-
boolean failOnInvalidModel,
461-
DefaultModelProblemCollector problems) {
462-
Map<String, Activation> interpolatedActivations =
463-
getProfileActivations(rawModel, true, failOnInvalidModel, problems);
433+
Model rawModel, DefaultProfileActivationContext context, DefaultModelProblemCollector problems) {
434+
Map<String, Activation> interpolatedActivations = getProfileActivations(rawModel, true);
464435

465436
if (interpolatedActivations.isEmpty()) {
466437
return Collections.emptyMap();
@@ -782,8 +753,7 @@ private void assembleInheritance(
782753
}
783754
}
784755

785-
private Map<String, Activation> getProfileActivations(
786-
Model model, boolean clone, boolean failOnInvalidModel, ModelProblemCollector problems) {
756+
private Map<String, Activation> getProfileActivations(Model model, boolean clone) {
787757
Map<String, Activation> activations = new HashMap<>();
788758
for (Profile profile : model.getProfiles()) {
789759
Activation activation = profile.getActivation();
@@ -796,11 +766,7 @@ private Map<String, Activation> getProfileActivations(
796766
activation = activation.clone();
797767
}
798768

799-
if (activations.put(profile.getId(), activation) != null) {
800-
problems.add(new ModelProblemCollectorRequest(
801-
failOnInvalidModel ? Severity.FATAL : Severity.WARNING, ModelProblem.Version.BASE)
802-
.setMessage("Duplicate activation for profile " + profile.getId()));
803-
}
769+
activations.put(profile.getId(), activation);
804770
}
805771

806772
return activations;
@@ -821,8 +787,7 @@ private void injectProfileActivations(Model model, Map<String, Activation> activ
821787

822788
private Model interpolateModel(Model model, ModelBuildingRequest request, ModelProblemCollector problems) {
823789
// save profile activations before interpolation, since they are evaluated with limited scope
824-
// at this stage we already failed if wanted to
825-
Map<String, Activation> originalActivations = getProfileActivations(model, true, false, problems);
790+
Map<String, Activation> originalActivations = getProfileActivations(model, true);
826791

827792
Model interpolatedModel =
828793
modelInterpolator.interpolateModel(model, model.getProjectDirectory(), request, problems);

maven-model-builder/src/test/java/org/apache/maven/model/building/DefaultModelBuilderTest.java

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
*/
1919
package org.apache.maven.model.building;
2020

21-
import java.io.File;
22-
2321
import org.apache.maven.model.Dependency;
2422
import org.apache.maven.model.Parent;
2523
import org.apache.maven.model.Repository;
@@ -29,8 +27,6 @@
2927
import org.junit.Test;
3028

3129
import static org.junit.Assert.assertNotNull;
32-
import static org.junit.Assert.assertTrue;
33-
import static org.junit.Assert.fail;
3430

3531
/**
3632
* @author Guillaume Nodet
@@ -91,38 +87,6 @@ public void testCycleInImports() throws Exception {
9187
builder.build(request);
9288
}
9389

94-
@Test
95-
public void testBadProfiles() {
96-
ModelBuilder builder = new DefaultModelBuilderFactory().newInstance();
97-
assertNotNull(builder);
98-
99-
DefaultModelBuildingRequest request = new DefaultModelBuildingRequest();
100-
request.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
101-
request.setModelSource(new FileModelSource(new File("src/test/resources/poms/building/badprofiles.xml")));
102-
request.setModelResolver(new BaseModelResolver());
103-
104-
try {
105-
builder.build(request); // throw, making "pom not available"
106-
fail();
107-
} catch (ModelBuildingException e) {
108-
assertTrue(e.getMessage().contains("Duplicate activation for profile badprofile"));
109-
}
110-
}
111-
112-
@Test
113-
public void testBadProfilesCheckDisabled() throws Exception {
114-
ModelBuilder builder = new DefaultModelBuilderFactory().newInstance();
115-
assertNotNull(builder);
116-
117-
DefaultModelBuildingRequest request = new DefaultModelBuildingRequest();
118-
request.getUserProperties().setProperty(DefaultModelBuilder.FAIL_ON_INVALID_MODEL, "false");
119-
request.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
120-
request.setModelSource(new FileModelSource(new File("src/test/resources/poms/building/badprofiles.xml")));
121-
request.setModelResolver(new BaseModelResolver());
122-
123-
builder.build(request); // does not throw, old behaviour (but result may be fully off)
124-
}
125-
12690
static class CycleInImportsResolver extends BaseModelResolver {
12791
@Override
12892
public ModelSource resolveModel(Dependency dependency) throws UnresolvableModelException {

maven-model-builder/src/test/resources/poms/building/badprofiles.xml

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)