}
@Override
public void launch(ILaunchConfiguration configuration, String mode, final ILaunch launch, IProgressMonitor monitor) throws CoreException {
// Register listener to clean up temp files on exit of launched JVM
final ProjectLauncher launcher = getProjectLauncher();
IDebugEventSetListener listener = new IDebugEventSetListener() {
public void handleDebugEvents(DebugEvent[] events) {
for (DebugEvent event : events) {
if (event.getKind() == DebugEvent.TERMINATE) {
Object source = event.getSource();
if (source instanceof IProcess) {
ILaunch processLaunch = ((IProcess) source).getLaunch();
if (processLaunch == launch) {
// Not interested in any further events =>
// unregister this listener
DebugPlugin.getDefault().removeDebugEventListener(this);
// Cleanup. Guard with a draconian catch because
// changes in the ProjectLauncher API
// *may* cause LinkageErrors.
try {
launcher.cleanup();
} catch (Throwable t) {
logger.logError("Error cleaning launcher temporary files", t);
}
}
}