Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Deleting Temp Directories While IRunnableProgress is Running
Deleting Temp Directories While IRunnableProgress is Running [message #882710] Thu, 07 June 2012 02:51
Melvin Mah is currently offline Melvin MahFriend
Messages: 24
Registered: July 2009
Junior Member
I have a written class to be used as a popup menu. What the class does is that it will create an artifact via copying the files into a temp directory and zipping it as a .bar file. The functions are okay, except that when I try to delete the temp directories after the zipping process has finished, it returns an error.

I am running this on Eclipse Indigo (32-bit RCP version) on Windows 7.

The code looks like this (the added line is in bold):

@Override
	public void run(IAction action) {
		Object selection = ( (IStructuredSelection) fSelection).getFirstElement();
		final IProject javaProject = (IProject) selection;
		IFolder diagramFolder = null;
		try {
		  diagramFolder = javaProject.getProject().getFolder(DiagramConstants.DIAGRAM_FOLDER);
		  if(diagramFolder == null) {
		    return;
		  }
		} catch(Throwable e) {
		  return;
		}
		final IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
    try {
      progressService.busyCursorWhile(new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
          
          try {
            IProject project = javaProject.getProject();
            
        		// Create folder structures
            IFolder deploymentFolder = project.getFolder("deployment");
            if (deploymentFolder.exists()) {
              deploymentFolder.delete(true, new NullProgressMonitor());
            }
        
            deploymentFolder.create(true, true, new NullProgressMonitor());
            
            IFolder tempbarFolder = project.getFolder("tempbar");
            if (tempbarFolder.exists()) {
              tempbarFolder.delete(true, new NullProgressMonitor());
            }
        
            tempbarFolder.create(true, true, new NullProgressMonitor());
            
            // processdefinition
            String processName = "";
            memberList = new ArrayList<IFile>();
            getMembersWithFilter(project, ".bpmn20.xml");
            if(memberList.size() > 0) {
              for (IFile bpmnResource : memberList) {
                String bpmnFilename = bpmnResource.getName();
                if(processName.length() == 0)
                  processName = bpmnFilename.substring(0, bpmnFilename.indexOf("."));
                bpmnResource.copy(tempbarFolder.getFile(bpmnFilename).getFullPath(), true, new NullProgressMonitor());
              }

              // png
              memberList = new ArrayList<IFile>();
              getMembersWithFilter(project, ".png");
              for (IFile pngResource : memberList) {
                String pngFilename = pngResource.getName();
                pngResource.copy(tempbarFolder.getFile(pngFilename).getFullPath(), true, new NullProgressMonitor());
              }
          
              compressPackage(deploymentFolder, tempbarFolder, processName + ".bar");
              
              // refresh the output folder to reflect changes

              deploymentFolder.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
             [b]tempbarFolder.delete(true, new NullProgressMonitor());[/b]
            }
            
          } catch(Exception e) {
            e.printStackTrace();
          }
          
        }
      });
      
    } catch(Exception e) {
      e.printStackTrace();
    }
  }


tempbarFolder.delete(true, new NullProgressMonitor());
The stacktrace shows like:

org.eclipse.core.internal.resources.ResourceException: Problems encountered while deleting resources.
	at org.eclipse.core.internal.resources.Resource.delete(Resource.java:793)
	at org.eclipse.core.internal.resources.Resource.delete(Resource.java:746)
	at workfloweditor.common.DeploymentMenu$1.run(DeploymentMenu.java:140)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Contains: Could not delete '/test34/tempbar'.
org.eclipse.core.internal.resources.ResourceException: Problems encountered while deleting resources.
	at org.eclipse.core.internal.localstore.FileSystemResourceManager.delete(FileSystemResourceManager.java:352)
	at org.eclipse.core.internal.resources.ResourceTree.internalDeleteFolder(ResourceTree.java:352)
	at org.eclipse.core.internal.resources.ResourceTree.standardDeleteFolder(ResourceTree.java:798)
	at org.eclipse.core.internal.resources.Resource.unprotectedDelete(Resource.java:1941)
	at org.eclipse.core.internal.resources.Resource.delete(Resource.java:780)
	at org.eclipse.core.internal.resources.Resource.delete(Resource.java:746)
	at workfloweditor.common.DeploymentMenu$1.run(DeploymentMenu.java:140)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Contains: Problems encountered while deleting files.
Contains: Could not delete: C:\runtime-workfloweditor.product\test34\tempbar\workflow1.bpmn20.xml.
Contains: Could not delete: C:\runtime-workfloweditor.product\test34\tempbar.


I am not very sure but it is likely that the lock on the directory has still yet to be released in order for those files to be deleted. Yet, if that code is run on the Mac version, it works fine.

Could someone please point out whether if I have missed out something in that or not?

Thanks,

Melvin

[Updated on: Thu, 07 June 2012 03:11]

Report message to a moderator

Previous Topic:DrillDownAdapter and org.eclipse.ui.menus extensions
Next Topic:Link with Editor in IViewPart
Goto Forum:
  


Current Time: Fri Nov 28 10:07:52 GMT 2014

Powered by FUDForum. Page generated in 0.06357 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software