Any way to "reduce" a "jar-URL" to an actual path? [message #329359] |
Fri, 20 June 2008 17:18  |
Eclipse User |
|
|
|
R3.3; WinXP
We have a clunky old 3rd-party bit of code to which we must supply, in
the form of Windows full-paths, concatenated with ";", the actual
class-paths of all code and jars in some set. Thanks to an earlier post
("How to compute classpath from bundle?") by Jeff Pilgrim (whose email
address is no longer valid, alas), I have some code that will extract
from the Platform and the Bundle API a collection of URL's. So far so
good. Here is an example list:
jar:file:C:\<my-Eclipse-install>\eclipse\plugins\org.eclipse.ui_3.3.0.I20070614-0800.jar!/
jar:file:C:\<my-Eclipse-install>\eclipse\plugins\org.eclipse.swt_3.3.0.v3346.jar!/
jar:file:C:\<my-Eclipse-install> \eclipse\plugins\org.eclipse.jface_3.3.0.I20070606-0010.jar! /
jar:file:C:\<my-Eclipse-install> \eclipse\plugins\org.eclipse.core.commands_3.3.0.I20070605-0 010.jar!/
where I have printed the URL values using URL.toString().
The problem is -- how to convert such a "jar-URL" to a string? Our
clunky old 3rd-party code would want the list to look like this:
C:\<my-Eclipse-install>\eclipse\plugins\org.eclipse.ui_3.3.0.I20070614-0800.jar
C:\<my-Eclipse-install>\eclipse\plugins\org.eclipse.swt_3.3.0.v3346.jar
C:\<my-Eclipse-install>\eclipse\plugins\org.eclipse.jface_3.3.0.I20070606-0010.jar
C:\<my-Eclipse-install> \eclipse\plugins\org.eclipse.core.commands_3.3.0.I20070605-0 010.jar
Now, I can (and probably soon will have to) build my own little parser,
whose input would be URL.toString(), but that's of course fragile and
bug-prone.
I'd prefer it if there were a Platform of FileLocator method that took
as input one of the URL's and gave me the desired String as output. But
FileLocator.resolve(URL) simply does not work (it does other nice
things), and in fact the URL's above are *ALREADY* the output of
FileLocator.resolve(). I've also tried FileLocator.toFileURL(), which
seems to simply return the same URL, in this case.
So what is to be done?
TIA,
Paul
|
|
|
|
|
|
|
Re: Any way to "reduce" a "jar-URL" to an actual path? [message #329436 is a reply to message #329428] |
Tue, 24 June 2008 05:12  |
Eclipse User |
|
|
|
Ed Merks wrote:
> Paul,
>
> Isn't there a danger that the jar will be unzipped when that might not
> be a desired side-effect? Of course you're right that if it has
> platform: or bundleentry: you'd need a more general approach...
>
>
> Paul Webster wrote:
>> FileLocator.toFileURL(*) is the method that should be used in your
>> case. It will convert any platform: URLs into file: URLs ... it might
>> be that passing in the jar: URLs is confusing it, and they should be
>> the platform: URLs
>>
>> PW
>>
Well, I started with what I took to be a platform URL (obtained from
"ManifestElement"), and used FileLocator.resolve(), which gave me the
"jar:"-URL's; if I try toFileURL(), I get as follows:
bundleentry://78/
mapped by FileLocator.resolve() =>
jar:file:C:\<my-eclipse-install>\eclipse\plugins\org.eclipse.ui_3.3.0.I20070614-0800.jar!/
mapped by FileLocator.toFileURL() =>
file:/C:/<my-eclipse-install> /eclipse/workspace/.metadata/.plugins/org.eclipse.pde.core/u dat.product/org.eclipse.osgi/bundles/78/1/.cp/
So it looks to me like the toFileURL() is unzipping (or anyway copying)
the jar into a sort of work-area defined and used by Eclipse.
-Paul
|
|
|
Powered by
FUDForum. Page generated in 0.04095 seconds