diff --git a/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysisMojo.java b/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysisMojo.java index f6f711ba68..de11902144 100644 --- a/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysisMojo.java +++ b/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysisMojo.java @@ -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; @@ -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); } diff --git a/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/LogFileEnhancer.java b/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/LogFileEnhancer.java index c425750e8f..1560b441a7 100644 --- a/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/LogFileEnhancer.java +++ b/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/LogFileEnhancer.java @@ -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; @@ -46,9 +48,11 @@ 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 notFoundConsumer) throws IOException { Map> 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; } @@ -56,6 +60,7 @@ public static void enhanceXml(File logDirectory, ApiAnalysisResult analysisResul Map documents = readDocuments(logDirectory); for (Entry> problemEntry : problems.entrySet()) { String path = problemEntry.getKey(); + boolean found = false; for (Entry documentEntry : documents.entrySet()) { Document document = documentEntry.getValue(); Element statsElement = getStatsElement(document); @@ -63,6 +68,7 @@ public static void enhanceXml(File logDirectory, ApiAnalysisResult analysisResul 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 list = problemEntry.getValue(); @@ -90,7 +96,9 @@ public static void enhanceXml(File logDirectory, ApiAnalysisResult analysisResul } } } - + if (!found) { + problemEntry.getValue().forEach(notFoundConsumer); + } } writeDocuments(needsUpdate, documents); }