From 2053018d076076bc1b56f56a10780d4474519c44 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Tue, 6 May 2014 20:45:26 +0200 Subject: [PATCH] Slap JRuby so that it can load the .jar file. --- ext/liboga/LibogaService.java | 2 -- lib/oga.rb | 15 +++++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ext/liboga/LibogaService.java b/ext/liboga/LibogaService.java index a132aaf..1339a1e 100644 --- a/ext/liboga/LibogaService.java +++ b/ext/liboga/LibogaService.java @@ -12,8 +12,6 @@ public class LibogaService implements BasicLibraryService { public boolean basicLoad(final Ruby runtime) throws IOException { - // Calling getModule on an instance of RubyModule? Nah fuck - // that, that would be too easy. RubyModule xml = (RubyModule) runtime.getModule("Oga") .getConstant("XML"); diff --git a/lib/oga.rb b/lib/oga.rb index 213e50b..1b92177 100644 --- a/lib/oga.rb +++ b/lib/oga.rb @@ -1,17 +1,20 @@ require 'set' +# Load these first so that the native extensions don't have to define the +# Oga::XML namespace. require_relative 'oga/xml/lexer' require_relative 'oga/xml/parser' require_relative 'oga/xml/pull_parser' -require_relative 'liboga' - -# FIXME: it looks like this should not be needed but stuff doesn't load without -# it. -if RUBY_ENGINE == 'jruby' - org.liboga.LibogaService.new.basicLoad(JRuby.runtime) +# JRuby is dumb as a brick and can only load .jar files using require() when +# ./lib is in the LOAD_PATH. require_relative, or any other form that uses +# absolute paths, does not work. +unless $:.include?(File.expand_path('../', __FILE__)) + $:.unshift(File.expand_path('../', __FILE__)) end +require 'liboga' + require_relative 'oga/xml/node' require_relative 'oga/xml/element' require_relative 'oga/xml/document'