/**
  * Deletes a set of files from the file system, and also their parent folders if those become
  * empty during this process.
  *
  * @param nameSet set of file paths
  * @param monitor progress monitor
  * @throws CoreException if an error occurs
  */
 private void deleteFiles(final Set<IPath> nameSet, IProgressMonitor monitor)
     throws CoreException {
   if (nameSet == null || nameSet.isEmpty()) {
     return;
   }
   Set<IContainer> subFolders = new HashSet<IContainer>();
   for (IPath filePath : nameSet) {
     // Generate new path
     IFile currentFile = project.getFile(filePath);
     if (currentFile.exists()) {
       // Retrieve parent folder and store for deletion
       IContainer folder = currentFile.getParent();
       subFolders.add(folder);
       currentFile.delete(true, monitor);
     }
     monitor.worked(1);
   }
   // Delete parent folders, if they are empty
   for (IContainer folder : subFolders) {
     if (folder.exists() && folder.members().length == 0) {
       folder.delete(true, monitor);
     }
     monitor.worked(1);
   }
 }
 protected void deleteEmptyParent(IProgressMonitor monitor, IContainer container)
     throws CoreException {
   final IContainer parent = container.getParent();
   if (container.members().length == 0) {
     container.delete(true, monitor);
     deleteEmptyParent(monitor, parent);
   }
 }
 private void removeGlobalEiq(IProject project) throws CoreException {
   final IResource globalEiqFile = project.findMember(MigratorConstants.GLOBAL_EIQ_PATH);
   if (globalEiqFile != null) {
     final IProgressMonitor monitor = new NullProgressMonitor();
     final IContainer parent = globalEiqFile.getParent();
     globalEiqFile.delete(true, monitor);
     if (parent.members().length == 0) {
       parent.delete(true, monitor);
     }
   }
 }
Example #4
0
 private void delete(
     IResource resource,
     OutputConfiguration config,
     EclipseResourceFileSystemAccess2 access,
     IProgressMonitor monitor)
     throws CoreException {
   if (monitor.isCanceled()) {
     throw new OperationCanceledException();
   }
   if (resource instanceof IContainer) {
     IContainer container = (IContainer) resource;
     for (IResource child : container.members()) {
       delete(child, config, access, monitor);
     }
     container.delete(IResource.KEEP_HISTORY, monitor);
   } else if (resource instanceof IFile) {
     IFile file = (IFile) resource;
     access.deleteFile(file, config.getName(), monitor);
   } else {
     resource.delete(IResource.KEEP_HISTORY, monitor);
   }
 }