Hi Charles,

Thanks for the comments. Nikolay got it working with two small modifications
to the method org.jruby.runtime.load.LoadService#findFileInClasspath.
However, I think it should be possible to reverse those edits (and remove
the dependency on eclipse from the JRuby code), by instead using the
setLoadServiceCreator() method of RubyInstanceConfig to 'inject' the new
code in at runtime. I've started prototyping this by creating my own
implementation of org.jruby.runtime.load.LoadService which overrides the
method 'findFileInClasspath' with the modified version that Nikolay
developed which uses org.eclipse.core.runtime.FileLocator to rewrite the
'bundleresource' URL of any match found on the classpath into a normal
'file:' URL before loading. Then I propose that this gets injected into the
Ruby runtime using code like:
      RubyInstanceConfig config = new RubyInstanceConfig() {{
          setLoadServiceCreator(new LoadServiceCreator() {
              public LoadService create(Ruby runtime) {
                  return new EclipseLoadService(runtime);
              }
          });
      }};
      Ruby runtime = Ruby.newInstance(config);

We've tested the FileLocator code directly in modified JRuby code, but have
not yet removed it and tested with the new approach above. If it works, it
represents a way to achieve what we need without modifying JRuby. One
problem with this approach is that we duplicate the code of the
'findFileInClasspath' method, and if that changes with JRuby upgrades we
have to notice that and incorporate the changes. The method is only about 50
lines long, but still. A more durable hack would be to have a hook in the
findFileInClasspath method that calls a URL rewriter method, which has a
default implementation in the JRuby code that simply returns the URL. Then
we would only have to overwrite that method, instead of the whole 50 lines.

Cheers, Craig

On Wed, Jul 1, 2009 at 7:03 PM, Charles Oliver Nutter
<head...@headius.com>wrote:

> On Mon, Jun 22, 2009 at 11:26 AM, Lagutko
> Nikolay<nikolay.lagu...@gersis-software.com> wrote:
> > I have a problem with working with JRuby in Eclipse. If required scripts
> > stored not in classpath directories but in other plugins JRuby cannot
> find
> > them. As I see the problem in Equinox environment. When JRuby calculates
> > path to required script it uses Equinox BundleClassLoader to load this
> > script and it will return path to file in bundle-dependent format, for
> > example
> >
> > bundleresource://9/./some_script.rb
> >
> > And in further calculations JRuby cannot correctly interpret this path.
> For
> > example function File.expand_path will return “/./some_script” instead of
> > full path “D:/path_to_plugin/some_script”.
> >
> >
> >
> > I find out how to resolve this problem with using FileLocator class from
> > org.eclipse.core.runtime plugin but I don’t want to have dependencies to
> > other plugins in my org.jruby plugin.
>
> Well, given that bundleresource is an org.eclipse.core thing, I'm not
> sure that the dependency on it is unreasonable. Obviously there's
> nothing in standard JVM/JDK classes that knows how to convert
> bundleresource://9/./ into D:/path_to_plugin, so you're already going
> to need help.
>
> Nick illustrated the other issues with using normal File APIs for
> URLs. It may be that we can add more URL-aware behaviors into File/Dir
> or we may consider writing a small URL library that acts like
> IO/File/Dir instead.
>
> - Charlie
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>

Reply via email to