简体   繁体   English

如何安全地使用Eclipse p2配置文件?

[英]How can I safely use an Eclipse p2 profile?

I encounter some problems when I try to update Eclipse plug-ins at the start up of Eclipse. 当我尝试在Eclipse启动时更新Eclipse插件时遇到一些问题。 My program pops up the dialog at Help -> Check for Updates at the start up of Eclipse. 我的程序在Eclipse启动时弹出Help -> Check for Updates对话框。 But, when the user proceeds with the update quickly, Eclipse throws an exception saying that the p2 profile is in use. 但是,当用户快速进行更新时,Eclipse会抛出一个异常,说明p2配置文件正在使用中。 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. 我相信这是因为其他Eclipse作业在启动时使用p2配置文件,因此我的程序无法使用p2配置文件来更新插件。 How can I safely use the p2 profile? 如何安全使用p2配置文件? How can I use the p2 profile in isolation? 如何单独使用p2配置文件?

I've uploaded the minimal piece of code that is needed to reproduce the problem on github . 我已经上传了在github上重现问题所需的最小代码片段。 And, I've described the problem and the steps to reproduce it in details in an issue on the github repository . 而且,我已经在github存储库的一个问题中详细描述了问题和重现它的步骤。

You can get the ProvisioningJob from your UpdateOperation , let it belongs to the family of running profile change job. 您可以从UpdateOperation获取ProvisioningJob ,让它属于运行配置文件更改作业的系列。 See org.eclipse.core.runtime.jobs.Job.belongsTo(Object) . 请参阅org.eclipse.core.runtime.jobs.Job.belongsTo(Object)

Besides I have two ideas to do it via using internal API, 此外,我有两个想法通过使用内部API,

  1. try to test lock the profile to see whether it's being changed. 尝试测试锁定配置文件以查看它是否被更改。 org.eclipse.equinox.internal.p2.engine.SimpleProfileRegistry.lockProfile(Profile)
  2. run your like before, but catch IlegalStateException, then register a ProvisioningListener on the IProvisioningEventBus to be notified when the running profilechangeoperation is finished. 之前运行你的喜欢,但捕获IlegalStateException,然后在IProvisioningEventBus上注册一个ProvisioningListener ,以便在运行profilechangeoperation完成时收到通知。

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.sdk.update”而不是调用以下方法来打开“检查更新”对话框。

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. 令人惊讶的是,这种变化似乎解决了访问p2配置文件时竞争条件的问题。 Does anyone have an explanation for how my commit removes the race condition? 有没有人解释我的提交如何消除竞争条件?

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

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