@@ -16,69 +16,65 @@ Rake::TestTask.new do |t|
1616 t . verbose = true
1717end
1818
19- spec = eval ( File . read ( File . expand_path ( '../ref.gemspec' , __FILE__ ) ) )
2019
21- Gem ::PackageTask . new ( spec ) do |p |
22- p . gem_spec = spec
23- end
24- Rake . application [ "package" ] . prerequisites . unshift ( "java:build" )
25- Rake . application [ "package" ] . prerequisites . unshift ( "rbx:delete_rbc_files" )
20+ GEM_NAME = 'ref'
21+ EXTENSION_NAME = 'extension'
22+ JAVA_EXT_NAME = 'ref_ext'
23+ CORE_GEMSPEC = Gem ::Specification . load ( 'ref.gemspec' )
2624
27- desc "Release to rubygems.org"
28- task :release => [ :package , "gem:push" ]
25+ if Ref . jruby?
26+ CORE_GEM = " #{ GEM_NAME } - #{ Ref :: VERSION } -java.gem"
2927
30- namespace :java do
31- desc "Build the jar files for Jruby support. You must set your JRUBY_HOME environment variable to the root of your jruby install."
32- task :build do
33- base_dir = File . dirname ( __FILE__ )
34- tmp_dir = File . join ( base_dir , "tmp" )
35- classes_dir = File . join ( tmp_dir , "classes" )
36- jar_dir = File . join ( base_dir , "lib" , "org" , "jruby" , "ext" , "ref" )
37- FileUtils . rm_rf ( classes_dir )
38- ext_dir = File . join ( base_dir , "ext" , "java" )
39- source_files = FileList [ "#{ base_dir } /ext/**/*.java" ]
40- jar_file = File . join ( jar_dir , 'references.jar' )
41- # Only build if any of the source files have changed
42- up_to_date = File . exist? ( jar_file ) && source_files . all? { |f | File . mtime ( f ) <= File . mtime ( jar_file ) }
43- unless up_to_date
44- FileUtils . mkdir_p ( classes_dir )
45- puts "#{ ENV [ 'JAVA_HOME' ] } /bin/javac -target 1.5 -classpath '#{ "#{ ENV [ 'JRUBY_HOME' ] } /lib/jruby.jar" } ' -d '#{ classes_dir } ' -sourcepath '#{ ext_dir } ' '#{ source_files . join ( "' '" ) } '"
46- `#{ ENV [ 'JAVA_HOME' ] } /bin/javac -target 1.5 -classpath '#{ "#{ ENV [ 'JRUBY_HOME' ] } /lib/jruby.jar" } ' -d '#{ classes_dir } ' -sourcepath '#{ ext_dir } ' '#{ source_files . join ( "' '" ) } '`
47- if $? == 0
48- FileUtils . rm_rf ( jar_dir ) if File . exist? ( jar_dir )
49- FileUtils . mkdir_p ( jar_dir )
50- `#{ ENV [ 'JAVA_HOME' ] } /bin/jar cf '#{ jar_file } ' -C '#{ classes_dir } ' org`
51- end
52- FileUtils . rm_rf ( classes_dir )
53- end
28+ require 'rake/javaextensiontask'
29+ Rake ::JavaExtensionTask . new ( JAVA_EXT_NAME , CORE_GEMSPEC ) do |ext |
30+ ext . ext_dir = 'ext'
5431 end
32+ else
33+ CORE_GEM = "#{ GEM_NAME } -#{ Ref ::VERSION } .gem"
5534end
5635
57- namespace :rbx do
58- desc "Cleanup *.rbc files in lib directory"
59- task :delete_rbc_files do
60- FileList [ "lib/**/*.rbc" ] . each do |rbc_file |
61- File . delete ( rbc_file )
62- end
63- nil
36+ task :clean do
37+ rm_f Dir . glob ( './**/*.so' )
38+ rm_f Dir . glob ( './**/*.bundle' )
39+ rm_f Dir . glob ( './lib/*.jar' )
40+ mkdir_p 'pkg'
41+ end
42+
43+
44+ namespace :build do
45+ build_deps = [ :clean ]
46+ build_deps << :compile if Ref . jruby?
47+ desc "Build #{ CORE_GEM } into the pkg directory"
48+ task :core => build_deps do
49+ sh "gem build #{ CORE_GEMSPEC . name } .gemspec"
50+ sh 'mv *.gem pkg/'
6451 end
6552end
6653
54+ if Ref . jruby?
55+ desc 'Build JRuby-specific core gem (alias for `build:core`)'
56+ task :build => [ 'build:core' ]
57+ end
58+
6759namespace :test do
6860 namespace :performance do
6961 desc "Run a speed test on how long it takes to create 100000 weak references"
7062 task :weak_reference do
7163 puts "Testing performance of weak references..."
72- t = Time . now
73- Process . fork do
74- 100000 . times do
75- Ref ::WeakReference . new ( Object . new )
64+ unless Ref . jruby?
65+ t = Time . now
66+ Process . fork do
67+ 100000 . times do
68+ Ref ::WeakReference . new ( Object . new )
69+ end
7670 end
71+ Process . wait
72+ puts "Creating 100,000 weak references took #{ Time . now - t } seconds"
73+ else
74+ puts 'Cannot run weak_reference performance test on JRuby - Fork is not available on this platform.'
7775 end
78- Process . wait
79- puts "Creating 100,000 weak references took #{ Time . now - t } seconds"
8076 end
81-
77+
8278 desc "Run a speed test on how long it takes to create 100000 soft references"
8379 task :soft_reference do
8480 puts "Testing performance of soft references..."
0 commit comments