Java Code Examples for org.eclipse.core.resources.IWorkspace#loadProjectDescription()
The following examples show how to use
org.eclipse.core.resources.IWorkspace#loadProjectDescription() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NewProjectCreatorTool.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
private static IProject importProject(String projectName, String directory) throws Exception { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IPath path = new Path(directory).append(IProjectDescription.DESCRIPTION_FILE_NAME); try { IProjectDescription projectFile = workspace.loadProjectDescription(path); IProjectDescription projectDescription = ResourcesPlugin.getWorkspace().newProjectDescription( projectName); projectDescription.setLocation(path); IProject project = workspace.getRoot().getProject(projectName); project.create(projectFile, null); project.open(null); GWTNature.addNatureToProject(project); return project; } catch (CoreException e) { GWTPluginLog.logError(e); throw new Exception("Could not import new GWT project"); } }
Example 2
Source File: PlantUmlExportTestUtils.java From txtUML with Eclipse Public License 1.0 | 6 votes |
public static IProject getModelsProject() throws IOException, CoreException { String projectPath = new File(TEST_MODEL_PATH).getCanonicalPath(); IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProjectDescription description = workspace .loadProjectDescription(new Path(projectPath + Path.SEPARATOR + PROJECT_FILE)); IProject genericProject = workspace.getRoot().getProject(description.getName()); if (!genericProject.exists()) { genericProject.create(description, new NullProgressMonitor()); } genericProject.open(new NullProgressMonitor()); if (!genericProject.isOpen()) { throw new RuntimeException("Couldn't open project: " + genericProject.getName()); } project = JavaCore.create(genericProject); genericProject.refreshLocal(IProject.DEPTH_INFINITE, new NullProgressMonitor()); return genericProject; }
Example 3
Source File: ProjectTestsUtils.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Imports a project by reference into the workspace * * @return the created project */ public static IProject importProjectNotCopy(IWorkspace workspace, File rootFolder, IProgressMonitor progressMonitor) throws CoreException { IPath path = new org.eclipse.core.runtime.Path(new File(rootFolder, "_project").getAbsolutePath()); IProjectDescription desc = workspace.loadProjectDescription(path); IProject project = workspace.getRoot().getProject(desc.getName()); project.create(desc, progressMonitor); project.open(progressMonitor); return project; }
Example 4
Source File: N4JSTasksExampleWizard.java From n4js with Eclipse Public License 1.0 | 5 votes |
private static void importProject(IWorkspace workspace, File rootFolder, IProgressMonitor progressMonitor) throws CoreException { IPath path = new org.eclipse.core.runtime.Path(new File(rootFolder, ".project").getAbsolutePath()); IProjectDescription desc = workspace.loadProjectDescription(path); IProject project = workspace.getRoot().getProject(desc.getName()); project.create(desc, progressMonitor); project.open(progressMonitor); }
Example 5
Source File: EclipseProjectImporter.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private void importDir(java.nio.file.Path dir, IProgressMonitor m) { SubMonitor monitor = SubMonitor.convert(m, 4); IWorkspace workspace = ResourcesPlugin.getWorkspace(); IPath dotProjectPath = new Path(dir.resolve(DESCRIPTION_FILE_NAME).toAbsolutePath().toString()); IProjectDescription descriptor; try { descriptor = workspace.loadProjectDescription(dotProjectPath); String name = descriptor.getName(); if (!descriptor.hasNature(JavaCore.NATURE_ID)) { return; } IProject project = workspace.getRoot().getProject(name); if (project.exists()) { IPath existingProjectPath = project.getLocation(); existingProjectPath = fixDevice(existingProjectPath); dotProjectPath = fixDevice(dotProjectPath); if (existingProjectPath.equals(dotProjectPath.removeLastSegments(1))) { project.open(IResource.NONE, monitor.newChild(1)); project.refreshLocal(IResource.DEPTH_INFINITE, monitor.newChild(1)); return; } else { project = findUniqueProject(workspace, name); descriptor.setName(project.getName()); } } project.create(descriptor, monitor.newChild(1)); project.open(IResource.NONE, monitor.newChild(1)); } catch (CoreException e) { JavaLanguageServerPlugin.log(e.getStatus()); throw new RuntimeException(e); } finally { monitor.done(); } }
Example 6
Source File: ResourceUtil.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
/** * @param projectPath * the project location * @param natureIds * the list of required natures * @param builderIds * the list of required builders * @return a project description for the project that includes the list of required natures and builders */ public static IProjectDescription getProjectDescription(IPath projectPath, String[] natureIds, String[] builderIds) { if (projectPath == null) { return null; } IProjectDescription description = null; IPath dotProjectPath = projectPath.append(IProjectDescription.DESCRIPTION_FILE_NAME); File dotProjectFile = dotProjectPath.toFile(); IWorkspace workspace = ResourcesPlugin.getWorkspace(); if (dotProjectFile.exists()) { // loads description from the existing .project file try { description = workspace.loadProjectDescription(dotProjectPath); if (Platform.getLocation().isPrefixOf(projectPath)) { description.setLocation(null); } } catch (CoreException e) { IdeLog.logWarning(CorePlugin.getDefault(), "Failed to load the existing .project file.", e); //$NON-NLS-1$ } } if (description == null) { // creates a new project description description = workspace.newProjectDescription(projectPath.lastSegment()); if (Platform.getLocation().isPrefixOf(projectPath)) { description.setLocation(null); } else { description.setLocation(projectPath); } } // adds the required natures to the project description if (!ArrayUtil.isEmpty(natureIds)) { Set<String> natures = CollectionsUtil.newInOrderSet(natureIds); CollectionsUtil.addToSet(natures, description.getNatureIds()); description.setNatureIds(natures.toArray(new String[natures.size()])); } // adds the required builders to the project description if (!ArrayUtil.isEmpty(builderIds)) { ICommand[] existingBuilders = description.getBuildSpec(); List<ICommand> builders = CollectionsUtil.newList(existingBuilders); for (String builderId : builderIds) { if (!hasBuilder(builderId, existingBuilders)) { ICommand newBuilder = description.newCommand(); newBuilder.setBuilderName(builderId); builders.add(newBuilder); } } description.setBuildSpec(builders.toArray(new ICommand[builders.size()])); } return description; }