rjb 1.2.6 → 1.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +16 -0
- data/ext/extconf.h +2 -2
- data/ext/jp_co_infoseek_hp_arton_rjb_RBridge.h +21 -21
- data/ext/rjb.c +21 -8
- data/lib/rjb.rb +68 -0
- data/test/test.rb +41 -5
- metadata +11 -26
data/ChangeLog
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
Fri Sep 17 arton
|
2
|
+
*test/test.rb
|
3
|
+
sort arguments order for test_java_methods (the order is implement dependent)
|
4
|
+
add fixnum conversion test for 64bit platform (test_64fixnum)
|
5
|
+
*ext/rjb.c
|
6
|
+
RJV_VERSION -> 1.2.8
|
7
|
+
fix rv2jlong bug, the solution was suggested by Ary Borenszweig
|
8
|
+
Sun Aug 29 arton
|
9
|
+
*ext/rjb.c
|
10
|
+
ignore no arguments method signature.
|
11
|
+
name base classes under Rjb module.
|
12
|
+
*lib/rjb.rb
|
13
|
+
implements public_methods and methods
|
14
|
+
*test/test.rb
|
15
|
+
add non arguments method sig test
|
16
|
+
add methods, public_methods, java_methods test
|
1
17
|
Thu Jul 22 arton
|
2
18
|
*ext/rjb.c
|
3
19
|
RJB_VERSION -> 1.2.6
|
data/ext/extconf.h
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
#ifndef EXTCONF_H
|
2
2
|
#define EXTCONF_H
|
3
3
|
#define HAVE_JNI_H 1
|
4
|
-
#define
|
4
|
+
#define HAVE_DL_H 1
|
5
5
|
#define HAVE_NL_LANGINFO 1
|
6
6
|
#define HAVE_SETLOCALE 1
|
7
7
|
#define HAVE_GETENV 1
|
8
|
-
#define RJB_RUBY_VERSION_CODE
|
8
|
+
#define RJB_RUBY_VERSION_CODE 187
|
9
9
|
#endif
|
@@ -1,21 +1,21 @@
|
|
1
|
-
/* DO NOT EDIT THIS FILE - it is machine generated */
|
2
|
-
#include <jni.h>
|
3
|
-
/* Header for class jp_co_infoseek_hp_arton_rjb_RBridge */
|
4
|
-
|
5
|
-
#ifndef _Included_jp_co_infoseek_hp_arton_rjb_RBridge
|
6
|
-
#define _Included_jp_co_infoseek_hp_arton_rjb_RBridge
|
7
|
-
#ifdef __cplusplus
|
8
|
-
extern "C" {
|
9
|
-
#endif
|
10
|
-
/*
|
11
|
-
* Class: jp_co_infoseek_hp_arton_rjb_RBridge
|
12
|
-
* Method: call
|
13
|
-
* Signature: (Ljava/lang/String;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;
|
14
|
-
*/
|
15
|
-
JNIEXPORT jobject JNICALL Java_jp_co_infoseek_hp_arton_rjb_RBridge_call
|
16
|
-
(JNIEnv *, jobject, jstring, jobject, jobjectArray);
|
17
|
-
|
18
|
-
#ifdef __cplusplus
|
19
|
-
}
|
20
|
-
#endif
|
21
|
-
#endif
|
1
|
+
/* DO NOT EDIT THIS FILE - it is machine generated */
|
2
|
+
#include <jni.h>
|
3
|
+
/* Header for class jp_co_infoseek_hp_arton_rjb_RBridge */
|
4
|
+
|
5
|
+
#ifndef _Included_jp_co_infoseek_hp_arton_rjb_RBridge
|
6
|
+
#define _Included_jp_co_infoseek_hp_arton_rjb_RBridge
|
7
|
+
#ifdef __cplusplus
|
8
|
+
extern "C" {
|
9
|
+
#endif
|
10
|
+
/*
|
11
|
+
* Class: jp_co_infoseek_hp_arton_rjb_RBridge
|
12
|
+
* Method: call
|
13
|
+
* Signature: (Ljava/lang/String;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;
|
14
|
+
*/
|
15
|
+
JNIEXPORT jobject JNICALL Java_jp_co_infoseek_hp_arton_rjb_RBridge_call
|
16
|
+
(JNIEnv *, jobject, jstring, jobject, jobjectArray);
|
17
|
+
|
18
|
+
#ifdef __cplusplus
|
19
|
+
}
|
20
|
+
#endif
|
21
|
+
#endif
|
data/ext/rjb.c
CHANGED
@@ -12,10 +12,10 @@
|
|
12
12
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
13
|
* Lesser General Public License for more details.
|
14
14
|
*
|
15
|
-
* $Id: rjb.c
|
15
|
+
* $Id: rjb.c 131 2010-09-16 15:53:33Z arton $
|
16
16
|
*/
|
17
17
|
|
18
|
-
#define RJB_VERSION "1.2.
|
18
|
+
#define RJB_VERSION "1.2.8"
|
19
19
|
|
20
20
|
#include "ruby.h"
|
21
21
|
#include "extconf.h"
|
@@ -56,10 +56,10 @@
|
|
56
56
|
var = (*jenv)->GetStaticMethodID(jenv, obj, name, sig); \
|
57
57
|
rjb_check_exception(jenv, 1)
|
58
58
|
#if defined(RUBINIUS)
|
59
|
-
#define CLASS_NEW(obj, name)
|
59
|
+
#define CLASS_NEW(obj, name) rb_define_class_under(rjb, name, obj)
|
60
60
|
#define CLASS_INHERITED(spr, kls) rb_funcall(spr, rb_intern("inherited"), 1, kls)
|
61
61
|
#else
|
62
|
-
#define CLASS_NEW(obj, name)
|
62
|
+
#define CLASS_NEW(obj, name) rb_define_class_under(rjb, name, obj)
|
63
63
|
#define CLASS_INHERITED(spr, kls) rb_class_inherited(spr, kls)
|
64
64
|
#endif
|
65
65
|
#define IS_RJB_OBJECT(v) (CLASS_INHERITED(rjbi, rb_obj_class(v)) || rb_obj_class(v) == rjb)
|
@@ -659,7 +659,7 @@ static void rv2jlong(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, int
|
|
659
659
|
switch (TYPE(val))
|
660
660
|
{
|
661
661
|
case T_FIXNUM:
|
662
|
-
jv->j =
|
662
|
+
jv->j = FIX2LONG(val);
|
663
663
|
break;
|
664
664
|
default:
|
665
665
|
#if HAVE_LONG_LONG
|
@@ -672,8 +672,17 @@ static void rv2jlong(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, int
|
|
672
672
|
}
|
673
673
|
static void rv2jshort(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, int release)
|
674
674
|
{
|
675
|
-
if (
|
676
|
-
|
675
|
+
if (release) return;
|
676
|
+
if (TYPE(val) == T_FIXNUM)
|
677
|
+
{
|
678
|
+
int n = FIX2INT(val);
|
679
|
+
if (abs(n) < 0x7fff)
|
680
|
+
{
|
681
|
+
jv->s = (short)n;
|
682
|
+
return;
|
683
|
+
}
|
684
|
+
}
|
685
|
+
rb_raise(rb_eRuntimeError, "can't change to short");
|
677
686
|
}
|
678
687
|
static void rv2jboolean(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, int release)
|
679
688
|
{
|
@@ -2181,7 +2190,11 @@ static VALUE get_signatures(VALUE mname, st_table* st)
|
|
2181
2190
|
ret = rb_ary_new();
|
2182
2191
|
for (; pm; pm = pm->next)
|
2183
2192
|
{
|
2184
|
-
|
2193
|
+
if (pm->basic.method_signature) {
|
2194
|
+
rb_ary_push(ret, rb_str_new2(pm->basic.method_signature));
|
2195
|
+
} else {
|
2196
|
+
rb_ary_push(ret, Qnil);
|
2197
|
+
}
|
2185
2198
|
}
|
2186
2199
|
return ret;
|
2187
2200
|
}
|
data/lib/rjb.rb
CHANGED
@@ -20,4 +20,72 @@ end
|
|
20
20
|
|
21
21
|
require 'rjbcore'
|
22
22
|
|
23
|
+
module Rjb
|
24
|
+
MODIFIER = import('java.lang.reflect.Modifier')
|
23
25
|
|
26
|
+
module JMethod
|
27
|
+
def instance_method?(m)
|
28
|
+
m.modifiers & MODIFIER.STATIC == 0
|
29
|
+
end
|
30
|
+
def public_method?(m)
|
31
|
+
(m.modifiers & MODIFIER.PUBLIC) == MODIFIER.PUBLIC
|
32
|
+
end
|
33
|
+
def jmethods(org, klass, &blk)
|
34
|
+
(org + klass.getMethods.select do |m|
|
35
|
+
blk.call(m)
|
36
|
+
end.map do |m|
|
37
|
+
m.name
|
38
|
+
end).uniq
|
39
|
+
end
|
40
|
+
def format_sigs(s)
|
41
|
+
if s.size < 0
|
42
|
+
''
|
43
|
+
elsif s.size == 1
|
44
|
+
s[0]
|
45
|
+
else
|
46
|
+
"[#{s.map{|m|m.nil? ? 'void' : m}.join(', ')}]"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class Rjb_JavaClass
|
52
|
+
include JMethod
|
53
|
+
def public_methods(inh = true)
|
54
|
+
jmethods(super(inh), self) do |m|
|
55
|
+
!instance_method?(m) && public_method?(m)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
def methods(inh = true)
|
59
|
+
jmethods(super(inh), self) do |m|
|
60
|
+
!instance_method?(m) && public_method?(m)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
def java_methods
|
64
|
+
jmethods([], self) do |m|
|
65
|
+
!instance_method?(m) && public_method?(m)
|
66
|
+
end.map do |m|
|
67
|
+
"#{m}(#{format_sigs(self.static_sigs(m))})"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
class Rjb_JavaProxy
|
72
|
+
include JMethod
|
73
|
+
def public_methods(inh = true)
|
74
|
+
jmethods(super(inh), getClass) do |m|
|
75
|
+
instance_method?(m) && public_method?(m)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
def methods(inh = true)
|
79
|
+
jmethods(super(inh), getClass) do |m|
|
80
|
+
instance_method?(m) && public_method?(m)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
def java_methods
|
84
|
+
jmethods([], getClass) do |m|
|
85
|
+
instance_method?(m) && public_method?(m)
|
86
|
+
end.map do |m|
|
87
|
+
"#{m}(#{format_sigs(getClass.sigs(m))})"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/test/test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/local/env ruby -Ku
|
2
2
|
# encoding: utf-8
|
3
|
-
# $Id: test.rb
|
3
|
+
# $Id: test.rb 133 2010-09-16 16:01:02Z arton $
|
4
4
|
|
5
5
|
begin
|
6
6
|
require 'rjb'
|
@@ -257,7 +257,7 @@ class TestRjb < Test::Unit::TestCase
|
|
257
257
|
def test_unbind()
|
258
258
|
it = TestIter.new
|
259
259
|
it = bind(it, 'java.util.Iterator')
|
260
|
-
|
260
|
+
assert_equal(it, unbind(it))
|
261
261
|
end
|
262
262
|
|
263
263
|
class TestComparator
|
@@ -274,9 +274,9 @@ class TestRjb < Test::Unit::TestCase
|
|
274
274
|
cp = bind(cp, 'java.util.Comparator')
|
275
275
|
test = import('jp.co.infoseek.hp.arton.rjb.Test')
|
276
276
|
a = test.new
|
277
|
-
|
278
|
-
|
279
|
-
|
277
|
+
assert_equal(0, a.check(cp, 123, 123))
|
278
|
+
assert_equal(5, a.check(cp, 81, 76))
|
279
|
+
assert_equal(-5, a.check(cp, 76, 81))
|
280
280
|
end
|
281
281
|
|
282
282
|
# assert_raise is useless in this test, because NumberFormatException may be defined in
|
@@ -683,6 +683,10 @@ class TestRjb < Test::Unit::TestCase
|
|
683
683
|
sig = @jString.sigs('indexOf').sort
|
684
684
|
assert_equal(expected, sig)
|
685
685
|
end
|
686
|
+
def test_fetch_method_without_signature
|
687
|
+
sig =
|
688
|
+
assert_equal([nil], @jString.sigs('toString'))
|
689
|
+
end
|
686
690
|
def test_fetch_static_method_signature
|
687
691
|
expected = ['Ljava.lang.String;[Ljava.lang.Object;',
|
688
692
|
'Ljava.util.Locale;Ljava.lang.String;[Ljava.lang.Object;']
|
@@ -694,5 +698,37 @@ class TestRjb < Test::Unit::TestCase
|
|
694
698
|
sig = @jInteger.ctor_sigs.sort
|
695
699
|
assert_equal(expected, sig)
|
696
700
|
end
|
701
|
+
def test_methods_extension
|
702
|
+
m = @jString.new('').methods
|
703
|
+
assert m.include?('indexOf')
|
704
|
+
end
|
705
|
+
def test_class_methods_extension
|
706
|
+
m = @jString.methods
|
707
|
+
assert m.include?('format')
|
708
|
+
end
|
709
|
+
def test_pmethods_extension
|
710
|
+
m = @jString.new('').public_methods
|
711
|
+
assert m.include?('indexOf')
|
712
|
+
end
|
713
|
+
def test_class_pmethods_extension
|
714
|
+
m = @jString.public_methods
|
715
|
+
assert m.include?('format')
|
716
|
+
end
|
717
|
+
def test_java_methods
|
718
|
+
indexof = @jString.new('').java_methods.find do |m|
|
719
|
+
m =~ /^indexOf/
|
720
|
+
end
|
721
|
+
args = indexof.match(/\[([^\]]+)\]/)[1]
|
722
|
+
assert_equal('Ljava.lang.String;I, II, I, Ljava.lang.String;'.split(/,\s*/).sort,
|
723
|
+
args.split(/,\s*/).sort)
|
724
|
+
end
|
725
|
+
def test_java_class_methods
|
726
|
+
m = @jString.java_methods
|
727
|
+
assert m.include?('format([Ljava.lang.String;[Ljava.lang.Object;, Ljava.util.Locale;Ljava.lang.String;[Ljava.lang.Object;])')
|
728
|
+
end
|
729
|
+
def test_64fixnum
|
730
|
+
big = @jLong.new_with_sig('J', 1230918239495)
|
731
|
+
assert_equal 1230918239495, big.long_value
|
732
|
+
end
|
697
733
|
end
|
698
734
|
|
metadata
CHANGED
@@ -1,13 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rjb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease: false
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 2
|
9
|
-
- 6
|
10
|
-
version: 1.2.6
|
4
|
+
version: 1.2.8
|
11
5
|
platform: ruby
|
12
6
|
authors:
|
13
7
|
- arton
|
@@ -15,7 +9,7 @@ autorequire:
|
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
11
|
|
18
|
-
date: 2010-
|
12
|
+
date: 2010-09-17 00:00:00 +09:00
|
19
13
|
default_executable:
|
20
14
|
dependencies: []
|
21
15
|
|
@@ -32,33 +26,32 @@ extra_rdoc_files: []
|
|
32
26
|
files:
|
33
27
|
- ext/RBridge.java
|
34
28
|
- ext/load.c
|
29
|
+
- ext/rjbexception.c
|
35
30
|
- ext/riconv.c
|
36
31
|
- ext/rjb.c
|
37
|
-
- ext/rjbexception.c
|
38
|
-
- ext/extconf.h
|
39
|
-
- ext/jniwrap.h
|
40
32
|
- ext/jp_co_infoseek_hp_arton_rjb_RBridge.h
|
41
33
|
- ext/riconv.h
|
34
|
+
- ext/extconf.h
|
35
|
+
- ext/jniwrap.h
|
42
36
|
- ext/rjb.h
|
43
37
|
- ext/depend
|
44
38
|
- data/rjb/jp/co/infoseek/hp/arton/rjb/RBridge.class
|
45
39
|
- lib/rjb.rb
|
46
40
|
- lib/rjbextension.rb
|
47
41
|
- samples/filechooser.rb
|
42
|
+
- test/test.rb
|
48
43
|
- test/exttest.rb
|
49
44
|
- test/gctest.rb
|
50
|
-
- test/test.rb
|
51
45
|
- test/jp/co/infoseek/hp/arton/rjb/Base.class
|
52
|
-
- test/jp/co/infoseek/hp/arton/rjb/ExtBase.class
|
53
46
|
- test/jp/co/infoseek/hp/arton/rjb/IBase.class
|
54
|
-
- test/jp/co/infoseek/hp/arton/rjb/Test$TestTypes.class
|
55
47
|
- test/jp/co/infoseek/hp/arton/rjb/Test.class
|
48
|
+
- test/jp/co/infoseek/hp/arton/rjb/Test$TestTypes.class
|
49
|
+
- test/jp/co/infoseek/hp/arton/rjb/ExtBase.class
|
56
50
|
- test/rjbtest.jar
|
57
51
|
- COPYING
|
58
52
|
- ChangeLog
|
59
53
|
- readme.sj
|
60
54
|
- readme.txt
|
61
|
-
- ext/extconf.rb
|
62
55
|
has_rdoc: true
|
63
56
|
homepage: http://rjb.rubyforge.org/
|
64
57
|
licenses: []
|
@@ -69,30 +62,22 @@ rdoc_options: []
|
|
69
62
|
require_paths:
|
70
63
|
- lib
|
71
64
|
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
-
none: false
|
73
65
|
requirements:
|
74
66
|
- - ">="
|
75
67
|
- !ruby/object:Gem::Version
|
76
|
-
hash: 51
|
77
|
-
segments:
|
78
|
-
- 1
|
79
|
-
- 8
|
80
|
-
- 2
|
81
68
|
version: 1.8.2
|
69
|
+
version:
|
82
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
-
none: false
|
84
71
|
requirements:
|
85
72
|
- - ">="
|
86
73
|
- !ruby/object:Gem::Version
|
87
|
-
hash: 3
|
88
|
-
segments:
|
89
|
-
- 0
|
90
74
|
version: "0"
|
75
|
+
version:
|
91
76
|
requirements:
|
92
77
|
- none
|
93
78
|
- JDK 5.0
|
94
79
|
rubyforge_project:
|
95
|
-
rubygems_version: 1.3.
|
80
|
+
rubygems_version: 1.3.5
|
96
81
|
signing_key:
|
97
82
|
specification_version: 3
|
98
83
|
summary: Ruby Java bridge
|