Skip to content

Instantly share code, notes, and snippets.

@stepheneb stepheneb/gist:46140
Created Jan 12, 2009

Embed
What would you like to do?
I'm trying to figure out how to modify a gem that uses a jar to instead use the Java class files directly. It's an experiment to then try and add it to jruby-complete and see if it works.
I'm working on the redcloth gem here: http://github.com/jgarber/redcloth/tree/master
# I've modified the Rakefile to copy the classes over to the lib directory in addition to the jar:
--- a/Rakefile
+++ b/Rakefile
@@ -47,7 +47,7 @@ end
#### Pre-compiled extensions for alternative platforms
def move_extensions
- Dir["ext/**/*.{bundle,so,jar}"].each { |file| mv file, "lib/" }
+ Dir["ext/**/*.{bundle,so,jar,class}"].each { |file| mv file, "lib/" }
end
# here's what's in the jar (fyi: using the jar works fine)
redcloth.git (nojar)]$ unzip -l lib/redcloth_scan.jar
Archive: lib/redcloth_scan.jar
Length Date Time Name
-------- ---- ---- ----
0 01-12-09 14:32 META-INF/
60 01-12-09 14:32 META-INF/MANIFEST.MF
24976 01-12-09 14:32 RedclothAttributes.class
560002 01-12-09 14:32 RedclothInline.class
9548 01-12-09 14:32 RedclothScanService$Base.class
597763 01-12-09 14:32 RedclothScanService$Transformer.class
5423 01-12-09 14:32 RedclothScanService.class
-------- -------
1197772 7 files
# the class files are also now in the lib/ dir
[redcloth.git (nojar)]$ ls -l lib/*.class
-rw-r--r-- 1 stephen staff 24976 Jan 12 14:32 lib/RedclothAttributes.class
-rw-r--r-- 1 stephen staff 560002 Jan 12 14:32 lib/RedclothInline.class
-rw-r--r-- 1 stephen staff 9548 Jan 12 14:32 lib/RedclothScanService$Base.class
-rw-r--r-- 1 stephen staff 597763 Jan 12 14:32 lib/RedclothScanService$Transformer.class
-rw-r--r-- 1 stephen staff 5423 Jan 12 14:32 lib/RedclothScanService.class
# Here's what I changed in redcloth.rb to try and use the classes directly:
diff --git a/lib/redcloth.rb b/lib/redcloth.rb
index d442103..66a2839 100644
--- a/lib/redcloth.rb
+++ b/lib/redcloth.rb
@@ -7,7 +7,15 @@ $:.unshift(File.dirname(__FILE__))
# appears to be fixed in Edge Rails [51e4106].
Object.send(:remove_const, :RedCloth) if Object.const_defined?(:RedCloth) && RedCloth.is_a?(Class)
-require 'redcloth_scan'
+# require 'redcloth_scan'
+require 'jruby'
+$CLASSPATH << File.dirname(File.expand_path(__FILE__)) + '/'
+include_class 'RedclothScanService'
+include_class 'RedclothInline'
+include_class 'RedclothAttributes'
+# include_class 'RedclothScanService$Base'
+# include_class 'RedclothScanService$Transformer'
+
require 'redcloth/version'
require 'redcloth/textile_doc'
require 'redcloth/formatters/base'
Running a short set of tests results in many errors:
$ jruby -S rake test TEST=test_parser.rb
...
=> 13 tests, 6 assertions, 1 failures, 9 errors
The only difference seems to be how I'm making the Java classes available.
However if I uncomment this statement:
include_class 'RedclothScanService$Base'
I get this error:
/Users/stephen/dev/ruby/src/jruby.git/lib/ruby/site_ruby/1.8/builtin/javasupport/core_ext/object.rb:74:in `include_class': undefined method `RedclothScanService' for main:Object (NoMethodError)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.