Skip to content

Commit

Permalink
Print not mapped API messages to the log
Browse files Browse the repository at this point in the history
Currently if a message can't be mapped to the logfile it is simply
ignored.

This now always print them to the log if they can't be mapped and print
a waring about the issue as it is usually some configuration problem.
  • Loading branch information
laeubi committed Feb 6, 2024
1 parent e1d4df4 commit e73f878
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -209,7 +210,23 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
if (enhanceLogs && logDirectory != null && logDirectory.isDirectory()) {
try {
LogFileEnhancer.enhanceXml(logDirectory, analysisResult);
AtomicInteger notMapped = new AtomicInteger();
LogFileEnhancer.enhanceXml(logDirectory, analysisResult, notfound -> {
notMapped.incrementAndGet();
if (printProblems) {
// it was already printed before...
return;
}
if (ApiPlugin.SEVERITY_ERROR == notfound.getSeverity()) {
printProblem(notfound, "API ERROR", log::error);
} else if (ApiPlugin.SEVERITY_WARNING == notfound.getSeverity()) {
printProblem(notfound, "API WARNING", log::warn);
}
});
int count = notMapped.get();
if (count > 0) {
log.warn(count + " API problems can't be mapped to the compiler log!");
}
} catch (IOException e) {
log.warn("Can't enhance logs in directory " + logDirectory);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
Expand All @@ -46,23 +48,27 @@ public class LogFileEnhancer {
private static final String ATTRIBUTES_INFOS = "infos";
private static final String ATTRIBUTES_ERRORS = "errors";

public static void enhanceXml(File logDirectory, ApiAnalysisResult analysisResult) throws IOException {
public static void enhanceXml(File logDirectory, ApiAnalysisResult analysisResult,
Consumer<IApiProblem> notFoundConsumer) throws IOException {
Map<String, List<IApiProblem>> problems = analysisResult.problems()
.collect(Collectors.groupingBy(IApiProblem::getResourcePath));
.collect(Collectors.groupingBy(problem -> Objects.requireNonNullElse(problem.getResourcePath(),
"no-path-" + System.identityHashCode(problem))));
if (problems.isEmpty()) {
return;
}
Set<File> needsUpdate = new HashSet<>();
Map<File, Document> documents = readDocuments(logDirectory);
for (Entry<String, List<IApiProblem>> problemEntry : problems.entrySet()) {
String path = problemEntry.getKey();
boolean found = false;
for (Entry<File, Document> documentEntry : documents.entrySet()) {
Document document = documentEntry.getValue();
Element statsElement = getStatsElement(document);
for (Element sources : document.getRootElement().getChildren("sources")) {
for (Element source : sources.getChildren("source")) {
String pathAttribute = source.getAttributeValue("path");
if (pathAttribute != null && !pathAttribute.isEmpty() && pathAttribute.endsWith(path)) {
found = true;
needsUpdate.add(documentEntry.getKey());
Element problemsElement = getProblemsElement(source);
List<IApiProblem> list = problemEntry.getValue();
Expand Down Expand Up @@ -90,7 +96,9 @@ public static void enhanceXml(File logDirectory, ApiAnalysisResult analysisResul
}
}
}

if (!found) {
problemEntry.getValue().forEach(notFoundConsumer);
}
}
writeDocuments(needsUpdate, documents);
}
Expand Down

0 comments on commit e73f878

Please sign in to comment.