use of org.eclipse.cdt.core.model.ICProject in project linuxtools by eclipse.
the class ProfileUIUtils method findCProjectWithAbsolutePath.
/**
* Find an ICProject that contains the specified absolute path.
*
* @param absPath An absolute path (usually to some file/folder in a project)
* @return an ICProject corresponding to the project that contains the absolute path
* @throws CoreException can be thrown if visiting (accepting) a project walking the ICElement tree fails.
*/
public static ICProject findCProjectWithAbsolutePath(final String absPath) throws CoreException {
final String workspaceLoc = ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString();
final ArrayList<ICProject> ret = new ArrayList<>();
// visitor object to check for the matching path string
ICElementVisitor vis = element -> {
if (element.getElementType() == ICElement.C_CCONTAINER || element.getElementType() == ICElement.C_PROJECT) {
return true;
} else if (absPath.equals(workspaceLoc + element.getPath().toFile().getAbsolutePath())) {
ret.add(element.getCProject());
}
return false;
};
ICProject[] cProjects = CCorePlugin.getDefault().getCoreModel().getCModel().getCProjects();
for (ICProject proj : cProjects) {
// visit every project
proj.accept(vis);
}
// is it possible to find more than one matching project ?
return ret.isEmpty() ? null : ret.get(0);
}
use of org.eclipse.cdt.core.model.ICProject in project linuxtools by eclipse.
the class AbstractProxyTest method createTestProjects.
protected void createTestProjects() {
if (localProject == null) {
try {
localProject = createProject(Platform.getBundle(PLUGIN), "localTestProject");
} catch (Exception e) {
fail("Failed to create local project for the tests: " + e.getMessage());
}
assertNotNull(localProject);
}
if (syncProject == null) {
ICProject project = null;
try {
project = createProject(Platform.getBundle(PLUGIN), "syncTestProject");
convertToSyncProject(project.getProject(), connection, "/tmp/" + PLUGIN);
} catch (Exception e) {
fail("Failed to create synchronized project for the tests: " + e.getMessage());
}
syncProject = project;
assertNotNull(syncProject);
}
}
use of org.eclipse.cdt.core.model.ICProject in project linuxtools by eclipse.
the class OpenGCAction method getDefaultBinary.
private String getDefaultBinary(IPath file) {
IFile c = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(file);
if (c != null) {
IProject project = c.getProject();
if (project != null && project.exists()) {
IContainer folder = c.getParent();
// $NON-NLS-1$
IFile infoFile = folder.getFile(new Path("AnalysisInfo.txt"));
try {
String defaultBinaryFromUserPref = getDefaultBinaryFromUserPref(project, infoFile);
if (defaultBinaryFromUserPref != null) {
return defaultBinaryFromUserPref;
}
} catch (IOException | CoreException ex) {
// do nothing here.
}
ICProject cproject = CoreModel.getDefault().create(project);
if (cproject != null) {
try {
IBinary[] b = cproject.getBinaryContainer().getBinaries();
if (b != null && b.length > 0 && b[0] != null) {
IResource r = b[0].getResource();
return r.getLocation().toOSString();
}
} catch (CModelException e) {
}
}
}
}
// $NON-NLS-1$
return "";
}
use of org.eclipse.cdt.core.model.ICProject in project linuxtools by eclipse.
the class GcovAnnotationModel method findSourceCoverageForElement.
private SourceFile findSourceCoverageForElement(ICElement element) {
List<SourceFile> sources = new ArrayList<>();
ICProject cProject = element.getCProject();
IResource elementResource = element.getResource();
IPath target = GcovAnnotationModelTracker.getInstance().getBinaryPath(cProject.getProject());
if (target == null) {
// We cannot find a target for this element, using it's project.
// This can be caused by linking in a file to the project which may
// not have a project or may point to another unseen project if the file originated
// there.
IProject[] trackedProjects = GcovAnnotationModelTracker.getInstance().getTrackedProjects();
for (IProject proj : trackedProjects) {
// element is linked in.
try {
FindLinkedResourceVisitor visitor = new FindLinkedResourceVisitor(element);
proj.accept(visitor, IResource.DEPTH_INFINITE);
// If we find a match, make note of the target and the real C project.
if (visitor.foundElement()) {
target = GcovAnnotationModelTracker.getInstance().getBinaryPath(proj);
cProject = CoreModel.getDefault().getCModel().getCProject(proj.getName());
elementResource = visitor.getResource();
break;
}
} catch (CoreException e) {
}
}
if (target == null) {
return null;
}
}
try {
IBinary[] binaries = cProject.getBinaryContainer().getBinaries();
for (IBinary b : binaries) {
if (b.getResource().getLocation().equals(target)) {
CovManager covManager = new CovManager(b.getResource().getLocation().toOSString());
covManager.processCovFiles(covManager.getGCDALocations(), null);
sources.addAll(covManager.getAllSrcs());
}
}
} catch (IOException | CoreException | InterruptedException e) {
}
if (elementResource != null) {
IPath elementLocation = elementResource.getLocation();
if (elementLocation != null) {
for (SourceFile sf : sources) {
IPath sfPath = new Path(sf.getName());
IFile file = STLink2SourceSupport.getFileForPath(sfPath, cProject.getProject());
if (file != null && elementLocation.equals(file.getLocation())) {
return sf;
}
// the sources. Fixes Bug 447554
if (!sfPath.isAbsolute()) {
sfPath = target.removeLastSegments(1).append(sf.getName());
if (elementLocation.equals(sfPath.makeAbsolute()) && sfPath.toFile().exists())
return sf;
}
}
}
}
URI elementURI = element.getLocationURI();
if (elementURI != null) {
IPath binFolder = target.removeLastSegments(1);
for (SourceFile sf : sources) {
String sfPath = Paths.get(binFolder.toOSString()).resolve(sf.getName()).normalize().toString();
if (sfPath.equals(elementURI.getPath())) {
return sf;
}
}
}
return null;
}
use of org.eclipse.cdt.core.model.ICProject in project linuxtools by eclipse.
the class SystemTapOptionsTab method getBinary.
private IBinary getBinary(ILaunchConfiguration config) {
try {
ICProject project = CDebugUtils.verifyCProject(config);
IBinary[] binaries = project.getBinaryContainer().getBinaries();
if (binaries != null && binaries.length > 0) {
if (binaries.length == 1 && binaries[0] != null) {
return binaries[0];
} else
return chooseBinary(binaries);
}
return null;
} catch (CoreException e) {
return null;
}
}
Aggregations