سؤال

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!

هل كانت مفيدة؟

المحلول 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.

نصائح أخرى

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");

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top