Changeset 163
- Timestamp:
- 04/08/2008 00:17:11 (8 months ago)
- Location:
- trunk
- Files:
-
- 3 modified
-
Rakefile (modified) (3 diffs)
-
ext/hpricot_scan/hpricot_scan.java.rl (modified) (4 diffs)
-
test/test_builder.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Rakefile
r162 r163 13 13 VERS = ENV['VERSION'] || "0.6" + (REV ? ".#{REV}" : "") 14 14 PKG = "#{NAME}-#{VERS}" 15 BIN = "*.{bundle,jar,so,obj,pdb,lib,def,exp }"15 BIN = "*.{bundle,jar,so,obj,pdb,lib,def,exp,class}" 16 16 ARCHLIB = "lib/#{::Config::CONFIG['arch']}" 17 CLEAN.include ["ext/hpricot_scan/#{BIN}", "ext/fast_xs/#{BIN}", "lib/**/#{BIN}", 17 CLEAN.include ["ext/hpricot_scan/#{BIN}", "ext/fast_xs/#{BIN}", "lib/**/#{BIN}", ARCHLIB, 18 18 'ext/fast_xs/Makefile', 'ext/hpricot_scan/Makefile', 19 '**/.*.sw?', '*.gem', '.config' ]19 '**/.*.sw?', '*.gem', '.config', 'pkg'] 20 20 RDOC_OPTS = ['--quiet', '--title', 'The Hpricot Reference', '--main', 'README', '--inline-source'] 21 21 PKG_FILES = %w(CHANGELOG COPYING README Rakefile) + 22 22 Dir.glob("{bin,doc,test,lib,extras}/**/*") + 23 23 Dir.glob("ext/**/*.{h,java,c,rb,rl}") + 24 %w[ext/hpricot_scan/hpricot_scan.c ] # needed because it's generated later24 %w[ext/hpricot_scan/hpricot_scan.c ext/hpricot_scan/HpricotScanService.java] # needed because it's generated later 25 25 SPEC = 26 26 Gem::Specification.new do |s| … … 175 175 ### JRuby Packages ### 176 176 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" 177 def 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}" : "" 187 end 188 189 def compile_java(filename, jarname) 190 sh %{javac -source 1.4 -target 1.4 #{java_classpath_arg} #{filename}} 191 sh %{jar cf #{jarname} *.class} 192 end 193 183 194 task :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 198 end 199 200 task :fast_xs_java do 201 Dir.chdir "ext/fast_xs" do 202 compile_java("FastXsService.java", "fast_xs.jar") 203 end 204 end 205 206 desc "Compiles the JRuby extensions" 207 task :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}"} 185 210 end 186 211 187 212 JRubySpec = SPEC.dup 188 213 JRubySpec.platform = 'jruby' 189 JRubySpec.files = PKG_FILES + ["#{ARCHLIB}/hpricot_scan.jar" ]214 JRubySpec.files = PKG_FILES + ["#{ARCHLIB}/hpricot_scan.jar", "#{ARCHLIB}/fast_xs.jar"] 190 215 JRubySpec.extensions = [] 191 216 … … 198 223 end 199 224 200 desc "Cross-compile the hpricot_scan extension for JRuby"201 file "hpricot_scan_jruby" => [JRUBY_PKG_DIR] do202 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 end205 206 225 desc "Build the RubyGems package for JRuby" 207 task :package_jruby => ["hpricot_scan_jruby"]do226 task :package_jruby => JRUBY_PKG_DIR do 208 227 Dir.chdir("#{JRUBY_PKG_DIR}") do 228 Rake::Task[:hpricot_java].invoke 209 229 Gem::Builder.new(JRubySpec).build 210 230 verbose(true) { -
trunk/ext/hpricot_scan/hpricot_scan.java.rl
r142 r163 7 7 import org.jruby.RubyModule; 8 8 import org.jruby.RubyNumeric; 9 import org.jruby.RubyObjectAdapter; 9 10 import org.jruby.RubyString; 11 import org.jruby.javasupport.JavaEmbedUtils; 10 12 import org.jruby.runtime.Block; 11 13 import org.jruby.runtime.CallbackFactory; … … 16 18 public class HpricotScanService implements BasicLibraryService { 17 19 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; 18 21 19 22 public void ELE(IRubyObject N) { … … 240 243 241 244 buffer_size = BUFSIZE; 242 if (r ecv.getInstanceVariable("@buffer_size") != null) {243 bufsize = r ecv.getInstanceVariable("@buffer_size");245 if (rubyApi.getInstanceVariable(recv, "@buffer_size") != null) { 246 bufsize = rubyApi.getInstanceVariable(recv, "@buffer_size"); 244 247 if (!bufsize.isNil()) { 245 248 buffer_size = RubyNumeric.fix2int(bufsize); … … 360 363 mHpricot.getMetaClass().defineMethod("scan",fact.getSingletonMethod("__hpricot_scan",IRubyObject.class)); 361 364 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 28 28 Hpricot(text).to_html 29 29 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>한글</b>", doc.to_html 36 end 30 37 end
