What is p2?

p2 is a provisioning platform for Eclipse-based applications. It replaces the older Update Manager as the mechanism for managing an Eclipse installation. Provisioning is the act of finding and installing new functionality, and updating or removing existing functionality; it is distinct from building.

p2 manages artifacts, such as bundles, features, and products; you can think of these as bags of bytes. p2 not only stores these artifacts, it also stores metadata about these artifacts, such as version information, cryptographic signatures, dependencies between artifacts, platform specifics, and special installation requirements.

Every p2 artifact is uniquely identified by an identifier and version number. For example, the Equinox OSGi container from the Indigo release is a bundle whose identifier is org.eclipse.osgi and version 3.7.0.v20110110. p2 assumes that two artifacts with the same identifier and same version number are the same artifact.

An artifact is made available to p2 by publishing the artifact to a repository, a process that also adds any metadata about the artifact. p2 comes with several publishers that know how to extract metadata for bundles, features, and products. Most Eclipse build systems (e.g., Tycho, Buckminister, PDE/Build) can automatically publish the artifacts during a build. Other publishers could be created using p2's APIs to handle other types of artifacts (e.g., Windows DLLs).

The p2 Director is responsible for installing a set of artifacts. The Director uses the metadata about an artifact, called an installable unit or IU, to determine how the artifact should be installed and to include any dependencies of those artifacts. Thus installing a product requires installing its associated features, which requires installing the specified bundles; installing the product also requires installing the platform-specific executable.

The Director is a wrapper around several lower-level p2 components. A Profile records the IUs installed. An Agent uses the Planner to determine the IUs to be managed, and uses the Engine to actually perform the sequence of installation steps. These installation steps are handled by touchpoints specific to each type of artifact.

Accessing Repositories

Why won't p2 replace an updated bundle in a repository?

p2 assumes that two artifacts with the exact same identifier and version are the same artifact. Once an artifact has been published to a repository, it cannot be replaced. This restriction acts both as a performance optimization, to avoid unnecessary downloads, as well as a consistency check. For example, the Equinox OSGi container from the Indigo release is a bundle whose identifier is org.eclipse.osgi and version 3.7.0.v20110110. Any update to an artifact must be published with a new version number.

Integration

How do I incorporate p2 into my RCP app?

The first approach, called the "User Interface API", is actually a framework for managing updates, complete with wizards and configurable scheduling. It is the same framework used by Eclipse's update management. Your application provides policies and other configuration values to guide this framework. Note that this API has a dependency on the Eclipse 3.x Platform UI (org.eclipse.ui), and requires the Platform UI compatibility layer for applications using the Eclipse 4 Application Platform.

The second approach is to use p2's higher-level Operation APIs to drive updates. These APIs provide a thin layer over the Core APIs (described next) to describe updates as an atomic install, uninstall, or update of an artifact. are more intended for headless applications.

Such messages are a symptom of the org.eclipse.update.configurator being installed. The org.eclipse.update.configurator causes all bundles in plugins to be installed into the runtime. To prevent this behaviour, set the org.eclipse.update.reconcile property to false for your product.

org.eclipse.update.configurator is included as part of the org.eclipse.rcp feature and cannot be removed for historical reasons.

But why aren't uninstalled bundles/features immediately removed?

p2 does not immediately remove bundles on uninstall for several reasons:

Minimizing waste: By retaining the bundles, p2 can save time and bandwidth to should these bundles be re-installed.

For safety: Many bundles do not properly support hot-swapping and removal. Writing bundles that can be uninstalled completely is surprisingly difficult, and even harder to test.

In practice the timing of deletion should not matter as p2 ensures that the bundles will not be re-installed (modulo the org.eclipse.update.configurator issue described elsewhere in this FAQ).

p2 does periodically perform a garbage collection of uninstalled features and bundles, typically after having performed another uninstall. See elsewhere in this FAQ for details on how to explicitly request a garbage collect.

Why aren't bundles being removed when their associated feature has been removed?

There are two aspects to this problem.

First, you should ensure that features are recorded when installing a feature by specifying the "org.eclipse.update.install.features=true" property, such that the bundles have a recorded dependency against the feature. This property is not the default, so if you are using the p2 director manually it is worth verifying.

