Search in sources :

Example 21 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription 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 22 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project linuxtools by eclipse.

the class RemoteProxyNatureMapping method getSchemeFromNature.

public String getSchemeFromNature(IProject project) throws CoreException {
    IProjectDescription description = project.getDescription();
    String[] natures = description.getNatureIds();
    IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(ProfileLaunchPlugin.PLUGIN_ID, EXTENSION_POINT_ID);
    IConfigurationElement[] infos = extensionPoint.getConfigurationElements();
    for (int i = 0; i < infos.length; i++) {
        IConfigurationElement configurationElement = infos[i];
        if (configurationElement.getName().equals(MANAGER_NAME)) {
            for (int j = 0; j < natures.length; j++) {
                if (configurationElement.getAttribute(NATURE_ID).equals(natures[j])) {
                    return configurationElement.getAttribute(SCHEME_ID);
                }
            }
        }
    }
    return null;
}
Also used : IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint)

Example 23 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project linuxtools by eclipse.

the class CProjectHelper method addNatureToProject.

private static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException {
    IProjectDescription description = proj.getDescription();
    String[] prevNatures = description.getNatureIds();
    String[] newNatures = new String[prevNatures.length + 1];
    System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
    newNatures[prevNatures.length] = natureId;
    description.setNatureIds(newNatures);
    proj.setDescription(description, monitor);
}
Also used : IProjectDescription(org.eclipse.core.resources.IProjectDescription)

Example 24 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project linuxtools by eclipse.

the class CProjectHelper method addNatureToProject.

private static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException {
    IProjectDescription description = proj.getDescription();
    String[] prevNatures = description.getNatureIds();
    String[] newNatures = new String[prevNatures.length + 1];
    System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
    newNatures[prevNatures.length] = natureId;
    description.setNatureIds(newNatures);
    proj.setDescription(description, monitor);
}
Also used : IProjectDescription(org.eclipse.core.resources.IProjectDescription)

Example 25 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project linuxtools by eclipse.

the class RPMProjectCreator method create.

/**
 * Creates a project with the given name in the given location.
 *
 * @param projectName
 *            The name of the project.
 * @param projectPath
 *            The parent location of the project.
 * @param monitor
 *            Progress monitor to report back status.
 * @return The newly created project.
 * @throws CoreException If the location is wrong.
 */
public IProject create(String projectName, IPath projectPath, IProgressMonitor monitor) throws CoreException {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IProject project = root.getProject(projectName);
    IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(project.getName());
    String parsedIPathString = null;
    if (!Platform.getLocation().equals(projectPath)) {
        // $NON-NLS-1$ //$NON-NLS-2$
        parsedIPathString = projectPath.toString().replaceFirst(":/", "://");
        try {
            description.setLocationURI(new URI(parsedIPathString));
        } catch (URISyntaxException e) {
            throw new CoreException(new Status(IStatus.ERROR, IRPMConstants.RPM_CORE_ID, e.getMessage(), e));
        }
    }
    description.setNatureIds(new String[] { IRPMConstants.RPM_NATURE_ID });
    project.create(description, monitor);
    monitor.worked(10);
    project.open(monitor);
    new RPMProject(project, layout);
    return project;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IProjectDescription(org.eclipse.core.resources.IProjectDescription) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) IProject(org.eclipse.core.resources.IProject)

Aggregations

IProjectDescription (org.eclipse.core.resources.IProjectDescription)68 IProject (org.eclipse.core.resources.IProject)35 CoreException (org.eclipse.core.runtime.CoreException)18 IWorkspace (org.eclipse.core.resources.IWorkspace)16 IPath (org.eclipse.core.runtime.IPath)13 ICommand (org.eclipse.core.resources.ICommand)12 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)11 File (java.io.File)9 IStatus (org.eclipse.core.runtime.IStatus)9 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 Path (org.eclipse.core.runtime.Path)8 Status (org.eclipse.core.runtime.Status)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 URI (java.net.URI)5 IResource (org.eclipse.core.resources.IResource)5 Test (org.junit.Test)5 HashSet (java.util.HashSet)4 InputStream (java.io.InputStream)3 IFile (org.eclipse.core.resources.IFile)3 Resource (org.eclipse.emf.ecore.resource.Resource)3