/** * Tries to delete an open project containing an irremovable file. Works only for Linux with * natives. */ public void testDeleteOpenProjectLinux() { if (!(Platform.getOS().equals(Platform.OS_LINUX) && isReadOnlySupported())) 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"); ensureExistsInWorkspace(new IResource[] {file1, file2}, true); projectRoot = project.getLocation().toFile(); // marks folder as read-only so its files cannot be deleted on Linux setReadOnly(folder, true); IFile projectFile = project.getFile(".project"); assertTrue("1.2", projectFile.exists()); assertTrue("1.3", projectFile.isSynchronized(IResource.DEPTH_INFINITE)); try { project.delete(IResource.FORCE, getMonitor()); fail("2.0 - should have failed"); } catch (CoreException ce) { // success - a file couldn't be removed } assertTrue("2.1", project.exists()); assertTrue("2.2", file1.exists()); assertTrue("2.3", !file2.exists()); assertTrue("2.5", folder.exists()); assertTrue("2.6", projectFile.exists()); assertTrue("2.7", project.isSynchronized(IResource.DEPTH_INFINITE)); setReadOnly(folder, false); assertTrue("3.5", project.isSynchronized(IResource.DEPTH_INFINITE)); try { project.delete(IResource.FORCE, getMonitor()); } catch (CoreException ce) { ce.printStackTrace(); fail("4.0", ce); } assertTrue("5.1", !project.exists()); assertTrue("5.2", !file1.exists()); assertTrue("5.3", file1.isSynchronized(IResource.DEPTH_INFINITE)); assertTrue("5.4", project.isSynchronized(IResource.DEPTH_INFINITE)); assertTrue("6.0", !projectRoot.exists()); } finally { if (folder != null && folder.exists()) setReadOnly(folder, false); if (projectRoot != null) ensureDoesNotExistInFileSystem(projectRoot); } }
/** * Creates an NL fragment project along with the locale specific properties files. * * @throws CoreException * @throws IOException * @throws InvocationTargetException * @throws InterruptedException */ private void internationalizePlugins(List plugins, List locales, Map overwrites) throws CoreException, IOException, InvocationTargetException, InterruptedException { Set created = new HashSet(); for (Iterator it = plugins.iterator(); it.hasNext(); ) { IPluginModelBase plugin = (IPluginModelBase) it.next(); for (Iterator iter = locales.iterator(); iter.hasNext(); ) { Locale locale = (Locale) iter.next(); IProject project = getNLProject(plugin, locale); if (created.contains(project) || overwriteWithoutAsking || !project.exists() || OVERWRITE == overwrites.get(project.getName())) { if (!created.contains(project) && project.exists()) { project.delete(true, getProgressMonitor()); } if (!created.contains(project)) { createNLFragment(plugin, project, locale); created.add(project); project.getFolder(RESOURCE_FOLDER_PARENT).create(false, true, getProgressMonitor()); } project .getFolder(RESOURCE_FOLDER_PARENT) .getFolder(locale.toString()) .create(true, true, getProgressMonitor()); createLocaleSpecificPropertiesFile(project, plugin, locale); } } } }
/** 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 testDeleteProjectWithVirtualFolderAndLink() { IPath folderLocation = getRandomLocation(); IFolder virtualFolder = existingProject.getFolder(getUniqueString()); IFolder linkedFolder = virtualFolder.getFolder("a_link"); try { try { folderLocation.toFile().mkdir(); virtualFolder.create(IResource.VIRTUAL, true, null); linkedFolder.createLink(folderLocation, IResource.NONE, getMonitor()); existingProject.delete(IResource.NEVER_DELETE_PROJECT_CONTENT, getMonitor()); existingProject.create(getMonitor()); } catch (CoreException e) { fail("1.0", e); } // virtual folder should not exist until the project is open assertTrue("2.0", !virtualFolder.exists()); assertTrue("3.0", !linkedFolder.exists()); try { existingProject.open(getMonitor()); } catch (CoreException e) { fail("4.0", e); } // virtual folder should now exist assertTrue("5.0", virtualFolder.exists()); assertTrue("6.0", virtualFolder.isVirtual()); // link should now exist assertTrue("7.0", linkedFolder.exists()); assertTrue("8.0", linkedFolder.isLinked()); assertEquals("9.0", folderLocation, linkedFolder.getLocation()); } finally { Workspace.clear(folderLocation.toFile()); } }
public void testDeleteProjectWithVirtualFolder() { IFolder virtualFolder = existingProject.getFolder(getUniqueString()); try { virtualFolder.create(IResource.VIRTUAL, true, null); existingProject.delete(IResource.NEVER_DELETE_PROJECT_CONTENT, getMonitor()); existingProject.create(getMonitor()); } catch (CoreException e) { fail("1.0", e); } // virtual folder should not exist until the project is open assertTrue("2.0", !virtualFolder.exists()); try { existingProject.open(getMonitor()); } catch (CoreException e) { fail("3.0", e); } // virtual folder should now exist assertTrue("4.0", virtualFolder.exists()); assertTrue("5.0", virtualFolder.isVirtual()); }
public void testCopyProjectWithVirtualFolder() { IPath fileLocation = getRandomLocation(); IPath folderLocation = getRandomLocation(); IFile linkedFile = existingVirtualFolderInExistingProject.getFile(getUniqueString()); IFolder linkedFolder = existingVirtualFolderInExistingProject.getFolder(getUniqueString()); try { try { createFileInFileSystem(fileLocation, getRandomContents()); folderLocation.toFile().mkdir(); linkedFolder.createLink(folderLocation, IResource.NONE, getMonitor()); linkedFile.createLink(fileLocation, IResource.NONE, getMonitor()); } catch (CoreException e) { fail("1.0", e); } // copy the project IProject destinationProject = getWorkspace().getRoot().getProject("CopyTargetProject"); try { existingProject.copy(destinationProject.getFullPath(), IResource.SHALLOW, getMonitor()); } catch (CoreException e) { fail("2.0", e); } IFile newFile = destinationProject.getFile(linkedFile.getProjectRelativePath()); assertTrue("3.0", newFile.isLinked()); assertEquals("3.1", linkedFile.getLocation(), newFile.getLocation()); assertTrue("3.2", newFile.getParent().isVirtual()); IFolder newFolder = destinationProject.getFolder(linkedFolder.getProjectRelativePath()); assertTrue("4.0", newFolder.isLinked()); assertEquals("4.1", linkedFolder.getLocation(), newFolder.getLocation()); assertTrue("4.2", newFolder.getParent().isVirtual()); // test project deep copy try { destinationProject.delete(IResource.NONE, getMonitor()); existingProject.copy(destinationProject.getFullPath(), IResource.NONE, getMonitor()); } catch (CoreException e) { fail("5.0", e); } assertTrue("5.1", newFile.isLinked()); assertEquals("5.2", linkedFile.getLocation(), newFile.getLocation()); assertTrue("5.3", newFile.getParent().isVirtual()); assertTrue("5.4", newFolder.isLinked()); assertEquals("5.5", linkedFolder.getLocation(), newFolder.getLocation()); assertTrue("5.6", newFolder.getParent().isVirtual()); try { destinationProject.delete(IResource.NONE, getMonitor()); } catch (CoreException e) { fail("6.0", e); } } finally { Workspace.clear(fileLocation.toFile()); Workspace.clear(folderLocation.toFile()); } }
/** Tries to delete an open project containing an unremovable file. Works only for Windows. */ public void testDeleteOpenProjectWindows() { if (!(isWindows())) return; IProject project = null; InputStream input = null; File projectRoot = null; try { IWorkspace workspace = getWorkspace(); project = workspace.getRoot().getProject(getUniqueString()); IFolder folder = project.getFolder("a_folder"); IFile 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(); assertExistsInFileSystem("0.0", file1); assertExistsInFileSystem("0.1", file2); assertExistsInFileSystem("0.2", file3); assertExistsInFileSystem("0.3", folder); assertExistsInFileSystem("0.4", projectFile); // opens a file so it cannot be removed on Windows try { input = file1.getContents(); } catch (CoreException ce) { ce.printStackTrace(); fail("1.0"); } assertTrue("1.2", projectFile.exists()); assertTrue("1.3", projectFile.isSynchronized(IResource.DEPTH_INFINITE)); try { project.delete(IResource.FORCE, getMonitor()); fail("2.0 - should have failed"); } catch (CoreException ce) { // success - a file couldn't be removed } // Delete is best-case so check all the files. // Do a check on disk and in the workspace in case something is out of sync. assertExistsInWorkspace("2.1.1", project); assertExistsInFileSystem("2.1.2", project); assertExistsInWorkspace("2.2.1", file1); assertExistsInFileSystem("2.2.2", file1); assertTrue("2.2.3", file1.isSynchronized(IResource.DEPTH_INFINITE)); assertDoesNotExistInWorkspace("2.3.1", file2); assertDoesNotExistInFileSystem("2.3.2", file2); assertTrue("2.3.3", file2.isSynchronized(IResource.DEPTH_INFINITE)); assertDoesNotExistInWorkspace("2.4.1", file3); assertDoesNotExistInFileSystem("2.4.2", file3); assertTrue("2.4.3", file3.isSynchronized(IResource.DEPTH_INFINITE)); assertExistsInWorkspace("2.5.1", folder); assertExistsInFileSystem("2.5.2", folder); assertTrue("2.5.3", folder.isSynchronized(IResource.DEPTH_INFINITE)); assertExistsInWorkspace("2.6.1", projectFile); assertExistsInFileSystem("2.6.2", projectFile); assertTrue("2.6.3", projectFile.isSynchronized(IResource.DEPTH_INFINITE)); assertTrue("2.7.0", project.isSynchronized(IResource.DEPTH_ZERO)); assertTrue("2.7.1", project.isSynchronized(IResource.DEPTH_INFINITE)); assertClose(input); assertTrue("3.5", project.isSynchronized(IResource.DEPTH_INFINITE)); try { project.delete(IResource.FORCE, getMonitor()); } catch (CoreException e) { fail("4.0", e); } assertTrue("5.1", !project.exists()); assertTrue("5.2", !file1.exists()); assertTrue("5.3", file1.isSynchronized(IResource.DEPTH_INFINITE)); assertTrue("5.4", project.isSynchronized(IResource.DEPTH_INFINITE)); assertTrue("6.0", !projectRoot.exists()); } finally { try { assertClose(input); } finally { 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); } } }
private void createProject(IFeatureModel model, IProgressMonitor monitor) throws CoreException { String name = model.getFeature().getId(); IFeaturePlugin[] plugins = model.getFeature().getPlugins(); for (int i = 0; i < plugins.length; i++) { if (name.equals(plugins[i].getId())) { name += "-feature"; // $NON-NLS-1$ break; } } String task = NLS.bind(MDEUIMessages.FeatureImportWizard_operation_creating2, name); monitor.beginTask(task, 9); try { IProject project = fRoot.getProject(name); if (project.exists() || new File(project.getParent().getLocation().toFile(), name).exists()) { if (queryReplace(project)) { if (!project.exists()) project.create(new SubProgressMonitor(monitor, 1)); project.delete(true, true, new SubProgressMonitor(monitor, 1)); try { RepositoryProvider.unmap(project); } catch (TeamException e) { } } else { return; } } else { monitor.worked(1); } IProjectDescription description = MDEPlugin.getWorkspace().newProjectDescription(name); if (fTargetPath != null) description.setLocation(fTargetPath.append(name)); project.create(description, new SubProgressMonitor(monitor, 1)); if (!project.isOpen()) { project.open(null); } File featureDir = new File(model.getInstallLocation()); importContent( featureDir, project.getFullPath(), FileSystemStructureProvider.INSTANCE, null, new SubProgressMonitor(monitor, 1)); IFolder folder = project.getFolder("META-INF"); // $NON-NLS-1$ if (folder.exists()) { folder.delete(true, null); } if (fBinary) { // Mark this project so that we can show image overlay // using the label decorator project.setPersistentProperty( MDECore.EXTERNAL_PROJECT_PROPERTY, MDECore.BINARY_PROJECT_VALUE); } createBuildProperties(project); setProjectNatures(project, model, monitor); if (project.hasNature(JavaCore.NATURE_ID)) setClasspath(project, model, monitor); } finally { monitor.done(); } }