Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Plugin install directory
Plugin install directory [message #290945] Mon, 05 September 2005 11:54 Go to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 15:44 Go to previous message
NiS is currently offline NiSFriend
Messages: 58
Registered: July 2009
Member
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
Previous Topic:DefaultUndoManager runtime error on linux
Next Topic:what is a handle
Goto Forum:
  


Current Time: Thu Sep 19 07:50:58 GMT 2024

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

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

Back to the top