开发者

Using Equinox P2 - Getting information about installed features and plugins

I'm using Eclipse 3.7 to develop a project and I need to do some things, using the information of installed plugins and features:

I'm using the P2 provisioning feature to allow software updates.

1: I need to get the list of plugins and features that are installed and currently running. I need something like what is displayed on the "Installed Software", which can be viewed t开发者_如何转开发hrough "Help> About> Installation Details".

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

2: I need to get a list of recent installed softwares. I need something like what is displayed on the "Installation History", which can be viewed through "Help> About> Installation Details".

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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