Plugin install directory [message #290945] |
Mon, 05 September 2005 11:54 |
Eclipse User |
|
|
|
Originally posted by: dcorbin.machturtle.com
I have a plugin that needs to find the fully qualified path to a file that
is part of the plugin (it's for an external process). I can't quit figure
a reliable way to do this.
I can cover some cases, but parsing out the bundle location, but that only
works if the "current directory" is the eclipse install directory, which
it's not guaranteed to be. I've not been able to programmatically find the
Eclipse install directory, either.
So is there an approved way to find either a plugin's install directory, or
the eclipse install directory?
Thanks.
David
|
|
|
Re: Plugin install directory [message #290953 is a reply to message #290945] |
Mon, 05 September 2005 12:14 |
Eclipse User |
|
|
|
Originally posted by: ac.cashware.biz
You can check the system property "osgi.install.area" (
System.getProperties().get( "osgi.install.area")). It retrieves the
installation directory.
Cheers,
|
|
|
Re: Plugin install directory [message #290955 is a reply to message #290945] |
Mon, 05 September 2005 12:18 |
Eclipse User |
|
|
|
Originally posted by: sunil_kamath.nohotspammail.com
"David Corbin" <dcorbin@machturtle.com> wrote in message
news:dfhbkr$g2e$1@news.eclipse.org...
>I have a plugin that needs to find the fully qualified path to a file that
> is part of the plugin (it's for an external process). I can't quit figure
> a reliable way to do this.
>
> I can cover some cases, but parsing out the bundle location, but that only
> works if the "current directory" is the eclipse install directory, which
> it's not guaranteed to be. I've not been able to programmatically find
> the
> Eclipse install directory, either.
>
> So is there an approved way to find either a plugin's install directory,
> or
> the eclipse install directory?
>
If the file is part of the bundle, then you should be able to call
getBundle().getEntry("/path/to/my/resource") to get the URL of the file.
The path should be relative to the bundle root. To get the bundle install
location, pass "/" as the path.
Once you have the URL, if it is a file: url, you can convert it to a File.
---
Sunil
|
|
|
Re: Plugin install directory [message #290972 is a reply to message #290955] |
Mon, 05 September 2005 14:20 |
Eclipse User |
|
|
|
Originally posted by: dcorbin.machturtle.com
Sunil Kamath wrote:
>
> "David Corbin" <dcorbin@machturtle.com> wrote in message
> news:dfhbkr$g2e$1@news.eclipse.org...
>>I have a plugin that needs to find the fully qualified path to a file that
>> is part of the plugin (it's for an external process). I can't quit
>> figure a reliable way to do this.
>>
>> I can cover some cases, but parsing out the bundle location, but that
>> only works if the "current directory" is the eclipse install directory,
>> which
>> it's not guaranteed to be. I've not been able to programmatically find
>> the
>> Eclipse install directory, either.
>>
>> So is there an approved way to find either a plugin's install directory,
>> or
>> the eclipse install directory?
>>
> If the file is part of the bundle, then you should be able to call
> getBundle().getEntry("/path/to/my/resource") to get the URL of the file.
> The path should be relative to the bundle root. To get the bundle install
> location, pass "/" as the path.
> Once you have the URL, if it is a file: url, you can convert it to a File.
> ---
> Sunil
When I call getBundle().getEntry("/").toString(), I get the terribly
unuseful "bundleentry://108/". (At least while debugging...)
|
|
|
Re: Plugin install directory [message #290976 is a reply to message #290953] |
Mon, 05 September 2005 14:23 |
Eclipse User |
|
|
|
Originally posted by: dcorbin.machturtle.com
Álvaro Corcuera wrote:
> You can check the system property "osgi.install.area" (
> System.getProperties().get( "osgi.install.area")). It retrieves the
> installation directory.
>
> Cheers,
So it does. Unfortuately, that turns out not to help when the plugin is
being debugged.
>
> Álvaro
>
> "David Corbin" <dcorbin@machturtle.com> escribió en el mensaje
> news:dfhbkr$g2e$1@news.eclipse.org...
>>I have a plugin that needs to find the fully qualified path to a file that
>> is part of the plugin (it's for an external process). I can't quit
>> figure a reliable way to do this.
>>
>> I can cover some cases, but parsing out the bundle location, but that
>> only works if the "current directory" is the eclipse install directory,
>> which
>> it's not guaranteed to be. I've not been able to programmatically find
>> the
>> Eclipse install directory, either.
>>
>> So is there an approved way to find either a plugin's install directory,
>> or
>> the eclipse install directory?
>>
>> Thanks.
>> David
|
|
|
Re: Plugin install directory [message #290982 is a reply to message #290972] |
Mon, 05 September 2005 14:55 |
Eclipse User |
|
|
|
Originally posted by: sunil_kamath.nohotspammail.com
"David Corbin" <dcorbin@machturtle.com> wrote in message
news:dfhk6j$rsg$1@news.eclipse.org...
> Sunil Kamath wrote:
>
>>> So is there an approved way to find either a plugin's install directory,
>>> or
>>> the eclipse install directory?
>>>
>> If the file is part of the bundle, then you should be able to call
>> getBundle().getEntry("/path/to/my/resource") to get the URL of the file.
>> The path should be relative to the bundle root. To get the bundle install
>> location, pass "/" as the path.
>> Once you have the URL, if it is a file: url, you can convert it to a
>> File.
>> ---
>> Sunil
>
> When I call getBundle().getEntry("/").toString(), I get the terribly
> unuseful "bundleentry://108/". (At least while debugging...)
>
Do you actually need the path to the file or the file contents?
If you really need the file itself, try:
IPath path = new Path ("myfile.txt");
URL resolvedURL = Platform.find(MyPlugin.getBundle(), path);
if(resolvedURL != nul) {
URL realURL = Platform.asLocalURL(resolvedURL);
File file = new File(realURL);
}
Be warned that if you are deploying your plugin as a single jar, this may
not work.
---
Sunil
|
|
|
Re: Plugin install directory [message #290991 is a reply to message #290982] |
Mon, 05 September 2005 17:34 |
Eclipse User |
|
|
|
Originally posted by: dcorbin.machturtle.com
Sunil Kamath wrote:
>
> "David Corbin" <dcorbin@machturtle.com> wrote in message
> news:dfhk6j$rsg$1@news.eclipse.org...
>> Sunil Kamath wrote:
>>
>>>> So is there an approved way to find either a plugin's install
>>>> directory, or
>>>> the eclipse install directory?
>>>>
>>> If the file is part of the bundle, then you should be able to call
>>> getBundle().getEntry("/path/to/my/resource") to get the URL of the file.
>>> The path should be relative to the bundle root. To get the bundle
>>> install location, pass "/" as the path.
>>> Once you have the URL, if it is a file: url, you can convert it to a
>>> File.
>>> ---
>>> Sunil
>>
>> When I call getBundle().getEntry("/").toString(), I get the terribly
>> unuseful "bundleentry://108/". (At least while debugging...)
>>
> Do you actually need the path to the file or the file contents?
I actually need the file. Well, I could get the contents and then write a
copy out to a temporary directory, but that seems wasteful.
> If you really need the file itself, try:
>
> IPath path = new Path ("myfile.txt");
> URL resolvedURL = Platform.find(MyPlugin.getBundle(), path);
> if(resolvedURL != nul) {
> URL realURL = Platform.asLocalURL(resolvedURL);
> File file = new File(realURL);
> }
Thanks
>
> Be warned that if you are deploying your plugin as a single jar, this may
> not work.
Not a problem yet.
|
|
|
|
Powered by
FUDForum. Page generated in 0.04586 seconds