如何安全地使用 Eclipse p2 配置文件?
当我尝试在 Eclipse 启动时更新 Eclipse 插件时遇到一些问题。我的程序弹出Help -> 对话框在 Eclipse 启动时检查更新
。但是,当用户快速进行更新时,Eclipse 会抛出异常,指出 p2 配置文件正在使用中。我相信这是因为其他 Eclipse 作业在启动时使用 p2 配置文件,因此我的程序无法使用 p2 配置文件来更新插件。如何安全使用 p2 配置文件?如何单独使用 p2 配置文件?
我已在 github 上上传了重现问题所需的最少代码。而且,我已经在 github 存储库上的问题中详细描述了该问题以及重现该问题的步骤。
I encounter some problems when I try to update Eclipse plug-ins at the start up of Eclipse. My program pops up the dialog at Help -> Check for Updates
at the start up of Eclipse. But, when the user proceeds with the update quickly, Eclipse throws an exception saying that the p2 profile is in use. I believe this is because other Eclipse jobs are using the p2 profile at the start up and thus my program fails to use the p2 profile to update the plug-ins. How can I safely use the p2 profile? How can I use the p2 profile in isolation?
I've uploaded the minimal piece of code that is needed to reproduce the problem on github. And, I've described the problem and the steps to reproduce it in details in an issue on the github repository.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以从
UpdateOperation
中获取ProvisioningJob
,让它属于正在运行的配置文件更改作业系列。请参阅org.eclipse.core.runtime.jobs.Job.belongsTo(Object)
。此外,我有两个想法可以通过使用内部 API 来完成此操作,
org.eclipse.equinox.internal.p2.engine.SimpleProfileRegistry.lockProfile(Profile)
上注册一个
。ProvisioningListener
当正在运行的配置文件更改操作完成时,将通知 IProvisioningEventBusYou can get the
ProvisioningJob
from yourUpdateOperation
, let it belongs to the family of running profile change job. Seeorg.eclipse.core.runtime.jobs.Job.belongsTo(Object)
.Besides I have two ideas to do it via using internal API,
org.eclipse.equinox.internal.p2.engine.SimpleProfileRegistry.lockProfile(Profile)
ProvisioningListener
on theIProvisioningEventBus
to be notified when the running profilechangeoperation is finished.我的提交通过调用命令“org.eclipse. equinox.p2.ui.sdk.update”而不是调用以下内容 方法。
org.eclipse.equinox.p2.ui.ProvisioningUI.openUpdateWizard(boolean, UpdateOperation, LoadMetadataRepositoryJob)
令人惊讶的是,此更改似乎修复了访问 p2 配置文件时的竞争条件问题。有人可以解释我的提交如何消除竞争条件吗?
My commit opens the "Check for Updates" dialog by invoking the command "org.eclipse.equinox.p2.ui.sdk.update" instead of invoking the following method.
org.eclipse.equinox.p2.ui.ProvisioningUI.openUpdateWizard(boolean, UpdateOperation, LoadMetadataRepositoryJob)
Surprisingly, this change seems to fix the issue with the race condition in accessing the p2 profile. Does anyone have an explanation for how my commit removes the race condition?