boc 0.3.2 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.rdoc CHANGED
@@ -1,6 +1,11 @@
1
1
 
2
2
  = boc Changes
3
3
 
4
+ == Version 0.4.2
5
+
6
+ * add jruby support
7
+ * add AlreadyEnabledError
8
+
4
9
  == Version 0.3.2
5
10
 
6
11
  * "rake test" now works without rake-compiler on Windows
data/README.rdoc CHANGED
@@ -30,7 +30,8 @@ Or from inside an unpacked .tgz download, <code>rake install</code> /
30
30
 
31
31
  Binding of caller: obtain a caller's binding.
32
32
 
33
- MRI 1.9.2 is required. Support for other Ruby platforms is a goal.
33
+ MRI 1.9.2 or JRuby 1.6+ is required. Support for other Ruby platforms
34
+ is a goal.
34
35
 
35
36
  == <code>Binding.of_caller</code>
36
37
 
@@ -64,15 +65,14 @@ convenience method for existing 1.8 code.
64
65
 
65
66
  == Implementation
66
67
 
67
- <code>Boc.enable(A, :f)</code> is essentially
68
+ When <code>Boc.enable(A, :f)</code> is called it first makes an alias,
68
69
 
69
70
  class A
70
71
  alias_method :f__impl, :f
71
72
  end
72
73
 
73
- followed by a redefinition of +f+. The new +f+ is a native method
74
- which sets <code>Boc.value</code> and then forwards the incoming
75
- arguments to +f__impl+.
74
+ Following that, +f+ is replaced by native method whose only tasks are
75
+ to set <code>Boc.value</code> and then call +f__impl+.
76
76
 
77
77
  == Background
78
78
 
data/Rakefile CHANGED
@@ -1,13 +1,139 @@
1
1
  require_relative 'devel/levitate'
2
+ require 'rbconfig'
2
3
 
3
- Levitate.new "boc" do |s|
4
- s.developers << ["James M. Lawrence", "quixoticsycophant@gmail.com"]
5
- s.username = "quix"
6
- s.required_ruby_version = ">= 1.9.2"
7
- s.development_dependencies << ["rake-compiler", "~> 0.7.6"]
8
-
9
- s.rdoc_files = %w[
4
+ def config
5
+ @s.developers << ["James M. Lawrence", "quixoticsycophant@gmail.com"]
6
+ @s.username = "quix"
7
+ @s.required_ruby_version = ">= 1.9.2"
8
+ @s.development_dependencies << ["rake-compiler", "~> 0.7.6"]
9
+ @s.rdoc_files = %w[
10
10
  lib/boc.rb
11
11
  lib/boc/version.rb
12
12
  ]
13
13
  end
14
+
15
+ def mri_ext
16
+ require 'rake/extensiontask'
17
+
18
+ Rake::ExtensionTask.new @s.gem_name, @s.gemspec do |ext|
19
+ ext.cross_compile = true
20
+ ext.cross_platform = 'i386-mswin32'
21
+ ext.lib_dir = "lib/#{@s.gem_name}"
22
+ end
23
+
24
+ # compensate for strange rake-compiler invocation
25
+ task :cross_native_gem do
26
+ Rake::Task[:gem].reenable
27
+ Rake.application.top_level_tasks.replace %w[cross native gem]
28
+ Rake.application.top_level
29
+ end
30
+
31
+ task :gem => :cross_native_gem
32
+
33
+ task :test => so_file
34
+
35
+ @s.gemspec.extensions = ["Rakefile"]
36
+ end
37
+
38
+ def jruby_ext
39
+ require "rake/javaextensiontask"
40
+
41
+ Levitate.no_warnings do
42
+ Rake::JavaExtensionTask.new @s.gem_name, @s.gemspec do |ext|
43
+ ext.ext_dir = "jext"
44
+ ext.lib_dir = "lib/#{@s.gem_name}"
45
+ end
46
+ end
47
+
48
+ task :jar => jar_file
49
+
50
+ case RUBY_ENGINE
51
+ when "jruby"
52
+ task :test => jar_file
53
+ when "ruby"
54
+ # building/releasing from MRI
55
+
56
+ task :jruby_gem => jar_file do
57
+ # compensate for strange rake-compiler invocation
58
+ Rake::Task[:gem].reenable
59
+ Rake.application.top_level_tasks.replace %w[java gem]
60
+ Rake.application.top_level
61
+ end
62
+
63
+ task :gem => :jruby_gem
64
+
65
+ task :test_jruby do
66
+ run_jruby = ENV["RUN_JRUBY"] || "jruby"
67
+ cmd = run_jruby + " --1.9 -J-Djruby.astInspector.enabled=0 -S rake"
68
+ sh(cmd + " test")
69
+ sh(cmd + " test_deps")
70
+ end
71
+
72
+ task :prerelease => :test_jruby
73
+
74
+ CLEAN.add jar_file
75
+ end
76
+ end
77
+
78
+ def jar_file
79
+ # the only path jruby recognizes
80
+ File.join("lib", @s.gem_name, @s.gem_name + ".jar")
81
+ end
82
+
83
+ def so_file
84
+ File.join("lib", @s.gem_name, @s.gem_name + "." + RbConfig::CONFIG["DLEXT"])
85
+ end
86
+
87
+ def native_file
88
+ case RUBY_ENGINE
89
+ when "ruby"
90
+ so_file
91
+ when "jruby"
92
+ jar_file
93
+ end
94
+ end
95
+
96
+ def append_installer
97
+ fu = FileUtils::Verbose
98
+
99
+ source = native_file
100
+ dir = File.join RbConfig::CONFIG["sitearchdir"], @s.gem_name
101
+ dest = File.join dir, File.basename(source)
102
+
103
+ task :install => source do
104
+ fu.mkdir dir unless File.directory? dir
105
+ fu.install source, dest
106
+ end
107
+
108
+ task :uninstall do
109
+ fu.rm dest if File.file? dest
110
+ fu.rmdir dir if File.directory? dir
111
+ end
112
+ end
113
+
114
+ def config_extension
115
+ case RUBY_ENGINE
116
+ when "jruby"
117
+ jruby_ext
118
+ when "ruby"
119
+ mri_ext
120
+ else
121
+ raise "sorry, platform `#{RUBY_ENGINE}' not supported"
122
+ end
123
+ end
124
+
125
+ Levitate.new "boc" do |s|
126
+ @s = s
127
+ config
128
+ if File.directory? ".git"
129
+ mri_ext if RUBY_ENGINE == "ruby"
130
+ jruby_ext
131
+ elsif not File.file?(native_file)
132
+ config_extension
133
+ end
134
+ append_installer
135
+ task :finish_release do
136
+ sh "gem", "push", "pkg/#{@s.gem_name}-#{@s.version}-java.gem"
137
+ sh "gem", "push", "pkg/#{@s.gem_name}-#{@s.version}-x86-mswin32.gem"
138
+ end
139
+ end