Using Equinox P2 - Getting Information About Installed Features and Plugins

I use Eclipse 3.7 to develop a project, and I need to do something using information about installed plugins and features:

I use the P2 provisioning feature to update the software.

1: I need to get a list of plugins and features that are installed and currently running. I need something like what is displayed in the "Installed Software", which can be viewed through "Help"> "Installation Information".

Note. I will use this information to get information about installed features, such as version number and description.

2: I need to get a list of recently installed programs. I need something like what is displayed in the Installation History, which can be viewed through Help> About> Installation Information.

Note. I will use this information to add functionality to clear old installations. Something like "Keep only the last five installations."

+4
source share
1 answer
import org.eclipse.core.runtime.Platform; import org.eclipse.equinox.p2.engine.IProfileRegistry; import org.eclipse.equinox.p2.metadata.IInstallableUnit; import org.eclipse.equinox.p2.metadata.Version; import org.eclipse.equinox.p2.operations.ProvisioningSession; import org.eclipse.equinox.p2.query.IQueryResult; import org.eclipse.equinox.p2.query.IQueryable; import org.eclipse.equinox.p2.query.QueryUtil; import org.eclipse.equinox.p2.ui.ProvisioningUI; ... try { ProvisioningUI provisioningUI = ProvisioningUI.getDefaultUI(); if ( null == provisioningUI ) { return; } String profileId = provisioningUI.getProfileId(); ProvisioningSession provisioningSession = provisioningUI.getSession(); if ( null == provisioningSession ) { return; } IQueryable<IInstallableUnit> queryable = ((IProfileRegistry) provisioningSession.getProvisioningAgent().getService(IProfileRegistry.SERVICE_NAME)) .getProfile( profileId ); if ( null == queryable ) { return; } // to get the product ID //String pId = Platform.getProduct().getId(); String pId = "feature.1"; if ( null != queryable ) { IQueryResult<IInstallableUnit> iqr = queryable.query( QueryUtil.createIUQuery( pId ), null ); if ( null != iqr ) { Iterator<IInstallableUnit> ius = iqr.iterator(); if( ius.hasNext() ) { IInstallableUnit iu = ius.next(); Version v = iu.getVersion(); if ( null != v ) { System.out.println( "ID: " + iu.getId() + " | IU: " + iu.toString() + " | Version: " + v.toString() ); } } } } } catch ( Exception e ) { System.out.println( e.getStackTrace() ); return; } 
+4
source

All Articles