I made a hack by replacing JavaProcess with decorated one:
IProcess p = launch.getProcesses()[0];
launch.addProcess(new JavaProcessDecorator(p));
launch.removeProcess(p);
And decorator is overriding terminate function.
public class JavaProcessDecorator implements IProcess {
private IProcess p;
public JavaProcessDecorator(IProcess p) {
this.p = p;
}
private boolean sigkill = false;
@SuppressWarnings("rawtypes")
@Override public Object getAdapter(Class arg) { return p.getAdapter(arg); }
...
@Override public ILaunch getLaunch() { return p.getLaunch(); }
@Override public IStreamsProxy getStreamsProxy() { return p.getStreamsProxy(); }
@Override public void setAttribute(String s1, String s2) { p.setAttribute(s1, s2); }
@Override public void terminate() throws DebugException {
if(!sigkill) {
try {
IDebugIService cs = DirmiServer.INSTANCE.getRemote("main", IDebugIService.class);
if(cs != null) cs.modelEvent(new TerminateRequest());
} catch (RemoteException e) { }
this.sigkill = true;
} else p.terminate();
}}
At first click on red button, I send a message to application asking for gently termination. If it is not working, second click on red button will kill it.