Skip to main content



      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 02:14 Go to next message
Eclipse UserFriend
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 03:24 Go to previous messageGo to next message
Eclipse UserFriend
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 03:56 Go to previous messageGo to next message
Eclipse UserFriend
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 04:24 Go to previous messageGo to next message
Eclipse UserFriend
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 05:09 Go to previous messageGo to next message
Eclipse UserFriend
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 05:19 Go to previous messageGo to next message
Eclipse UserFriend
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 04:52 Go to previous messageGo to next message
Eclipse UserFriend
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 11:31 Go to previous messageGo to next message
Eclipse UserFriend
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 12:34 Go to previous messageGo to next message
Eclipse UserFriend
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 02:37 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: How to list files in a bundleresource:// URL? [message #1694362 is a reply to message #641894] Mon, 04 May 2015 15:13 Go to previous message
Eclipse UserFriend
Is there any alternative to "FileLocator.toFileURL(url)" ? This is not available under some OSGi containers ie Kura
Previous Topic:How to update to Mars M7 when IDE was installed by Oomph?
Next Topic:Possible Memory Leak in WorkbenchStatusDialogManagerImpl
Goto Forum:
  


Current Time: Thu Jul 10 08:19:27 EDT 2025

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

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

Back to the top