Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a Workspace Job to perform API analysis #4105

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading