|
19 | 19 | import java.util.Collection;
|
20 | 20 | import java.util.List;
|
21 | 21 | import java.util.Map;
|
| 22 | +import java.util.Map.Entry; |
22 | 23 | import java.util.Objects;
|
23 | 24 | import java.util.Optional;
|
24 | 25 | import java.util.Set;
|
25 |
| -import java.util.concurrent.atomic.AtomicInteger; |
26 | 26 | import java.util.function.Consumer;
|
27 | 27 | import java.util.stream.Collectors;
|
28 | 28 |
|
|
48 | 48 | import org.eclipse.tycho.MavenRepositoryLocation;
|
49 | 49 | import org.eclipse.tycho.TargetEnvironment;
|
50 | 50 | import org.eclipse.tycho.TychoConstants;
|
| 51 | +import org.eclipse.tycho.core.EcJLogFileEnhancer; |
51 | 52 | import org.eclipse.tycho.core.TychoProjectManager;
|
| 53 | +import org.eclipse.tycho.core.EcJLogFileEnhancer.Source; |
52 | 54 | import org.eclipse.tycho.core.osgitools.DefaultReactorProject;
|
53 | 55 | import org.eclipse.tycho.model.project.EclipseProject;
|
54 | 56 | import org.eclipse.tycho.osgi.framework.EclipseApplication;
|
@@ -207,22 +209,14 @@ public void execute() throws MojoExecutionException, MojoFailureException {
|
207 | 209 | }
|
208 | 210 | if (enhanceLogs && logDirectory != null && logDirectory.isDirectory()) {
|
209 | 211 | try {
|
210 |
| - AtomicInteger notMapped = new AtomicInteger(); |
211 |
| - LogFileEnhancer.enhanceXml(logDirectory, analysisResult, notfound -> { |
212 |
| - notMapped.incrementAndGet(); |
213 |
| - if (printProblems) { |
214 |
| - // it was already printed before... |
215 |
| - return; |
| 212 | + Map<String, List<IApiProblem>> problemsMap = analysisResult.problems().collect( |
| 213 | + Collectors.groupingBy(problem -> Objects.requireNonNullElse(problem.getResourcePath(), |
| 214 | + "no-path-" + System.identityHashCode(problem)))); |
| 215 | + if (!problemsMap.isEmpty()) { |
| 216 | + try (EcJLogFileEnhancer enhancer = EcJLogFileEnhancer.create(logDirectory)) { |
| 217 | + enhanceLog(enhancer, problemsMap); |
216 | 218 | }
|
217 |
| - if (ApiPlugin.SEVERITY_ERROR == notfound.getSeverity()) { |
218 |
| - printProblem(notfound, "API ERROR", log::error); |
219 |
| - } else if (ApiPlugin.SEVERITY_WARNING == notfound.getSeverity()) { |
220 |
| - printProblem(notfound, "API WARNING", log::warn); |
221 |
| - } |
222 |
| - }); |
223 |
| - int count = notMapped.get(); |
224 |
| - if (count > 0) { |
225 |
| - log.warn(count + " API problems can't be mapped to the compiler log!"); |
| 219 | + return; |
226 | 220 | }
|
227 | 221 | } catch (IOException e) {
|
228 | 222 | log.warn("Can't enhance logs in directory " + logDirectory);
|
@@ -253,13 +247,61 @@ public void execute() throws MojoExecutionException, MojoFailureException {
|
253 | 247 | }
|
254 | 248 | }
|
255 | 249 |
|
| 250 | + private void enhanceLog(EcJLogFileEnhancer enhancer, Map<String, List<IApiProblem>> problemsMap) { |
| 251 | + Log log = getLog(); |
| 252 | + int notMapped = 0; |
| 253 | + for (Entry<String, List<IApiProblem>> problemEntry : problemsMap.entrySet()) { |
| 254 | + String path = problemEntry.getKey(); |
| 255 | + List<IApiProblem> problemsList = problemEntry.getValue(); |
| 256 | + List<Source> list = enhancer.sources().filter(source -> { |
| 257 | + String pathAttribute = source.getPath(); |
| 258 | + return pathAttribute != null && !pathAttribute.isEmpty() && pathAttribute.endsWith(path); |
| 259 | + }).toList(); |
| 260 | + if (list.isEmpty()) { |
| 261 | + for (IApiProblem notfound : problemsList) { |
| 262 | + notMapped++; |
| 263 | + if (printProblems) { |
| 264 | + // it was already printed before... |
| 265 | + continue; |
| 266 | + } |
| 267 | + if (ApiPlugin.SEVERITY_ERROR == notfound.getSeverity()) { |
| 268 | + printProblem(notfound, "API ERROR", log::error); |
| 269 | + } else if (ApiPlugin.SEVERITY_WARNING == notfound.getSeverity()) { |
| 270 | + printProblem(notfound, "API WARNING", log::warn); |
| 271 | + } |
| 272 | + } |
| 273 | + } else { |
| 274 | + Map<Integer, List<IApiProblem>> problemsBySeverity = problemsList.stream() |
| 275 | + .collect(Collectors.groupingBy(IApiProblem::getSeverity)); |
| 276 | + List<IApiProblem> errors = problemsBySeverity.getOrDefault(ApiPlugin.SEVERITY_ERROR, List.of()); |
| 277 | + List<IApiProblem> warnings = problemsBySeverity.getOrDefault(ApiPlugin.SEVERITY_WARNING, List.of()); |
| 278 | + for (Source sourceEntry : list) { |
| 279 | + for (IApiProblem problem : warnings) { |
| 280 | + sourceEntry.addProblem(EcJLogFileEnhancer.SEVERITY_WARNING, problem.getLineNumber(), |
| 281 | + problem.getCharStart(), problem.getCharEnd(), problem.getCategory(), problem.getId(), |
| 282 | + problem.getMessage()); |
| 283 | + } |
| 284 | + for (IApiProblem problem : errors) { |
| 285 | + sourceEntry.addProblem(EcJLogFileEnhancer.SEVERITY_ERROR, problem.getLineNumber(), |
| 286 | + problem.getCharStart(), problem.getCharEnd(), problem.getCategory(), problem.getId(), |
| 287 | + problem.getMessage()); |
| 288 | + } |
| 289 | + } |
| 290 | + |
| 291 | + } |
| 292 | + } |
| 293 | + if (notMapped > 0) { |
| 294 | + log.warn(notMapped + " API problems can't be mapped to the compiler log!"); |
| 295 | + } |
| 296 | + |
| 297 | + } |
| 298 | + |
256 | 299 | private ApiAnalysisResult performAnalysis(Collection<Path> baselineBundles, Collection<Path> dependencyBundles,
|
257 | 300 | EclipseFramework eclipseFramework, EclipseProject eclipseProject) throws MojoExecutionException {
|
258 | 301 | try {
|
259 | 302 | ApiAnalysis analysis = new ApiAnalysis(baselineBundles, dependencyBundles, project.getName(),
|
260 | 303 | eclipseProject.getFile(fileToPath(apiFilter)), eclipseProject.getFile(fileToPath(apiPreferences)),
|
261 |
| - fileToPath(project.getBasedir()), debug, |
262 |
| - fileToPath(project.getArtifact().getFile()), |
| 304 | + fileToPath(project.getBasedir()), debug, fileToPath(project.getArtifact().getFile()), |
263 | 305 | stringToPath(project.getBuild().getOutputDirectory()));
|
264 | 306 | return eclipseFramework.execute(analysis);
|
265 | 307 | } catch (Exception e) {
|
@@ -345,7 +387,6 @@ private Collection<TargetEnvironment> getBaselineEnvironments() {
|
345 | 387 | return targetEnvironments;
|
346 | 388 | }
|
347 | 389 |
|
348 |
| - |
349 | 390 | private String time(long start) {
|
350 | 391 | long ms = System.currentTimeMillis() - start;
|
351 | 392 | if (ms < 1000) {
|
|
0 commit comments