Plugin install directory [message #290945] |
Mon, 05 September 2005 07: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 #290955 is a reply to message #290945] |
Mon, 05 September 2005 08: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 10: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 #290982 is a reply to message #290972] |
Mon, 05 September 2005 10: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 13: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.
|
|
|
Re: Plugin install directory [message #291090 is a reply to message #290945] |
Wed, 07 September 2005 11:44  |
Eclipse User |
|
|
|
The following is ugly, but works:
1/ here is my plugin:
public class KIDE extends AbstractUIPlugin {
//The shared instance.
private static KIDE fPlugin;
public KIDE() {
fPlugin = this;
}
static final public File getFile(String filename) {
Bundle bundle = fPlugin.getBundle();
URL resource;
resource = bundle.getResource(filename);
if (!BundleUtility.isReady(bundle))
return null;
if(resource==null)
resource = bundle.getEntry(filename);
if(resource==null)
return null;
//String s = resource.getFile();
try {
String path = Platform.asLocalURL(resource).getPath();
File file = new File(path);
return file;
}
catch (IOException e) {
// Auto-generated catch block
e.printStackTrace();
}
return null;
}
....
}
THEN just call something like
java.io.File file =
KIDE.getPlugin().getFile("templates"+File.separator+"bsh");
et hop!
"David Corbin" <dcorbin@machturtle.com> a
|
|
|
Powered by
FUDForum. Page generated in 0.35747 seconds