Skip to content

Commit d0f217f

Browse files
laeubieclipse-tycho-bot
authored andcommitted
Add an option to enhance the compile log with baseline problems
(cherry picked from commit 6ee7934)
1 parent 4fa783a commit d0f217f

File tree

6 files changed

+306
-196
lines changed

6 files changed

+306
-196
lines changed

tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysisMojo.java

+60-19
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
import java.util.Collection;
2020
import java.util.List;
2121
import java.util.Map;
22+
import java.util.Map.Entry;
2223
import java.util.Objects;
2324
import java.util.Optional;
2425
import java.util.Set;
25-
import java.util.concurrent.atomic.AtomicInteger;
2626
import java.util.function.Consumer;
2727
import java.util.stream.Collectors;
2828

@@ -48,7 +48,9 @@
4848
import org.eclipse.tycho.MavenRepositoryLocation;
4949
import org.eclipse.tycho.TargetEnvironment;
5050
import org.eclipse.tycho.TychoConstants;
51+
import org.eclipse.tycho.core.EcJLogFileEnhancer;
5152
import org.eclipse.tycho.core.TychoProjectManager;
53+
import org.eclipse.tycho.core.EcJLogFileEnhancer.Source;
5254
import org.eclipse.tycho.core.osgitools.DefaultReactorProject;
5355
import org.eclipse.tycho.model.project.EclipseProject;
5456
import org.eclipse.tycho.osgi.framework.EclipseApplication;
@@ -207,22 +209,14 @@ public void execute() throws MojoExecutionException, MojoFailureException {
207209
}
208210
if (enhanceLogs && logDirectory != null && logDirectory.isDirectory()) {
209211
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);
216218
}
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;
226220
}
227221
} catch (IOException e) {
228222
log.warn("Can't enhance logs in directory " + logDirectory);
@@ -253,13 +247,61 @@ public void execute() throws MojoExecutionException, MojoFailureException {
253247
}
254248
}
255249

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+
256299
private ApiAnalysisResult performAnalysis(Collection<Path> baselineBundles, Collection<Path> dependencyBundles,
257300
EclipseFramework eclipseFramework, EclipseProject eclipseProject) throws MojoExecutionException {
258301
try {
259302
ApiAnalysis analysis = new ApiAnalysis(baselineBundles, dependencyBundles, project.getName(),
260303
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()),
263305
stringToPath(project.getBuild().getOutputDirectory()));
264306
return eclipseFramework.execute(analysis);
265307
} catch (Exception e) {
@@ -345,7 +387,6 @@ private Collection<TargetEnvironment> getBaselineEnvironments() {
345387
return targetEnvironments;
346388
}
347389

348-
349390
private String time(long start) {
350391
long ms = System.currentTimeMillis() - start;
351392
if (ms < 1000) {

tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/LogFileEnhancer.java

-171
This file was deleted.

tycho-artifactcomparator/src/main/java/org/eclipse/tycho/zipcomparator/internal/ClassfileComparator.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ public boolean matches(String extension) {
8181
return TYPE.equalsIgnoreCase(extension);
8282
}
8383

84-
private static final class ClassfileArtifactDelta extends SimpleArtifactDelta {
84+
public static final class ClassfileArtifactDelta extends SimpleArtifactDelta {
8585

8686
private ComparatorInputStream baselineStream;
8787
private ComparatorInputStream reactorStream;
8888

89-
public ClassfileArtifactDelta(String baseline, String reactor, ComparatorInputStream baselineStream,
89+
ClassfileArtifactDelta(String baseline, String reactor, ComparatorInputStream baselineStream,
9090
ComparatorInputStream reactorStream) {
9191
super("different", baseline, reactor);
9292
this.baselineStream = baselineStream;

0 commit comments

Comments
 (0)