Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNG-8141] Do not loose model builder warnings #1567

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ private interface InterpolateString {

private Map<String, Activation> getInterpolatedActivations(
Model rawModel, DefaultProfileActivationContext context, DefaultModelProblemCollector problems) {
Map<String, Activation> interpolatedActivations = getProfileActivations(rawModel, true);
Map<String, Activation> interpolatedActivations = getProfileActivations(rawModel, true, problems);

if (interpolatedActivations.isEmpty()) {
return Collections.emptyMap();
Expand Down Expand Up @@ -753,7 +753,7 @@ private void assembleInheritance(
}
}

private Map<String, Activation> getProfileActivations(Model model, boolean clone) {
private Map<String, Activation> getProfileActivations(Model model, boolean clone, ModelProblemCollector problems) {
Map<String, Activation> activations = new HashMap<>();
for (Profile profile : model.getProfiles()) {
Activation activation = profile.getActivation();
Expand All @@ -766,9 +766,11 @@ private Map<String, Activation> getProfileActivations(Model model, boolean clone
activation = activation.clone();
}

activations.put(profile.getId(), activation);
if (activations.put(profile.getId(), activation) != null) {
problems.add(new ModelProblemCollectorRequest(Severity.WARNING, ModelProblem.Version.BASE)
.setMessage("Duplicate activation for profile " + profile.getId()));
}
}

return activations;
}

Expand All @@ -787,7 +789,7 @@ private void injectProfileActivations(Model model, Map<String, Activation> activ

private Model interpolateModel(Model model, ModelBuildingRequest request, ModelProblemCollector problems) {
// save profile activations before interpolation, since they are evaluated with limited scope
Map<String, Activation> originalActivations = getProfileActivations(model, true);
Map<String, Activation> originalActivations = getProfileActivations(model, true, problems);

Model interpolatedModel =
modelInterpolator.interpolateModel(model, model.getProjectDirectory(), request, problems);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public List<ModelProblem> getProblems() {
return Collections.unmodifiableList(result.getProblems());
}

private static String toMessage(ModelBuildingResult result) {
public static String toMessage(ModelBuildingResult result) {
if (result != null && !result.getModelIds().isEmpty()) {
return toMessage(result.getModelIds().get(0), result.getProblems());
}
Expand All @@ -137,7 +137,7 @@ private static String toMessage(String modelId, List<ModelProblem> problems) {
writer.print(problems.size());
writer.print((problems.size() == 1) ? " problem was " : " problems were ");
writer.print("encountered while building the effective model");
if (modelId != null && modelId.length() > 0) {
if (modelId != null && !modelId.isEmpty()) {
writer.print(" for ");
writer.print(modelId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import javax.inject.Singleton;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
Expand All @@ -37,6 +38,7 @@
import org.apache.maven.model.building.ModelBuilder;
import org.apache.maven.model.building.ModelBuildingException;
import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.model.building.ModelBuildingResult;
import org.apache.maven.model.building.ModelProblem;
import org.apache.maven.model.resolution.UnresolvableModelException;
import org.eclipse.aether.RepositoryEvent;
Expand Down Expand Up @@ -67,6 +69,8 @@
import org.eclipse.aether.spi.locator.Service;
import org.eclipse.aether.spi.locator.ServiceLocator;
import org.eclipse.aether.transfer.ArtifactNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* @author Benjamin Bentmann
Expand All @@ -91,6 +95,8 @@ public class DefaultArtifactDescriptorReader implements ArtifactDescriptorReader
private final ArtifactDescriptorReaderDelegate artifactDescriptorReaderDelegate =
new ArtifactDescriptorReaderDelegate();

private final Logger logger = LoggerFactory.getLogger(getClass());

@Deprecated
public DefaultArtifactDescriptorReader() {
// enable no-arg constructor
Expand Down Expand Up @@ -281,7 +287,25 @@ private Model loadPom(
modelRequest.setModelSource(new FileModelSource(pomArtifact.getFile()));
}

model = modelBuilder.build(modelRequest).getEffectiveModel();
ModelBuildingResult modelResult = modelBuilder.build(modelRequest);
// ModelBuildingEx is thrown only on FATAL and ERROR severities, but we still can have WARNs
// that may lead to unexpected build failure, log them
if (!modelResult.getProblems().isEmpty()) {
if (logger.isDebugEnabled()) {
String message = ModelBuildingException.toMessage(modelResult);
if (message != null) {
logger.warn(message);
}
} else {
List<ModelProblem> problems = modelResult.getProblems();
logger.warn(
"{} {} encountered while building the effective model for {}",
problems.size(),
(problems.size() == 1) ? "problem was" : "problems were",
request.getArtifact());
}
}
model = modelResult.getEffectiveModel();
} catch (ModelBuildingException e) {
for (ModelProblem problem : e.getProblems()) {
if (problem.getException() instanceof UnresolvableModelException) {
Expand Down