Search in sources :

Example 46 with IWorkspaceRoot

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);
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IProject(org.eclipse.core.resources.IProject)

Example 47 with IWorkspaceRoot

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;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IPath(org.eclipse.core.runtime.IPath) SubMonitor(org.eclipse.core.runtime.SubMonitor) IProject(org.eclipse.core.resources.IProject) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 48 with IWorkspaceRoot

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);
    }
}
Also used : Path(org.eclipse.xtend.lib.macro.file.Path) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test) JavaIoFileSystemTest(org.eclipse.xtend.ide.tests.macros.JavaIoFileSystemTest)

Example 49 with IWorkspaceRoot

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);
    }
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IProject(org.eclipse.core.resources.IProject) After(org.junit.After)

Example 50 with IWorkspaceRoot

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);
}
Also used : IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IProject(org.eclipse.core.resources.IProject)

Aggregations

IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)172 IProject (org.eclipse.core.resources.IProject)69 IPath (org.eclipse.core.runtime.IPath)60 IResource (org.eclipse.core.resources.IResource)57 IFile (org.eclipse.core.resources.IFile)53 CoreException (org.eclipse.core.runtime.CoreException)50 IWorkspace (org.eclipse.core.resources.IWorkspace)34 File (java.io.File)30 Path (org.eclipse.core.runtime.Path)29 IContainer (org.eclipse.core.resources.IContainer)26 URI (java.net.URI)18 IFolder (org.eclipse.core.resources.IFolder)17 IOException (java.io.IOException)15 IProjectDescription (org.eclipse.core.resources.IProjectDescription)13 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)13 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)12 IStatus (org.eclipse.core.runtime.IStatus)11 IJavaProject (org.eclipse.jdt.core.IJavaProject)11 Location (ch.acanda.eclipse.pmd.domain.Location)10