Skip to content

Commit

Permalink
Use a Workspace Job to perform API analysis
Browse files Browse the repository at this point in the history
We sometimes see "disposed" components from the workspace Baseline e.g.
eclipse-pde/eclipse.pde#1310 what seem to
indicate that some operation interfere here.

This wraps the execution of the Api Analysis part in a workspace job to
ensure these actions are delayed until we are done with the baseline.

(cherry picked from commit 3449471)
  • Loading branch information
laeubi committed Aug 12, 2024
1 parent cfc482c commit aa35262
Showing 1 changed file with 45 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceDescription;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.WorkspaceJob;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.IJobChangeListener;
import org.eclipse.core.runtime.jobs.IJobManager;
Expand Down Expand Up @@ -158,33 +162,51 @@ public void aboutToRun(IJobChangeEvent event) {
deleteAllProjects();
IPath projectPath = IPath.fromOSString(projectDir);
IProject project = getProject(projectPath);
BundleComponent projectComponent = getApiComponent(project, projectPath);
IApiBaseline baseline = createBaseline(baselineBundles, baselineName + " - baseline");
ResolverError[] resolverErrors = projectComponent.getErrors();
ApiAnalysisResult result = new ApiAnalysisResult(getVersion());
if (resolverErrors != null && resolverErrors.length > 0) {
for (ResolverError error : resolverErrors) {
result.addResolverError(error);
}
}
IApiFilterStore filterStore = getApiFilterStore(projectComponent);
Properties preferences = getPreferences();
BaseApiAnalyzer analyzer = new BaseApiAnalyzer();
try {
analyzer.setContinueOnResolverError(true);
analyzer.analyzeComponent(null, filterStore, preferences, baseline, projectComponent, new BuildContext(),
new NullProgressMonitor());
IApiProblem[] problems = analyzer.getProblems();
for (IApiProblem problem : problems) {
result.addProblem(problem, project);
debug(String.valueOf(problem));
WorkspaceJob job = new WorkspaceJob("Tycho API Analysis") {

@Override
public IStatus runInWorkspace(IProgressMonitor monitor) {
try {
BundleComponent projectComponent = getApiComponent(project, projectPath);
IApiBaseline baseline = createBaseline(baselineBundles, baselineName + " - baseline");
ResolverError[] resolverErrors = projectComponent.getErrors();
if (resolverErrors != null && resolverErrors.length > 0) {
for (ResolverError error : resolverErrors) {
result.addResolverError(error);
}
}
IApiFilterStore filterStore = getApiFilterStore(projectComponent);
Properties preferences = getPreferences();
BaseApiAnalyzer analyzer = new BaseApiAnalyzer();
try {
analyzer.setContinueOnResolverError(true);
analyzer.analyzeComponent(null, filterStore, preferences, baseline, projectComponent,
new BuildContext(), new NullProgressMonitor());
IApiProblem[] problems = analyzer.getProblems();
for (IApiProblem problem : problems) {
result.addProblem(problem, project);
debug(String.valueOf(problem));
}
} finally {
analyzer.dispose();
ResourcesPlugin.getWorkspace().save(true, new NullProgressMonitor());
}
} catch (Exception e) {
return Status.error("Api Analysis failed", e);
}
return Status.OK_STATUS;
}
} finally {
analyzer.dispose();
ResourcesPlugin.getWorkspace().save(true, new NullProgressMonitor());
}
};
job.setRule(ResourcesPlugin.getWorkspace().getRoot());
job.schedule();
job.join();
IStatus status = job.getResult();
JRTUtil.reset(); // reclaim space due to loaded multiple JRTUtil should better be fixed to not
// use that much space
if (!status.isOK() && status.getException() instanceof Exception error) {
throw error;
}
return result;
}

Expand Down

0 comments on commit aa35262

Please sign in to comment.