joi, 20 iunie 2013

Eclipse RCP: Installing and Updating with p2 (Part I)

With Eclipse RCP you can build complex platform independent applications using a powerful framework. As it is very important to keep your applications updated, one of the most interesting feature of Eclipse RCP is Equinox p2. Provisioning is the act of finding and installing new functionality, and updating or removing existing functionality. Equinox p2 is a provisioning platform for Eclipse-based applications and debuted in Eclipse v3.4 as a replacement for the old Update Manager.

Although the update system represents a very important aspect for a professional software product, the issues encountered during implementation by a lot of developers shows that it is not quite strait forward to build one and integrate it.

The scope of this article is to make a step-by-step presentation of how to create an update-able application using Eclipse RCP. The tutorial is composed of two parts:
  • In Part I we will create an Eclipse RCP application and we will also integrate the p2 update system.
  • In tutorial's Part II we will add a default update site, create a new version of the application and some new features which will be installed using the integrated update system created in Part I.
Development Environment
  • IDE: Eclipse Juno (4.2.2)
  • Eclipse Platform 3.8.2
  • JDK
  1. As the example is intended for Eclipse Platform 3.x based applications, we should set the target platform in IDE: Window → Preferences → Plugin Development → Target Platform
  2. Create a New Plug-in Project and choose RCP application with a view from the Available Templates (add branding also).
  3. Create a Product Configuration for this plugin: Right click on the project → New
    → Product Configuration
  4. You can test your product by clicking on in application.product Overview tab. You have just created an Eclipse RCP application which can also be exported using Exporting section from application.product Overview tab:
  5. The product is currently based on plug-ins and contains (Dependencies tab) among others, the plug-in defined in Step 2.  As only features can be updated we will have to change the product and make it based on features:
  6. Create a new feature (File→New→Feature Project). Add the following plugins to this feature: org.eclipse.equinox.ds, org.eclipse.ui.forms and the plugin created on Step 2. (In my example ro.ecojocaru.rpc.application)
  7. Go to Product (application.product) and on Dependencies tab add the newly created feature on Step 6, plus the following features (required for product run and update system): org.eclipse.rcp, org.eclipse.equinox.p2.user.ui, org.eclipse.equinox.p2.core.feature, org.eclipse.equinox.p2.rcp.feature, org.eclipse.equinox.p2.extras.feature (or by adding the first two features and pressing Add Required will add the rest of them)
  8. At this step you can test your product again and it should run successfully based on features as it was running based on plug-ins.
  9. The next step is to integrate the menu that will allow user to perform updates. You can observe that in Eclipse IDE, updates can be handled through Help → Check for Updates and Help → Install New Software... Go to the application main plugin (created on Step 2), open plugin.xml and choose Extensions tab. On extension org.eclipse.ui.menus add a new menu with label &Help and id help. By creating this menu, update handler menu items  will automatically be added, due to *p2 features added to the product.
  10. Ensure that you have in product (application.product), Configuration tab, the correct start levels and auto-start flags set for the bundles required to run the p2 processes.
  11. You can now test again your product and notice that Help menu is added to the menu bar and also it contains update handler menu items, similar with the ones from Eclipse IDE.
  12. Update features do not work correctly in development mode so you will have to export the product (If you developed on a different JDK than system's default take care also to specify the location of the correct JRE or you can bundle the JRE for development environment with product in Launching tab).
  13. Go to your exported product and run the application. You now have an Eclipse RCP application with a functional p2 update system integrated.
In the second part of this tutorial we will add some update sites and also we will create new features to our application and update it using the integrated update system.