[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.platform] programmatic update/deprecated PluginVersionIdentifier

Hello,

I have an RCP application that programatically tries to update itself when 
it starts.  The code for this was written in the 3.0 days.   It works still, 
but I am trying to clean the code up in light of the big osgi refactoring. 
There is a deprecated class org.eclipse.core.runtime.PluginVersionIdentifier 
in there.  I looked and it says I should be using org.osgi.framework.Version 
instead.  I am using stuff out of org.eclipse.update.core and 
org.eclipse.update.operations.   The org.osgi.framework.Version class is 
obviously an OSGI class.   I could not find any methods in there that help 
me build a bridge between org.eclipse.update.core, and org.osgi.framework. 
This may be because I am working with features, not plugin/bundles.

I am sure that I can get this to work, but it feels hacky.  There is a 
private variable (featureVersion) in IFeatureReference that would be perfect 
to send to Version.parseVersion().  But I cannot get to it.  I may be forced 
to String parse IFeatureReference..getVersionedIdentifier().getIdentifier().

I suspect this all of this should somehow be easier.   This code is manually 
checking ConfiguredSites, and comparing feature versions.   I just need the 
application to detect that features are available for update, and (seperate 
method) update them.  I do need a level of control over things because of 
the environment.  We are running off a flash memory card, with windows XP 
embedded.   So if updates are found, there is a whole sequence of events 
that have to occur to commit the update to the flash card.

Here is some sample code that illustrates what I am doing.  I appreciate any 
and all advice.

- Dom
public List<IFeature> getFeaturesToInstall(SortedMap<String, 
List<IFeatureReference>> featureMap) throws CoreException {

    List<IFeature> featuresToInstall = new LinkedList<IFeature>();


    URL updateURL = null;

    try {

        updateURL = new URL(updateLocation);

    } catch (MalformedURLException e) {

        logger.error("invalid update url = " + updateLocation, e);

    }


    ISite updateSite = SiteManager.getSite(updateURL, false, null);


    ISiteFeatureReference[] featureReferences = 
updateSite.getFeatureReferences();


    for (ISiteFeatureReference featureReference : featureReferences) {

        VersionedIdentifier featureVersionedId = 
featureReference.getVersionedIdentifier();

        logger.info("Feature on update site: " + featureVersionedId);

        Version oldVersion = getInstalledVersion(featureMap, 
featureVersionedId.getIdentifier());


        Version newVersion = 
Version.parseVersion(featureVersionedId.getIdentifier());

        if ((oldVersion != null) && (newVersion.compareTo(oldVersion) > 0)) 
{

            IFeature feature = featureReference.getFeature(null);

            featuresToInstall.add(feature);

            logger.info("New feature version found: " + featureVersionedId);

        }

    }

return featuresToInstall;

}