【发布时间】:2016-06-27 10:44:11
【问题描述】:
我正在尝试为 OSGI 控制台 (Equinox) 创建自定义命令,但我似乎无法正确注册或使用该命令。捆绑包启动并尝试调用mock:command 或command 无济于事。使用的 Eclipse 相当旧:3.6.2.R36x_v20110210 并且包含的包是手动启动的。有什么想法吗?
public class Activator extends Plugin
{
private static Activator plugin;
private MockCommand service;
@Override
public void start(BundleContext context) throws Exception{
plugin = this;
Dictionary<String, Object> properties = new Hashtable<String, Object>();
properties.put("osgi.command.scope", "mock");
properties.put("osgi.command.function", new String[] {MockCommand.COMMAND});
service = new MockCommand();
context.registerService(MockCommand.class.getName(),service, null);
super.start(context);
}
@Override
public void stop(BundleContext context) throws Exception{
plugin = null;
service = null;
super.stop(context);
}
public static Activator getDefault(){
return plugin;
}
}
还有 CommandProvider:
public class MockCommand implements CommandProvider{
public static String COMMAND ="command";
public void _command(CommandInterpreter ci) throws Exception {
String commandID = "com.sample.project.fetchMySampleDataCommandId";
((IHandlerService)PlatformUI.getWorkbench().getService(IHandlerService.class)).executeCommand(commandID, null);
}
@Override
public String getHelp() {
StringBuffer buffer = new StringBuffer();
buffer.append("--- Available commands to call by ID ---\n\t");
buffer.append("command --> com.sample.project.fetchMySampleDataCommandId\n\t");
return buffer.toString();
}
}
【问题讨论】: