Question

Using Platform.getBundleGroupProviders() and org.eclipse.core.runtime.IBundleGroup I am able to retrieve the list of installed features in Eclipse, but, is there an API through which I can get the list of installed software?

Thanks for your help!

Was it helpful?

Solution 2

This code lists all the installable units in the current profile:

ProvisioningUI provisioningUI = ProvisioningUI.getDefaultUI();

String profileId = provisioningUI.getProfileId();

ProvisioningSession provisioningSession = provisioningUI.getSession();

IProfileRegistry profileReg = (IProfileRegistry)provisioningSession.getProvisioningAgent().getService(IProfileRegistry.SERVICE_NAME);

IQueryable<IInstallableUnit> queryable = profileReg.getProfile(profileId);

IQuery<IInstallableUnit> query = QueryUtil.createIUAnyQuery();

IQueryResult<IInstallableUnit> result = queryable.query(query, new NullProgressMonitor());

for (final IInstallableUnit iu : result)
  {
    System.out.println(iu);
  }

I have left out lots of null checks and exception catching.

You can use QueryUtil to create various other queries such as IUs which are groups.

OTHER TIPS

Here is the final code that returns the complete list of installed software:

private static final String FEATURE_NAME = "df_LT.featureName";

private static List<String> installedSoftwareList(String toMatch) {

    ProvisioningUI provisioningUI = ProvisioningUI.getDefaultUI();
    String profileId = provisioningUI.getProfileId();
    ProvisioningSession provisioningSession = provisioningUI.getSession();
    IProfileRegistry profileReg = (IProfileRegistry)provisioningSession.getProvisioningAgent().getService(IProfileRegistry.SERVICE_NAME);
    IQueryable<IInstallableUnit> queryable = profileReg.getProfile(profileId);
    IQuery<IInstallableUnit> query = QueryUtil.createIUPropertyQuery(QueryUtil.PROP_TYPE_GROUP, "true"); 
    IQueryResult<IInstallableUnit> iqr = queryable.query(query, new NullProgressMonitor());

    List<String> softwareList = null;

    for(IInstallableUnit iu : iqr.toSet()){
        if(softwareList ==  null){
            softwareList = new ArrayList<String>();
        }
        String id = iu.getId();
        String propName = iu.getProperty(IInstallableUnit.PROP_NAME);
        String featureName = iu.getProperty(FEATURE_NAME);

        if (id.startsWith(toMatch)) {
            softwareList.add(propName.equals("%featureName") ? featureName : propName);
            //System.out.println( "ID: " + id + " | Name: " + (propName.equals("%featureName") ? featureName : propName));
        }
    }

    return softwareList;
}

For example, to get all installed software with id = org.eclipse.* , you can call: installedSoftwareList("org.eclipse");

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top