Reputation: 2402
I wish to programatically determine the version of my RCP Product.
I've found the Platform.getProduct() method, which returns an IProduct object. But, this does not have version details. I can navigate into the getDefiningBundle object, but that only has the version id of the plugin project, not the version number in the .product file.
Any tips most welcome.
Upvotes: 1
Views: 2667
Reputation: 509
Hi may be this code will help you to get the version of you product file
IProduct product = Platform.getProduct();
Version version = product.getDefiningBundle().getVersion();
Upvotes: 2
Reputation: 735
Eventually figured out you can query the p2 product IUs to retrieve the versions of installed products. I'm doing this in a custom splash handler, and have a lot of null guards in as I'm not entirely sure how much of this API will be available in development environment launch configs. You might be comfortable removing those! I think you could probably construct a P2 query for the specific product IU instead of looping through all the products like I did. Pretty sure it's also possible to obtain the active profile without using ProvisioningUI, but that was good enough for me.
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.engine.IProfile;
import org.eclipse.equinox.p2.engine.IProfileRegistry;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.operations.ProvisioningSession;
import org.eclipse.equinox.p2.query.IQuery;
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.equinox.p2.ui.ProvisioningUI;
private org.eclipse.equinox.p2.metadata.Version getProductVersion() {
ProvisioningUI provisioningUI = ProvisioningUI.getDefaultUI();
if (provisioningUI == null) return null;
String profileId = provisioningUI.getProfileId();
ProvisioningSession session = provisioningUI.getSession();
if (profileId == null || session == null) return null;
IProvisioningAgent provisioningAgent = session.getProvisioningAgent();
if (provisioningAgent == null) return null;
IProfileRegistry registry = (IProfileRegistry) provisioningAgent.getService(IProfileRegistry.SERVICE_NAME);
if (registry == null) return null;
IProfile profile = registry.getProfile(profileId);
if (profile == null) return null;
IQuery<IInstallableUnit> iuProductQuery = QueryUtil.createIUProductQuery();
IQueryResult<IInstallableUnit> result = profile.query(iuProductQuery, null);
if (result == null) return null;
for (IInstallableUnit productIU : result) {
if (PRODUCT_ID.equals(productIU.getId())) {
return productIU.getVersion();
}
}
return null;
}
Upvotes: 2
Reputation: 10654
As @dystroy mentioned, the only product version that is available from the IProduct is the defining/branding bundle's version. If they match, then you're done.
These days, the product version is stored in the RCP application's p2 profile, in the product IU.
eclipse -noSplash \
-application org.eclipse.equinox.p2.director \
-metadataRepository \
file://$(pwd)/p2/org.eclipse.equinox.p2.engine/profileRegistry/SDKProfile.profile \
-list | grep ^org.eclipse.sdk.ide
returns org.eclipse.sdk.ide=4.2.2.M20121008-1100
. But I'm not sure of the p2 wizardry necessary to extract IUs from the currently running instance's p2 profile.
Upvotes: 1