21.2. FeaturesManually dealing with collections of plug-ins is quite problematic. Human error and miscommunication cause you to get a few too many plug-ins, miss a few plug-ins, or pick up the wrong versions of plug-ins. Features allow you to abstract away the packaging details and talk about arbitrarily complex collections of plug-ins that can be built and deployed. 21.2.1. Uses of FeaturesUpdate uses features to manage plug-ins in the following ways:
21.2.2. What Is a Feature?A feature is a list of related plug-ins and other features. They are defined in a feature.xml file that lives in a feature directory, as shown in Figure 21-1. Figure 21-1. Feature directory structureAt its simplest, a feature is an id/version pair and a list of plug-ins. As with plug-in ids, feature ids typically follow Java package naming conventions and their version numbers take the form major.minor.micro.qualifier. The example below shows an abbreviated version of the feature.xml for the org.eclipse.rcp feature in your Eclipse 3.1 target platform. The body of the feature lists the plug-ins that comprise the RCP Base. These plug-ins are said to be included in the feature. This means that if you install the RCP Base feature, all listed plug-ins are installed. org.eclipse.rcp/feature.xml Note It is important to note that features do not contain the plug-ins. Rather, features reference their constituent parts. This allows the same plug-in to appear in many features, but only be installed once. The previous snippet shows the XML form of the featurethis reiterates the idea that a feature is really just a list of plug-ins and other features. In practice, you never have to edit the XML directly as PDE includes a comprehensive feature editor. You can open the editor on the RCP feature using File > Open File... and navigating to the feature in your target (e.g., c:\target\eclipse\features\org.eclipse.rcp_3.1.0\feature.xml) or by double-clicking on the RCP Base feature in the Included Features list of the Hyperbola feature. Either way, open the editor and flip to the Plug-ins page, as shown in Figure 21-2. Figure 21-2. RCP feature plug-in list[View full size image] Notice that the list shown has a number of entries related to SWT. These entries are the SWT fragments that contain the code specific to a given OS, window system, and processor architecture. If you install the RCP Base feature on Windows, for example, you need a different SWT fragment than if the feature is installed on Linux using GTK. The Plug-in Details shown indicates that the selected fragment (org.eclipse.swt.gtk.linux.x86) is specific to "linux", "gtk", and "x86". As such, Update ignores this fragment on other configurations. Only the relevant attributes need to be specified. For example, if your plug-in runs on all Motif systems, simply setting the Window System to "motif" is sufficient. Of course, if the plug-in or fragment includes native code, you must specify at least the Operating System and Architecture attributes. Note Notice also that the selected fragment is marked as not needing to be unpacked during installation. Plug-ins on an update site are stored as JARs. Traditionally, Update has unpacked these JARs into plug-in directories after downloading. As of Eclipse 3.1, many plug-ins no longer need to be unpacked and therefore have this option deselected. Now that you have the RCP Base feature, you no longer have to laboriously list each of the RCP plug-ins when defining other features. Figure 21-3 shows the Included Feature page for the Hyperbola feature editor. Included are the RCP Base feature you added back in Chapter 14 and org.eclipsercp. hyperbola.feature.muc, an additional feature used to demonstrate the notion of optional features. Figure 21-3. Including features[View full size image] Here, the Included Feature Details section shows the MUC feature marked as optional. Typically, a parent feature fails to install if some of its included features and plug-ins are not present. However, marking a feature as optional allows the parent to be installed even if the optional feature is not present or cannot be installed. This is ideal for defining products that are extensible according to user needs or OS facilities. The above examples illustrate the definition of feature contentfeatures are made up of the plug-ins and features that are included in their definition. If you install a feature, all its constituents are also installed, if not already available. This is powerful, but the inclusion characteristic is limiting. Typically, when you include some plug-ins or features, you are committing to shipping them. If your product is to be installed with others, it is better to simply state a dependency on the parts that are needed. For example, the Hyperbola feature could specify a requirement that the RCP Base feature already be installed. This does not commit you to delivering the RCP Base, but it does express the dependency so that it can be checked. On the Dependencies page, you can list the features and plug-ins that must be present to successfully install your feature. Figure 21-4 shows a feature that declares the RCP Base feature and Browser and Intro plug-ins as required, but not supplied. Installing this feature makes no attempt to download or install the listed elements; rather, the information is used by the Update UI to verify the correctness of a configuration. Figure 21-4. Feature dependencies[View full size image] Tip To install features using Update, the features must have a license agreement. This agreement is shown to the user as he goes through the Update/Install wizard. To define the license, go to the License Agreement tab on the Information page of the feature editor. There you can fill in the license text and a URL to use when showing the license to the user. |
Wednesday, October 21, 2009
Section 21.2. Features
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment