2012-09-25 82 views
0

我在eclipse中創建了一個動態IProject。這個IProject就像eclipse中的「帶JAR歸檔的新插件」項目一樣。然後我指向這個外部jar文件的引用。哪btw我提取然後鏈接到臨時IProject。在Java中刪除目錄

<linkedResources> 
    <link> 
     <name>SampleTestSuite</name> 
     <type>2</type> 
     <location>D:/eclipse-rcp-indigo/tests/SampleTestSuite</location> 
    </link> 
</linkedResources> 

現在,我打算製作這個IProject Run-As JUnit。我想在JUnit之後刪除提取和鏈接的jar文件。這是我在運行JUnit時的代碼,但在刪除文件後,它會拋出一個錯誤,因爲鏈接的資源不會在那裏。任何想法如何監視JUnit是否已經完成,以便鏈接的資源將被刪除?

Activator.getDisplay().syncExec(new Runnable() { 
    public void run() { 
    Job job = new Job("Test Runner JUnit") { 
    @Override 
       protected IStatus run(IProgressMonitor monitor) { 
        monitor.beginTask("Launching JUnit", 100); 
        try { 
         ILaunch launch = new Launch(launchConfiguration, 
           "run", null); 
         launch.setAttribute(
           "org.eclipse.debug.ui.ATTR_CONSOLE_ENCODING", 
           DebugPlugin.getDefault().getLaunchManager() 
             .getEncoding(launchConfiguration)); 
         DebugPlugin.getDefault().getLaunchManager() 
           .addLaunch(launch); 
         launchDelegate.launch(launchConfiguration, "run", 
           launch, monitor); 
        } catch (CoreException e) { 
         return e.getStatus(); 
        } finally { 
         monitor.done(); 
        } 

        return Status.OK_STATUS; 
       } 
      }; 

      job.addJobChangeListener(new JobChangeAdapter() { 
       public void done(IJobChangeEvent event) { 
        if (event.getResult().isOK()) { 
         System.out.println("Job completed successfully"); 
         // delete the file here 
        } else 
         System.out 
           .println("Job did not complete successfully"); 
       } 
      }); 


      job.setPriority(Job.INTERACTIVE); 
      job.schedule(); 
     } 
    }); 

回答

0

我只是說這個

IProcess[] processes = launch.getProcesses(); 
    for (IProcess process : processes) { 
    while (!process.isTerminated()) { 
    } 
     //delete here 
    }