删除Java中的目录

时间:2012-09-25 02:29:33

标签: java eclipse junit

我正在eclipse中创建一个动态IProject。这个IProject就像eclipse中的“JAR压缩新插件”项目。然后我指向这个外部jar文件的引用。我提取哪个btw然后链接到临时IProject。

<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();
        }
    });

1 个答案:

答案 0 :(得分:0)

我刚添加了这个

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