Search in sources :

Example 31 with IProjectDescription

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

the class ProjectInitializationRule method getTargetWorkspaceProject.

/**
 * Creates or opens the project in the target/JUnit workspace.
 *
 * @param projectSourcePath
 *            the absolute path to the project
 * @param targetWorkspace
 *            the target workspace in which the project should be created
 * @return the project
 * @throws CoreException
 * @throws InvocationTargetException
 * @throws InterruptedException
 */
public static IProject getTargetWorkspaceProject(final IPath projectSourcePath, final IWorkspace targetWorkspace) throws CoreException, InvocationTargetException, InterruptedException {
    final IPath dotProjectPath = projectSourcePath.addTrailingSeparator().append(".project");
    final IProjectDescription description = targetWorkspace.loadProjectDescription(dotProjectPath);
    final String projectName = description.getName();
    final IProject project = targetWorkspace.getRoot().getProject(projectName);
    if (project.exists() && !targetWorkspace.getRoot().getFile(project.getFile(".project").getFullPath()).exists()) {
        project.delete(true, null);
    } else if (project.exists() && !project.isOpen()) {
        project.open(null);
    } else if (!project.exists()) {
        createProject(description, projectName, targetWorkspace, project);
        final SyncFileSystemStructureProvider syncFileSystemStructureProvider = new SyncFileSystemStructureProvider.Builder(projectSourcePath, project.getLocation()).ignoreRelativeSourcePaths(".svn", ".git", "target", "bin").build();
        final List<File> filesToImport = syncFileSystemStructureProvider.getChildren(projectSourcePath.toFile());
        if (filesToImport != null && filesToImport.size() > 0) {
            ImportOperation operation = new ImportOperation(project.getFullPath(), projectSourcePath.toFile(), syncFileSystemStructureProvider, pathString -> IOverwriteQuery.YES, filesToImport);
            operation.setContext(null);
            // need to overwrite modified files
            operation.setOverwriteResources(true);
            operation.setCreateContainerStructure(false);
            operation.run(null);
        }
    }
    return project;
}
Also used : IPath(org.eclipse.core.runtime.IPath) IncrementalProjectBuilder(org.eclipse.core.resources.IncrementalProjectBuilder) ImportOperation(org.eclipse.ui.wizards.datatransfer.ImportOperation) IProjectDescription(org.eclipse.core.resources.IProjectDescription) File(java.io.File) IProject(org.eclipse.core.resources.IProject)

Example 32 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project knime-core by knime.

the class MetaInfoFile method createKnimeProject.

/**
 * Creates a new workflow group project (with the referring nature).
 * @param name name of the project
 * @param natureId one of {@link KNIMEProjectNature}
 *  or {@link KNIMEWorkflowSetProjectNature}
 * @return the created project (already open and with description)
 * @throws CoreException if something goes wrong
 *
 * @see KNIMEWorkflowSetProjectNature
 */
public static IProject createKnimeProject(final String name, final String natureId) throws CoreException {
    if (!KNIMEProjectNature.ID.equals(natureId) && !KNIMEWorkflowSetProjectNature.ID.equals(natureId)) {
        throw new IllegalArgumentException("Unsupported project nature " + natureId + ". " + "Only KnimeProjectNature and " + "KnimeWorkflowSetProjectNature are supported!");
    }
    IProject newProject = null;
    try {
        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
        newProject = root.getProject(name);
        newProject.create(null);
        newProject.open(null);
        IProjectDescription desc = newProject.getDescription();
        desc.setNatureIds(new String[] { natureId });
        newProject.setDescription(desc, null);
    } catch (CoreException e) {
        LOGGER.error("Error while creating project " + name, e);
        throw e;
    }
    return newProject;
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IProject(org.eclipse.core.resources.IProject)

Example 33 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project knime-core by knime.

the class WorkflowGroupCreationOperation method execute.

/**
 * {@inheritDoc}
 */
@Override
protected void execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
    ContainerGenerator generator = new ContainerGenerator(m_targetPath);
    m_resultContainer = generator.generateContainer(monitor);
    if (m_resultContainer instanceof IProject) {
        // get project description
        // set nature
        // set description
        final IProject project = (IProject) m_resultContainer;
        IProjectDescription desc = project.getDescription();
        desc.setNatureIds(new String[] { KNIMEWorkflowSetProjectNature.ID });
        project.setDescription(desc, monitor);
    // only one workflow group can be created at a time
    // -> thus, only necessary to create this meta info file
    }
    // this has to be done in any case!
    MetaInfoFile.createMetaInfoFile(new File(m_resultContainer.getLocationURI()), false);
    m_resultContainer.refreshLocal(IResource.DEPTH_ONE, monitor);
}
Also used : ContainerGenerator(org.eclipse.ui.dialogs.ContainerGenerator) IProjectDescription(org.eclipse.core.resources.IProjectDescription) File(java.io.File) MetaInfoFile(org.knime.workbench.ui.metainfo.model.MetaInfoFile) IProject(org.eclipse.core.resources.IProject)

Example 34 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project knime-core by knime.

the class WorkflowImportOperation method handleLinkedProject.

private void handleLinkedProject(final IWorkflowImportElement importElement, final IProgressMonitor monitor) throws CoreException, IOException {
    // link to the referring destination
    if (!m_targetPath.equals(Path.ROOT)) {
        throw new IllegalArgumentException("Workflows must be linked into " + "workspace root!");
    }
    if (!(importElement instanceof WorkflowImportElementFromFile)) {
        throw new IllegalArgumentException("Only unzipped workflows can be linked " + "into workspace root!");
    }
    WorkflowImportElementFromFile fileImportElement = (WorkflowImportElementFromFile) importElement;
    String projectName = importElement.getName();
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IProject project = workspace.getRoot().getProject(projectName);
    File projectDescrFile = new File(fileImportElement.getFile(), IProjectDescription.DESCRIPTION_FILE_NAME);
    FileInputStream io = new FileInputStream(projectDescrFile);
    IProjectDescription description = null;
    try {
        description = ResourcesPlugin.getWorkspace().loadProjectDescription(io);
    } finally {
        io.close();
    }
    if (description == null) {
        // error case
        description = workspace.newProjectDescription(projectName);
    }
    IPath locationPath = new Path(fileImportElement.getFile().getAbsolutePath());
    // If it is under the root use the default location
    if (Platform.getLocation().isPrefixOf(locationPath)) {
        description.setLocation(null);
    } else {
        description.setLocation(locationPath);
    }
    description.setName(projectName);
    project.create(description, new SubProgressMonitor(monitor, 30));
    project.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 70));
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) MetaInfoFile(org.knime.workbench.ui.metainfo.model.MetaInfoFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject) FileInputStream(java.io.FileInputStream) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 35 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project knime-core by knime.

the class WorkflowImportOperation method setProjectNature.

private void setProjectNature(final IWorkflowImportElement importElement) throws CoreException {
    // get name
    String projectName = importElement.getName();
    // get project
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IProject project = workspace.getRoot().getProject(projectName);
    if (!project.exists()) {
        // project description for it
        assert importElement.getRenamedPath().segmentCount() > 1;
        return;
    }
    IProjectDescription description = project.getDescription();
    if (description == null) {
        description = workspace.newProjectDescription(projectName);
    }
    String natureId = KNIMEWorkflowSetProjectNature.ID;
    // check whether workflow or workflow group
    if (importElement.isWorkflow()) {
        natureId = KNIMEProjectNature.ID;
    }
    // set nature in project description
    description.setNatureIds(new String[] { natureId });
    project.setDescription(description, new NullProgressMonitor());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) 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