Skip to content

Commit

Permalink
[API-Tools] Determine reliably if a project is a binary project
Browse files Browse the repository at this point in the history
Fixes #789
  • Loading branch information
HannesWell authored and laeubi committed Oct 8, 2023
1 parent 7c33f3e commit bcf2c51
Showing 1 changed file with 7 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
Expand Down Expand Up @@ -115,37 +115,20 @@ public static IApiComponent newApiComponent(IApiBaseline baseline, IPluginModelB
if (location == null) {
return null;
}
BundleComponent component = null;
if (isBinaryProject(location)) {
component = new BundleComponent(baseline, location, getBundleID());
} else {
BundleComponent component;
IResource resource = model.getUnderlyingResource();
IProject project = resource != null ? resource.getProject() : null;
if (project != null && project.exists() && !Util.isBinaryProject(project)) {
component = new ProjectComponent(baseline, location, model, getBundleID());
} else {
component = new BundleComponent(baseline, location, getBundleID());
}
if (component.isValidBundle()) {
return component;
}
return null;
}

/**
* Returns if the specified location is an imported binary project.
* <p>
* We accept projects that are plug-ins even if not API enabled (i.e. with
* API nature), as we still need them to make a complete API baseline
* without resolution errors.
* </p>
*
* @param location
* @return true if the location is an imported binary project, false
* otherwise
* @throws CoreException
*/
private static boolean isBinaryProject(String location) throws CoreException {
IPath path = IPath.fromOSString(location);
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(path.lastSegment());
return project != null && (!project.exists() || Util.isBinaryProject(project));
}

/**
* Creates a new empty {@link IApiBaseline} with the given name. Its
* execution environment will be automatically resolved when components are
Expand Down

0 comments on commit bcf2c51

Please sign in to comment.