Time for action – depending on other features

If a feature needs functionality provided by another feature, it can be declared via the feature.xml file of the feature itself. For example, installing the E4 feature may depend on some runtime components provided by JGit, so installing the JGit feature will mean that everything required is present.

To add JGit as a dependency to the E4 feature.

  1. Edit the feature.xml file and go to the Dependencies tab:
    Time for action – depending on other features
  2. Click on Add Feature and select org.eclipse.jgit from the list. It will fill in a version range using the exact version specified in the plug-in; invariably it is better to substitute that with a lower-bound version number since that will allow the feature to be installed with a dependency that is slightly lower. This will result in a feature.xml that looks like:
    <feature id="com.packtpub.e4.feature" label="Feature"
      version="1.0.0.qualifier" provider-name="PACKTPUB">
      <requires>
        <import feature="org.eclipse.jgit" version="4.0.0" match="greaterOrEqual"/>
      </requires>
     <plugin id="com.packtpub.e4.clock.ui"
        download-size="0"
        install-size="0"
        version="0.0.0"
        unpack="false"/>
    <feature/>
  3. Run the Build All again. The features/ directory will contain just the com.packtpub.e4.feature, and the plugins/ directory will contain just the com.packtpub.e4.clock.ui plug-in.
  4. Install the feature again (or navigate to Help | Check for Updates if the directory has already been added). This time, as well as installing the example feature, it should prompt to install JGit, which it will get from the standard Eclipse update sites, provided that JGit is not already installed.

What just happened?

By adding a dependency on another feature, when it is installed into a running Eclipse platform, it requires that the other feature be present. Suppose the Consult all update sites checkbox is ticked; then if the feature is not installed and cannot be found from the current update site, other update sites will be consulted to acquire the missing feature.

Note that the JGit feature will not be present in the exported site. This is generally desirable since it is unnecessary to duplicate features that are available elsewhere. However, if this is desired then remove the dependency from the Dependency tab and add it to the Included features tab. This will result in the requires dependency being changed to an includes dependency in the feature.xml file.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.95.244