use of org.eclipse.core.resources.IWorkspaceRoot in project linuxtools by eclipse.
the class STLink2SourceSupport method getFileForPathImpl.
private static IFile getFileForPathImpl(IPath path, IProject project) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
if (path.isAbsolute()) {
return root.getFileForLocation(path);
}
if (project != null && project.exists()) {
ICProject cproject = CoreModel.getDefault().create(project);
if (cproject != null) {
try {
ISourceRoot[] roots = cproject.getAllSourceRoots();
for (ISourceRoot sourceRoot : roots) {
IContainer r = sourceRoot.getResource();
IResource res = r.findMember(path);
if (res != null && res.exists() && res instanceof IFile) {
return (IFile) res;
}
}
IOutputEntry[] entries = cproject.getOutputEntries();
for (IOutputEntry pathEntry : entries) {
IPath p = pathEntry.getPath();
IResource r = root.findMember(p);
if (r instanceof IContainer) {
IContainer parent = (IContainer) r;
IResource res = parent.findMember(path);
if (res != null && res.exists() && res instanceof IFile) {
return (IFile) res;
}
}
}
} catch (CModelException e) {
Activator.getDefault().getLog().log(e.getStatus());
}
}
}
// no match found...try and see if we are dealing with a link
IPath realPath = project.getLocation().append(path).makeAbsolute();
URI realURI = URIUtil.toURI(realPath.toString());
try {
FindLinkedResourceVisitor visitor = new STLink2SourceSupport.FindLinkedResourceVisitor(realURI);
project.accept(visitor, IResource.DEPTH_INFINITE);
// If we find a match, make note of the target and the real C project.
if (visitor.foundElement()) {
return (IFile) visitor.getResource();
}
} catch (CoreException e) {
}
return null;
}
use of org.eclipse.core.resources.IWorkspaceRoot in project linuxtools by eclipse.
the class RemoteProxyCMainTab method updateWorkingDirFromConfig.
protected void updateWorkingDirFromConfig(ILaunchConfiguration config) {
if (workingDirText != null) {
String projectDir = EMPTY_STRING;
try {
projectDir = config.getAttribute(ATTR_REMOTE_WORKING_DIRECTORY_NAME, EMPTY_STRING);
} catch (CoreException ce) {
ProfileLaunchPlugin.log(ce);
}
if (projectDir.equals(EMPTY_STRING)) {
if (this.fProjText != null) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject(this.fProjText.getText());
try {
projectDir = RemoteProxyManager.getInstance().getRemoteProjectLocation(project);
} catch (CoreException e) {
setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.error_accessing_working_directory);
}
}
}
workingDirText.setText(projectDir);
}
}
use of org.eclipse.core.resources.IWorkspaceRoot in project linuxtools by eclipse.
the class CProjectHelper method createCProject2.
/**
* Creates a ICProject.
*/
private static ICProject createCProject2(final String projectName, String binFolderName) throws CoreException {
final IWorkspace ws = ResourcesPlugin.getWorkspace();
final ICProject[] newProject = new ICProject[1];
ws.run((IWorkspaceRunnable) monitor -> {
IWorkspaceRoot root = ws.getRoot();
IProject project = root.getProject(projectName);
if (!project.exists()) {
project.create(null);
} else {
project.refreshLocal(IResource.DEPTH_INFINITE, null);
}
if (!project.isOpen()) {
project.open(null);
}
if (!project.hasNature(CProjectNature.C_NATURE_ID)) {
String projectId = PLUGIN_ID + ".TestProject";
addNatureToProject(project, CProjectNature.C_NATURE_ID, null);
CCorePlugin.getDefault().mapCProjectOwner(project, projectId, false);
}
addDefaultBinaryParser(project);
newProject[0] = CCorePlugin.getDefault().getCoreModel().create(project);
}, null);
return newProject[0];
}
use of org.eclipse.core.resources.IWorkspaceRoot in project linuxtools by eclipse.
the class ResourceHelper method cleanUp.
/**
* Clean-up any files created as part of a unit test.
* This method removes *all* Workspace IResources and any external
* files / folders created with the #createWorkspaceFile #createWorkspaceFolder
* methods in this class
*/
public static void cleanUp() throws CoreException {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
root.refreshLocal(IResource.DEPTH_INFINITE, NULL_MONITOR);
// Delete all external files & folders created using ResourceHelper
for (String loc : externalFilesCreated) {
File f = new File(loc);
if (f.exists())
deleteRecursive(f);
}
externalFilesCreated.clear();
// Remove IResources created by this helper
for (IResource r : resourcesCreated) {
if (r.exists()) {
try {
r.delete(true, NULL_MONITOR);
} catch (CoreException e) {
// Ignore
}
}
}
resourcesCreated.clear();
}
use of org.eclipse.core.resources.IWorkspaceRoot in project linuxtools by eclipse.
the class ProfileUIUtils method openEditorAndSelect.
/**
* Opens the specified file in an editor (or selects an already open
* editor) and highlights the specified line.
* @param result - result of performing source lookup with a org.eclipse.debug.core.model.ISourceLocator
* @param line - line number to select, 0 to not select a line
* @throws PartInitException - Failed to open editor
* @throws BadLocationException - Line number not valid in file
* @see DebugUITools#lookupSource(Object, org.eclipse.debug.core.model.ISourceLocator)
*/
public static void openEditorAndSelect(ISourceLookupResult result, int line) throws PartInitException, BadLocationException {
IEditorInput input = result.getEditorInput();
String editorID = result.getEditorId();
if (input == null || editorID == null) {
// Consult the CDT DebugModelPresentation
Object sourceElement = result.getSourceElement();
if (sourceElement != null) {
// Resolve IResource in case we get a LocalFileStorage object
if (sourceElement instanceof LocalFileStorage) {
IPath filePath = ((LocalFileStorage) sourceElement).getFullPath();
URI fileURI = URIUtil.toURI(filePath);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IFile[] files = root.findFilesForLocationURI(fileURI);
if (files.length > 0) {
// Take the first match
sourceElement = files[0];
}
}
IDebugModelPresentation pres = DebugUITools.newDebugModelPresentation(CDebugCorePlugin.getUniqueIdentifier());
input = pres.getEditorInput(sourceElement);
editorID = pres.getEditorId(input, sourceElement);
pres.dispose();
}
}
if (input != null && editorID != null) {
// Open the editor
IWorkbenchPage activePage = ProfileUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart editor = IDE.openEditor(activePage, input, editorID);
// Select the line
if (editor instanceof ITextEditor) {
ITextEditor textEditor = (ITextEditor) editor;
if (line > 0) {
IDocumentProvider provider = textEditor.getDocumentProvider();
IDocument document = provider.getDocument(textEditor.getEditorInput());
// zero-indexed
IRegion lineRegion = document.getLineInformation(line - 1);
textEditor.selectAndReveal(lineRegion.getOffset(), lineRegion.getLength());
}
}
}
}
Aggregations