Packaging and distributing RCP applications using p2
The last enhancement you'll look at in this tutorial is a new method of packaging and distributing plug-ins. In previous versions of Eclipse, the packaging was essentially creating a ZIP archive of all the relevant files, along with an appropriate manifest, and placing it on a publicly available server. These could then be installed either by using the Help > Updates feature from the menu, or many users simply opted to download and unzip the plug-in archive directly in the appropriate Eclipse installation folder. The p2 mechanism streamlines this process, allowing for a clean packaging and automated distribution. In this section, you'll create a p2 update site and package your plug-in for distribution through it.
Packages contain features, which themselves are composed of plug-ins. So to package your organizer plug-in for p2, you have to start by creating a feature list. You do this by using the new project wizard. From the Eclipse menu, select New > Project > Plug-in Development > Feature Project and click Next.
Figure 41. Creating a new feature project
Name this project com.devworks.tutorial.po.feature and store
it in the default location for simplicity. Leave the feature ID as its default of the
project name, but change the feature name to Personal Task
Organizer. Leave the rest of the fields at their defaults, then click Next.
Figure 42. Feature properties editor
Eclipse will display a screen asking for the plug-in that should be used to initialize this feature set. Since this feature set is all about your personal-organizer plug-in, select com.devworks.tutorial.po from the list, then Finish.
Figure 43. Selecting the plug-in that provides the definition of the feature
The wizard completes by creating a new project and populating a file called feature.xml. This contains information about the features,
dependencies, licensing, and build instructions for your plug-ins — in short, everything needed to build a distribution.
Figure 44. The feature.xml shown in the editor
The update site you'll create next will use this feature list.
Now that you have a feature set, you can use this create a site from which to distribute it. What is created is a set of files that can be made publicly available on the Internet or on a corporate intranet, or distributed on disc, or as a ZIP file. The files and structure created are simply made in a directory that you can then distribute as you wish.
Creating a new update site is simple. Once again, the New Project wizard steps in. From the Project Explorer, select New > Project > Plug-in Development > Update Site Project, then select Next.
Figure 45. Creating a new update site project
This will start a wizard that will create a new project that represents your update
site (see Figure 46). Enter com.devworks.tutorial.updatesite
as the project name and save it on your local file system. (Selecting the default
location will create the update site in your current workspace; choosing an external
location will make this tutorial a bit clearer, but you decide.) Click Finish.
Figure 46. The update site project properties editor
The wizard will create a project with a single site.xml file, displayed in the editor. It describes the package as the updater will see it.
Figure 47. The site.xml shown in the editor
You now need to configure that site.xml to add a category and features. This
fleshes out the update site with the material you are intending it to distribute. Click
New Category on the site.xml editor, and the right side of the editor will
display properties you will edit (see Figure 48). Enter Personal
Task Organizer for the name, and Tutorial for the
label. You can enter a description of your choice; we used This is
a Personal Task Organizer.
Figure 48. Adding the category
Now highlight the Personal Task Organizer on the left-side list box, then click Add Feature. Eclipse will display a list of available features, including the one you created earlier (see Figure 49). Select com.devworks.tutorial.po.feature from the list, then click OK.
Figure 49. Selecting the feature to add to the update site
This will add it to the list of features in your category.
Figure 50. Feature shown in the site.xml editor
You're ready to build out your distribution physically on your disk. Save your edits, then highlight the Personal Task Organizer again in the list of categories. Click Build All, and this will create an update site in your given path.
Congratulations! You have created a distribution of your organizer, suitable for publishing to the world. Let's see how it would look to a user seeking to download and install it in his Eclipse environment, by loading it into your own Eclipse environment.
You will add your plug-in the same as you did the Subversive plug-in, by way of the Software Updates function. Navigate to Help > Software Updates, then click Add Site. This time, however, instead of a URL on the Web, click Local, and Eclipse will display a file browse box. Navigate to the directory where you created your update site, click OK, then OK again on the Add screen.
Figure 51. Adding the location of the new site in Software Updates
Your update site now appears in the list of available updates.
Figure 52. The organizer in the software update list
To install your plug-in, select it from the list, then click Install. You will see your plug-in listed in a standard plug-in install screen.
Figure 53. The organizer installation screen
Click Next, and you will be presented with a license screen (see Figure 54). Since you didn't enter a license, you'll see a default message, but be sure to select I accept, then click Finish.
Figure 54. Licensing terms screen
Eclipse will install the organizer plug-in and prompt for a restart. After the restart, you will find your plug-in under Window > Show View > Other > Other.
Figure 55. Opening the organizer
Click OK, and your personal organizer will load and run within the Eclipse workbench.
Figure 56. The organizer in the Eclipse workbench
Your personal organizer is now a part of your Eclipse workbench ready for you to use alongside everything else that makes up the Eclipse experience.



