rjb 1.4.5 → 1.4.6
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +504 -504
- data/ChangeLog +6 -1
- data/data/rjb/jp/co/infoseek/hp/arton/rjb/RBridge.class +0 -0
- data/ext/RBridge.java +39 -39
- data/ext/depend +23 -23
- data/ext/extconf.h +1 -0
- data/ext/extconf.rb +77 -77
- data/ext/jp_co_infoseek_hp_arton_rjb_RBridge.h +21 -21
- data/ext/load.c +408 -408
- data/ext/riconv.c +218 -218
- data/ext/riconv.h +24 -24
- data/ext/rjb.c +3317 -3317
- data/ext/rjb.h +164 -164
- data/ext/rjbexception.c +167 -167
- data/lib/rjb.rb +122 -122
- data/readme.txt +35 -35
- data/samples/filechooser.rb +35 -35
- data/samples/unzip.rb +66 -66
- data/test/gctest.rb +24 -24
- data/test/listtest.rb +56 -56
- data/test/osx_jvmcheck.rb +9 -9
- data/test/rjbtest.jar +0 -0
- data/test/test.rb +873 -873
- data/test/test_osxjvm.rb +23 -23
- data/test/test_osxload.rb +64 -64
- data/test/test_unload.rb +0 -0
- metadata +15 -17
- data/lib/rjbcore.so +0 -0
data/lib/rjb.rb
CHANGED
@@ -1,122 +1,122 @@
|
|
1
|
-
=begin
|
2
|
-
Copyright(c) 2006-2010,2012 arton
|
3
|
-
=end
|
4
|
-
|
5
|
-
require 'rbconfig'
|
6
|
-
|
7
|
-
module RjbConf
|
8
|
-
if /darwin/ =~ RUBY_PLATFORM
|
9
|
-
if ENV['JVM_LIB'].nil? || ENV['JVM_LIB'] == ''
|
10
|
-
if ENV['JAVA_HOME'].nil? || ENV['JAVA_HOME'] == ''
|
11
|
-
jvms = Dir.glob("#{`/usr/libexec/java_home`.strip}/**/libjvm.dylib")
|
12
|
-
else
|
13
|
-
jvms = Dir.glob("#{ENV['JAVA_HOME']}/**/libjvm.dylib")
|
14
|
-
end
|
15
|
-
if jvms.size > 0
|
16
|
-
ENV['JVM_LIB'] = jvms[0]
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
dir = File.join(File.dirname(File.dirname(__FILE__)), 'data')
|
22
|
-
if File.exist?(dir)
|
23
|
-
datadir = dir
|
24
|
-
else
|
25
|
-
datadir = RbConfig::CONFIG['datadir']
|
26
|
-
end
|
27
|
-
BRIDGE_FILE = File.join(datadir, 'rjb', 'jp', 'co', 'infoseek', 'hp',
|
28
|
-
'arton', 'rjb', 'RBridge.class')
|
29
|
-
unless File.exist?(BRIDGE_FILE)
|
30
|
-
raise 'bridge file not found'
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
require 'rjbcore'
|
35
|
-
|
36
|
-
module Rjb
|
37
|
-
module MODIFIER
|
38
|
-
def self.STATIC
|
39
|
-
8
|
40
|
-
end
|
41
|
-
def self.PUBLIC
|
42
|
-
1
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
module JMethod
|
47
|
-
def instance_method?(m)
|
48
|
-
m.modifiers & MODIFIER.STATIC == 0
|
49
|
-
end
|
50
|
-
def public_method?(m)
|
51
|
-
(m.modifiers & MODIFIER.PUBLIC) == MODIFIER.PUBLIC
|
52
|
-
end
|
53
|
-
def jmethods(org, klass, &blk)
|
54
|
-
(org + klass.getMethods.select do |m|
|
55
|
-
blk.call(m)
|
56
|
-
end.map do |m|
|
57
|
-
m.name
|
58
|
-
end).uniq
|
59
|
-
end
|
60
|
-
def format_sigs(s)
|
61
|
-
if s.size < 0
|
62
|
-
''
|
63
|
-
elsif s.size == 1
|
64
|
-
s[0]
|
65
|
-
else
|
66
|
-
"[#{s.map{|m|m.nil? ? 'void' : m}.join(', ')}]"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
class Rjb_JavaClass
|
72
|
-
include JMethod
|
73
|
-
def public_methods(inh = true)
|
74
|
-
jmethods(super(inh), self) do |m|
|
75
|
-
!instance_method?(m) && public_method?(m)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
def methods(inh = true)
|
79
|
-
jmethods(super(inh), self) do |m|
|
80
|
-
!instance_method?(m) && public_method?(m)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
def java_methods
|
84
|
-
jmethods([], self) do |m|
|
85
|
-
!instance_method?(m) && public_method?(m)
|
86
|
-
end.map do |m|
|
87
|
-
"#{m}(#{format_sigs(self.static_sigs(m))})"
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
class Rjb_JavaProxy
|
92
|
-
include JMethod
|
93
|
-
def initialize_proxy
|
94
|
-
end
|
95
|
-
def public_methods(inh = true)
|
96
|
-
jmethods(super(inh), getClass) do |m|
|
97
|
-
instance_method?(m) && public_method?(m)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
def methods(inh = true)
|
101
|
-
jmethods(super(inh), getClass) do |m|
|
102
|
-
instance_method?(m) && public_method?(m)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
def java_methods
|
106
|
-
jmethods([], getClass) do |m|
|
107
|
-
instance_method?(m) && public_method?(m)
|
108
|
-
end.map do |m|
|
109
|
-
"#{m}(#{format_sigs(getClass.sigs(m))})"
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
class Rjb_JavaBridge
|
114
|
-
def method_missing(name, *args)
|
115
|
-
@wrapped.__send__(name, *args)
|
116
|
-
end
|
117
|
-
def respond_to?(name, inc_private = false)
|
118
|
-
@wrapped.respond_to?(name, inc_private)
|
119
|
-
end
|
120
|
-
attr_reader :wrapped
|
121
|
-
end
|
122
|
-
end
|
1
|
+
=begin
|
2
|
+
Copyright(c) 2006-2010,2012 arton
|
3
|
+
=end
|
4
|
+
|
5
|
+
require 'rbconfig'
|
6
|
+
|
7
|
+
module RjbConf
|
8
|
+
if /darwin/ =~ RUBY_PLATFORM
|
9
|
+
if ENV['JVM_LIB'].nil? || ENV['JVM_LIB'] == ''
|
10
|
+
if ENV['JAVA_HOME'].nil? || ENV['JAVA_HOME'] == ''
|
11
|
+
jvms = Dir.glob("#{`/usr/libexec/java_home`.strip}/**/libjvm.dylib")
|
12
|
+
else
|
13
|
+
jvms = Dir.glob("#{ENV['JAVA_HOME']}/**/libjvm.dylib")
|
14
|
+
end
|
15
|
+
if jvms.size > 0
|
16
|
+
ENV['JVM_LIB'] = jvms[0]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
dir = File.join(File.dirname(File.dirname(__FILE__)), 'data')
|
22
|
+
if File.exist?(dir)
|
23
|
+
datadir = dir
|
24
|
+
else
|
25
|
+
datadir = RbConfig::CONFIG['datadir']
|
26
|
+
end
|
27
|
+
BRIDGE_FILE = File.join(datadir, 'rjb', 'jp', 'co', 'infoseek', 'hp',
|
28
|
+
'arton', 'rjb', 'RBridge.class')
|
29
|
+
unless File.exist?(BRIDGE_FILE)
|
30
|
+
raise 'bridge file not found'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
require 'rjbcore'
|
35
|
+
|
36
|
+
module Rjb
|
37
|
+
module MODIFIER
|
38
|
+
def self.STATIC
|
39
|
+
8
|
40
|
+
end
|
41
|
+
def self.PUBLIC
|
42
|
+
1
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
module JMethod
|
47
|
+
def instance_method?(m)
|
48
|
+
m.modifiers & MODIFIER.STATIC == 0
|
49
|
+
end
|
50
|
+
def public_method?(m)
|
51
|
+
(m.modifiers & MODIFIER.PUBLIC) == MODIFIER.PUBLIC
|
52
|
+
end
|
53
|
+
def jmethods(org, klass, &blk)
|
54
|
+
(org + klass.getMethods.select do |m|
|
55
|
+
blk.call(m)
|
56
|
+
end.map do |m|
|
57
|
+
m.name
|
58
|
+
end).uniq
|
59
|
+
end
|
60
|
+
def format_sigs(s)
|
61
|
+
if s.size < 0
|
62
|
+
''
|
63
|
+
elsif s.size == 1
|
64
|
+
s[0]
|
65
|
+
else
|
66
|
+
"[#{s.map{|m|m.nil? ? 'void' : m}.join(', ')}]"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class Rjb_JavaClass
|
72
|
+
include JMethod
|
73
|
+
def public_methods(inh = true)
|
74
|
+
jmethods(super(inh), self) do |m|
|
75
|
+
!instance_method?(m) && public_method?(m)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
def methods(inh = true)
|
79
|
+
jmethods(super(inh), self) do |m|
|
80
|
+
!instance_method?(m) && public_method?(m)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
def java_methods
|
84
|
+
jmethods([], self) do |m|
|
85
|
+
!instance_method?(m) && public_method?(m)
|
86
|
+
end.map do |m|
|
87
|
+
"#{m}(#{format_sigs(self.static_sigs(m))})"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
class Rjb_JavaProxy
|
92
|
+
include JMethod
|
93
|
+
def initialize_proxy
|
94
|
+
end
|
95
|
+
def public_methods(inh = true)
|
96
|
+
jmethods(super(inh), getClass) do |m|
|
97
|
+
instance_method?(m) && public_method?(m)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
def methods(inh = true)
|
101
|
+
jmethods(super(inh), getClass) do |m|
|
102
|
+
instance_method?(m) && public_method?(m)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
def java_methods
|
106
|
+
jmethods([], getClass) do |m|
|
107
|
+
instance_method?(m) && public_method?(m)
|
108
|
+
end.map do |m|
|
109
|
+
"#{m}(#{format_sigs(getClass.sigs(m))})"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
class Rjb_JavaBridge
|
114
|
+
def method_missing(name, *args)
|
115
|
+
@wrapped.__send__(name, *args)
|
116
|
+
end
|
117
|
+
def respond_to?(name, inc_private = false)
|
118
|
+
@wrapped.respond_to?(name, inc_private)
|
119
|
+
end
|
120
|
+
attr_reader :wrapped
|
121
|
+
end
|
122
|
+
end
|
data/readme.txt
CHANGED
@@ -1,35 +1,35 @@
|
|
1
|
-
Rjb is Ruby-Java bridge using Java Native Interface.
|
2
|
-
|
3
|
-
How to install
|
4
|
-
|
5
|
-
you need to install Java2 sdk, and setup JAVA_HOME enviromental varible except for OS X.
|
6
|
-
I assume that OS X's JAVA_HOME is reported by calling /usr/libexec/java_home.
|
7
|
-
|
8
|
-
then,
|
9
|
-
|
10
|
-
ruby setup.rb config
|
11
|
-
ruby setup.rb setup
|
12
|
-
|
13
|
-
(in Unix)
|
14
|
-
sudo ruby setup.rb install
|
15
|
-
or
|
16
|
-
(in win32)
|
17
|
-
ruby setup.rb install
|
18
|
-
|
19
|
-
How to test
|
20
|
-
in Win32
|
21
|
-
cd test
|
22
|
-
ruby test.rb
|
23
|
-
|
24
|
-
in Unix
|
25
|
-
see test/readme.unix
|
26
|
-
you must set LD_LIBRARY_PATH environmental variable to run rjb.
|
27
|
-
|
28
|
-
-- Notice for opening non-ASCII 7bit filename
|
29
|
-
If you'll plan to open the non-ascii character named file by Java class through Rjb, it may require to set LC_ALL environment variable in you sciprt.
|
30
|
-
For example in Rails, set above line in production.rb as your environment.
|
31
|
-
ENV['LC_ALL'] = 'en_us.utf8' # or ja_JP.utf8 etc.
|
32
|
-
cf: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4733494
|
33
|
-
(Thanks Paul for this information).
|
34
|
-
|
35
|
-
artonx@yahoo.co.jp
|
1
|
+
Rjb is Ruby-Java bridge using Java Native Interface.
|
2
|
+
|
3
|
+
How to install
|
4
|
+
|
5
|
+
you need to install Java2 sdk, and setup JAVA_HOME enviromental varible except for OS X.
|
6
|
+
I assume that OS X's JAVA_HOME is reported by calling /usr/libexec/java_home.
|
7
|
+
|
8
|
+
then,
|
9
|
+
|
10
|
+
ruby setup.rb config
|
11
|
+
ruby setup.rb setup
|
12
|
+
|
13
|
+
(in Unix)
|
14
|
+
sudo ruby setup.rb install
|
15
|
+
or
|
16
|
+
(in win32)
|
17
|
+
ruby setup.rb install
|
18
|
+
|
19
|
+
How to test
|
20
|
+
in Win32
|
21
|
+
cd test
|
22
|
+
ruby test.rb
|
23
|
+
|
24
|
+
in Unix
|
25
|
+
see test/readme.unix
|
26
|
+
you must set LD_LIBRARY_PATH environmental variable to run rjb.
|
27
|
+
|
28
|
+
-- Notice for opening non-ASCII 7bit filename
|
29
|
+
If you'll plan to open the non-ascii character named file by Java class through Rjb, it may require to set LC_ALL environment variable in you sciprt.
|
30
|
+
For example in Rails, set above line in production.rb as your environment.
|
31
|
+
ENV['LC_ALL'] = 'en_us.utf8' # or ja_JP.utf8 etc.
|
32
|
+
cf: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4733494
|
33
|
+
(Thanks Paul for this information).
|
34
|
+
|
35
|
+
artonx@yahoo.co.jp
|
data/samples/filechooser.rb
CHANGED
@@ -1,35 +1,35 @@
|
|
1
|
-
#!/usr/local/bin/ruby -Ks
|
2
|
-
#coding: cp932
|
3
|
-
|
4
|
-
require 'rjb'
|
5
|
-
|
6
|
-
Rjb::load
|
7
|
-
|
8
|
-
unless RUBY_VERSION =~ /^1\.9/
|
9
|
-
class String
|
10
|
-
def encode(s)
|
11
|
-
self
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
class FileChooser
|
17
|
-
@@klass = Rjb::import('javax.swing.JFileChooser')
|
18
|
-
def initialize(ext = '*', desc = 'any files')
|
19
|
-
@selected = nil
|
20
|
-
end
|
21
|
-
|
22
|
-
def show()
|
23
|
-
chooser = @@klass.new
|
24
|
-
if chooser.showOpenDialog(nil) == @@klass.APPROVE_OPTION
|
25
|
-
@selected = chooser.getSelectedFile
|
26
|
-
end
|
27
|
-
end
|
28
|
-
attr_reader :selected
|
29
|
-
end
|
30
|
-
|
31
|
-
f = FileChooser.new
|
32
|
-
if f.show
|
33
|
-
puts f.selected.getAbsolutePath.encode('cp932')
|
34
|
-
end
|
35
|
-
puts 'bye'
|
1
|
+
#!/usr/local/bin/ruby -Ks
|
2
|
+
#coding: cp932
|
3
|
+
|
4
|
+
require 'rjb'
|
5
|
+
|
6
|
+
Rjb::load
|
7
|
+
|
8
|
+
unless RUBY_VERSION =~ /^1\.9/
|
9
|
+
class String
|
10
|
+
def encode(s)
|
11
|
+
self
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class FileChooser
|
17
|
+
@@klass = Rjb::import('javax.swing.JFileChooser')
|
18
|
+
def initialize(ext = '*', desc = 'any files')
|
19
|
+
@selected = nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def show()
|
23
|
+
chooser = @@klass.new
|
24
|
+
if chooser.showOpenDialog(nil) == @@klass.APPROVE_OPTION
|
25
|
+
@selected = chooser.getSelectedFile
|
26
|
+
end
|
27
|
+
end
|
28
|
+
attr_reader :selected
|
29
|
+
end
|
30
|
+
|
31
|
+
f = FileChooser.new
|
32
|
+
if f.show
|
33
|
+
puts f.selected.getAbsolutePath.encode('cp932')
|
34
|
+
end
|
35
|
+
puts 'bye'
|
data/samples/unzip.rb
CHANGED
@@ -1,66 +1,66 @@
|
|
1
|
-
require 'rjb'
|
2
|
-
|
3
|
-
if Rjb::VERSION < '1.3.4'
|
4
|
-
$stderr.puts "require rjb-1.3.4 or later, bye."
|
5
|
-
exit 1
|
6
|
-
end
|
7
|
-
|
8
|
-
class ZipFile
|
9
|
-
include Enumerable
|
10
|
-
Zip = Rjb::import('java.util.zip.ZipFile')
|
11
|
-
def initialize(file, &block)
|
12
|
-
@zipfile = Zip.new(file)
|
13
|
-
if block
|
14
|
-
yield self
|
15
|
-
@zipfile.close
|
16
|
-
end
|
17
|
-
end
|
18
|
-
def close
|
19
|
-
@zipfile.close
|
20
|
-
end
|
21
|
-
def each(&block)
|
22
|
-
unless block
|
23
|
-
Enumerator.new(self)
|
24
|
-
else
|
25
|
-
e = @zipfile.entries
|
26
|
-
while e.has_more_elements
|
27
|
-
yield e.next_element
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
def size
|
32
|
-
@zipfile.size
|
33
|
-
end
|
34
|
-
def unzip(ent)
|
35
|
-
if String === ent
|
36
|
-
ent = @zipfile.entry(ent)
|
37
|
-
end
|
38
|
-
is = @zipfile.input_stream(ent)
|
39
|
-
buff = "\0" * 4096
|
40
|
-
File.open(ent.name, 'wb') do |fout|
|
41
|
-
loop do
|
42
|
-
len = is.read(buff, 0, buff.size)
|
43
|
-
break if len < 0
|
44
|
-
fout.write(buff[0, len])
|
45
|
-
end
|
46
|
-
is.close
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
if __FILE__ == $0
|
52
|
-
if ARGV.size == 0
|
53
|
-
puts 'usage: ruby unzip.rb filename'
|
54
|
-
else
|
55
|
-
ARGV.each do |file|
|
56
|
-
ZipFile.new(file) do |zip|
|
57
|
-
zip.each do |f|
|
58
|
-
puts "#{f.name}, #{f.size}"
|
59
|
-
unless f.directory?
|
60
|
-
zip.unzip(f)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
1
|
+
require 'rjb'
|
2
|
+
|
3
|
+
if Rjb::VERSION < '1.3.4'
|
4
|
+
$stderr.puts "require rjb-1.3.4 or later, bye."
|
5
|
+
exit 1
|
6
|
+
end
|
7
|
+
|
8
|
+
class ZipFile
|
9
|
+
include Enumerable
|
10
|
+
Zip = Rjb::import('java.util.zip.ZipFile')
|
11
|
+
def initialize(file, &block)
|
12
|
+
@zipfile = Zip.new(file)
|
13
|
+
if block
|
14
|
+
yield self
|
15
|
+
@zipfile.close
|
16
|
+
end
|
17
|
+
end
|
18
|
+
def close
|
19
|
+
@zipfile.close
|
20
|
+
end
|
21
|
+
def each(&block)
|
22
|
+
unless block
|
23
|
+
Enumerator.new(self)
|
24
|
+
else
|
25
|
+
e = @zipfile.entries
|
26
|
+
while e.has_more_elements
|
27
|
+
yield e.next_element
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
def size
|
32
|
+
@zipfile.size
|
33
|
+
end
|
34
|
+
def unzip(ent)
|
35
|
+
if String === ent
|
36
|
+
ent = @zipfile.entry(ent)
|
37
|
+
end
|
38
|
+
is = @zipfile.input_stream(ent)
|
39
|
+
buff = "\0" * 4096
|
40
|
+
File.open(ent.name, 'wb') do |fout|
|
41
|
+
loop do
|
42
|
+
len = is.read(buff, 0, buff.size)
|
43
|
+
break if len < 0
|
44
|
+
fout.write(buff[0, len])
|
45
|
+
end
|
46
|
+
is.close
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
if __FILE__ == $0
|
52
|
+
if ARGV.size == 0
|
53
|
+
puts 'usage: ruby unzip.rb filename'
|
54
|
+
else
|
55
|
+
ARGV.each do |file|
|
56
|
+
ZipFile.new(file) do |zip|
|
57
|
+
zip.each do |f|
|
58
|
+
puts "#{f.name}, #{f.size}"
|
59
|
+
unless f.directory?
|
60
|
+
zip.unzip(f)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|