Second, you must invoke the p2 garbage collector.[1] By default, p2 only performs a garbage collect at its discretion. Normally this is fine since the actual bundles to be loaded are still known and managed (either in the config.ini file or by the simpleconfigurator).

You can cause a garbage collect in one of 3 ways:

Configure your product to invoke a GC on startup by adding the following line to your product's plugin_customization.ini (requires the org.eclipse.equinox.p2.ui.sdk.scheduler bundle):

To understand and solve this message requires understanding three key concepts about how p2 manages installations.

Root IUs: When an IU (e.g., a product, feature, or bundle) is explicitly provisioned, the IU is recorded in the p2 profile as a root IU. A root IU will never change until explicitly removed. When a new IU is requested to be installed (i.e., to become a new root IU), p2's planner attempts to find a configuration that satisfies the dependencies of the new IU with the dependencies of the existing root IUs. If no such configuration can be found then the installation fails, and the planner provides an explanation of the failing constraint, like the text above. A little known fact: this planning phase could result in a configuration where some dependent IU is downgraded to an older version so as to satisfy the dependencies!

Singleton IUs: Many IUs are marked as singletons, such that two versions of an IU cannot be installed at the same time. Products and features, for example, are singletons. Although OSGi allows installing and running multiple versions of a bundle (useful for supporting different versions of org.apache.collections, for example), certain types of bundles are marked as singletons, like an Eclipse plugin that contributes extensions to the extension registry, presumably because the extension registry does not support differentiating between multiple versions of a plugin and extension. Other IUs, like products IUs, are singletons as they actually correspond to files on disk (e.g., "eclipse.exe"): it's impossible for two different versions of a product to be installed at the same time.

Version ranges: p2 expresses dependencies between IUs using version ranges. But several of PDE's standard artifacts, notably products and features (both of which are also singletons), historically specify their dependencies using exact version numbers. Thus a product that requires version 2.0.2 of a feature cannot be satisfied with version of 2.0.3.

Installation vs Update: Although only an isssue when using the lower-level p2 Core APIs, specifying an IU to install (as a root IU) does not automatically update any existing versions of that IU. Although the p2 planner will consider replacing a non-root IU to satisfy a dependency, p2 will never update a root IU. Updating a root IU requires explicitly uninstalling the old IU and installing the new version. Note that the p2 Install New Software / Update Software wizard does detect this situation and transforms installations into updates.

With this knowledge, we can now interpret the situation leading to the error in the example above. The user has requested that feature com.mytool.feature 2.0.3 be installed. Because features are singletons, only one of com.mytool.feature 2.0.2 and 2.0.3 can be installed at once. Product com.mytool.product 2.0.2, which we know is a singleton and by default specifies exact version dependencies, requires exactly version 2.0.2 of com.mytool.feature. Since products are typically root IUs, product com.mytool.product 2.0.2 cannot be uninstalled and thus com.mytool.feature 2.0.2 cannot be uninstalled, and so the installation fails. The solution is to relax the com.mytool.product definition to allow a version range on the com.mytool.feature rather than an exact version by complementing the .product file with a carefully-crafted p2.inf file.[3]

Decouple features based on API vs implementation dependencies. If your feature does not actually depend on the implementation of a particular version of a feature, then don't specify that requirement: instead ensure the features are required in a higher-level mechanism, like a product. Or specify such feature dependencies using the "Dependency" tab of the feature editor (akak imports). For example, in Eclipse Platform 4.2, the org.eclipse.rcp feature has an exact requirement on the org.eclipse.e4.rcp feature as there is an implementation dependency (i.e., org.eclipse.rcp 4.2 may not work with org.eclipse.e4.rcp 4.3), but org.eclipse.e4.rcp has an import dependency using a version range on two EMF features as it is an API dependency.

Use p2.inf files where necessary to work around PDE artifacts that historically specify exact versions.[4]

How can I determine what is a root IU?

You can see the items marked as a root by looking at the latest profile file in .../p2/org.eclipse.p2.engine/profileRegistry/<profileName>/ and looking for the string 'org.eclipse.equinox.p2.type.root'.

How can I tell if an IU is a singleton?

One way is to examine the content.xml for the containing repository, and find the IU's <unit>.