我正在开发一个实现org.eclipse.pde.ui.IPluginContentWizard接口的向导。因此,它将作为插件项目模板添加到插件项目向导的末尾。所有文件都可以正常创建,但项目中有一个错误。插件没有声明为singleton,这是扩展扩展点时必须声明的。
如何在向导中执行此操作?我认为它需要在performFinish(IProject项目,IPluginModelBase模型,IProgressMonitor监视器)中完成,但无论是项目还是模型都不能给我这样做的可能性。
编辑:给未来的读者:我的错误是,我没有通过API添加扩展,而是通过“手动”生成plugin.xml。这导致后台没有任何机制来完成它们的工作,因此没有设置singleton指令。
发布于 2019-04-12 02:40:47
这种方式太长了,让我们使用更多的PDE API:
首先,定义模板部分
import org.eclipse.pde.ui.templates.OptionTemplateSection;
public class YourTemplateSection extends OptionTemplateSection {
//implement abstract methods according your needs
@Override
protected void updateModel(IProgressMonitor monitor) throws CoreException {
IPluginBase plugin = model.getPluginBase();
//do what is needed
plugin.add(extension);//here the "singleton" directive will be set
}
}然后使用带有向导的部分
import org.eclipse.pde.ui.templates.ITemplateSection;
import org.eclipse.pde.ui.templates.NewPluginTemplateWizard;
public class YourContentWizard extends NewPluginTemplateWizard {
@Override
public ITemplateSection[] createTemplateSections() {
return new ITemplateSection[] { new YourTemplateSection() };
}
}发布于 2019-04-12 22:00:59
以防有人犯了和我一样的菜鸟错误,我想把我后来重温这个项目后想出来的解决方案贴出来:
不要手动创建plugin.xml,使用插件模型的PDE API来添加扩展。
在org.eclipse.pde.ui.IPluginContentWizard实现的performFinish(...)方法中,执行以下操作:
try {
IPluginExtension extension = model.getExtensions().getModel().getFactory().createExtension();
extension.setPoint("org.eclipse.elk.core.layoutProviders");
IPluginElement provider = model.getPluginFactory().createElement(extension);
provider.setName("provider");
provider.setAttribute("class", id + "." + algorithmName + "MetadataProvider");
extension.add(provider);
model.getExtensions().add(extension);
} catch (CoreException e) {
e.printStackTrace();
}https://stackoverflow.com/questions/53006329
复制相似问题