Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Programatically installing a plugin
Programatically installing a plugin [message #160388] Fri, 21 November 2003 18:22 Go to next message
Eclipse UserFriend
I am trying to automatically hit our update site when I launch our
application. I can get to it and browse all of the features, but when I
try to install the feature I get an UnsupportedOperationException. Here
is the code:

feature.install(feature, new FeatureInstallVerifyListener(), new
NullProgressMonitor());

Any ideas? Am I going about this completely wrong?

The javadoc for IFeature.install(...) states:

"Install the contents of this feature into the specified target feature.
All optional features will be installed"

What is the target feature supposed to be? I think that is screwing me
up, but I am not sure. The full code is below.

Thanks in advance,
-Phil


try {
String featureID = "foo.bar";
ISite site = SiteManager.getSite(new
URL("http://foo.com/bar"), new NullProgressMonitor());
ISiteFeatureReference[] featureReferences =
site.getFeatureReferences();

IFeature remoteFeature = null;
for (int x = 0; x < featureReferences.length; x++) {
if
(featureReferences[x].getVersionedIdentifier().toString().st artsWith(featureID
+ "_")) {
remoteFeature = featureReferences[x].getFeature(new
NullProgressMonitor());
break;
}
}

if (remoteFeature == null) {
throw Utilities.newCoreException(
"The com.amirsys.acresconsole feature could not be
found on this update site.",
null);
}

PluginVersionIdentifier remoteVersion =
remoteFeature.getVersionedIdentifier().getVersion();

PluginVersionIdentifier localVersion = null;
IPlatformConfiguration platformConfiguration =
BootLoader.getCurrentPlatformConfiguration();
IPlatformConfiguration.IFeatureEntry[] localFeatures =
platformConfiguration.getConfiguredFeatureEntries();
for (int x = 0; x < localFeatures.length; x++) {
if
(localFeatures[x].getFeatureIdentifier().toString().startsWi th(featureID
+ "_")) {
localVersion = new
PluginVersionIdentifier(localFeatures[x].getFeatureVersion() );
}
}

if (localVersion == null ||
remoteVersion.isGreaterThan(localVersion)) {
System.out.println("[CorePlugin] updating from version
" + localVersion + " to version " + remoteVersion);
System.out.println("[CorePlugin] installing...");

remoteFeature.install(remoteFeature, new
FeatureInstallVerifyListener(), new NullProgressMonitor());

System.out.println("[CorePlugin] ...installed");
} else {
System.out.println("[CorePlugin] Your system is up to
date!");
}
} catch (MalformedURLException e) {
log("", e);
} catch (CoreException e) {
log("", e);
}
Re: Programatically installing a plugin [message #160413 is a reply to message #160388] Fri, 21 November 2003 21:05 Go to previous message
Eclipse UserFriend
Originally posted by: dorian.birsan.net

Philip, what eclipse version are you using/
In 3.0 you can use the new org.eclipse.update.operations package for
programmatically installing features, or even the classes in the
org.eclipse.update.standalone.

"Philip Borlin" <pborlin@amirsys.com> wrote in message
news:bpm6n8$c83$1@eclipse.org...
> I am trying to automatically hit our update site when I launch our
> application. I can get to it and browse all of the features, but when I
> try to install the feature I get an UnsupportedOperationException. Here
> is the code:
>
> feature.install(feature, new FeatureInstallVerifyListener(), new
> NullProgressMonitor());
>
> Any ideas? Am I going about this completely wrong?
>
> The javadoc for IFeature.install(...) states:
>
> "Install the contents of this feature into the specified target feature.
> All optional features will be installed"
>
> What is the target feature supposed to be? I think that is screwing me

I think there are two kind of features, remote features (those you get from
an update site), and target features, which are the features created by
installing a remote feature locally.
The API layer you are using is very low level and error prone. Use
org.eclipse.update.operations or org.eclipse.update.standalone.

If you don't want to use the standalone commands, you can at least look at
the code and see how they call the operations layer.

The update code works kind of like

Update UI Standalone commands for update/install/etc. operations
| |
| |
v ___________________v
org.eclipse.update.operations
|
|
______v_______________
low level IFeature.install, etc.

> up, but I am not sure. The full code is below.
>
> Thanks in advance,
> -Phil
>
>
> try {
> String featureID = "foo.bar";
> ISite site = SiteManager.getSite(new
> URL("http://foo.com/bar"), new NullProgressMonitor());
> ISiteFeatureReference[] featureReferences =
> site.getFeatureReferences();
>
> IFeature remoteFeature = null;
> for (int x = 0; x < featureReferences.length; x++) {
> if
>
(featureReferences[x].getVersionedIdentifier().toString().st artsWith(feature
ID
> + "_")) {
> remoteFeature = featureReferences[x].getFeature(new
> NullProgressMonitor());
> break;
> }
> }
>
> if (remoteFeature == null) {
> throw Utilities.newCoreException(
> "The com.amirsys.acresconsole feature could not be
> found on this update site.",
> null);
> }
>
> PluginVersionIdentifier remoteVersion =
> remoteFeature.getVersionedIdentifier().getVersion();
>
> PluginVersionIdentifier localVersion = null;
> IPlatformConfiguration platformConfiguration =
> BootLoader.getCurrentPlatformConfiguration();
> IPlatformConfiguration.IFeatureEntry[] localFeatures =
> platformConfiguration.getConfiguredFeatureEntries();
> for (int x = 0; x < localFeatures.length; x++) {
> if
> (localFeatures[x].getFeatureIdentifier().toString().startsWi th(featureID
> + "_")) {
> localVersion = new
> PluginVersionIdentifier(localFeatures[x].getFeatureVersion() );
> }
> }
>
> if (localVersion == null ||
> remoteVersion.isGreaterThan(localVersion)) {
> System.out.println("[CorePlugin] updating from version
> " + localVersion + " to version " + remoteVersion);
> System.out.println("[CorePlugin] installing...");
>

Two problems with the code below:
1. if you update an existing feature, you must first disable the old one.
Lots of gory details you need to wory about...
2. the first argument should be TargetFeature, basically a feature that
supports the install operation. The remote feature is used as a source for
the install operation.

> remoteFeature.install(remoteFeature, new
> FeatureInstallVerifyListener(), new NullProgressMonitor());
>
> System.out.println("[CorePlugin] ...installed");
> } else {
> System.out.println("[CorePlugin] Your system is up to
> date!");
> }
> } catch (MalformedURLException e) {
> log("", e);
> } catch (CoreException e) {
> log("", e);
> }
>
Previous Topic:How do you load a JAR on your Plugin Classpath? (Snippet)
Next Topic:Developing Applications
Goto Forum:
  


Current Time: Mon May 12 15:07:16 EDT 2025

Powered by FUDForum. Page generated in 0.18511 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top