diff --git a/ext/java/Liboga.java b/ext/java/Liboga.java new file mode 100644 index 0000000..625d9c7 --- /dev/null +++ b/ext/java/Liboga.java @@ -0,0 +1,14 @@ +package org.liboga; + +import org.jruby.Ruby; + +public class Liboga +{ + /** + * Bootstraps the JRuby extension. + */ + public static void load(final Ruby runtime) + { + org.liboga.xml.Lexer.load(runtime); + } +} diff --git a/ext/java/LibogaService.java b/ext/java/LibogaService.java deleted file mode 100644 index 9bf79dc..0000000 --- a/ext/java/LibogaService.java +++ /dev/null @@ -1,31 +0,0 @@ -import java.io.IOException; - -import org.jruby.Ruby; -import org.jruby.RubyModule; -import org.jruby.RubyClass; -import org.jruby.runtime.load.BasicLibraryService; -import org.jruby.runtime.load.Library; - -public class LibogaService implements BasicLibraryService -{ - /** - * Bootstraps the JRuby extension. - * - * In order to load this extension properly you have to make sure that the - * lib/ directory is in the Ruby load path. If this is the case you can - * load it as following: - * - * require 'liboga' - * - * Using absolute paths (e.g. with `require_relative`) requires you to - * manually call this method: - * - * LibogaService.new.basicLoad(JRuby.runtime) - */ - public boolean basicLoad(final Ruby runtime) throws IOException - { - org.liboga.xml.Lexer.load(runtime); - - return true; - } -} diff --git a/lib/oga.rb b/lib/oga.rb index 1b92177..5258da2 100644 --- a/lib/oga.rb +++ b/lib/oga.rb @@ -6,14 +6,11 @@ require_relative 'oga/xml/lexer' require_relative 'oga/xml/parser' require_relative 'oga/xml/pull_parser' -# 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_relative 'liboga' -require 'liboga' +if RUBY_PLATFORM == 'java' + org.liboga.Liboga.load(JRuby.runtime) +end require_relative 'oga/xml/node' require_relative 'oga/xml/element'