Search in sources :

Example 6 with ICProject

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);
}
Also used : IDebugModelPresentation(org.eclipse.debug.ui.IDebugModelPresentation) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) IDE(org.eclipse.ui.ide.IDE) CDebugCorePlugin(org.eclipse.cdt.debug.core.CDebugCorePlugin) HashMap(java.util.HashMap) CoreException(org.eclipse.core.runtime.CoreException) DebugUITools(org.eclipse.debug.ui.DebugUITools) ArrayList(java.util.ArrayList) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IDocument(org.eclipse.jface.text.IDocument) CCorePlugin(org.eclipse.cdt.core.CCorePlugin) IProject(org.eclipse.core.resources.IProject) IPath(org.eclipse.core.runtime.IPath) PartInitException(org.eclipse.ui.PartInitException) Map(java.util.Map) IndexFilter(org.eclipse.cdt.core.index.IndexFilter) IFile(org.eclipse.core.resources.IFile) BadLocationException(org.eclipse.jface.text.BadLocationException) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) URI(java.net.URI) IIndexFile(org.eclipse.cdt.core.index.IIndexFile) RemoteProxyManager(org.eclipse.linuxtools.profiling.launch.RemoteProxyManager) ICProject(org.eclipse.cdt.core.model.ICProject) EFS(org.eclipse.core.filesystem.EFS) IEditorPart(org.eclipse.ui.IEditorPart) IFunction(org.eclipse.cdt.core.dom.ast.IFunction) IFileStore(org.eclipse.core.filesystem.IFileStore) IBinding(org.eclipse.cdt.core.dom.ast.IBinding) LocalFileStorage(org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage) IRegion(org.eclipse.jface.text.IRegion) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IEditorInput(org.eclipse.ui.IEditorInput) ICElement(org.eclipse.cdt.core.model.ICElement) ProfileUIPlugin(org.eclipse.linuxtools.internal.profiling.ui.ProfileUIPlugin) IOException(java.io.IOException) ISourceLookupResult(org.eclipse.debug.ui.sourcelookup.ISourceLookupResult) File(java.io.File) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IIndexName(org.eclipse.cdt.core.index.IIndexName) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) IIndexManager(org.eclipse.cdt.core.index.IIndexManager) Path(org.eclipse.core.runtime.Path) ICElementVisitor(org.eclipse.cdt.core.model.ICElementVisitor) IIndex(org.eclipse.cdt.core.index.IIndex) URIUtil(org.eclipse.core.filesystem.URIUtil) ICElementVisitor(org.eclipse.cdt.core.model.ICElementVisitor) ICProject(org.eclipse.cdt.core.model.ICProject) ArrayList(java.util.ArrayList)

Example 7 with ICProject

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);
    }
}
Also used : ICProject(org.eclipse.cdt.core.model.ICProject) CoreException(org.eclipse.core.runtime.CoreException) RemoteConnectionException(org.eclipse.remote.core.exception.RemoteConnectionException)

Example 8 with ICProject

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 "";
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) ICProject(org.eclipse.cdt.core.model.ICProject) CModelException(org.eclipse.cdt.core.model.CModelException) IOException(java.io.IOException) IBinary(org.eclipse.cdt.core.model.IBinary) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 9 with ICProject

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) ICProject(org.eclipse.cdt.core.model.ICProject) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) IBinary(org.eclipse.cdt.core.model.IBinary) IOException(java.io.IOException) URI(java.net.URI) IProject(org.eclipse.core.resources.IProject) CovManager(org.eclipse.linuxtools.internal.gcov.parser.CovManager) CoreException(org.eclipse.core.runtime.CoreException) SourceFile(org.eclipse.linuxtools.internal.gcov.parser.SourceFile) IResource(org.eclipse.core.resources.IResource)

Example 10 with ICProject

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;
    }
}
Also used : ICProject(org.eclipse.cdt.core.model.ICProject) CoreException(org.eclipse.core.runtime.CoreException) IBinary(org.eclipse.cdt.core.model.IBinary)

Aggregations

ICProject (org.eclipse.cdt.core.model.ICProject)18 CoreException (org.eclipse.core.runtime.CoreException)14 IProject (org.eclipse.core.resources.IProject)10 IResource (org.eclipse.core.resources.IResource)10 IBinary (org.eclipse.cdt.core.model.IBinary)7 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)6 IPath (org.eclipse.core.runtime.IPath)6 CCorePlugin (org.eclipse.cdt.core.CCorePlugin)5 ICProjectDescription (org.eclipse.cdt.core.settings.model.ICProjectDescription)5 IFile (org.eclipse.core.resources.IFile)5 IWorkspace (org.eclipse.core.resources.IWorkspace)5 ResourcesPlugin (org.eclipse.core.resources.ResourcesPlugin)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)5 CCProjectNature (org.eclipse.cdt.core.CCProjectNature)4 CProjectNature (org.eclipse.cdt.core.CProjectNature)4 CModelException (org.eclipse.cdt.core.model.CModelException)4 ICConfigExtensionReference (org.eclipse.cdt.core.settings.model.ICConfigExtensionReference)4 IProjectDescription (org.eclipse.core.resources.IProjectDescription)4 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)4 Path (org.eclipse.core.runtime.Path)4