Skip to main content



      Home
Home » Newcomers » Newcomers » Getting access to my plugin home directory?
Getting access to my plugin home directory? [message #120616] Tue, 29 November 2005 16:49 Go to next message
Eclipse UserFriend
Originally posted by: pete_c_johnson_2.yahoo.com

Hello and thanks for reading my post,

I'm developing a plug-in that I hope to be able to allow people to
customize based on files they would drip in my plugin home directory (ie:
<Eclipse home>/plugins/<my plugin>/<some dir>. I tried following the
example of what AbstractUIPlugin.imageDescriptorFromPlugin() does behind
the scenes, but had some trouble.

I can get the Bundle no problem, but can't seem to find a way to turn the
URL syntax of that object into something I could pass to a java.io.File.
What I want to do is get access to that directory so that I can inspect
it's contents for the customizations.

Is there a way to do this without resorting to an environment variable or
calling internal methods? Can you take something out of the Bundle and
massage it into an absolute file path?

Thanks in advance.
Re: Getting access to my plugin home directory? [message #120645 is a reply to message #120616] Tue, 29 November 2005 17:20 Go to previous messageGo to next message
Eclipse UserFriend
Pete wrote:
> Hello and thanks for reading my post,
>
> I'm developing a plug-in that I hope to be able to allow people to
> customize based on files they would drip in my plugin home directory
> (ie: <Eclipse home>/plugins/<my plugin>/<some dir>. I tried following
> the example of what AbstractUIPlugin.imageDescriptorFromPlugin() does
> behind the scenes, but had some trouble.
>
> I can get the Bundle no problem, but can't seem to find a way to turn
> the URL syntax of that object into something I could pass to a
> java.io.File. What I want to do is get access to that directory so that
> I can inspect it's contents for the customizations.
>
> Is there a way to do this without resorting to an environment variable
> or calling internal methods? Can you take something out of the Bundle
> and massage it into an absolute file path?
>
> Thanks in advance.
>

Perhaps this is close to what you're after ?

myfile = ResourcesPlugin
.getWorkspace()
.getRoot()
.getProject("FileProject")
.getFile("FileName") // IFile
.getLocation()
.toFile(); // file
Re: Getting access to my plugin home directory? [message #120667 is a reply to message #120645] Wed, 30 November 2005 00:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: pete_c_johnson_2.yahoo.com

Steve Blass wrote:

> Pete wrote:
>> Hello and thanks for reading my post,
>>
>> I'm developing a plug-in that I hope to be able to allow people to
>> customize based on files they would drip in my plugin home directory
>> (ie: <Eclipse home>/plugins/<my plugin>/<some dir>. I tried following
>> the example of what AbstractUIPlugin.imageDescriptorFromPlugin() does
>> behind the scenes, but had some trouble.
>>
>> I can get the Bundle no problem, but can't seem to find a way to turn
>> the URL syntax of that object into something I could pass to a
>> java.io.File. What I want to do is get access to that directory so that
>> I can inspect it's contents for the customizations.
>>
>> Is there a way to do this without resorting to an environment variable
>> or calling internal methods? Can you take something out of the Bundle
>> and massage it into an absolute file path?
>>
>> Thanks in advance.
>>

> Perhaps this is close to what you're after ?

> myfile = ResourcesPlugin
> .getWorkspace()
> .getRoot()
> .getProject("FileProject")
> .getFile("FileName") // IFile
> .getLocation()
> .toFile(); // file

Thanks for the information, I really appreciate it.

Unfortunately, that didn't get what I needed. I need the home directory
of my plugin, which is not part of the Workspace. When I tried the code
above, it croaked when it discovered that the resource did not exist.

I get pretty close with the Bundle, but it uses a unique URL syntax for
identifiying items in the Bundle that I can't figure out how to convert
into something closer to File. When I look at it in the debugger, I can
see that the information I need is in there, but not through
non-internally marked objects (which gives me a compiler warning and I
don't want to depend on internal classes that Eclipse can change at their
whim if I don't have to.)

For example, when I call this:

Bundle bundle = Platform.getBundle("my plugin name");

In the debugger this object is of type BundleHost and it contains a
bundledata, which contains a fileName that is exactly what I need. Those
pieces of data, though, appear to only be accessible using internally
marked methods.

AbstractUIPlugin.imageDescriptorFromPlugin() uses this same scheme, but it
is passing in one of these special URLs (whose URI looks like this:
bundleentry://136/<directory name>) to the Image infrastructure which
knows how to handle them. I've been unable to find a File equivalent.
Re: Getting access to my plugin home directory? [message #120918 is a reply to message #120667] Wed, 30 November 2005 15:12 Go to previous messageGo to next message
Eclipse UserFriend
Pete wrote:
> Steve Blass wrote:
>
>> Pete wrote:
>>
>>> Hello and thanks for reading my post,
>>>
>>> I'm developing a plug-in that I hope to be able to allow people to
>>> customize based on files they would drip in my plugin home directory
>>> (ie: <Eclipse home>/plugins/<my plugin>/<some dir>. I tried
>>> following the example of what
>>> AbstractUIPlugin.imageDescriptorFromPlugin() does behind the scenes,
>>> but had some trouble.
>>>
>>> I can get the Bundle no problem, but can't seem to find a way to turn
>>> the URL syntax of that object into something I could pass to a
>>> java.io.File. What I want to do is get access to that directory so
>>> that I can inspect it's contents for the customizations.
>>>
>>> Is there a way to do this without resorting to an environment
>>> variable or calling internal methods? Can you take something out of
>>> the Bundle and massage it into an absolute file path?
>>>
>>> Thanks in advance.
>>>
>
>> Perhaps this is close to what you're after ?
>
>
>> myfile = ResourcesPlugin
>> .getWorkspace()
>> .getRoot()
>> .getProject("FileProject")
>> .getFile("FileName") // IFile
>> .getLocation()
>> .toFile(); // file
>
>
> Thanks for the information, I really appreciate it.
>
> Unfortunately, that didn't get what I needed. I need the home directory
> of my plugin, which is not part of the Workspace. When I tried the code
> above, it croaked when it discovered that the resource did not exist.
>
> I get pretty close with the Bundle, but it uses a unique URL syntax for
> identifiying items in the Bundle that I can't figure out how to convert
> into something closer to File. When I look at it in the debugger, I can
> see that the information I need is in there, but not through
> non-internally marked objects (which gives me a compiler warning and I
> don't want to depend on internal classes that Eclipse can change at
> their whim if I don't have to.)
>
> For example, when I call this:
>
> Bundle bundle = Platform.getBundle("my plugin name");
>
> In the debugger this object is of type BundleHost and it contains a
> bundledata, which contains a fileName that is exactly what I need.
> Those pieces of data, though, appear to only be accessible using
> internally marked methods.
>
> AbstractUIPlugin.imageDescriptorFromPlugin() uses this same scheme, but
> it is passing in one of these special URLs (whose URI looks like this:
> bundleentry://136/<directory name>) to the Image infrastructure which
> knows how to handle them. I've been unable to find a File equivalent.
>

My mistake, I missed the fact that you were looking under the plugins/
directory instead of in the workspace. Searching google for

site:eclipse.org find plugin directory path

turned up this post from the ve-dev list

http://dev.eclipse.org/mhonarc/lists/ve-dev/msg00941.html

which says that we can use something like the following to get the path
to a file in a plugin

URL u = Platform.find(yourbundle, IPath to your file under your bundle);
if (u != null) {
u = Platform.resolveURL(u);
IPath p = new Path(new File(u.getFile()).getAbsolutePath());
...
}


-
Steve
Re: Getting access to my plugin home directory? [message #121930 is a reply to message #120918] Mon, 05 December 2005 17:17 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: pete_c_johnson_2.yahoo.com

Awesome, that did it. Thanks!
Re: Getting access to my plugin home directory? [message #123147 is a reply to message #120616] Fri, 09 December 2005 20:48 Go to previous message
Eclipse UserFriend
Originally posted by: manahan.NOSPAM.ca.ibm.com

Pete wrote:
> Hello and thanks for reading my post,
>
> I'm developing a plug-in that I hope to be able to allow people to
> customize based on files they would drip in my plugin home directory
> (ie: <Eclipse home>/plugins/<my plugin>/<some dir>. I tried following
> the example of what AbstractUIPlugin.imageDescriptorFromPlugin() does
> behind the scenes, but had some trouble.
>
> I can get the Bundle no problem, but can't seem to find a way to turn
> the URL syntax of that object into something I could pass to a
> java.io.File. What I want to do is get access to that directory so that
> I can inspect it's contents for the customizations.
>
> Is there a way to do this without resorting to an environment variable
> or calling internal methods? Can you take something out of the Bundle
> and massage it into an absolute file path?
>
> Thanks in advance.
>

It is generally recommended that you consider the plugins and the plugin
directory to be considered read-only. If you need resources outside of a
plugin you should create a preference which the user can change to
indicate where to get your resources.

If your plugin will every be a shipped as a jar: common now for 3.1+ plugins
or
needs to be run by a user that doesn't have write permissions to the
plugin install directory (common on *nix's)
of
you expect to update your plugin: when you update the plugin you
normally ship a new version which means a new directory and your path
will be incorrect.

So it may be worthwhile to consider not storing your data in the
plugin directory

Peter
Previous Topic:How does one locate the java executable and various JAR files in the classpath?
Next Topic:Eclipse 3.2 run on J2SE 1.5.0_06
Goto Forum:
  


Current Time: Fri May 09 18:54:23 EDT 2025

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

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

Back to the top