From 8e6260dd26a71785f4e3205f5626bf19a6b7ce08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Wed, 29 Nov 2023 21:42:18 +0100 Subject: [PATCH] Calculate severity level based on the project not on the problem ApiProblem.getSeverity() always returns the workspace defaults because it always passes null. Also the method is actually never used inside API Tools. Instead we recalculate the real severity based on the currently processed project. (cherry picked from commit 7aec992ac34d3252d4545d6dd69d62fbf62823d8) --- .../eclipse/tycho/apitools/ApiAnalysis.java | 39 +++++++++++-------- .../tycho/apitools/ApiAnalysisResult.java | 5 ++- .../eclipse/tycho/apitools/ApiProblemDTO.java | 7 +++- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysis.java b/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysis.java index c9c0ca4692..93ca134ea6 100644 --- a/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysis.java +++ b/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysis.java @@ -156,7 +156,9 @@ public void aboutToRun(IJobChangeEvent event) { disableJVMDiscovery(); setTargetPlatform(); deleteAllProjects(); - BundleComponent projectComponent = importProject(); + IPath projectPath = IPath.fromOSString(projectDir); + IProject project = getProject(projectPath); + BundleComponent projectComponent = getApiComponent(project, projectPath); IApiBaseline baseline = createBaseline(baselineBundles, baselineName + " - baseline"); ResolverError[] resolverErrors = projectComponent.getErrors(); if (resolverErrors != null && resolverErrors.length > 0) { @@ -173,7 +175,7 @@ public void aboutToRun(IJobChangeEvent event) { new NullProgressMonitor()); IApiProblem[] problems = analyzer.getProblems(); for (IApiProblem problem : problems) { - result.addProblem(problem); + result.addProblem(problem, project); debug(String.valueOf(problem)); } } finally { @@ -191,21 +193,7 @@ private void disableJVMDiscovery() { instanceNode.putBoolean(LaunchingPlugin.PREF_DETECT_VMS_AT_STARTUP, false); } - private BundleComponent importProject() throws CoreException, IOException { - IPath projectPath = IPath.fromOSString(projectDir); - IPath projectDescriptionFile = projectPath.append(IProjectDescription.DESCRIPTION_FILE_NAME); - IProjectDescription projectDescription = ResourcesPlugin.getWorkspace() - .loadProjectDescription(projectDescriptionFile); - projectDescription.setLocation(projectPath); - projectDescription.setBuildSpec(new ICommand[0]); - // FIXME ApiTools wrongly assumes that the location matches the project name - // see: https://github.com/eclipse-pde/eclipse.pde/issues/789 - // therefore we here must not use projectDescription.getName() but - // projectPath.lastSegment() ... - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectPath.lastSegment()); - project.create(projectDescription, new NullProgressMonitor()); - project.open(new NullProgressMonitor()); - createOutputFolder(project, projectPath); + private BundleComponent getApiComponent(IProject project, IPath projectPath) throws CoreException, IOException { IApiBaseline workspaceBaseline = ApiPlugin.getDefault().getApiBaselineManager().getWorkspaceBaseline(); IApiComponent component = workspaceBaseline.getApiComponent(project); if (component instanceof ProjectComponent projectComponent) { @@ -235,6 +223,23 @@ private BundleComponent importProject() throws CoreException, IOException { throw new RuntimeException("Can't import project"); } + private IProject getProject(IPath projectPath) throws CoreException, IOException { + IPath projectDescriptionFile = projectPath.append(IProjectDescription.DESCRIPTION_FILE_NAME); + IProjectDescription projectDescription = ResourcesPlugin.getWorkspace() + .loadProjectDescription(projectDescriptionFile); + projectDescription.setLocation(projectPath); + projectDescription.setBuildSpec(new ICommand[0]); + // FIXME ApiTools wrongly assumes that the location matches the project name + // see: https://github.com/eclipse-pde/eclipse.pde/issues/789 + // therefore we here must not use projectDescription.getName() but + // projectPath.lastSegment() ... + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectPath.lastSegment()); + project.create(projectDescription, new NullProgressMonitor()); + project.open(new NullProgressMonitor()); + createOutputFolder(project, projectPath); + return project; + } + private void createOutputFolder(IProject project, IPath projectPath) throws IOException, CoreException { IJavaProject javaProject = JavaCore.create(project); if (javaProject != null) { diff --git a/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysisResult.java b/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysisResult.java index ebdf11a7f1..fdfc6fdfea 100644 --- a/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysisResult.java +++ b/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysisResult.java @@ -17,6 +17,7 @@ import java.util.List; import java.util.stream.Stream; +import org.eclipse.core.resources.IProject; import org.eclipse.osgi.service.resolver.ResolverError; import org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblem; @@ -33,8 +34,8 @@ public Stream resolveErrors() { return resolveError.stream(); } - public void addProblem(IApiProblem problem) { - problems.add(new ApiProblemDTO(problem)); + public void addProblem(IApiProblem problem, IProject project) { + problems.add(new ApiProblemDTO(problem, project)); } public void addResolverError(ResolverError error) { diff --git a/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiProblemDTO.java b/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiProblemDTO.java index 21394ea0f1..82b9e7e936 100644 --- a/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiProblemDTO.java +++ b/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiProblemDTO.java @@ -14,6 +14,9 @@ import java.io.Serializable; +import org.eclipse.core.resources.IProject; +import org.eclipse.pde.api.tools.internal.problems.ApiProblemFactory; +import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin; import org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblem; public class ApiProblemDTO implements IApiProblem, Serializable { @@ -34,8 +37,8 @@ public class ApiProblemDTO implements IApiProblem, Serializable { private final int flags; private final String toString; - public ApiProblemDTO(IApiProblem problem) { - severity = problem.getSeverity(); + public ApiProblemDTO(IApiProblem problem, IProject project) { + severity = ApiPlugin.getDefault().getSeverityLevel(ApiProblemFactory.getProblemSeverityId(problem), project); elementKind = problem.getElementKind(); messageid = problem.getMessageid(); resourcePath = problem.getResourcePath();