Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How to list files in a bundleresource:// URL?
How to list files in a bundleresource:// URL? [message #554085] Fri, 20 August 2010 06:14 Go to next message
Tassilo Horn is currently offline Tassilo Horn
Messages: 93
Registered: July 2009
Member
Hi all,

we have a graph library that also includes a graph querying language.
That language has an extensible function library, i.e. all function
classes extend some abstract Greql2Function class and reside in a fixed
package. On startup, there's a Greql2FunctionLibrary class residing in
the same package as the functions which checks for available functions
and registeres them. It gets the available resources using

Enumeration<URL> resources = Greql2FunctionLibrary.class
.getClassLoader().getResources(nondottedPackageName);

where nondottedPackageName is the package name of the funlib with dots
replaced by /.

When the library project is used by another eclipse project as project
dependency, one resource is a file URL, and the functions are registered
by iterating the files in Greql2FunctionLibrary.class's directory. When
the lib is used as JAR, I get a jar:file: URL and use a JarFile and
iterate the JarEntries.

But now we would like to provide the library also as Eclipse plugin.
But then, the URL I get is

bundleresource://355.fwk626614097/de/uni_koblenz/jgralab/gre ql2/funlib/

How do I iterate the contents of that URL/directory?

If possible, I'd much prefer a plain java.* solution, because I don't
want the library to depend on anything eclipse specific only in order to
make it usable from eclipse.

Thanks for pointers,
Tassilo
--
Dipl.-Inform. Tassilo Horn | Room: B015
University of Koblenz-Landau, Campus Koblenz | Phone: +49 (261) 287-2745
Institute for Software Technology | Mail: horn@uni-koblenz.de
Universitätsstr. 1, 56070 Koblenz, Germany |
Re: How to list files in a bundleresource:// URL? [message #554094 is a reply to message #554085] Fri, 20 August 2010 07:24 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5419
Registered: July 2009
Senior Member
Hi,

It's not the real answer to your question but e4's CSS engine has the
same problem you have. It would like to be extensible in OSGi and
none-OSGi environments.

See https://bugs.eclipse.org/bugs/show_bug.cgi?id=322189 for a
discussion on how we try to target the problem in Eclipse 4.1 (it
currently looks like we'll take the plugin.xml way which also works out
side OSGi).

Another idea is that if you get the bundle you'll get access to the its
location (e.g. the real jar, the real directory) and you can walk this
directory/jar to find the appropriate classes you'll load through the
Bundle once more

Tom

Am 20.08.10 08:14, schrieb Tassilo Horn:
> Hi all,
>
> we have a graph library that also includes a graph querying language.
> That language has an extensible function library, i.e. all function
> classes extend some abstract Greql2Function class and reside in a fixed
> package. On startup, there's a Greql2FunctionLibrary class residing in
> the same package as the functions which checks for available functions
> and registeres them. It gets the available resources using
>
> Enumeration<URL> resources = Greql2FunctionLibrary.class
> .getClassLoader().getResources(nondottedPackageName);
>
> where nondottedPackageName is the package name of the funlib with dots
> replaced by /.
>
> When the library project is used by another eclipse project as project
> dependency, one resource is a file URL, and the functions are registered
> by iterating the files in Greql2FunctionLibrary.class's directory. When
> the lib is used as JAR, I get a jar:file: URL and use a JarFile and
> iterate the JarEntries.
>
> But now we would like to provide the library also as Eclipse plugin.
> But then, the URL I get is
>
> bundleresource://355.fwk626614097/de/uni_koblenz/jgralab/gre ql2/funlib/
>
> How do I iterate the contents of that URL/directory?
>
> If possible, I'd much prefer a plain java.* solution, because I don't
> want the library to depend on anything eclipse specific only in order to
> make it usable from eclipse.
>
> Thanks for pointers,
> Tassilo
Re: How to list files in a bundleresource:// URL? [message #554100 is a reply to message #554094] Fri, 20 August 2010 07:56 Go to previous messageGo to next message
Tassilo Horn is currently offline Tassilo Horn
Messages: 93
Registered: July 2009
Member
Tom Schindl <tom.schindl@bestsolution.at> writes:

Hi Tom,

> It's not the real answer to your question but e4's CSS engine has the
> same problem you have. It would like to be extensible in OSGi and
> none-OSGi environments.
>
> See https://bugs.eclipse.org/bugs/show_bug.cgi?id=322189 for a
> discussion on how we try to target the problem in Eclipse 4.1 (it
> currently looks like we'll take the plugin.xml way which also works
> out side OSGi).

Thanks, I'll keep an eye on that.

> Another idea is that if you get the bundle you'll get access to the
> its location (e.g. the real jar, the real directory) and you can walk
> this directory/jar to find the appropriate classes you'll load through
> the Bundle once more

That sounds like a good workaround until there's something better. But
could you please elaborate a bit on how to get the "real jar" from such
a bundleresource URL?

Bye,
Tassilo
--
Dipl.-Inform. Tassilo Horn | Room: B015
University of Koblenz-Landau, Campus Koblenz | Phone: +49 (261) 287-2745
Institute for Software Technology | Mail: horn@uni-koblenz.de
Universitätsstr. 1, 56070 Koblenz, Germany |
Re: How to list files in a bundleresource:// URL? [message #554112 is a reply to message #554100] Fri, 20 August 2010 08:24 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5419
Registered: July 2009
Senior Member
Well in OSGi you do
Platform.getBundle("mybundle.symbolic.name").getLocation()

