`
salever
  • 浏览: 250385 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

使用Equinox P2 实现RCP程序更新

    博客分类:
  • 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:

package org.eclipse.update.example.policy;

import org.eclipse.equinox.internal.provisional.p2.ui.policy.IUViewQueryContext;
import org.eclipse.equinox.internal.provisional.p2.ui.policy.Policy;

/**
 * @author salever
 *
 */
public class UpdatePolicy extends Policy{

	public UpdatePolicy() {
		// Disable the ability to manipulate repositories.
		setRepositoryManipulator(null);
		// View everything in the repository.
		IUViewQueryContext context =
		new IUViewQueryContext(IUViewQueryContext.AVAILABLE_VIEW_FLAT);
		context.setVisibleAvailableIUProperty(null);
		setQueryContext(context);
		}
}

  然后在Activtor中使用这个policy.

public void start(BundleContext context) throws Exception {
		plugin = this;
		registration = context.registerService(Policy.class.getName(),
			new UpdatePolicy(), null);
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
	 */
	public void stop(BundleContext context) throws Exception {
		context.ungetService(registration.getReference());
		registration = null;
	}

      同时你还可以使用扩展点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是无效的。

8
1
分享到:
评论
17 楼 salever 2012-03-28  
desertfox633 写道
您好,我想问一下
打包时就有的feature则麻烦一些,必须使用每次打包时生成的repository文件夹下的内容作为更新源,单独导出feature是无效的
始终不明白这个是什么意思,对于打包时就有的插件进行更新,你能给出一些具体的步骤么,试了好多方法都不行
发邮箱也行:desertfox633@163.com
小弟在这里跪谢了

有些feature,是在product的配置文件中的,对于这样的feature就不能单独导出,比如示例中的org.eclipse.update.example feature。有些feature是独立的,比如eclipse的很多project,比如gef,这些feature的更新就不用导出整个product。

有什么不懂得可以发我邮箱 salever@126.com
16 楼 desertfox633 2012-03-23  
您好,我想问一下
打包时就有的feature则麻烦一些,必须使用每次打包时生成的repository文件夹下的内容作为更新源,单独导出feature是无效的
始终不明白这个是什么意思,对于打包时就有的插件进行更新,你能给出一些具体的步骤么,试了好多方法都不行
发邮箱也行:desertfox633@163.com
小弟在这里跪谢了
15 楼 salever 2012-03-21  
desertfox633 写道
http://www.ceclipse.org/read-cec-tid-28124.html
这些网页都不可访问了,怎么回事呢?


不好意思 社区更新了,http://www.ceclipse.org/forum.php?mod=viewthread&tid=28124
14 楼 desertfox633 2012-03-20  
http://www.ceclipse.org/read-cec-tid-28124.html
这些网页都不可访问了,怎么回事呢?
13 楼 salever 2012-02-16  
paulguard 写道
你好,我使用的是Eclipse的3.7版本,但是我下载了你的代码导入之后发现
org.eclipse.equinox.internal.provisional.p2.ui.policy.Policy
这个类是找不到的,而相应的有
org.eclipse.equinox.p2.ui.Policy

但是里面的方法都不同了

org.eclipse.equinox.internal.provisional.p2.ui.policy.IUViewQueryContext
这个类也找不到,似乎也换成了
org.eclipse.equinox.internal.p2.ui.query.IUViewQueryContext

那在这样的情况下,我应该如何配置我的Policy呢?望指点


这个建议你看看http://www.ceclipse.org/read-cec-tid-28124.html 这本书,或者去eclipse的WIKI上找找看
12 楼 paulguard 2012-02-09  
你好,我使用的是Eclipse的3.7版本,但是我下载了你的代码导入之后发现
org.eclipse.equinox.internal.provisional.p2.ui.policy.Policy
这个类是找不到的,而相应的有
org.eclipse.equinox.p2.ui.Policy

但是里面的方法都不同了

org.eclipse.equinox.internal.provisional.p2.ui.policy.IUViewQueryContext
这个类也找不到,似乎也换成了
org.eclipse.equinox.internal.p2.ui.query.IUViewQueryContext

那在这样的情况下,我应该如何配置我的Policy呢?望指点
11 楼 salever 2011-12-29  
langel 写道
不知道为什么, 我按你的方法配置后,运行起来的窗口中没有update菜单项……
望指点

必须要导出product,才能看到update 菜单
10 楼 langel 2011-12-28  
不知道为什么, 我按你的方法配置后,运行起来的窗口中没有update菜单项……
望指点
9 楼 salever 2011-04-06  
R 1.执照你说的,我能更新出来了,但同时又出来了另一个问题:它更新到最新的,下载产品的plugins后,并没有提示重启;我自己重启一下,发现它并不显示更新后的东西,这个应该怎么解决?(使其提示重启,并显示最新的内容)这个你要看看configuration下面的log,查看一下原因,会有一些日志信息的
2.对于新增的feature,建立category.xml,怎么使用这个XML导出metadata repository?使用Update Site  Project方法放在一个新site中,更新,它是灰掉的,说:已经更新过了。
我说的新增的意思指,不包含在product中的feature,这些feature的更新可以使用Update Site Project的方式更新,但这好象是Eclipse3.5的问题,3.6不知道还有没有这个问题

8 楼 salever 2011-04-06  
tianlihu 写道
能不能给一个可用的源码?

这个就是可用的 Eclipse插件工程无法正常运行是很常见的事 你要会摆弄它
7 楼 tianlihu 2011-04-04  
能不能给一个可用的源码?
6 楼 soundycui 2011-03-26  
1.执照你说的,我能更新出来了,但同时又出来了另一个问题:它更新到最新的,下载产品的plugins后,并没有提示重启;我自己重启一下,发现它并不显示更新后的东西,这个应该怎么解决?(使其提示重启,并显示最新的内容)
2.对于新增的feature,建立category.xml,怎么使用这个XML导出metadata repository?使用Update Site  Project方法放在一个新site中,更新,它是灰掉的,说:已经更新过了。
  此两种方案都不知道如何解决,请赐教
5 楼 salever 2011-03-25  
soundycui 写道
为什么,我把Build生成以后的feature和plugins文件夹都放在update site中,且与原来相比都还多了一个jar包,check for update时,总是:There is nothing to update.

这个就要看你要更新的feature是哪一种情况了,如果是RCP里面已经有的feature,那么每次feature更新需要重新export product,然后用respository作为update site的内容。
4 楼 soundycui 2011-03-25  
为什么,我把Build生成以后的feature和plugins文件夹都放在update site中,且与原来相比都还多了一个jar包,check for update时,总是:There is nothing to update.
3 楼 tantec 2010-08-04  
是版本问题,eclipse的插件版本不一致,我按照你的方法重新新建了一次,实现了更新功能。非常感谢!
2 楼 salever 2010-08-04  
是代码不能运行还是更新功能用不了?

方便的话邮件交流。

salever@126.com
1 楼 tantec 2010-08-02  
你这个源代码好像不能用哦

相关推荐

Global site tag (gtag.js) - Google Analytics