通过程序获取eclipse中已安装软件的列表

时间:2014-02-21 17:38:09

标签: eclipse plugins rcp

使用Platform.getBundleGroupProviders()和org.eclipse.core.runtime.IBundleGroup我能够在Eclipse中检索已安装功能的列表,但是,是否有API可以通过它获取已安装软件的列表?< / p>

感谢您的帮助!

2 个答案:

答案 0 :(得分:1)

以下是返回已安装软件完整列表的最终代码:

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;
}

例如,要使用id = org.eclipse。*获取所有已安装的软件,您可以调用: installedSoftwareList( “org.eclipse”);

答案 1 :(得分:0)

此代码列出了当前配置文件中的所有可安装单元:

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

我遗漏了很多null次检查和异常捕获。

您可以使用QueryUtil创建各种其他查询,例如作为组的IU。