private void closeSolution(String slnId) { if (slnId == null) { return; } Map<String, IProject> projectMap = getProjectMap(); SolutionEntry solutionEntry = session.getSolutions().get(session.getCurrentSolution()); LinkedHashSet<String> openProjects = new LinkedHashSet<String>(); Set<String> projectNames = solutionEntry.getProjectNames(); for (String pName : projectNames) { if (projectMap.get(pName).isOpen()) { openProjects.add(pName); } } solutionEntry.setOpenProjects(openProjects.toArray(new String[0])); for (String pName : openProjects) { IProject p = projectMap.get(pName); try { p.close(null); } catch (CoreException e) { e.printStackTrace(); } } }
/** A convenience method for closing the given project. */ public static void closeProject(IProject project) { try { project.close(new NullProgressMonitor()); } catch (CoreException e) { CorePlugin.logError("Could not close project", e); } }
private void configureProject(IProject newProject) { try { final IProjectDescription desc = newProject.getDescription(); desc.setNatureIds(new String[0]); newProject.setDescription(desc, null); desc.setNatureIds(MODEL_NATURES); if (ProductCustomizerMgr.getInstance() != null) { String productName = ProductCustomizerMgr.getInstance().getProductName(); if (!CoreStringUtil.isEmpty(productName)) { desc.setComment(productName + ", version " + ModelerCore.ILicense.VERSION); // $NON-NLS-1$ } } newProject.setDescription(desc, null); if (!ProductCustomizerMgr.getInstance() .getProductCharacteristics() .isHiddenProjectCentric()) { // Defect 11480 - closing and opening the project sets the overlay icon properly newProject.close(null); } newProject.open(null); } catch (final CoreException err) { UiConstants.Util.log(IStatus.ERROR, err, err.getMessage()); } }
/** Tests a builder that requests deltas for closed and missing projects. */ public void testRequestMissingProject() { // add builder and do an initial build to get the instance try { addBuilder(project1, DeltaVerifierBuilder.BUILDER_NAME); project1.build(IncrementalProjectBuilder.FULL_BUILD, getMonitor()); } catch (CoreException e) { fail("1.0", e); } final DeltaVerifierBuilder builder = DeltaVerifierBuilder.getInstance(); assertTrue("1.1", builder != null); // always check deltas for all projects final IProject[] allProjects = new IProject[] {project1, project2, project3, project4}; try { project2.close(getMonitor()); project3.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, getMonitor()); } catch (CoreException e1) { fail("1.99", e1); } builder.checkDeltas(allProjects); // modify a file in project1 to force an autobuild try { file1.setContents(getRandomContents(), IResource.NONE, getMonitor()); } catch (CoreException e2) { fail("2.99", e2); } }
public void test000_removeClosed() throws Exception { IProject p1 = createExisting("t000-p1"); waitForJobsToComplete(); IMavenProjectFacade f1 = manager.create(p1, monitor); MavenProjectChangedEvent event; // assertEquals(1, events.size()); // event = events.get(0); // assertEquals(MavenProjectChangedEvent.KIND_ADDED, event.getKind()); // assertNull(event.getOldMavenProject()); // assertSame(f1, event.getMavenProject()); assertEquals(p1.getFullPath(), f1.getFullPath()); events.clear(); p1.close(monitor); waitForJobsToComplete(); assertNull(manager.create(p1, monitor)); assertEquals(1, events.size()); event = events.get(0); assertEquals(MavenProjectChangedEvent.KIND_REMOVED, event.getKind()); assertSame(f1, event.getOldMavenProject()); assertNull(event.getMavenProject()); }
@AfterClass public static void deleteProject() throws Exception { try { project.close(null); project.delete(true, null); } catch (Exception e) { } }
/** Deletes the temporary project under current workspace. */ public static void removeTemporaryProject() { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); IProject p = root.getProject(PluginConstants.T24_TEMPORARY_IDE_PROJECT); try { p.close(null); p.delete(true, true, null); } catch (CoreException e) { e.printStackTrace(); } }
private void refreshProject(final IProject project) { try { NullProgressMonitor monitor = new NullProgressMonitor(); project.refreshLocal(DEPTH_INFINITE, monitor); project.close(monitor); project.open(monitor); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
/** * @see * it.unitn.disi.unagi.application.services.IManageProjectsService#closeProject(org.eclipse.core.runtime.IProgressMonitor, * org.eclipse.core.resources.IProject) */ @Override public void closeProject(IProgressMonitor progressMonitor, IProject project) throws CouldNotCloseUnagiProjectException { String name = project.getName(); LogUtil.log.info("Closing project: {0}.", name); // $NON-NLS-1$ // Attempts to close the project. try { project.close(progressMonitor); } // If any other errors occurred, throw an exception. catch (CoreException e) { LogUtil.log.error( "Unagi caught an Eclipse exception while trying to close project: {0}.", e, name); // $NON-NLS-1$ throw new CouldNotCloseUnagiProjectException(project, e); } }
private void erase(String projectName, Set<File> dirs) throws CoreException, IOException { IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); if (project.exists()) { RepositoryMapping repo = RepositoryMapping.getMapping(project); if (repo != null) { IPath gitDirAbsolutePath = repo.getGitDirAbsolutePath(); File canonicalFile = gitDirAbsolutePath.toFile().getCanonicalFile(); dirs.add(canonicalFile); File workspacePath = ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile().getCanonicalFile(); File gitDirParent = canonicalFile.getParentFile(); if (!(gitDirParent.toString() + File.separator) .startsWith(workspacePath.toString() + File.separator)) if (!(gitDirParent.toString() + File.separator) .startsWith(getTestDirectory().getAbsolutePath().toString() + File.separator)) fail( "Attempting cleanup of directory neither in workspace nor test directory" + canonicalFile); new DisconnectProviderOperation(Collections.singleton(project)).execute(null); } project.close(null); project.delete(true, true, null); } }
/** * The worker method. It will create a new project, then create the appropriate Soar heirarchy and * files. */ private void doFinish(String projectName, IProgressMonitor monitor) throws CoreException { monitor.beginTask("Creating " + projectName, 7); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject newProject = root.getProject(projectName); // creation of the project if (newProject.exists()) { throwCoreException("Project \"" + projectName + "\" already exists"); } else { newProject.create(monitor); newProject.open(monitor); try { IProjectDescription description = newProject.getDescription(); String[] natures = description.getNatureIds(); String[] newNatures = new String[natures.length + 1]; System.arraycopy(natures, 0, newNatures, 0, natures.length); newNatures[natures.length] = SoarProjectNature.NATURE_ID; description.setNatureIds(newNatures); newProject.setDescription(description, IResource.FORCE, monitor); newProject.setPersistentProperty(DataMap.VERTEX_ID, "0"); } catch (CoreException e) { e.printStackTrace(); } // catch } // else monitor.worked(2); // Create the contents of the project's root directory IFolder folderAll = newProject.getFolder("all"); if (!folderAll.exists()) { folderAll.create(true, true, monitor); } // if FileMarker.markResource(folderAll, "file"); IFolder folderElaborations = newProject.getFolder("elaborations"); if (!folderElaborations.exists()) { folderElaborations.create(true, true, monitor); } // if FileMarker.markResource(folderElaborations, "file"); IFile file_firstload = newProject.getFile("_firstload.soar"); if (!file_firstload.exists()) { file_firstload.create( Utility.getFileTemplate(file_firstload, "_firstload.soar"), true, monitor); } // if FileMarker.markResource(file_firstload, "file"); IFile filedatamap = newProject.getFile("datamap.xdm"); if (!filedatamap.exists()) { filedatamap.create(Utility.getFileTemplate(filedatamap, "datamap.xdm"), true, monitor); } // if monitor.worked(3); // Create the contents of the elaborations folder IFile file_all = folderElaborations.getFile("_all.soar"); if (!file_all.exists()) { file_all.create(Utility.getFileTemplate(file_all, "_all.soar"), true, monitor); } // if FileMarker.markResource(file_all, "file"); IFile filetopstate = folderElaborations.getFile("top-state.soar"); if (!filetopstate.exists()) { filetopstate.create(Utility.getFileTemplate(filetopstate, "top-state.soar"), true, monitor); } // if FileMarker.markResource(filetopstate, "file"); SourcingFile.createSourcingFile(newProject, monitor); newProject.close(monitor); newProject.open(monitor); monitor.worked(2); monitor.done(); } // void doFinish(...)
/** * Tries to delete a closed project containing an unremovable file. Works only for Linux with * natives. * * <p>TODO: enable this test once bug 48321 is fixed. */ public void testDeleteClosedProjectLinux() { if (!(Platform.getOS().equals(Platform.OS_LINUX))) return; IProject project = null; File projectRoot = null; IFolder folder = null; try { IWorkspace workspace = getWorkspace(); project = workspace.getRoot().getProject(getUniqueString()); folder = project.getFolder("a_folder"); IFile file1 = folder.getFile("file1.txt"); IFile file2 = project.getFile("file2.txt"); IFile projectFile = project.getFile(new Path(".project")); ensureExistsInWorkspace(new IResource[] {file1, file2}, true); projectRoot = project.getLocation().toFile(); // marks folder as read-only so its files cannot be removed on Linux setReadOnly(folder, true); try { project.close(getMonitor()); } catch (CoreException e) { fail("1.0", e); } try { project.delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, getMonitor()); fail("2.0 - should have failed"); } catch (CoreException ce) { // success - a file couldn't be removed } assertTrue("3.0", project.exists()); assertTrue("3.1", project.isSynchronized(IResource.DEPTH_INFINITE)); assertExistsInFileSystem("3.2", projectFile); try { project.open(getMonitor()); } catch (CoreException e) { fail("4.0", e); } setReadOnly(folder, false); try { project.delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, getMonitor()); } catch (CoreException ce) { ce.printStackTrace(); fail("5.0", ce); } assertTrue("6.0", !project.exists()); assertTrue("6.1", project.isSynchronized(IResource.DEPTH_INFINITE)); assertTrue("6.2", !projectRoot.exists()); assertDoesNotExistInFileSystem("6.3", projectFile); } finally { if (folder != null && folder.exists()) setReadOnly(folder, false); if (projectRoot != null) ensureDoesNotExistInFileSystem(projectRoot); } }
/** Tries to delete a closed project containing an unremovable file. Works only for Windows. */ public void testDeleteClosedProjectWindows() { if (!isWindows()) return; IProject project = null; InputStream input = null; File projectRoot = null; IFile file1 = null; try { IWorkspace workspace = getWorkspace(); project = workspace.getRoot().getProject(getUniqueString()); IFolder folder = project.getFolder("a_folder"); file1 = folder.getFile("file1.txt"); IFile file2 = project.getFile("file2.txt"); IFile file3 = folder.getFile("file3.txt"); IFile projectFile = project.getFile(new Path(".project")); ensureExistsInWorkspace(new IResource[] {file1, file2, file3}, true); projectRoot = project.getLocation().toFile(); // opens a file so it cannot be removed on Windows try { input = file1.getContents(); } catch (CoreException ce) { ce.printStackTrace(); fail("1.0"); } try { project.close(getMonitor()); } catch (CoreException e) { fail("1.1", e); } try { project.delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, getMonitor()); fail("2.0 - should have failed"); } catch (CoreException ce) { // success - a file couldn't be removed } assertTrue("2.1", project.exists()); assertTrue("2.7", project.isSynchronized(IResource.DEPTH_INFINITE)); assertExistsInFileSystem("2.8", projectFile); assertClose(input); assertTrue("3.5", project.isSynchronized(IResource.DEPTH_INFINITE)); try { project.delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, getMonitor()); } catch (CoreException ce) { ce.printStackTrace(); fail("4.0", ce); } assertTrue("5.1", !project.exists()); assertTrue("5.3", project.isSynchronized(IResource.DEPTH_INFINITE)); assertTrue("6.0", !projectRoot.exists()); assertDoesNotExistInFileSystem("7.0", projectFile); } finally { try { if (input != null) input.close(); } catch (IOException e) { fail("8.0", e); } finally { if (projectRoot != null) ensureDoesNotExistInFileSystem(projectRoot); } } }