@Execute public void execute(IWorkspace workspace, IProgressMonitor monitor) { String projectName = findUnsusedProjectName(workspace); final IProject project = workspace.getRoot().getProject(projectName); final IProjectDescription pd = workspace.newProjectDescription(projectName); try { pd.setLocationURI(new URI(ISemanticFileSystem.SCHEME, null, "/" + projectName, null)); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); return; } try { workspace.run( new IWorkspaceRunnable() { public void run(IProgressMonitor monitor1) throws CoreException { if (!project.exists()) { project.create(pd, monitor1); } if (!project.isOpen()) { project.open(monitor1); RepositoryProvider.map(project, ISemanticFileSystem.SFS_REPOSITORY_PROVIDER); System.out.println("Created at: " + project.getLocationURI()); } } }, monitor); } catch (CoreException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
/** * @see org.teiid.designer.core.workspace.ModelWorkspace#createModelProject(java.lang.String, * java.lang.String, org.eclipse.core.runtime.IProgressMonitor) * @since 4.0 */ @Override public ModelProject createModelProject( final String name, final IPath path, final IProgressMonitor monitor) throws CoreException { CoreArgCheck.isNotNull(name); // Check if project already exists if (findModelProject(name) != null) { throw new ModelWorkspaceException( ModelerCore.Util.getString( "ModelWorkspaceImpl.cannotCreateModelProject", name)); // $NON-NLS-1$ } // Validate name final IWorkspace workspace = ModelerCore.getWorkspace(); final IStatus status = workspace.validateName(name, IResource.PROJECT); if (!status.isOK()) { throw new ModelWorkspaceException( new ModelStatusImpl(status.getSeverity(), status.getCode(), status.getMessage())); } // Create new model project final IProject project = workspace.getRoot().getProject(name); final IProjectDescription desc = workspace.newProjectDescription(project.getName()); desc.setLocation(path); desc.setNatureIds(MODEL_NATURES); final IWorkspaceRunnable op = new IWorkspaceRunnable() { @Override public void run(final IProgressMonitor monitor) throws CoreException { project.create(desc, monitor); project.open(monitor); } }; workspace.run(op, monitor); return new ModelProjectImpl(project, this); }
private IProject createNewProject() { final IProject newProjectHandle = mainPage.getProjectHandle(); // get a project descriptor URI location = null; if (!mainPage.useDefaults()) { location = mainPage.getLocationURI(); } // Set the project location for non default workspace locations final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName()); description.setLocationURI(location); SuiteGeneratorOptions.Libraries lib = this.libraryPage.getLibraries(); final SuiteGeneratorOptions options = new SuiteGeneratorOptions(false, false); // options.setAllFiles(mainPage.getSourceFile()); if (!mainPage.isDefaultStructure()) options.setStructureXmlFile(structPage.getStructureFile()); // options.setContentXmlFile(mainPage.getContentsFile()); options.setLibraries(lib); ArrayList<ProjectGeneratorOptions> proj = projectPage.getProjectOptions(); if (proj.size() == 0) { proj.add(new ProjectGeneratorOptions("work")); } options.setNewProjects(projectPage.getProjectOptions()); options.setNewLibraries(projectPage.getLibraryOptions()); SuiteGenerator.getInstance().createSuite(newProjectHandle, description, options); return newProjectHandle; }
/** * Creates a new project resource with the selected name. * * <p>In normal usage, this method is invoked after the user has pressed Finish on the wizard; the * enablement of the Finish button implies that all controls on the pages currently contain valid * values. * * @return the created project resource, or <code>null</code> if the project was not created */ IProject createExistingProject() { String projectName = projectNameField.getText(); final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IProject project = workspace.getRoot().getProject(projectName); if (this.description == null) { this.description = workspace.newProjectDescription(projectName); IPath locationPath = getLocationPath(); // If it is under the root use the default location if (isPrefixOfRoot(locationPath)) { this.description.setLocation(null); } else { this.description.setLocation(locationPath); } } else { this.description.setName(projectName); } // create the new project operation WorkspaceModifyOperation op = new WorkspaceModifyOperation() { @Override protected void execute(IProgressMonitor monitor) throws CoreException { SubMonitor subMonitor = SubMonitor.convert(monitor, 100); project.create(description, subMonitor.split(50)); project.open(IResource.BACKGROUND_REFRESH, subMonitor.split(50)); } }; // run the new project creation operation try { getContainer().run(true, true, op); } catch (InterruptedException e) { return null; } catch (InvocationTargetException e) { // ie.- one of the steps resulted in a core exception Throwable t = e.getTargetException(); if (t instanceof CoreException) { if (((CoreException) t).getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) { MessageDialog.open( MessageDialog.ERROR, getShell(), DataTransferMessages.WizardExternalProjectImportPage_errorMessage, NLS.bind( DataTransferMessages.WizardExternalProjectImportPage_caseVariantExistsError, projectName), SWT.SHEET); } else { ErrorDialog.openError( getShell(), DataTransferMessages.WizardExternalProjectImportPage_errorMessage, null, ((CoreException) t).getStatus()); } } return null; } return project; }
private static IProjectDescription createProjectDescription(IProject project, URI location) { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProjectDescription description = workspace.newProjectDescription(project.getName()); description.setLocationURI(location); description.setNatureIds(new String[] {DartCore.DART_PROJECT_NATURE}); ICommand command = description.newCommand(); command.setBuilderName(DartCore.DART_BUILDER_ID); description.setBuildSpec(new ICommand[] {command}); return description; }
public IProject createNewProject(IPath newPath, String name, IProgressMonitor monitor) { IProject newProject = ResourcesPlugin.getWorkspace().getRoot().getProject(name); IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IProjectDescription description = workspace.newProjectDescription(newProject.getName()); description.setLocation(newPath); // run the new project creation operation try { boolean doit = false; if (!newProject.exists()) { // Defect 24558 - Text Importer may result in New Project being created with NO PATH, so // check if NULL // before if (newPath != null && OSPlatformUtil.isWindows()) { // check to see if path exists but case is different IPath path = new Path(FileUiUtils.INSTANCE.getExistingCaseVariantFileName(newPath)); newProject = ResourcesPlugin.getWorkspace().getRoot().getProject(path.lastSegment()); description.setLocation(path); doit = !newProject.exists(); } else { doit = true; } if (doit) { createProject(description, newProject, monitor); } } } catch (CoreException e) { if (e.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) { MessageDialog.openError( getShell(), ResourceMessages.NewProject_errorMessage, NLS.bind(ResourceMessages.NewProject_caseVariantExistsError, newProject.getName())); } else { ErrorDialog.openError( getShell(), ResourceMessages.NewProject_errorMessage, null, // no special message e.getStatus()); } return null; } catch (Exception theException) { return null; } configureProject(newProject); return newProject; }
@Override public boolean performFinish() { boolean retVal = true; final String projectName = generalPage.getProjectName(); IPath workspacePath = ResourcesPlugin.getWorkspace().getRoot().getLocation(); IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IProject projHandle = workspace.getRoot().getProject(projectName); final IProjectDescription desc = workspace.newProjectDescription(projHandle.getName()); WorkspaceModifyOperation modifyOperation = new WorkspaceModifyOperation() { @Override protected void execute(IProgressMonitor monitor) throws CoreException { try { projHandle.create(desc, monitor); projHandle.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 2000)); } finally { monitor.done(); } } }; try { ProjectCreationRequest projectCreationRequest = new ProjectCreationRequest(); projectCreationRequest.setTemplateName(generalPage.getTemplateName()); projectCreationRequest.setBaseDir(PathsUtil.toOsLocation(workspacePath)); projectCreationRequest.setProjectName(projectName); projectCreationRequest.setProvider(providerPage.getProvider()); projectCreationRequest.setDefaultPackageName(generalPage.getDefaultPackageName()); projectCreationRequest.setHostName(providerPage.getHostName()); projectCreationRequest.setHostPort(Integer.parseInt(providerPage.getHostPort())); projectCreationRequest.setCodePage(providerPage.getCodePage()); projectCreationRequest.setSupportTheme(generalPage.isProjectSupportTheme()); projectCreationRequest.setProjectTheme(themePage.getProjectTheme()); projectCreationRequest.setZipFile(generalPage.getZipFile()); projectCreationRequest.setTemplateFetcher(retriever.getTemplateFetcher()); EclipseDesignTimeExecuter.instance().createProject(projectCreationRequest); } catch (Exception e) { throw (new RuntimeException(e)); } try { getContainer().run(true, true, modifyOperation); } catch (Exception e) { throw (new RuntimeException(e)); } return retVal; }
public void testSwitchBranchClosesOpenProjectsThatDontExistOnDestinationBranch() throws Throwable { testAddBranch(); assertCurrentBranch("master"); assertSwitchBranch("my_new_branch"); GitIndex index = getRepo().index(); assertTrue("Expected changed file listing to be empty", index.changedFiles().isEmpty()); // Create a new project on this branch! String projectName = "project_on_branch" + System.currentTimeMillis(); File projectDir = getRepo().workingDirectory().append(projectName).toFile(); projectDir.mkdirs(); IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProject project = workspace.getRoot().getProject(projectName); IProjectDescription description = workspace.newProjectDescription(projectName); description.setLocation(getRepo().workingDirectory().append(projectName)); project.create(description, new NullProgressMonitor()); // Commit the project on this branch! index.refresh(new NullProgressMonitor()); // Now there should be a single file that's been changed! List<ChangedFile> changed = index.changedFiles(); assertEquals( "repository changed file listing should contain one entry for new .project file, but does not", 1, changed.size()); // Make sure it's shown as having unstaged changes only and is NEW assertNewUnstagedFile(changed.get(0)); // Stage the new file assertStageFiles(index, changed); assertNewStagedFile(changed.get(0)); assertCommit(index, "Initial commit"); assertSwitchBranch("master"); // Assert that the new project is closed! project = workspace.getRoot().getProject(projectName); assertFalse(project.isOpen()); // assert that there's no .project file stranded there File dotProject = new File(projectDir, IProjectDescription.DESCRIPTION_FILE_NAME); assertFalse(dotProject.exists()); }
private IProject createProject(String dirPath) throws CoreException { long start = System.currentTimeMillis(); IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); String projectName = "test"; IProject project = root.getProject(projectName); IProjectDescription description = workspace.newProjectDescription(projectName); description.setLocation(new Path(dirPath)); project.create(description, null); project.open(null); long delta = System.currentTimeMillis() - start; System.out.println("Open project in " + delta + " ms"); return project; }
private void createProject(DBRProgressMonitor monitor) throws DBException, CoreException { IWorkspace workspace = DBeaverCore.getInstance().getWorkspace(); IProject project = workspace.getRoot().getProject(data.getName()); if (project.exists()) { throw new DBException( NLS.bind(CoreMessages.dialog_project_create_wizard_error_already_exists, data.getName())); } project.create(monitor.getNestedMonitor()); project.open(monitor.getNestedMonitor()); if (!CommonUtils.isEmpty(data.getDescription())) { final IProjectDescription description = workspace.newProjectDescription(project.getName()); description.setComment(data.getDescription()); project.setDescription(description, monitor.getNestedMonitor()); } }
/** * Creates CDT project in a specific path in workspace adding specified configurations and opens * it. * * @param projectName - project name. * @param pathInWorkspace - path relative to workspace root. * @param configurationIds - array of configuration IDs. * @return - new {@link IProject}. * @throws CoreException - if the project can't be created. * @throws OperationCanceledException... */ public static IProject createCDTProject( String projectName, String pathInWorkspace, String[] configurationIds) throws OperationCanceledException, CoreException { CCorePlugin cdtCorePlugin = CCorePlugin.getDefault(); IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); IProject project = root.getProject(projectName); IndexerPreferences.set(project, IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_NO_INDEXER); resourcesCreated.add(project); IProjectDescription prjDescription = workspace.newProjectDescription(projectName); if (pathInWorkspace != null) { IPath absoluteLocation = root.getLocation().append(pathInWorkspace); prjDescription.setLocation(absoluteLocation); } if (configurationIds != null && configurationIds.length > 0) { ICProjectDescriptionManager prjDescManager = cdtCorePlugin.getProjectDescriptionManager(); project.create(NULL_MONITOR); project.open(NULL_MONITOR); ICProjectDescription icPrjDescription = prjDescManager.createProjectDescription(project, false); ICConfigurationDescription baseConfiguration = cdtCorePlugin.getPreferenceConfiguration(TestCfgDataProvider.PROVIDER_ID); for (String cfgId : configurationIds) { icPrjDescription.createConfiguration(cfgId, cfgId + " Name", baseConfiguration); } prjDescManager.setProjectDescription(project, icPrjDescription); } project = cdtCorePlugin.createCDTProject(prjDescription, project, NULL_MONITOR); waitForProjectRefreshToFinish(); Assert.assertNotNull(project); project.open(null); Assert.assertTrue(project.isOpen()); return project; }
protected boolean createProject( final IProgressMonitor monitor, final IPath projectLocation, final String projectName, final Collection<IPath> includeDirs, final Collection<IPath> sourceDirs, final IPath outputDir) throws InvocationTargetException { final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IProject project = workspace.getRoot().getProject(projectName); final IProjectDescription description = workspace.newProjectDescription(projectName); description.setLocation(projectLocation); final ICommand[] old = description.getBuildSpec(), specs = new ICommand[old.length + 1]; System.arraycopy(old, 0, specs, 0, old.length); final ICommand command = description.newCommand(); command.setBuilderName(ErlangPlugin.BUILDER_ID); specs[old.length] = command; description.setBuildSpec(specs); description.setNatureIds(new String[] {ErlangPlugin.NATURE_ID}); try { monitor.beginTask(WizardMessages.WizardProjectsImportPage_CreateProjectsTask, 1000); project.create(description, monitor); // final int subTicks = 600 / fileSystemObjects.size(); // createLinks(theProjectPath, fileSystemObjects, monitor, project, // subTicks); // project.create(description, IResource.REPLACE, // new SubProgressMonitor(monitor, 30)); project.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 300)); final OldErlangProjectProperties erlangProjectProperties = new OldErlangProjectProperties(project); erlangProjectProperties.setIncludeDirs(includeDirs); erlangProjectProperties.setSourceDirs(sourceDirs); erlangProjectProperties.setOutputDir(outputDir); } catch (final CoreException e) { throw new InvocationTargetException(e); } finally { monitor.done(); } return true; }
/** * Creates CDT project in a specific location and opens it. * * @param projectName - project name. * @param locationURI - location. * @return - new {@link IProject}. * @throws CoreException - if the project can't be created. * @throws OperationCanceledException... */ public static IProject createCDTProject(String projectName, URI locationURI) throws OperationCanceledException, CoreException { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); IProject project = root.getProject(projectName); IndexerPreferences.set(project, IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_NO_INDEXER); resourcesCreated.add(project); IProjectDescription description = workspace.newProjectDescription(projectName); description.setLocationURI(locationURI); project = CCorePlugin.getDefault().createCDTProject(description, project, NULL_MONITOR); waitForProjectRefreshToFinish(); Assert.assertNotNull(project); project.open(null); Assert.assertTrue(project.isOpen()); return project; }
/* * Copied from BasicNewProjectResourceWizard (modified) */ private WorkspaceModifyOperation createNewSimpleProjectOperation() { final IProject newProjectHandle = fMainPage.getProjectHandle(); URI location = null; if (!fMainPage.useDefaults()) { location = fMainPage.getLocationURI(); } IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName()); description.setLocationURI(location); WorkspaceModifyOperation op = new WorkspaceModifyOperation() { @Override protected void execute(IProgressMonitor monitor) throws CoreException { createProject(description, newProjectHandle, monitor); doPostCreateProjectAction(newProjectHandle, monitor); } }; return op; }
public static IProject createProject( String projectName, boolean deleteIfExists, String... natures) throws CoreException { Activator.getOrStartInstance(); IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProject project = workspace.getRoot().getProject(projectName); if (project.exists()) { if (deleteIfExists) { try { project.delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, null); } catch (CoreException e) { e.printStackTrace(); } } else { return project; } } IProjectDescription desc = workspace.newProjectDescription(projectName); desc.setNatureIds(natures); project.create(desc, null); project.open(null); return project; }
public void testRepoRelativePath() throws Throwable { IProject project = null; try { GitRepository repo = createRepo(); IPath repoPath = repo.workingDirectory(); String projectName = repoPath.lastSegment(); IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProjectDescription description = workspace.newProjectDescription(projectName); description.setLocation(repoPath); project = workspace.getRoot().getProject(projectName); project.create(description, null); project.open(null); IPath relativePath = repo.relativePath(project); assertTrue("Expected relative path of root of repo to be empty", relativePath.isEmpty()); } finally { if (project != null) { project.delete(true, null); } } }
private IProjectDescription createProjectDescription() { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProjectDescription result = workspace.newProjectDescription(projectName); result.setLocation(projectLocation); return result; }
/** * Move the project structure to the location provided by user. Also configure JDK, server, server * application and key features like session affinity, caching, debugging if user wants to do so. * * @param projName : Name of the project * @param projLocation : Location of the project * @param isDefault : whether location of project is default * @param selWorkingSets * @param workingSetManager * @param depMap : stores configurations done on WATagPage * @param ftrMap : stores configurations done on WAKeyFeaturesPage * @param selProj */ private void doFinish( String projName, String projLocation, boolean isDefault, IWorkingSet[] selWorkingSets, IWorkingSetManager workingSetManager, Map<String, String> depMap, Map<String, Boolean> ftrMap, IProject selProj) { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); IProject project = null; try { WindowsAzureRole role = waProjMgr.getRoles().get(0); // logic for handling deploy page components and their values. if (!depMap.isEmpty()) { File templateFile = new File(depMap.get("tempFile")); role = WizardUtilMethods.configureJDKServer(role, depMap); /* * Handling adding server application * without configuring server/JDK. * Always add cloud attributes as * approot directory is not created yet * hence all applications are * imported from outside of the Azure project */ if (!tabPg.getAppsAsNames().isEmpty()) { for (int i = 0; i < tabPg.getAppsList().size(); i++) { AppCmpntParam app = tabPg.getAppsList().get(i); if (!app.getImpAs().equalsIgnoreCase(Messages.helloWorld)) { role.addServerApplication( app.getImpSrc(), app.getImpAs(), app.getImpMethod(), templateFile, true); } } } } /** Handling for HelloWorld application in plug-in */ if (tabPg != null) { if (!tabPg.getAppsAsNames().contains(Messages.helloWorld)) { List<WindowsAzureRoleComponent> waCompList = waProjMgr.getRoles().get(0).getServerApplications(); for (WindowsAzureRoleComponent waComp : waCompList) { if (waComp.getDeployName().equalsIgnoreCase(Messages.helloWorld) && waComp.getImportPath().isEmpty()) { waComp.delete(); } } } } role = WizardUtilMethods.configureKeyFeatures(role, ftrMap); waProjMgr.save(); WindowsAzureProjectManager.moveProjFromTemp(projName, projLocation); String launchFilePath = projLocation + File.separator + projName + LAUNCH_FILE_PATH; ParseXML.setProjectNameinLaunch(launchFilePath, Messages.pWizWinAzureProj, projName); root.touch(null); project = root.getProject(projName); IProjectDescription projDescription = workspace.newProjectDescription(projName); Path path = new Path(projLocation + File.separator + projName); projDescription.setLocation(path); projDescription.setNatureIds(new String[] {WAProjectNature.NATURE_ID}); if (!project.exists()) { if (isDefault) { project.create(null); } else { project.create(projDescription, null); } } project.open(null); projDescription = project.getDescription(); projDescription.setName(projName); projDescription.setNatureIds(new String[] {WAProjectNature.NATURE_ID}); project.move(projDescription, IResource.FORCE, null); workingSetManager.addToWorkingSets(project, selWorkingSets); root.touch(null); if (project != null) { WADependencyBuilder builder = new WADependencyBuilder(); builder.addBuilder(project, "com.persistent.winazure.eclipseplugin.Builder"); } } catch (Exception e) { Display.getDefault() .syncExec( new Runnable() { public void run() { MessageDialog.openError(null, Messages.pWizErrTitle, Messages.pWizErrMsg); } }); Activator.getDefault().log(Messages.pWizErrMsg, e); } }
/** * Creates a new project resource with the entered name. * * @return the created project resource, or <code>null</code> if the project was not created */ protected IProject createNewProject(final Object... additionalArgsToConfigProject) { // get a project handle final IProject newProjectHandle = projectPage.getProjectHandle(); // get a project descriptor IPath defaultPath = Platform.getLocation(); IPath newPath = projectPage.getLocationPath(); if (defaultPath.equals(newPath)) { newPath = null; } else { // The user entered the path and it's the same as it'd be if he chose the default path. IPath withName = defaultPath.append(newProjectHandle.getName()); if (newPath.toFile().equals(withName.toFile())) { newPath = null; } } IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName()); description.setLocation(newPath); // update the referenced project if provided if (referencePage != null) { IProject[] refProjects = referencePage.getReferencedProjects(); if (refProjects.length > 0) { description.setReferencedProjects(refProjects); } } final String projectType = projectPage.getProjectType(); final String projectInterpreter = projectPage.getProjectInterpreter(); // define the operation to create a new project WorkspaceModifyOperation op = new WorkspaceModifyOperation() { protected void execute(IProgressMonitor monitor) throws CoreException { createAndConfigProject( newProjectHandle, description, projectType, projectInterpreter, monitor, additionalArgsToConfigProject); } }; // run the operation to create a new project try { getContainer().run(true, true, op); } catch (InterruptedException e) { return null; } catch (InvocationTargetException e) { Throwable t = e.getTargetException(); if (t instanceof CoreException) { if (((CoreException) t).getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) { MessageDialog.openError( getShell(), "Unable to create project", "Another project with the same name (and different case) already exists."); } else { ErrorDialog.openError( getShell(), "Unable to create project", null, ((CoreException) t).getStatus()); } } else { // Unexpected runtime exceptions and errors may still occur. PydevPlugin.log(IStatus.ERROR, t.toString(), t); MessageDialog.openError(getShell(), "Unable to create project", t.getMessage()); } return null; } return newProjectHandle; }