문제

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