Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » P2 » How to know if an InstallableUnit is already installed?
How to know if an InstallableUnit is already installed? [message #837203] Thu, 05 April 2012 11:44 Go to next message
Jean-Philippe Schneider is currently offline Jean-Philippe SchneiderFriend
Messages: 4
Registered: January 2012
Junior Member
Hello,

I'm writing an Eclipse plugin that have to check if some feature is installed or not.

I already found how to install this feature from my plugin but I don't find how to know if it is already installed.

Any idea?
Re: How to know if an InstallableUnit is already installed? [message #837213 is a reply to message #837203] Thu, 05 April 2012 11:57 Go to previous messageGo to next message
Pascal Rapicault is currently offline Pascal RapicaultFriend
Messages: 333
Registered: July 2009
Location: Ottawa
Senior Member
Use the following snippet.


private IProvisioningAgent getAgent() {
Collection<ServiceReference<IProvisioningAgent>> ref = null;
try {
ref = Activator.getContext().getServiceReferences(IProvisioningAgent.class, '(' + IProvisioningAgent.SERVICE_CURRENT + '=' + Boolean.TRUE.toString() + ')');
} catch (InvalidSyntaxException e) {
//ignore can't happen since we write the filter ourselves
}
if (ref == null || ref.size() == 0)
throw new IllegalStateException("no agent");
IProvisioningAgent agent = Activator.getContext().getService(ref.iterator().next());
Activator.getContext().ungetService(ref.iterator().next());
return agent;
}

public void getFeature() {
IProfileRegistry registry = (IProfileRegistry) getAgent().getService(IProfileRegistry.SERVICE_NAME);
IProfile profile = registry.getProfile(IProfileRegistry.SELF);
result = profile.query(QueryUtil.createIUQuery("my.feature"), new NullProgressMonitor()); //Note that the feature id are usually suffixed by feature.group. so ide would be called ide.feature.group
}

Note though that while running the app from within eclipse you will not get a profile unless you select the "support software installation [...]" option in the configuration tab of the launch configuration and even that is only so precise since for example features won't be there.
The best way to try this out is to use export the plugin and try it on your running eclipse.

Pascal
=-=-=
Consulting, training, bug fixing - pascal at rapicault dot net
Re: How to know if an InstallableUnit is already installed? [message #837244 is a reply to message #837213] Thu, 05 April 2012 12:42 Go to previous message
Jean-Philippe Schneider is currently offline Jean-Philippe SchneiderFriend
Messages: 4
Registered: January 2012
Junior Member
Great it is exactly what I needed Smile
Thanks a lot!!
Previous Topic:Mandatory repositories in p2f-files?
Next Topic:Updates are not installed properly?
Goto Forum:
  


Current Time: Sun Dec 08 00:50:57 GMT 2024

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

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

Back to the top