felix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff McAffer <Jeff_McAf...@ca.ibm.com>
Subject Re: OSGi URL to file
Date Thu, 14 Sep 2006 12:58:48 GMT
Hmmm, yes, this is a different problem.  Even in Equinox I would be 
surprised if toFileURL was helping you since you then have to get the 
modified class file on the classpath of the bundle's classloader (unless 
of course you are using your own classloader).  A better approach is as 
Richard says, built in bytecode modification facilities.  We have various 
hooks in Equinox and it can likely be done in Felix and other frameworks 
but there is no standard in the area.

Jeff



"Richard S. Hall" <heavy@ungoverned.org> 
09/14/2006 12:43 AM
Please respond to
felix-dev@incubator.apache.org


To
felix-dev@incubator.apache.org
cc

Subject
Re: OSGi URL to file






Erik Bengtson wrote:
> My use case is the following:
>
> I want to modify the bytecode of some classes at runtime.
>
> I thought that I could get a url.getConnection().getOutputStream() to do 
that,
> but it does not seems to work (sort of non supported protocol).
> 

Providing better support for byte code manipulation is a topic of 
discussion inside CPEG...

-> richard

> Thanks Jeff and Richard again for the reponses.
>
>
> Quoting Jeff McAffer <Jeff_McAffer@ca.ibm.com>:
>
> 
>> yes, the usecases for this are somewhat rare but they do come up.  Most 
of
>> the time it relates to bundles that supply files to non-OSGi aware
>> systems.  For example:
>> - a bundle that supplies an executable that is in turn exec()'d by the
>> bundle.  The executalbe must be directly in the filesystem since the OS
>> does not know how to read JARs.  Native headers don't do it for you 
since
>> you actually need the real path fo the executable in the file system
>> - a bundle that supplies content to a browser.  A help or doc system 
for
>> exampe.  Again, the browser does not know how to look into JARs so the
>> content must be directly in the filesystem and you need a file: url to
>> pass to the browser
>>
>> We've seen both of these (and more) in Eclipse and so added the
>> FileLocator.toFileURL() helper method Erik mentioned.    Here is the
>> Javadoc
>>
>>         /**
>>          * Converts a URL that uses a user-defined protocol into a URL
>> that uses the file
>>          * protocol. The contents of the URL may be extracted into a 
cache
>> on the file-system
>>          * in order to get a file URL.
>>          * <p>
>>          * If the protocol for the given URL is not recognized by this
>> converter, the original
>>          * URL is returned as-is.
>>          * </p>
>>          * @param url the original URL
>>          * @return the converted file URL or the original URL passed in 
if
>> it is
>>          *      not recognized by this converter
>>          * @throws IOException if an error occurs during the conversion
>>          */
>>
>> In practice this takes things that you would get back from getResource 
or
>> getEntry and converts them to file:.  In the case of a directory based
>> bundle, the file is likely already directly in the filesystem so its 
file:
>> url is returned.  In the case of a JAR'd bundle, the file (or 
directory)
>> is extracted to a cache and that location returned.
>>
>> Jeff
>>
>>
>>
>>
>> "Richard S. Hall" <heavy@ungoverned.org>
>> 09/13/2006 07:52 PM
>> Please respond to
>> felix-dev@incubator.apache.org
>>
>>
>> To
>> felix-dev@incubator.apache.org
>> cc
>>
>> Subject
>> Re: OSGi URL to file
>>
>>
>>
>>
>>
>>
>> No, there is no standard way, nor any equivalent method in Felix.
>>
>> This is something you could construct for Felix, perhaps, but it seems
>> like bad form since the whole point of getResource() is to eliminate 
the
>> dependencies on file locations.
>>
>> And what happens if the resource is in a JAR file, then it will never 
be
>> a file: resource?
>>
>> You might be trying to do something and this is the only way to do it,
>> but it would certainly be better if there was another way.
>>
>> -> richard
>>
>> Erik Bengtson wrote:
>> 
>>> Hi,
>>>
>>> I need to convert the URL given by
>>> URL url =
>>>
>>> 
>> 
Bundle.loadClass('something').getClassLoader().getResource('anotherthing');
>> 
>>> Using equinox I get "bundleresource://" protocol, so I want to convert
>>> 
>> to
>> 
>>> file://.
>>>
>>> To convert I use:
>>>
>>> URL fileURL = org.eclipse.core.runtime.FileLocator.toFileURL(url);
>>>
>>> Is there an Felix equivalent or in the OSGI standard?
>>>
>>> Thanks,
>>>
>>> Erik Bengtson
>>>
>>>
>>> PS:
>>> Richard,
>>>
>>> thanks for the previous answer regarding best pratices on 
dependencies.
>>>
>>> 
>> 
>
>
>
> 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message