Search in sources :

Example 46 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project translationstudio8 by heartsome.

the class ImportProjectWizardPage method createExistingProject.

/**
	 * Create the project described in record. If it is successful return true.
	 * 
	 * @param record
	 * @return boolean <code>true</code> if successful
	 * @throws InterruptedException
	 */
private boolean createExistingProject(final ProjectRecord record, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    String projectName = record.getProjectName();
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IProject project = workspace.getRoot().getProject(projectName);
    createdProjects.add(project);
    if (record.description == null) {
        // error case
        record.description = workspace.newProjectDescription(projectName);
        IPath locationPath = new Path(record.projectSystemFile.getAbsolutePath());
        // If it is under the root use the default location
        if (Platform.getLocation().isPrefixOf(locationPath)) {
            record.description.setLocation(null);
        } else {
            record.description.setLocation(locationPath);
        }
    } else {
        record.description.setName(projectName);
    }
    if (record.projectArchiveFile != null) {
        // import from archive
        List fileSystemObjects = structureProvider.getChildren(record.parent);
        structureProvider.setStrip(record.level);
        ImportOperation operation = new ImportOperation(project.getFullPath(), structureProvider.getRoot(), structureProvider, this, fileSystemObjects);
        operation.setContext(getShell());
        operation.run(monitor);
        return true;
    }
    // import from file system
    File importSource = null;
    if (copyFiles) {
        // import project from location copying files - use default project
        // location for this workspace
        URI locationURI = record.description.getLocationURI();
        // some error condition occured.
        if (locationURI != null) {
            // validate the location of the project being copied
            IStatus result = ResourcesPlugin.getWorkspace().validateProjectLocationURI(project, locationURI);
            if (!result.isOK())
                throw new InvocationTargetException(new CoreException(result));
            importSource = new File(locationURI);
            IProjectDescription desc = workspace.newProjectDescription(projectName);
            desc.setBuildSpec(record.description.getBuildSpec());
            desc.setComment(record.description.getComment());
            desc.setDynamicReferences(record.description.getDynamicReferences());
            desc.setNatureIds(record.description.getNatureIds());
            desc.setReferencedProjects(record.description.getReferencedProjects());
            record.description = desc;
        }
    }
    try {
        monitor.beginTask(DataTransferMessages.WizardProjectsImportPage_CreateProjectsTask, 100);
        project.create(record.description, new SubProgressMonitor(monitor, 30));
        project.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 70));
    } catch (CoreException e) {
        throw new InvocationTargetException(e);
    } finally {
        monitor.done();
    }
    // import operation to import project files if copy checkbox is selected
    if (copyFiles && importSource != null) {
        List filesToImport = FileSystemStructureProvider.INSTANCE.getChildren(importSource);
        ImportOperation operation = new ImportOperation(project.getFullPath(), importSource, FileSystemStructureProvider.INSTANCE, this, filesToImport);
        operation.setContext(getShell());
        // need to overwrite
        operation.setOverwriteResources(true);
        // .project, .classpath
        // files
        operation.setCreateContainerStructure(false);
        operation.run(monitor);
    }
    return true;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) ImportOperation(org.eclipse.ui.wizards.datatransfer.ImportOperation) URI(java.net.URI) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) List(java.util.List) ArrayList(java.util.ArrayList) ZipFile(java.util.zip.ZipFile) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) File(java.io.File)

Example 47 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project ow by vtst.

the class Utils method setProjectNature.

/**
   * Set or remove a nature to a project.
   * @param project  The project.
   * @param nature  The ID of the nature.
   * @param status  true to set the nature, false to remove it.
   * @throws CoreException
   */
public static void setProjectNature(IProject project, String nature, boolean status) throws CoreException {
    IProjectDescription description = project.getDescription();
    String[] newNatures = setFlagInArrayOfFlags(description.getNatureIds(), nature, status);
    if (newNatures != null) {
        description.setNatureIds(newNatures);
        project.setDescription(description, null);
    }
}
Also used : IProjectDescription(org.eclipse.core.resources.IProjectDescription)

Example 48 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project XobotOS by xamarin.

the class SharpenNature method deconfigure.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.core.resources.IProjectNature#deconfigure()
	 */
public void deconfigure() throws CoreException {
    IProjectDescription description = getProject().getDescription();
    ICommand[] commands = description.getBuildSpec();
    for (int i = 0; i < commands.length; ++i) {
        if (commands[i].getBuilderName().equals(SharpenBuilder.BUILDER_ID)) {
            ICommand[] newCommands = new ICommand[commands.length - 1];
            System.arraycopy(commands, 0, newCommands, 0, i);
            System.arraycopy(commands, i + 1, newCommands, i, commands.length - i - 1);
            description.setBuildSpec(newCommands);
            return;
        }
    }
}
Also used : ICommand(org.eclipse.core.resources.ICommand) IProjectDescription(org.eclipse.core.resources.IProjectDescription)

Example 49 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project XobotOS by xamarin.

the class SharpenNature method configure.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.core.resources.IProjectNature#configure()
	 */
public void configure() throws CoreException {
    IProjectDescription desc = _project.getDescription();
    ICommand[] commands = desc.getBuildSpec();
    if (containsBuilderCommand(commands))
        return;
    desc.setBuildSpec(append(commands, newBuilderCommand(desc)));
    _project.setDescription(desc, null);
}
Also used : ICommand(org.eclipse.core.resources.ICommand) IProjectDescription(org.eclipse.core.resources.IProjectDescription)

Example 50 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project mechanoid by robotoworks.

the class MechanoidXtextAddingEditorCallback method toggleNature.

public void toggleNature(IProject project) {
    try {
        IProjectDescription description = project.getDescription();
        String[] natures = description.getNatureIds();
        for (int i = 0; i < natures.length; ++i) {
            if (XtextProjectHelper.NATURE_ID.equals(natures[i])) {
                // Remove the nature
                String[] newNatures = new String[natures.length - 1];
                System.arraycopy(natures, 0, newNatures, 0, i);
                System.arraycopy(natures, i + 1, newNatures, i, natures.length - i - 1);
                description.setNatureIds(newNatures);
                project.setDescription(description, null);
                return;
            }
        }
        // Add the nature
        String[] newNatures = new String[natures.length + 1];
        System.arraycopy(natures, 0, newNatures, 0, natures.length);
        newNatures[natures.length] = XtextProjectHelper.NATURE_ID;
        description.setNatureIds(newNatures);
        project.setDescription(description, null);
    } catch (CoreException e) {
        log.error(e);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IProjectDescription(org.eclipse.core.resources.IProjectDescription)

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