Skip to content

Commit

Permalink
Use the project component api baseline to lookup the component
Browse files Browse the repository at this point in the history
Currently the api-tools heavily rely on a common shared "workspace
baseline" this baseline can be disposed and then changes at any time.
While this can work in an IDE context, it makes it quite hard for other
tools to use this standalone because there is no way to reliable use an
alternative mean of "workspace baseline".

This now changes the ProjectApiDescription in a way where the baseline
is passed in from the project component and it only fall back to the
static singleton if the baseline is disposed.
  • Loading branch information
laeubi committed Dec 29, 2024
1 parent 2f6b308 commit 4c5c75f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,17 @@ public synchronized static ApiDescriptionManager getManager() {
public synchronized IApiDescription getApiDescription(ProjectComponent component, BundleDescription bundle) {
IJavaProject project = component.getJavaProject();
ProjectApiDescription description = (ProjectApiDescription) fDescriptions.get(project);
if (description == null) {
if (description == null || description.baseline != component.getBaseline()) {
if (Util.isApiProject(project)) {
description = new ProjectApiDescription(project);
description = new ProjectApiDescription(project, component.getBaseline());
} else {
description = new NonApiProjectDescription(project);
description = new NonApiProjectDescription(project, component.getBaseline());
}
try {
restoreDescription(project, description);
} catch (CoreException e) {
ApiPlugin.log(e.getStatus());
description = new ProjectApiDescription(project);
description = new ProjectApiDescription(project, component.getBaseline());
}
fDescriptions.put(project, description);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.pde.api.tools.internal.provisional.descriptors.IElementDescriptor;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiBaseline;

/**
* An API description for a project that does not have an API Tools nature.
Expand All @@ -26,9 +27,11 @@ public class NonApiProjectDescription extends ProjectApiDescription {

/**
* Constructs API description for the given project.
*
* @param baseline
*/
public NonApiProjectDescription(IJavaProject project) {
super(project);
NonApiProjectDescription(IJavaProject project, IApiBaseline baseline) {
super(project, baseline);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public class ProjectApiDescription extends ApiDescription {
*/
private volatile boolean fInSynch;

/**
* this holds the baseline this description is currently connected to
*/
IApiBaseline baseline;

/**
* A node for a package.
*/
Expand Down Expand Up @@ -328,10 +333,13 @@ public String toString() {

/**
* Constructs a new API description for the given project API component.
*
* @param baseline the baseline this description should be connected with
*/
public ProjectApiDescription(IJavaProject project) {
ProjectApiDescription(IJavaProject project, IApiBaseline baseline) {
super(project.getElementName());
fProject = project;
this.baseline = baseline;
}

@Override
Expand Down Expand Up @@ -527,12 +535,12 @@ ManifestNode newNode(ManifestNode parent, IElementDescriptor element, int vis, i
*/
void refreshPackages() {
if (fRefreshingInProgress) {
logPackafesRefresh();
logPackagesRefresh();
return;
}
synchronized (this) {
if (fRefreshingInProgress) {
logPackafesRefresh();
logPackagesRefresh();
return;
}
// check if in synch
Expand Down Expand Up @@ -569,7 +577,7 @@ void refreshPackages() {
}
}

private void logPackafesRefresh() {
private void logPackagesRefresh() {
if (ApiPlugin.DEBUG_API_DESCRIPTION) {
StringBuilder buffer = new StringBuilder();
buffer.append("Refreshing manifest node: "); //$NON-NLS-1$
Expand Down Expand Up @@ -706,8 +714,14 @@ public String toString() {
* @return API component
* @exception CoreException if the API component cannot be located
*/
private ProjectComponent getApiComponent() throws CoreException {
IApiBaseline baseline = ApiBaselineManager.getManager().getWorkspaceBaseline();
private synchronized ProjectComponent getApiComponent() throws CoreException {
if (baseline == null || baseline.isDisposed()) {
baseline = ApiBaselineManager.getManager().getWorkspaceBaseline();
}
return getApiComponent(baseline);
}

private ProjectComponent getApiComponent(IApiBaseline baseline) throws CoreException {
ProjectComponent component = (ProjectComponent) baseline.getApiComponent(getJavaProject().getProject());
if (component == null) {
throw new CoreException(Status.error("Unable to resolve project API component for API description")); //$NON-NLS-1$
Expand Down

0 comments on commit 4c5c75f

Please sign in to comment.