Skip to content

Commit

Permalink
Calculate severity level based on the project not on the problem
Browse files Browse the repository at this point in the history
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 7aec992)
  • Loading branch information
laeubi committed Nov 30, 2023
1 parent 5f6b4eb commit 8e6260d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -33,8 +34,8 @@ public Stream<ResolverError> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
Expand Down

0 comments on commit 8e6260d

Please sign in to comment.