Changeset 163

Show
Ignore:
Timestamp:
04/08/2008 00:17:11 (8 months ago)
Author:
why
Message:
  • ext/hpricot_scan/hpricot_scan.java.rl: applied patch by nick sieger to get hpricot up to the latest jruby. thankyou for being persistent kid!
Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/Rakefile

    r162 r163  
    1313VERS = ENV['VERSION'] || "0.6" + (REV ? ".#{REV}" : "") 
    1414PKG = "#{NAME}-#{VERS}" 
    15 BIN = "*.{bundle,jar,so,obj,pdb,lib,def,exp}" 
     15BIN = "*.{bundle,jar,so,obj,pdb,lib,def,exp,class}" 
    1616ARCHLIB = "lib/#{::Config::CONFIG['arch']}" 
    17 CLEAN.include ["ext/hpricot_scan/#{BIN}", "ext/fast_xs/#{BIN}", "lib/**/#{BIN}",  
     17CLEAN.include ["ext/hpricot_scan/#{BIN}", "ext/fast_xs/#{BIN}", "lib/**/#{BIN}", ARCHLIB, 
    1818               'ext/fast_xs/Makefile', 'ext/hpricot_scan/Makefile',  
    19                '**/.*.sw?', '*.gem', '.config'] 
     19               '**/.*.sw?', '*.gem', '.config', 'pkg'] 
    2020RDOC_OPTS = ['--quiet', '--title', 'The Hpricot Reference', '--main', 'README', '--inline-source'] 
    2121PKG_FILES = %w(CHANGELOG COPYING README Rakefile) + 
    2222      Dir.glob("{bin,doc,test,lib,extras}/**/*") +  
    2323      Dir.glob("ext/**/*.{h,java,c,rb,rl}") +  
    24       %w[ext/hpricot_scan/hpricot_scan.c] # needed because it's generated later 
     24      %w[ext/hpricot_scan/hpricot_scan.c ext/hpricot_scan/HpricotScanService.java] # needed because it's generated later 
    2525SPEC = 
    2626  Gem::Specification.new do |s| 
     
    175175### JRuby Packages ### 
    176176 
    177 compile_java = proc do 
    178   sh %{javac -source 1.4 -target 1.4 -classpath $JRUBY_HOME/lib/jruby.jar HpricotScanService.java} 
    179   sh %{jar cf hpricot_scan.jar HpricotScanService.class} 
    180 end 
    181  
    182 desc "Compiles the JRuby extension" 
     177def java_classpath_arg  
     178  # A myriad of ways to discover the JRuby classpath 
     179  classpath = begin 
     180    require 'java'  
     181    # Already running in a JRuby JVM 
     182    Java::java.lang.System.getProperty('java.class.path') 
     183  rescue LoadError 
     184    ENV['JRUBY_PARENT_CLASSPATH'] || ENV['JRUBY_HOME'] && FileList["#{ENV['JRUBY_HOME']}/lib/*.jar"].join(File::PATH_SEPARATOR) 
     185  end 
     186  classpath ? "-cp #{classpath}" : "" 
     187end 
     188 
     189def compile_java(filename, jarname) 
     190  sh %{javac -source 1.4 -target 1.4 #{java_classpath_arg} #{filename}} 
     191  sh %{jar cf #{jarname} *.class} 
     192end 
     193 
    183194task :hpricot_scan_java => [:ragel_java] do 
    184   Dir.chdir("ext/hpricot_scan", &compile_java) 
     195  Dir.chdir "ext/hpricot_scan" do 
     196    compile_java("HpricotScanService.java", "hpricot_scan.jar") 
     197  end 
     198end 
     199 
     200task :fast_xs_java do 
     201  Dir.chdir "ext/fast_xs" do 
     202    compile_java("FastXsService.java", "fast_xs.jar") 
     203  end 
     204end 
     205 
     206desc "Compiles the JRuby extensions" 
     207task :hpricot_java => [:hpricot_scan_java, :fast_xs_java] do 
     208  mkdir_p "#{ARCHLIB}" 
     209  %w(hpricot_scan fast_xs).each {|ext| mv "ext/#{ext}/#{ext}.jar", "#{ARCHLIB}"} 
    185210end 
    186211 
    187212JRubySpec = SPEC.dup 
    188213JRubySpec.platform = 'jruby' 
    189 JRubySpec.files = PKG_FILES + ["#{ARCHLIB}/hpricot_scan.jar"] 
     214JRubySpec.files = PKG_FILES + ["#{ARCHLIB}/hpricot_scan.jar", "#{ARCHLIB}/fast_xs.jar"] 
    190215JRubySpec.extensions = [] 
    191216 
     
    198223end 
    199224 
    200 desc "Cross-compile the hpricot_scan extension for JRuby" 
    201 file "hpricot_scan_jruby" => [JRUBY_PKG_DIR] do 
    202   Dir.chdir("#{JRUBY_PKG_DIR}/ext/hpricot_scan", &compile_java) 
    203   mv "#{JRUBY_PKG_DIR}/ext/hpricot_scan/hpricot_scan.jar", "#{JRUBY_PKG_DIR}/#{ARCHLIB}" 
    204 end 
    205  
    206225desc "Build the RubyGems package for JRuby" 
    207 task :package_jruby => ["hpricot_scan_jruby"] do 
     226task :package_jruby => JRUBY_PKG_DIR do 
    208227  Dir.chdir("#{JRUBY_PKG_DIR}") do 
     228    Rake::Task[:hpricot_java].invoke 
    209229    Gem::Builder.new(JRubySpec).build 
    210230    verbose(true) { 
  • trunk/ext/hpricot_scan/hpricot_scan.java.rl

    r142 r163  
    77import org.jruby.RubyModule; 
    88import org.jruby.RubyNumeric; 
     9import org.jruby.RubyObjectAdapter; 
    910import org.jruby.RubyString; 
     11import org.jruby.javasupport.JavaEmbedUtils; 
    1012import org.jruby.runtime.Block; 
    1113import org.jruby.runtime.CallbackFactory; 
     
    1618public class HpricotScanService implements BasicLibraryService { 
    1719       public static String NO_WAY_SERIOUSLY="*** This should not happen, please send a bug report with the HTML you're parsing to why@whytheluckystiff.net.  So sorry!"; 
     20       private static RubyObjectAdapter rubyApi; 
    1821 
    1922       public void ELE(IRubyObject N) { 
     
    240243 
    241244  buffer_size = BUFSIZE; 
    242   if (recv.getInstanceVariable("@buffer_size") != null) { 
    243     bufsize = recv.getInstanceVariable("@buffer_size"); 
     245  if (rubyApi.getInstanceVariable(recv, "@buffer_size") != null) { 
     246    bufsize = rubyApi.getInstanceVariable(recv, "@buffer_size"); 
    244247    if (!bufsize.isNil()) { 
    245248      buffer_size = RubyNumeric.fix2int(bufsize); 
     
    360363  mHpricot.getMetaClass().defineMethod("scan",fact.getSingletonMethod("__hpricot_scan",IRubyObject.class)); 
    361364  mHpricot.defineClassUnder("ParseError",runtime.getClass("Exception"),runtime.getClass("Exception").getAllocator()); 
    362 } 
    363 } 
     365  rubyApi = JavaEmbedUtils.newObjectAdapter(); 
     366} 
     367} 
  • trunk/test/test_builder.rb

    r154 r163  
    2828      Hpricot(text).to_html 
    2929  end 
     30 
     31  def test_korean_utf8_entities 
     32    # a = '한Ꞁ' 
     33    a = "\xed\x95\x9c\xea\xb8\x80" 
     34    doc = Hpricot() { b a } 
     35    assert_equal "<b>&#54620;&#44544;</b>", doc.to_html 
     36  end 
    3037end