Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Querying for plugin location
Querying for plugin location [message #335689] Tue, 21 April 2009 21:29 Go to next message
Amit Mookerjee is currently offline Amit Mookerjee
Messages: 47
Registered: July 2009
Member
Hi,
I am trying to determine the location of plugins that contribute to an
extension point defined in my plugin.

My code is as follows:

IExtensionPoint ep =
Platform.getExtensionRegistry().getExtensionPoint(myExtensio n >);

for (IExtension e : ep.getExtensions()) {
for (IConfigurationElement configElement : e
.getConfigurationElements()) {

/* get the location on disk of the plugin */
Bundle bundle = Platform.getBundle(configElement
.getContributor().getName());
String pluginLoc = FileLocator
.resolve(bundle.getEntry("/")).getPath();

On windows this evaluates to : /C:/tmp while on linux it evaluates to
/tmp. For different platforms I have to process this field differently.



Is there a platform independent way of getting the plugin location?

Thanks
Amit
Re: Querying for plugin location [message #335690 is a reply to message #335689] Wed, 22 April 2009 05:25 Go to previous messageGo to next message
Walter Harley is currently offline Walter Harley
Messages: 847
Registered: July 2009
Senior Member
"Amit Mookerjee" <amitm@ti.com> wrote in message
news:c51a57922917b2afef7889f5415fd623$1@www.eclipse.org...
> Hi,
> I am trying to determine the location of plugins that contribute to an
> extension point defined in my plugin.
>
> My code is as follows:
>
> IExtensionPoint ep =
> Platform.getExtensionRegistry().getExtensionPoint(myExtensio n >);
>
> for (IExtension e : ep.getExtensions()) {
> for (IConfigurationElement configElement : e
> .getConfigurationElements()) {
>
> /* get the location on disk of the plugin */
> Bundle bundle = Platform.getBundle(configElement
> .getContributor().getName());
> String pluginLoc = FileLocator
> .resolve(bundle.getEntry("/")).getPath();
>
> On windows this evaluates to : /C:/tmp while on linux it evaluates to
> /tmp. For different platforms I have to process this field differently.
>
>
>
> Is there a platform independent way of getting the plugin location?


Precisely what are you trying to do? The plugin location is almost never
the right thing to know (especially if you consider that a plugin may or may
not be in a jar, may or may not be in a writeable or shared location, etc.).

Depending on what you're trying to do, one of the Platform.get*Location()
methods may be more appropriate; there are five or six of them, like
getUserLocation(), getStateLocation(). Or if you are trying to access a
file within the plugin, you should probably be using Bundle.getResource().
Re: Querying for plugin location [message #335710 is a reply to message #335690] Thu, 23 April 2009 00:54 Go to previous messageGo to next message
Amit Mookerjee is currently offline Amit Mookerjee
Messages: 47
Registered: July 2009
Member
> Precisely what are you trying to do?
Walter,
An element in my plugin extension refers to a directory relative to the
folder the plugin is located. I need to find the absolute path to the
directory referred by the element. I compute this value by finding the
folder in which the plugin is located and then appending the relative
path.

Let me know if there is a better way to do this computation.

Regards
Amit
Re: Querying for plugin location [message #335726 is a reply to message #335710] Thu, 23 April 2009 20:47 Go to previous messageGo to next message
Walter Harley is currently offline Walter Harley
Messages: 847
Registered: July 2009
Senior Member
"Amit Mookerjee" <amitm@ti.com> wrote in message
news:e566cab8590ebbe0153d4933b35b9a64$1@www.eclipse.org...
>> Precisely what are you trying to do?
> Walter,
> An element in my plugin extension refers to a directory relative to the
> folder the plugin is located.

Why? You should really not be making assumptions about where the plugin is
located, or even that it is located in a directory at all (it might be
inside a jar, it might be split into multiple folders, it might be on a
server somewhere across a service protocol of some sort...).

What does that directory contain, and who creates it? I suspect that
probably one of the methods I mentioned earlier is going to give you what
you need.
Re: Querying for plugin location [message #335738 is a reply to message #335726] Fri, 24 April 2009 16:44 Go to previous messageGo to next message
Amit Mookerjee is currently offline Amit Mookerjee
Messages: 47
Registered: July 2009
Member
> What does that directory contain, and who creates it?
Walter,
We are releasing our product with an eclipse extension.
This product is integrated in a eclipse based IDE. The plugins provide
useful information about the product to the IDE - like the location of
repositories containing target content.

Our product directory structure is as follows:

[<prod_dir>]
[eclipse]
[features]
[plugins]
[<product>_versionname]
plugin.xml
[META-INF]
.eclipseextension
[packages]


The directory structure is fixed. The eclipse folder always exists at the
top level. So the plugin always knows the location of other elements in
the product -like the [packages] folder - relative to its location. The
IDE needs to compute the absolute path of these elements by querying the
extension in the plugin. And this is where the problem arises.

Amit
Re: Querying for plugin location [message #335744 is a reply to message #335738] Sat, 25 April 2009 05:19 Go to previous message
Walter Harley is currently offline Walter Harley
Messages: 847
Registered: July 2009
Senior Member
"Amit Mookerjee" <amitm@ti.com> wrote in message
news:94b511c788662089ad07ac153709b020$1@www.eclipse.org...
>> What does that directory contain, and who creates it?
> Walter,
> We are releasing our product with an eclipse extension.
> This product is integrated in a eclipse based IDE. The plugins provide
> useful information about the product to the IDE - like the location of
> repositories containing target content.
>
> Our product directory structure is as follows:
>
> [<prod_dir>]
> [eclipse]
> [features]
> [plugins]
> [<product>_versionname]
> plugin.xml
> [META-INF]
> .eclipseextension
> [packages]
>
> The directory structure is fixed. The eclipse folder always exists at the
> top level. So the plugin always knows the location of other elements in
> the product -like the [packages] folder - relative to its location. The
> IDE needs to compute the absolute path of these elements by querying the
> extension in the plugin. And this is where the problem arises.


Hmm, yeah, I see why you're having problems. Linked plugins probably get a
bit less exercise than the normal kind, just because Eclipse itself isn't
built on them, and then the question you're (programmatically) asking is one
that Eclipse is sadly not very interested in helping you answer. Eclipse is
trying to abstract away the fact that your plugin lives in a filesystem
somewhere; it doesn't want you to make that assumption.

I'm afraid I don't have any ideas better than the one you led with. Sorry!

It does seem like kind of a hole in the functionality (unless someone else
thinks of something I'm missing). I wonder if you should submit a feature
request in Bugzilla. I'm not sure what the API would look like; in
particular, if you have a method like Platform.getBundleLocation(Bundle), I
think you'd want it to return something consistently useful regardless of
whether the plugin is linked or not and whether it is expanded or packaged
as a jar. I'm not sure quite what that would be. But it's worth giving it
some thought.
Previous Topic:JFace Install
Next Topic:Problem with Navigator
Goto Forum:
  


Current Time: Sun Sep 21 12:14:18 GMT 2014

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

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