Eclipse 插件:如何 运行 在 for 循环中同步启动配置?
Eclipse Plugin: How to run Launch-Configurations in a for-loop synchronously?
这是我的代码的简化版本。 configurations
是类型 ILaunchConfiguration
的 数组 。
for (int j = 0; j < configurations.length; j++) {
configurations[j].launch("debug", null);
}
我想实现每个 ILaunchConfiguration
只在前一个终止时启动。使用我当前的代码,我有 Thread 行为。所有配置同时启动。
我应该改变什么?
你不能在一个简单的循环中真正做到这一点,因为你必须使用 IDebugEventSetListener
侦听器来侦听启动终止时创建的每个进程。
当您调用 ILaunchConfiguration.launch
时,您会得到一个 ILaunch
对象。然后,您可以调用 ILaunch.getProcesses
来获取由启动创建的 IProcess
个对象的数组(可能创建了多个进程)。
设置 IDebugSetEventListener
使用:
DebugPlugin.getDefault().addDebugEventListener(listener);
在侦听器 handleDebugEvents
中,您可以检查完成的进程,例如:
public void handleDebugEvents(DebugEvent [] events)
{
for (DebugEvent event : events) {
Object source = event.getSource();
if (source instanceof IProcess &&
event.getKind() == DebugEvent.TERMINATE) {
// TODO check if the process terminating is one you are interested in
}
}
}
一次启动的所有进程终止后,您就可以进行下一次启动。
这是我的代码的简化版本。 configurations
是类型 ILaunchConfiguration
的 数组 。
for (int j = 0; j < configurations.length; j++) {
configurations[j].launch("debug", null);
}
我想实现每个 ILaunchConfiguration
只在前一个终止时启动。使用我当前的代码,我有 Thread 行为。所有配置同时启动。
我应该改变什么?
你不能在一个简单的循环中真正做到这一点,因为你必须使用 IDebugEventSetListener
侦听器来侦听启动终止时创建的每个进程。
当您调用 ILaunchConfiguration.launch
时,您会得到一个 ILaunch
对象。然后,您可以调用 ILaunch.getProcesses
来获取由启动创建的 IProcess
个对象的数组(可能创建了多个进程)。
设置 IDebugSetEventListener
使用:
DebugPlugin.getDefault().addDebugEventListener(listener);
在侦听器 handleDebugEvents
中,您可以检查完成的进程,例如:
public void handleDebugEvents(DebugEvent [] events)
{
for (DebugEvent event : events) {
Object source = event.getSource();
if (source instanceof IProcess &&
event.getKind() == DebugEvent.TERMINATE) {
// TODO check if the process terminating is one you are interested in
}
}
}
一次启动的所有进程终止后,您就可以进行下一次启动。