Java Code Examples for org.eclipse.core.resources.IWorkspace#newProjectDescription()
The following examples show how to use
org.eclipse.core.resources.IWorkspace#newProjectDescription() .
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: MavenProjectImporterTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testPreexistingIProjectDifferentName() throws Exception { File from = new File(getSourceProjectDirectory(), "maven/salut"); Path projectDir = Files.createTempDirectory("testImportDifferentName"); IWorkspaceRoot wsRoot = WorkspaceHelper.getWorkspaceRoot(); IWorkspace workspace = wsRoot.getWorkspace(); String projectName = projectDir.getFileName().toString(); IProject salut = wsRoot.getProject("salut"); salut.delete(true, monitor); IProjectDescription description = workspace.newProjectDescription(projectName); description.setLocation(new org.eclipse.core.runtime.Path(projectDir.toFile().getAbsolutePath())); IProject project = wsRoot.getProject(projectName); project.create(description, monitor); assertTrue(WorkspaceHelper.getAllProjects().contains(project)); FileUtils.copyDirectory(from, projectDir.toFile()); assertTrue(project.exists()); Job updateJob = projectsManager.updateWorkspaceFolders(Collections.singleton(new org.eclipse.core.runtime.Path(projectDir.toString())), Collections.emptySet()); updateJob.join(20000, monitor); assertTrue("Failed to import preexistingProjectTest:\n" + updateJob.getResult().getException(), updateJob.getResult().isOK()); }
Example 2
Source File: ResourceUtilTest.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
/** * Create test parameter for the parameterized runner. * * @return The list of test parameters * @throws CoreException * if core error occurs */ @Parameters(name = "{index}: ({0})") public static Iterable<Object[]> getTracePaths() throws CoreException { IProgressMonitor progressMonitor = new NullProgressMonitor(); IWorkspace workspace = ResourcesPlugin.getWorkspace(); // Create a project inside workspace location fWorkspaceRoot = workspace.getRoot(); fSomeProject = fWorkspaceRoot.getProject(SOME_PROJECT_NAME); fSomeProject.create(progressMonitor); fSomeProject.open(progressMonitor); // Create an other project outside the workspace location URI projectLocation = fProjectFolder.getRoot().toURI(); fSomeOtherProject = fWorkspaceRoot.getProject(SOME_OTHER_PROJECT_NAME); IProjectDescription description = workspace.newProjectDescription(fSomeOtherProject.getName()); if (projectLocation != null) { description.setLocationURI(projectLocation); } fSomeOtherProject.create(description, progressMonitor); fSomeOtherProject.open(progressMonitor); return Arrays.asList(new Object[][] { {fSomeProject}, {fSomeOtherProject} }); }
Example 3
Source File: CargoTools.java From corrosion with Eclipse Public License 2.0 | 5 votes |
public static void ensureDotCargoImportedAsProject(IProgressMonitor monitor) throws CoreException { File cargoFolder = new File(System.getProperty("user.home") + "/.cargo"); //$NON-NLS-1$ //$NON-NLS-2$ if (!cargoFolder.exists()) { return; } IWorkspace workspace = ResourcesPlugin.getWorkspace(); for (IProject project : workspace.getRoot().getProjects()) { if (!project.isOpen() && project.getName().startsWith(".cargo")) { //$NON-NLS-1$ project.open(monitor); } IPath location = project.getLocation(); if (location != null) { File projectFolder = location.toFile().getAbsoluteFile(); if (cargoFolder.getAbsolutePath().startsWith(projectFolder.getAbsolutePath())) { return; // .cargo already imported } } } // No .cargo folder available in workspace String projectName = ".cargo"; //$NON-NLS-1$ while (workspace.getRoot().getProject(projectName).exists()) { projectName += '_'; } IProjectDescription description = workspace.newProjectDescription(projectName); description.setLocation(Path.fromOSString(cargoFolder.getAbsolutePath())); IProject cargoProject = workspace.getRoot().getProject(projectName); cargoProject.create(description, monitor); cargoProject.open(monitor); }
Example 4
Source File: CreateAppEngineWtpProject.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
@Override public void execute(IProgressMonitor monitor) throws InvocationTargetException, CoreException { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProject newProject = config.getProject(); URI location = config.getEclipseProjectLocationUri(); String name = newProject.getName(); IProjectDescription description = workspace.newProjectDescription(name); description.setLocationURI(location); String operationLabel = getDescription(); SubMonitor subMonitor = SubMonitor.convert(monitor, operationLabel, 120); CreateProjectOperation operation = new CreateProjectOperation(description, operationLabel); try { operation.execute(subMonitor.newChild(10), uiInfoAdapter); mostImportant = createAndConfigureProjectContent(newProject, config, subMonitor.newChild(80)); } catch (ExecutionException ex) { throw new InvocationTargetException(ex); } IFacetedProject facetedProject = ProjectFacetsManager.create( newProject, true /* convertIfNecessary */, subMonitor.newChild(5)); addAppEngineFacet(facetedProject, subMonitor.newChild(6)); addAdditionalDependencies(newProject, config, subMonitor.newChild(20)); fixTestSourceDirectorySettings(newProject, subMonitor.newChild(5)); }
Example 5
Source File: EclipseFileSystemTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@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); } }
Example 6
Source File: PyStructureConfigHelpers.java From Pydev with Eclipse Public License 1.0 | 5 votes |
/** * Creates a new project resource with the entered name. * * @param projectName The name of the project * @param projectLocationPath the location for the project. If null, the default location (in the workspace) * will be used to create the project. * @param references The projects that should be referenced from the newly created project * * @return the created project resource, or <code>null</code> if the project was not created * @throws CoreException * @throws OperationCanceledException */ public static IProject createPydevProject(String projectName, IPath projectLocationPath, IProject[] references, IProgressMonitor monitor, String projectType, String projectInterpreter, ICallback<List<IContainer>, IProject> getSourceFolderHandlesCallback, ICallback<List<String>, IProject> getExternalSourceFolderHandlesCallback, ICallback<List<IPath>, IProject> getExistingSourceFolderHandlesCallback, ICallback<Map<String, String>, IProject> getVariableSubstitutionCallback) throws OperationCanceledException, CoreException { // get a project handle final IProject projectHandle = getProjectHandle(projectName); IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IProjectDescription description = workspace.newProjectDescription(projectHandle.getName()); description.setLocation(projectLocationPath); // update the referenced project if provided if (references != null && references.length > 0) { description.setReferencedProjects(references); } createPydevProject(description, projectHandle, monitor, projectType, projectInterpreter, getSourceFolderHandlesCallback, getExternalSourceFolderHandlesCallback, getExistingSourceFolderHandlesCallback, getVariableSubstitutionCallback); return projectHandle; }
Example 7
Source File: ProjectHelper.java From eclipse-extras with Eclipse Public License 1.0 | 4 votes |
private IProjectDescription createProjectDescription() { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProjectDescription result = workspace.newProjectDescription( projectName ); result.setLocation( projectLocation ); return result; }
Example 8
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; }