Tom

Am 20.08.10 09:56, schrieb Tassilo Horn:
> Tom Schindl <tom.schindl@bestsolution.at> writes:
>
> Hi Tom,
>
>> It's not the real answer to your question but e4's CSS engine has the
>> same problem you have. It would like to be extensible in OSGi and
>> none-OSGi environments.
>>
>> See https://bugs.eclipse.org/bugs/show_bug.cgi?id=322189 for a
>> discussion on how we try to target the problem in Eclipse 4.1 (it
>> currently looks like we'll take the plugin.xml way which also works
>> out side OSGi).
>
> Thanks, I'll keep an eye on that.
>
>> Another idea is that if you get the bundle you'll get access to the
>> its location (e.g. the real jar, the real directory) and you can walk
>> this directory/jar to find the appropriate classes you'll load through
>> the Bundle once more
>
> That sounds like a good workaround until there's something better. But
> could you please elaborate a bit on how to get the "real jar" from such
> a bundleresource URL?
>
> Bye,
> Tassilo
Re: How to list files in a bundleresource:// URL? [message #554125 is a reply to message #554112] Fri, 20 August 2010 09:09 Go to previous messageGo to next message
Tassilo Horn is currently offline Tassilo Horn
Messages: 93
Registered: July 2009
Member
Tom Schindl <tom.schindl@bestsolution.at> writes:

Hi Tom,

> Well in OSGi you do
> Platform.getBundle("mybundle.symbolic.name").getLocation()

Ok, thanks. And the symbolic name is

bundleresource://355.fwk626614097/de/uni_koblenz/jgralab/gre ql2/funlib/

without the protocol? Or only the host part (335.fwk626614097)?

Bye,
Tassilo
--
Dipl.-Inform. Tassilo Horn | Room: B015
University of Koblenz-Landau, Campus Koblenz | Phone: +49 (261) 287-2745
Institute for Software Technology | Mail: horn@uni-koblenz.de
Universitätsstr. 1, 56070 Koblenz, Germany |
Re: How to list files in a bundleresource:// URL? [message #554132 is a reply to message #554125] Fri, 20 August 2010 09:19 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5419
Registered: July 2009
Senior Member
It's the name found in the MANIFEST.MF or if you know a class in the
bundle you can use "FrameworkUtil.getBundle(My.Class).getLocation()"

Tom

Am 20.08.10 11:09, schrieb Tassilo Horn:
> Tom Schindl <tom.schindl@bestsolution.at> writes:
>
> Hi Tom,
>
>> Well in OSGi you do
>> Platform.getBundle("mybundle.symbolic.name").getLocation()
>
> Ok, thanks. And the symbolic name is
>
> bundleresource://355.fwk626614097/de/uni_koblenz/jgralab/gre ql2/funlib/
>
> without the protocol? Or only the host part (335.fwk626614097)?
>
> Bye,
> Tassilo
Re: How to list files in a bundleresource:// URL? [message #558321 is a reply to message #554132] Sat, 11 September 2010 08:52 Go to previous messageGo to next message
Andreas Scherer is currently offline Andreas Scherer
Messages: 6
Registered: September 2010
Junior Member
Hi Tassilo,

maybe you have already implemented a solution, but my suggestion would be:

URL url = mybundle.getEntry("mydirectory");
URI uri = FileLocator.toFileURL(url).toURI();
File mydirectory = new File(uri);

and now you can browse your directory. Be aware that toFile() copies your files to a cache on the file system.

Andreas
Re: How to list files in a bundleresource:// URL? [message #641837 is a reply to message #558321] Sun, 28 November 2010 16:31 Go to previous messageGo to next message
Robert  is currently offline Robert
Messages: 1
Registered: November 2010
Junior Member
Hi,

you can use the URLConverterImpl (org.eclipse.core.runtime.internal.adaptor.URLConverterImpl)
Method toFileUrl(URL bunderesource)

Robert
Re: How to list files in a bundleresource:// URL? [message #641846 is a reply to message #641837] Sun, 28 November 2010 17:34 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5419
Registered: July 2009
Senior Member
Not a good idea because this is not API.

Tom

Am 28.11.10 17:31, schrieb Robert:
> Hi,
>
> you can use the URLConverterImpl
> (org.eclipse.core.runtime.internal.adaptor.URLConverterImpl)
> Method toFileUrl(URL bunderesource)
>
> Robert
Re: How to list files in a bundleresource:// URL? [message #641894 is a reply to message #641837] Mon, 29 November 2010 07:37 Go to previous message
Daniel Krügler is currently offline Daniel Krügler
Messages: 853
Registered: July 2009
Senior Member
On 11/28/2010 17:31, Robert wrote:
> Hi,
>
> you can use the URLConverterImpl
> (org.eclipse.core.runtime.internal.adaptor.URLConverterImpl)
> Method toFileUrl(URL bunderesource)

As Tom correctly concerned, you should not use non-API methods. You can
realize the same thing with official means. Just acquire the osgi
service for the interface
org.eclipse.osgi.service.urlconversion.URLConverter and proceed as you
describe. We used this approach in our spring
PathMatchingResourcePatternResolver implementation to convert bundle
resources into file-based URLs.

HTH & Greetings from Bremen,

Daniel Krügler
Previous Topic:how get the extension name of selected resouce creating external tools?
Next Topic:Subversion url and revision number of a file in workspace
Goto Forum:
  


Current Time: Thu Oct 23 14:41:29 GMT 2014

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

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