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;
}
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;
}
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);
}
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));
}
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());
}
Aggregations