简体   繁体   English

如何正确结束Eclipse启动配置执行?

[英]How to properly end Eclipse launch configuration execution?

I am writing an Eclipse plugin contributing a new launch configuration type. 我正在编写一个Eclipse插件,它提供了一个新的启动配置类型。 It works perfectly expected that when the execution of a launch configuration for this new type is completed, the launch configuration button tooltip still indicates that my configuration is running. 完全可以预期,当完成此新类型的启动配置的执行时,启动配置按钮工具提示仍指示我的配置正在运行。

This causes problem when I want to launch several of such configurations using launch groups, the second configuration waits indefinitely for the first one to complete (I am using the wait until termination option from the launch group). 当我想使用启动组启动多个此类配置时,这会导致问题,第二个配置无限期地等待第一个配置完成(我使用启动组的等待直到终止选项)。 So I guess I am missing something to tell the platform that the execution of the launch config is completed. 所以我想我错过了告诉平台启动配置执行完成的事情。

If I remember correctly, you need to start a new system Process when your launch configuration is launched ( ILaunchConfigurationDelegate#launch ) and then create a RuntimeProcess for this Process . 如果我没记错的话,你需要在启动启动配置时启动一个新的系统ProcessILaunchConfigurationDelegate#launch ),然后为这个Process创建一个RuntimeProcess The RuntimeProcess will then generate the necessary DebugEvents and notify the corresponding ILaunch when it was terminated. 然后, RuntimeProcess将生成必要的DebugEvents并在终止时通知相应的ILaunch

You will usually create the RuntimeProcess by calling DebugPlugin#newProcess(ILaunch, Process, String) but it is also possible to instantiate it directly (eg if you want to extend the class RuntimeProcess ). 您通常会通过调用DebugPlugin#newProcess(ILaunch, Process, String)来创建RuntimeProcess ,但也可以直接实例化它(例如,如果您想扩展RuntimeProcess类)。

By looking at sample launch configurations (mainly the one provided by the Ant plugin), there is an org.eclipse.debug.core.model.ITerminate interface that is implemented in the process/debug targets that execute in the launch. 通过查看示例启动配置(主要是Ant插件提供的配置),有一个org.eclipse.debug.core.model.ITerminate接口,它在启动时执行的进程/调试目标中实现。

A org.eclipse.debug.core.IDebugEventSetListener is registered to handle terminate events which are triggered by calling the following statement: 注册org.eclipse.debug.core.IDebugEventSetListener以处理通过调用以下语句触发的终止事件:

DebugPlugin.getDefault().fireDebugEventSet(
                  new DebugEvent[] {new DebugEvent(this, DebugEvent.TERMINATE)});

Sample code from the AntLaunchDelegate class: AntLaunchDelegate类的示例代码:

final boolean[] terminated = new boolean[1];
terminated[0] = launch.isTerminated();
IDebugEventSetListener listener = new IDebugEventSetListener() {
    public void handleDebugEvents(DebugEvent[] events) {
        for (int i = 0; i < events.length; i++) {
            DebugEvent event = events[i];
            for (int j = 0, numProcesses = processes.length; j < numProcesses; j++) {
                if (event.getSource() == processes[j]
                        && event.getKind() == DebugEvent.TERMINATE) {
                    terminated[0] = true;
                    break;
                }
            }
        }
    }
};
DebugPlugin.getDefault().addDebugEventListener(listener);
monitor
        .subTask(AntLaunchConfigurationMessages.AntLaunchDelegate_28);
while (!monitor.isCanceled() && !terminated[0]) {
    try {
        Thread.sleep(50);
    } catch (InterruptedException e) {
    }
}
DebugPlugin.getDefault().removeDebugEventListener(listener);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM