use of org.eclipse.core.resources.IWorkspaceRoot in project eclipse.platform.text by eclipse.
the class ResourceHelper method deleteProject.
public static void deleteProject(String projectName) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject(projectName);
if (project.exists())
delete(project);
}
use of org.eclipse.core.resources.IWorkspaceRoot in project eclipse.platform.text by eclipse.
the class ContainerCreator method createContainer.
/**
* Creates this container.
*
* @param progressMonitor the progress monitor or <code>null</code> if none
* @return the container specified by this container creator's full path
* @throws CoreException if this container creator's full path denotes a file or creating
* either the project or folders for the given container fails
*/
public IContainer createContainer(IProgressMonitor progressMonitor) throws CoreException {
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
SubMonitor subMonitor = SubMonitor.convert(monitor, FileBuffersMessages.ContainerCreator_task_creatingContainer, fContainerFullPath.segmentCount());
if (fContainer != null)
return;
// Does the container exist already?
IWorkspaceRoot root = fWorkspace.getRoot();
IResource found = root.findMember(fContainerFullPath);
if (found instanceof IContainer) {
fContainer = (IContainer) found;
return;
} else if (found != null) {
// fContainerFullPath specifies a file as directory
throw new CoreException(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, NLSUtility.format(FileBuffersMessages.ContainerCreator_destinationMustBeAContainer, fContainerFullPath), null));
}
// Create the containers for the given path
fContainer = root;
for (int i = 0; i < fContainerFullPath.segmentCount(); i++) {
String currentSegment = fContainerFullPath.segment(i);
IResource resource = fContainer.findMember(currentSegment);
if (resource != null) {
if (resource instanceof IContainer) {
fContainer = (IContainer) resource;
subMonitor.split(1);
} else {
// fContainerFullPath specifies a file as directory
throw new CoreException(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, NLSUtility.format(FileBuffersMessages.ContainerCreator_destinationMustBeAContainer, resource.getFullPath()), null));
}
} else {
if (i == 0) {
IProject projectHandle = createProjectHandle(root, currentSegment);
fContainer = createProject(projectHandle, subMonitor.split(1));
} else {
IFolder folderHandle = createFolderHandle(fContainer, currentSegment);
fContainer = createFolder(folderHandle, subMonitor.split(1));
}
}
}
}
};
// Get scheduling rule
IWorkspaceRoot root = fWorkspace.getRoot();
IPath existingParentPath = fContainerFullPath;
while (!root.exists(existingParentPath)) existingParentPath = existingParentPath.removeLastSegments(1);
IResource schedulingRule = root.findMember(existingParentPath);
fWorkspace.run(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, progressMonitor);
return fContainer;
}
use of org.eclipse.core.resources.IWorkspaceRoot in project xtext-xtend by eclipse.
the class EclipseFileSystemTest method testGetURIForImportedProject.
@Test
public void testGetURIForImportedProject() {
try {
final IWorkspace ws = ResourcesPlugin.getWorkspace();
final IWorkspaceRoot root = ws.getRoot();
final IProjectDescription description = ws.newProjectDescription("bar");
description.setLocation(root.getLocation().append("foo/bar"));
final IProject project = root.getProject("bar");
project.create(description, null);
project.open(null);
final Path file = new Path("/bar/Foo.text");
Assert.assertFalse(this.fs.exists(file));
Assert.assertNull(this.fs.toURI(file));
try {
this.fs.setContents(file, "Hello Foo");
Assert.fail();
} catch (final Throwable _t) {
if (_t instanceof IllegalArgumentException) {
} else {
throw Exceptions.sneakyThrow(_t);
}
}
Assert.assertFalse(this.fs.exists(file));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.core.resources.IWorkspaceRoot in project xtext-xtend by eclipse.
the class EclipseFileSystemTest method tearDown.
@After
public void tearDown() {
try {
final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject[] _projects = root.getProjects();
for (final IProject p : _projects) {
boolean _remove = this.knownProjects.remove(p.getName());
boolean _not = (!_remove);
if (_not) {
p.delete(true, null);
}
}
Assert.assertTrue(this.knownProjects.isEmpty());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.core.resources.IWorkspaceRoot in project linuxtools by eclipse.
the class STLink2SourceSupport method openSourceFileAtLocation.
/**
* Open a C Editor at the given location.
*
* @param binaryLoc A path to a binary file.
* @param sourceLoc The location of the source file.
* @param lineNumber The line to open at.
* @return <code>true</code> if the link-to-source was successful, <code>false</code> otherwise
*/
private static boolean openSourceFileAtLocation(IPath binaryLoc, IPath sourceLoc, int lineNumber) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IFile binary = root.getFileForLocation(binaryLoc);
IProject project = null;
if (binary != null) {
project = binary.getProject();
}
return openFileImpl(project, sourceLoc, lineNumber);
}
Aggregations