/**
   * 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);
      }
    }
  }