使用Equinox P2 实现RCP程序更新

   Eclipse的软件管理很方便,尤其是在E3.4以及以后的版本中使用了Equinox P2框架以后,本文将如何使用Equinox P2框架实现RCP 程序的软件安装、更新、管理等进行介绍。

 

    使用旧的UpdateManagerUI 实现更新RCP程序(E3.4以前)请见:

http://www.ibm.com/developerworks/cn/opensource/os-ecl-rcpum/

 

    Equinox P2方式进行Eclipse插件安装介绍请见:

http://www.ibm.com/developerworks/cn/opensource/os-eclipse-equinox-p2/index.html

 

    Equinox P2 进行Update另见:

http://www.vogella.de/articles/EclipseP2Update/article.html#firstfeature_category

http://wiki.eclipse.org/Equinox/p2/Adding_Self-Update_to_an_RCP_Application

http://www.ralfebert.de/blog/eclipsercp/p2_updates_tutorial/

 

Equinox P2

Placid Systems写道
插件更新设备在 Eclipse V3.4 中已经完全重写,它现在使用 Equinox p2 框架代替了原来的更新管理器。Equinox p2 是一个新的、非常高级的配置系统,用于安装、搜索和管理 Eclipse 安装,并且比以前的更新管理器更容易使用。

    使用Equinox P2框架实现RCP 更新,首先需要获得P2相关的插件。Eclipse SDK版本都会包这些插件,如果您的版本中没有,那么请到eclipse.org上自行下载,或者使用Eclipse的Installer New Software功能在线更新。

    主要用到的插件为org.eclispe.equinox.p2.ui以及其依赖的其他插件。

 

Feature

    Feature用来组织插件,更新时需要使用Feature。RCP程序都会包含一个基础Feature——org.eclipse.rcp,它包含了 RCP程序需要的基础插件,内容为见eclipse目录下 features/org.eclipse.rcp_3.5.0.v20090519-9SA0FwxFv6x089WEf-TWh11。

    先创建一个用于更新的RCP程序,org.eclipse.update.example。具体过程略。运行效果为:

    update-example

    下面来创建一个Feature Project。

     File——New——Project——Plug-in Development——Feature Project,Feature工程一般命名为XXXX.featue,主要目的是为了与Plug-in工程区别开,但是Feature的ID却不一定以 feature结尾。

    new feature

    Feature Initialize Plug-in设置,这里设置为org.eclipse.update.example和org.eclipse.ui.forms。

    feature-plugin

 

配置Product

    先给org.eclipse.update.example添加一个product configuration,添加完毕以后,进行product配置。在product中有很多依赖插件,没有这些插件,RCP程序将无法启动。默认情况 下product是基于plug-in的,在这里需要修改为基于feature。修改位置:

product-config

    这时候以feature为依赖项的product就配置好了。但是运行提示失败,因为还没有给它添加以来的feature,在product的 Dependencies中添加我们刚刚创建feature“org.eclipse.update.example”。具体原因和步骤可以参考“ Equinox P2方式进行Eclipse插件”。

    现在我们让插件依赖于feature,所以在对应的feature中必须定义包含的插件,不然RCP会因为找不到依赖项而无法启动。

配置Feature

    feature的配置包括以下几个方面:

    1,包含插件:这些插件就是上面prodcut的依赖项

    2,包含feature:如果使用了eclipse定义的基本feature,那么使用它们会减少工作量。主要是向feature中添加plug-in的 工作量

    3,Update site:更新源URL,可以是一个网址,也可以使本地文件,这里使用本地文件测试。

    首先在feature.xml的Included Feature中添加 org.eclispe.rcp,org.eclipse.equinox.p2.user.ui,org.eclipse.help,这样它们所包含的 插件就无需再添加到包含插件中了。接着在feature.xml的Plug-in中添加org.eclipse.update.example。更新源 URL的设置比较简单,在feature.xml的Overview中,进行设置。注意URL的格式,这里使用本地文件E:/updates。

    4, Dependencies:Feature自己也有依赖项。这里添加org.eclipse.ui, org.eclipse.core.runtime. org.eclipse.equinox.p2.ui.

feature-overview

  如果配置正确,这时候再启动org.eclipse.update.example(使用product),就会发现多出一些菜单项和首选项了。

 update-menu

    更新相关首选项:

update-pref

    这时候更新功能是不能用的,需要继续配置。

    注意这时候Export Product时一定要记得选中Generate Metadata Repository选项,否则Update功能不能使用。大家可以发现选中与不选中时,产生的config.ini文件是不一样的。

 

配置Equinox P2

    P2提供了自定义Update UI的功能,你可以通过扩展 org.eclipse.equinox.internal.provisional.p2.ui.policy.Policy来实现UI的定制。

   比如UpdatePolicy:

Java代码   收藏代码
  1. package org.eclipse.update.example.policy;  
  2.   
  3. import org.eclipse.equinox.internal.provisional.p2.ui.policy.IUViewQueryContext;  
  4. import org.eclipse.equinox.internal.provisional.p2.ui.policy.Policy;  
  5.   
  6. /** 
  7.  * @author salever 
  8.  * 
  9.  */  
  10. public class UpdatePolicy extends Policy{  
  11.   
  12.     public UpdatePolicy() {  
  13.         // Disable the ability to manipulate repositories.  
  14.         setRepositoryManipulator(null);  
  15.         // View everything in the repository.  
  16.         IUViewQueryContext context =  
  17.         new IUViewQueryContext(IUViewQueryContext.AVAILABLE_VIEW_FLAT);  
  18.         context.setVisibleAvailableIUProperty(null);  
  19.         setQueryContext(context);  
  20.         }  
  21. }  

  然后在Activtor中使用这个policy.

Java代码   收藏代码
  1. public void start(BundleContext context) throws Exception {  
  2.         plugin = this;  
  3.         registration = context.registerService(Policy.class.getName(),  
  4.             new UpdatePolicy(), null);  
  5.     }  
  6.   
  7.     /* 
  8.      * (non-Javadoc) 
  9.      * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) 
  10.      */  
  11.     public void stop(BundleContext context) throws Exception {  
  12.         context.ungetService(registration.getReference());  
  13.         registration = null;  
  14.     }  

      同时你还可以使用扩展点org.eclipse.ui.about.installationPages来定义软件安装页面。

 

配置Update Site

    New——Plug-in Development——Update Site Project,然后添加Category和要更新的Feature。

    update site

    点击上面的Build按钮,在工程目录下会生成更新源文件,将这些文件复制到update site目录中。

 

    稍后会给出实例源码。

 

     注意Eclipse3.5 下使用Equinox p2方式更新Feature时有2种情况,一种是针对新安装的插件的更新,另一种是针对打包时就有的插件的更新,两种方式下更新源文件的制作方式不同。

     1,新安装的插件的更新:给插件对应的Feature建立category.xml,然后使用这个XML导出metadata repository,就可以作为更新源,也可以使用上面的Update Site  Project方法。

     2,打包时就有的feature则麻烦一些,必须使用每次打包时生成的repository文件夹下的内容作为更新源,单独导出feature是无效的。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值