rjb 1.2.1-x86-mswin32-60 → 1.2.8-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,68 @@
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
17
+ Thu Jul 22 arton
18
+ *ext/rjb.c
19
+ RJB_VERSION -> 1.2.6
20
+ export jv2rv for rjbexception.c
21
+ *ext/rjb.h
22
+ export jv2rv for rjbexception.c
23
+ *ext/rjbexception.c
24
+ create and keep java exception object for its properties.
25
+ *test/test.rb
26
+ add Exception#cause test
27
+ Wed Jun 9 arton
28
+ *ext/load.c
29
+ accept JAVA_HOME having an extra slash at the end
30
+ *ext/rjb.c
31
+ RJB_VERSION -> 1.2.5
32
+ Fri Jun 5 arton
33
+ *ext/rjb.h
34
+ defin HAVE_LONG_LONG if no HAVE_LONG_LONG but LP64
35
+ *ext/rjb.c
36
+ remove unused variables
37
+ RJB_VERSION -> 1.2.4
38
+ Fri Jun 4 arton
39
+ *ext/riconv.c
40
+ remove unused function if build with Ruby 1.9
41
+ *ext/rjb.c
42
+ RJB_VERSION -> 1.2.3
43
+ to accomodate with rubinius
44
+ *ext/load.c
45
+ to accomodate with rubinius
46
+ *ext/rjbexception.c
47
+ to accomodate with rubinius
48
+ Sun May 30 arton
49
+ *lib/rjbextension.rb
50
+ Rjb extension from Andreas Ronge's neo4j
51
+ - directly import jar by require method
52
+ - Rjb::import without quotations (Java class as Ruby object)
53
+ *test/exttest.rb
54
+ test for rjbextension.rb
55
+ *test/rjbtest.jar
56
+ test file for rjbextension.rb
57
+ Sat May 29 arton on behalf of atoulme
58
+ *ext/rjb.c
59
+ *ext/load.c
60
+ *ext/rjbexception.c
61
+ to accomodate with rubinius
62
+ thanks atoulme !
63
+ Wed May 12 arton
64
+ *test/test.rb
65
+ add Class name for TestMixin module because ruby 1.9 doesn't handle the constant.
1
66
  Tue May 11 arton
2
67
  *ext/rjb.c
3
68
  fix duplicate method registering while no alias.
@@ -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/load.c CHANGED
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * Rjb - Ruby <-> Java Bridge
3
- * Copyright(c) 2004,2005,2006,2009 arton
3
+ * Copyright(c) 2004,2005,2006,2009,2010 arton
4
4
  *
5
5
  * This library is free software; you can redistribute it and/or
6
6
  * modify it under the terms of the GNU Lesser General Public
@@ -12,7 +12,7 @@
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: load.c 105 2010-05-04 00:01:26Z arton $
15
+ * $Id: load.c 124 2010-06-08 18:24:45Z arton $
16
16
  */
17
17
 
18
18
  #include <stdlib.h>
@@ -104,11 +104,13 @@ static int open_jvm(char* libpath)
104
104
  VALUE* argv;
105
105
 
106
106
  rb_require("dl");
107
+ #if !defined(RUBINIUS)
107
108
  if (!rb_const_defined_at(rb_cObject, rb_intern("DL")))
108
109
  {
109
110
  rb_raise(rb_eRuntimeError, "Constants DL is not defined.");
110
111
  return 0;
111
112
  }
113
+ #endif
112
114
  argv = ALLOCA_N(VALUE, 4);
113
115
  *argv = rb_const_get(rb_cObject, rb_intern("DL"));
114
116
  *(argv + 1) = rb_intern("dlopen");
@@ -146,12 +148,20 @@ static int load_jvm(char* jvmtype)
146
148
  }
147
149
  else
148
150
  {
149
- if (strlen(jh) > HOME_NAME_LEN
150
- && strcasecmp(jh + strlen(jh) - HOME_NAME_LEN, HOME_NAME) == 0)
151
+ if (strlen(jh) > HOME_NAME_LEN)
151
152
  {
152
- char* p = ALLOCA_N(char, strlen(jh) + 8);
153
- sprintf(p, "%s/..", jh);
154
- jh = p;
153
+ int len = strlen(jh);
154
+ char* p = ALLOCA_N(char, len + 8);
155
+ jh = strcpy(p, jh);
156
+ if (*(jh + len - 1) == '/')
157
+ {
158
+ --len;
159
+ *(jh + len) = '\0';
160
+ }
161
+ if (strcasecmp(jh + len - HOME_NAME_LEN, HOME_NAME) == 0)
162
+ {
163
+ strcpy(p + len, "/..");
164
+ }
155
165
  }
156
166
  }
157
167
  #endif
@@ -204,8 +214,13 @@ static int load_bridge(JNIEnv* jenv)
204
214
  jmethodID getSysLoader = (*jenv)->GetStaticMethodID(jenv, loader,
205
215
  "getSystemClassLoader", "()Ljava/lang/ClassLoader;");
206
216
  jobject iloader = (*jenv)->CallStaticObjectMethod(jenv, loader, getSysLoader);
217
+ #if defined(RUBINIUS)
218
+ VALUE v = rb_const_get(rb_cObject, rb_intern("RjbConf"));
219
+ v = rb_const_get(v, rb_intern("BRIDGE_FILE"));
220
+ #else
207
221
  VALUE v = rb_const_get_at(rb_const_get(rb_cObject, rb_intern("RjbConf")),
208
222
  rb_intern("BRIDGE_FILE"));
223
+ #endif
209
224
  bridge = StringValuePtr(v);
210
225
  #if defined(DOSISH)
211
226
  bridge = ALLOCA_N(char, strlen(bridge) + 8);
@@ -295,7 +310,8 @@ int rjb_create_jvm(JNIEnv** pjenv, JavaVMInitArgs* vm_args, char* userpath, VALU
295
310
  }
296
311
  #endif
297
312
  }
298
- #if RJB_RUBY_VERSION_CODE < 190
313
+
314
+ #if RJB_RUBY_VERSION_CODE < 190 && !defined(RUBINIUS)
299
315
  ruby_errinfo = Qnil;
300
316
  #else
301
317
  rb_set_errinfo(Qnil);
@@ -366,4 +382,3 @@ int rjb_create_jvm(JNIEnv** pjenv, JavaVMInitArgs* vm_args, char* userpath, VALU
366
382
  }
367
383
  return result;
368
384
  }
369
-
data/ext/riconv.c CHANGED
@@ -12,7 +12,7 @@
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: riconv.c 104 2010-03-16 12:19:18Z arton $
15
+ * $Id: riconv.c 117 2010-06-04 12:16:25Z arton $
16
16
  */
17
17
 
18
18
  #include "ruby.h"
@@ -43,6 +43,7 @@ static const char* const CS_SJIS = "SHIFT_JIS";
43
43
  static const char* const CS_UTF8 = "UTF-8";
44
44
 
45
45
 
46
+ #if RJB_RUBY_VERSION_CODE < 190
46
47
  static VALUE objIconvJ2R;
47
48
  static VALUE objIconvR2J;
48
49
  static const char* charcode; //is this necessary?
@@ -58,7 +59,9 @@ static int find_table(const char* const str, const char* const table[])
58
59
  }
59
60
  return 0;
60
61
  }
62
+ #endif
61
63
 
64
+ #if RJB_RUBY_VERSION_CODE < 190
62
65
  static const char* get_charcode_name_by_locale(const char* const name)
63
66
  {
64
67
  if (find_table(name, LOCALE_UTF8_TABLE))
@@ -119,8 +122,9 @@ static const char* get_charcode_name()
119
122
  }
120
123
  return result;
121
124
  }
125
+ #endif
122
126
 
123
-
127
+ #if RJB_RUBY_VERSION_CODE < 190
124
128
  static void reinit()
125
129
  {
126
130
  charcode = get_charcode_name();
@@ -142,7 +146,9 @@ static void reinit()
142
146
  objIconvR2J = objIconvJ2R = Qnil;
143
147
  }
144
148
  }
149
+ #endif
145
150
 
151
+ #if RJB_RUBY_VERSION_CODE < 190
146
152
  static void check_kcode()
147
153
  {
148
154
  VALUE rb_iconv_klass = rb_const_get(rb_cObject, rb_intern("Iconv"));
@@ -161,6 +167,7 @@ static void check_kcode()
161
167
  objIconvR2J = objIconvJ2R = Qnil;
162
168
  }
163
169
  }
170
+ #endif
164
171
 
165
172
  VALUE exticonv_local_to_utf8(VALUE local_string)
166
173
  {
data/ext/rjb.c CHANGED
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * Rjb - Ruby <-> Java Bridge
3
- * Copyright(c) 2004,2005,2006,2007,2008,2009 arton
3
+ * Copyright(c) 2004,2005,2006,2007,2008,2009,2010 arton
4
4
  *
5
5
  * This library is free software; you can redistribute it and/or
6
6
  * modify it under the terms of the GNU Lesser General Public
@@ -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 109 2010-05-11 13:04:25Z arton $
15
+ * $Id: rjb.c 131 2010-09-16 15:53:33Z arton $
16
16
  */
17
17
 
18
- #define RJB_VERSION "1.2.1"
18
+ #define RJB_VERSION "1.2.8"
19
19
 
20
20
  #include "ruby.h"
21
21
  #include "extconf.h"
@@ -55,7 +55,14 @@
55
55
  #define RJB_LOAD_STATIC_METHOD(var, obj, name, sig) \
56
56
  var = (*jenv)->GetStaticMethodID(jenv, obj, name, sig); \
57
57
  rjb_check_exception(jenv, 1)
58
- #define IS_RJB_OBJECT(v) (rb_class_inherited(rjbi, RBASIC(v)->klass) || RBASIC(v)->klass == rjb)
58
+ #if defined(RUBINIUS)
59
+ #define CLASS_NEW(obj, name) rb_define_class_under(rjb, name, obj)
60
+ #define CLASS_INHERITED(spr, kls) rb_funcall(spr, rb_intern("inherited"), 1, kls)
61
+ #else
62
+ #define CLASS_NEW(obj, name) rb_define_class_under(rjb, name, obj)
63
+ #define CLASS_INHERITED(spr, kls) rb_class_inherited(spr, kls)
64
+ #endif
65
+ #define IS_RJB_OBJECT(v) (CLASS_INHERITED(rjbi, rb_obj_class(v)) || rb_obj_class(v) == rjb)
59
66
  #define USER_INITIALIZE "@user_initialize"
60
67
 
61
68
  static void register_class(VALUE, VALUE);
@@ -296,7 +303,7 @@ static VALUE jv2rv_r(JNIEnv* jenv, jvalue val)
296
303
  return v;
297
304
  }
298
305
 
299
- static VALUE jv2rv(JNIEnv* jenv, jvalue val)
306
+ VALUE jv2rv(JNIEnv* jenv, jvalue val)
300
307
  {
301
308
  if (RTEST(primitive_conversion))
302
309
  {
@@ -652,7 +659,7 @@ static void rv2jlong(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, int
652
659
  switch (TYPE(val))
653
660
  {
654
661
  case T_FIXNUM:
655
- jv->j = NUM2INT(val);
662
+ jv->j = FIX2LONG(val);
656
663
  break;
657
664
  default:
658
665
  #if HAVE_LONG_LONG
@@ -665,8 +672,17 @@ static void rv2jlong(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, int
665
672
  }
666
673
  static void rv2jshort(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, int release)
667
674
  {
668
- if (!release)
669
- jv->s = (short)NUM2INT(val);
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");
670
686
  }
671
687
  static void rv2jboolean(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, int release)
672
688
  {
@@ -774,13 +790,13 @@ static void rv2jobject(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, in
774
790
  Data_Get_Struct(val, struct jvi_data, ptr);
775
791
  jv->l = ptr->obj;
776
792
  }
777
- else if (RBASIC(val)->klass == rjbb)
793
+ else if (rb_obj_class(val) == rjbb)
778
794
  {
779
795
  struct rj_bridge* ptr;
780
796
  Data_Get_Struct(val, struct rj_bridge, ptr);
781
797
  jv->l = ptr->proxy;
782
798
  }
783
- else if (rb_class_inherited(rjbc, RBASIC(val)->klass))
799
+ else if (CLASS_INHERITED(rjbc, rb_obj_class(val)))
784
800
  {
785
801
  struct jv_data* ptr;
786
802
  Data_Get_Struct(val, struct jv_data, ptr);
@@ -1596,14 +1612,14 @@ static void load_constants(JNIEnv* jenv, jclass klass, VALUE self, jobjectArray
1596
1612
  strcpy(pname, cname);
1597
1613
  *pname = toupper(*pname);
1598
1614
  if (!isupper(*pname)
1599
- || rb_const_defined(RBASIC(self)->klass, rb_intern(pname)))
1615
+ || rb_const_defined(rb_obj_class(self), rb_intern(pname)))
1600
1616
  {
1601
1617
  pname = NULL;
1602
1618
  }
1603
1619
  }
1604
1620
  if (pname)
1605
1621
  {
1606
- rb_define_const(RBASIC(self)->klass, pname, j2r(jenv, jv));
1622
+ rb_define_const(rb_obj_class(self), pname, j2r(jenv, jv));
1607
1623
  }
1608
1624
  rjb_release_string(jenv, nm, cname);
1609
1625
  }
@@ -1735,8 +1751,8 @@ static VALUE rjb_s_load(int argc, VALUE* argv, VALUE self)
1735
1751
  }
1736
1752
 
1737
1753
  jklass = import_class(jenv, j_class, rb_str_new2("java.lang.Class"));
1738
- rb_define_method(RBASIC(jklass)->klass, "forName", rjb_class_forname, -1);
1739
- rb_define_method(RBASIC(jklass)->klass, "for_name", rjb_class_forname, -1);
1754
+ rb_define_method(rb_singleton_class(jklass), "forName", rjb_class_forname, -1);
1755
+ rb_define_method(rb_singleton_class(jklass), "for_name", rjb_class_forname, -1);
1740
1756
  rb_gc_register_address(&jklass);
1741
1757
 
1742
1758
  return Qnil;
@@ -1780,7 +1796,16 @@ static int clear_classes(VALUE key, VALUE val, VALUE dummy)
1780
1796
  static VALUE rjb_s_unload(int argc, VALUE* argv, VALUE self)
1781
1797
  {
1782
1798
  int result = 0;
1799
+ #if defined(HAVE_RB_HASH_FOREACH) || defined(RUBINIUS)
1800
+ rb_hash_foreach(rjb_loaded_classes, clear_classes, 0);
1801
+ #else
1802
+ #if defined(RHASH_TBL)
1783
1803
  st_foreach(RHASH_TBL(rjb_loaded_classes), clear_classes, 0);
1804
+ #else
1805
+ st_foreach(RHASH(rjb_loaded_classes)->tbl, clear_classes, 0);
1806
+ #endif
1807
+ #endif
1808
+
1784
1809
  if (rjb_jvm)
1785
1810
  {
1786
1811
  JNIEnv* jenv = rjb_attach_current_thread();
@@ -2165,7 +2190,11 @@ static VALUE get_signatures(VALUE mname, st_table* st)
2165
2190
  ret = rb_ary_new();
2166
2191
  for (; pm; pm = pm->next)
2167
2192
  {
2168
- rb_ary_push(ret, rb_str_new2(pm->basic.method_signature));
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
+ }
2169
2198
  }
2170
2199
  return ret;
2171
2200
  }
@@ -2254,8 +2283,11 @@ static VALUE rjb_class_eval(int argc, VALUE* argv, VALUE self)
2254
2283
  */
2255
2284
  static VALUE rjb_s_unbind(VALUE self, VALUE rbobj)
2256
2285
  {
2257
- JNIEnv* jenv = rjb_prelude();
2286
+ #if defined(RUBINIUS)
2287
+ return rb_funcall(proxies, rb_intern("delete"), 1, rbobj);
2288
+ #else
2258
2289
  return rb_ary_delete(proxies, rbobj);
2290
+ #endif
2259
2291
  }
2260
2292
 
2261
2293
  /*
@@ -2293,7 +2325,16 @@ static void register_class(VALUE self, VALUE clsname)
2293
2325
  /*
2294
2326
  * the hash was frozen, so it need to call st_ func directly.
2295
2327
  */
2328
+
2329
+ #if defined(HAVE_RB_HASH_ASET) || defined(RUBINIUS)
2330
+ rb_hash_aset(rjb_loaded_classes, clsname, self);
2331
+ #else
2332
+ #ifdef RHASH_TBL
2296
2333
  st_insert(RHASH_TBL(rjb_loaded_classes), clsname, self);
2334
+ #else
2335
+ st_insert(RHASH(rjb_loaded_classes)->tbl, clsname, self);
2336
+ #endif
2337
+ #endif
2297
2338
  }
2298
2339
 
2299
2340
  /*
@@ -2796,7 +2837,7 @@ static VALUE rjb_missing(int argc, VALUE* argv, VALUE self)
2796
2837
  {
2797
2838
  VALUE r, args[2];
2798
2839
  int state = 0;
2799
- args[0] = RBASIC(self)->klass;
2840
+ args[0] = rb_obj_class(self);
2800
2841
  args[1] = rmid;
2801
2842
  r = rb_protect(find_const, (VALUE)args, &state);
2802
2843
  if (!state)
@@ -2832,15 +2873,20 @@ static VALUE rjb_class_forname(int argc, VALUE* argv, VALUE self)
2832
2873
  */
2833
2874
  void Init_rjbcore()
2834
2875
  {
2876
+ #if defined(RUBINIUS)
2877
+ rb_require("iconv");
2878
+ #else
2835
2879
  rb_protect((VALUE(*)(VALUE))rb_require, (VALUE)"iconv", NULL);
2836
-
2880
+ #endif
2837
2881
  rjb_loaded_classes = rb_hash_new();
2882
+ #ifndef RUBINIUS
2838
2883
  OBJ_FREEZE(rjb_loaded_classes);
2884
+ #endif
2839
2885
  rb_global_variable(&rjb_loaded_classes);
2840
2886
  proxies = rb_ary_new();
2841
2887
  rb_global_variable(&proxies);
2842
2888
  user_initialize = rb_intern(USER_INITIALIZE);
2843
-
2889
+
2844
2890
  rjb = rb_define_module("Rjb");
2845
2891
  rb_define_module_function(rjb, "load", rjb_s_load, -1);
2846
2892
  rb_define_module_function(rjb, "unload", rjb_s_unload, -1);
@@ -2854,14 +2900,14 @@ void Init_rjbcore()
2854
2900
  rb_define_const(rjb, "VERSION", rb_str_new2(RJB_VERSION));
2855
2901
 
2856
2902
  /* Java class object */
2857
- rjbc = rb_class_new(rb_cObject);
2903
+ rjbc = CLASS_NEW(rb_cObject, "Rjb_JavaClass");
2858
2904
  rb_gc_register_address(&rjbc);
2859
2905
  rb_define_method(rjbc, "method_missing", rjb_missing, -1);
2860
2906
  rb_define_method(rjbc, "_invoke", rjb_invoke, -1);
2861
2907
  rb_define_method(rjbc, "_classname", rjb_i_class, 0);
2862
2908
 
2863
2909
  /* Java instance object */
2864
- rjbi = rb_class_new(rb_cObject);
2910
+ rjbi = CLASS_NEW(rb_cObject, "Rjb_JavaProxy");
2865
2911
  rb_gc_register_address(&rjbi);
2866
2912
  rb_define_method(rjbi, "method_missing", rjb_i_missing, -1);
2867
2913
  rb_define_method(rjbi, "_invoke", rjb_i_invoke, -1);
@@ -2870,7 +2916,7 @@ void Init_rjbcore()
2870
2916
  rb_define_alias(rjbi, "include", "extend");
2871
2917
 
2872
2918
  /* Ruby-Java Bridge object */
2873
- rjbb = rb_class_new(rb_cObject);
2919
+ rjbb = CLASS_NEW(rb_cObject, "Rjb_JavaBridge");
2874
2920
  rb_gc_register_address(&rjbb);
2875
2921
  }
2876
2922
 
data/ext/rjb.h CHANGED
@@ -12,7 +12,7 @@
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.h 81 2008-08-26 12:44:44Z arton $
15
+ * $Id: rjb.h 126 2010-07-22 13:58:15Z arton $
16
16
  * $Log: rjb.h,v $
17
17
  * Revision 1.1 2005/01/16 17:36:10 arton
18
18
  * Initial revision
@@ -53,6 +53,9 @@
53
53
  #define _I64_MAX 9223372036854775807i64
54
54
  #endif
55
55
 
56
+ #if !defined(HAVE_LONG_LONG) && defined(__LP64__)
57
+ #define HAVE_LONG_LONG 1
58
+ #endif
56
59
 
57
60
  /* in load.c */
58
61
  extern int rjb_create_jvm(JNIEnv** pjenv, JavaVMInitArgs*, char*, VALUE);
@@ -70,6 +73,7 @@ extern jclass rjb_find_class(JNIEnv* jenv, VALUE name);
70
73
  extern void rjb_release_string(JNIEnv *jenv, jstring str, const char* chrs);
71
74
  extern VALUE rjb_load_vm_default();
72
75
  extern VALUE rjb_safe_funcall(VALUE args);
76
+ extern VALUE jv2rv(JNIEnv* jenv, jvalue val);
73
77
 
74
78
  /* in rjbexception.c */
75
79
  extern VALUE rjb_get_exception_class(JNIEnv* jenv, jstring str);
data/ext/rjbexception.c CHANGED
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * Rjb - Ruby <-> Java Bridge
3
- * Copyright(c) 2004,2005,2006 arton
3
+ * Copyright(c) 2004,2005,2006,2010 arton
4
4
  *
5
5
  * This library is free software; you can redistribute it and/or
6
6
  * modify it under the terms of the GNU Lesser General Public
@@ -12,7 +12,7 @@
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: rjbexception.c 94 2009-09-10 13:54:42Z arton $
15
+ * $Id: rjbexception.c 126 2010-07-22 13:58:15Z arton $
16
16
  */
17
17
 
18
18
  #include "ruby.h"
@@ -26,6 +26,12 @@
26
26
  #include "riconv.h"
27
27
  #include "rjb.h"
28
28
 
29
+ static VALUE missing_delegate(int argc, VALUE* argv, VALUE self)
30
+ {
31
+ ID rmid = rb_to_id(argv[0]);
32
+ return rb_funcall(rb_ivar_get(self, rb_intern("@cause")), rmid, argc - 1, argv + 1);
33
+ }
34
+
29
35
  /*
30
36
  * handle Java exception
31
37
  * At this time, the Java exception is defined without the package name.
@@ -54,7 +60,17 @@ VALUE rjb_get_exception_class(JNIEnv* jenv, jstring str)
54
60
  if (rexp == Qnil)
55
61
  {
56
62
  rexp = rb_define_class(pcls, rb_eStandardError);
57
- st_insert(RHASH_TBL(rjb_loaded_classes), cname, rexp);
63
+ rb_define_method(rexp, "method_missing", missing_delegate, -1);
64
+ #if defined(HAVE_RB_HASH_ASET) || defined(RUBINIUS)
65
+ rb_hash_aset(rjb_loaded_classes, cname, rexp);
66
+ #else
67
+ #ifdef RHASH_TBL
68
+ st_insert(RHASH_TBL(rjb_loaded_classes), cname, rexp);
69
+ #else
70
+ st_insert(RHASH(rjb_loaded_classes)->tbl, cname, rexp);
71
+ #endif
72
+ #endif
73
+
58
74
  }
59
75
  return rexp;
60
76
  }
@@ -128,13 +144,17 @@ void rjb_check_exception(JNIEnv* jenv, int t)
128
144
  }
129
145
  if (rexp == Qnil)
130
146
  {
147
+ (*jenv)->DeleteLocalRef(jenv, exp);
131
148
  rb_raise(rb_eRuntimeError, "%s", msg);
132
149
  }
133
150
  else
134
151
  {
135
- rb_raise(rexp, "%s", msg);
152
+ VALUE rexpi = rb_funcall(rexp, rb_intern("new"), 1, rb_str_new2(msg));
153
+ jvalue val;
154
+ val.l = exp;
155
+ rb_ivar_set(rexpi, rb_intern("@cause"), jv2rv(jenv, val));
156
+ rb_exc_raise(rexpi);
136
157
  }
137
158
  }
138
159
  }
139
160
  }
140
-
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/lib/rjbcore.so CHANGED
Binary file
@@ -0,0 +1,135 @@
1
+ =begin
2
+ Copyright(c) 2010 arton
3
+
4
+ This library is free software; you can redistribute it and/or
5
+ modify it under the terms of the GNU Lesser General Public
6
+ License as published by the Free Software Foundation; either
7
+ version 2.1 of the License, or (at your option) any later version.
8
+
9
+ This library is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ Lesser General Public License for more details.
13
+
14
+ $Id: rjbextension.rb 116 2010-05-30 14:23:07Z arton $
15
+
16
+ This file is from Andreas Ronge project neo4j
17
+ http://github.com/andreasronge/neo4j/blob/rjb/lib/rjb_ext.rb
18
+
19
+ Copyright (c) 2008 Andreas Ronge
20
+
21
+ Permission is hereby granted, free of charge, to any person obtaining a copy
22
+ of this software and associated documentation files (the "Software"), to deal
23
+ in the Software without restriction, including without limitation the rights
24
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
25
+ copies of the Software, and to permit persons to whom the Software is
26
+ furnished to do so, subject to the following conditions:
27
+
28
+ The above copyright notice and this permission notice shall be included in
29
+ all copies or substantial portions of the Software.
30
+
31
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
37
+ THE SOFTWARE.
38
+ =end
39
+
40
+ # Loads the JVM with the given <tt>classpath</tt> and arguments to the jre.
41
+ # All needed .jars should be included in <tt>classpath</tt>.
42
+
43
+ module Kernel
44
+ alias rjb_original_require require
45
+
46
+ def require(path)
47
+ rjb_original_require(path)
48
+ rescue LoadError
49
+ # check that it's not a jar file
50
+ raise unless path =~ /\.jar/
51
+
52
+ # This will maybe use the wrong jar file from a previous version of the GEM
53
+ # puts "LOAD PATH #{$LOAD_PATH}"
54
+ found_path = $LOAD_PATH.reverse.find{|p| File.exist?(File.join(p,path))}
55
+ raise unless found_path
56
+
57
+ abs_path = File.join(found_path, path)
58
+ # check that the file exists
59
+ raise unless File.exist?(abs_path)
60
+
61
+ # try to load it using RJB
62
+ @@rjb_jars ||= []
63
+ @@rjb_jars << abs_path unless @@rjb_jars.include?(abs_path)
64
+ # TODO
65
+ end
66
+
67
+ @@jvm_loaded = false
68
+
69
+ def load_jvm(jargs = [])
70
+ # avoid starting the JVM twice
71
+ return if @@jvm_loaded
72
+
73
+ @@jvm_loaded = true
74
+ classpath = ENV['CLASSPATH'] ||= ''
75
+ @@rjb_jars.each do |jar|
76
+ classpath += File::PATH_SEPARATOR unless classpath.empty?
77
+ classpath += jar
78
+ end
79
+ Rjb::load(classpath, jargs)
80
+ end
81
+ end
82
+
83
+ class JavaPackage
84
+
85
+ def initialize(pack_name, parent_pack = nil)
86
+ @pack_name = pack_name
87
+ @parent_pack = parent_pack
88
+ @cache = {}
89
+ end
90
+
91
+ def method_missing(m, *args)
92
+ # return if possible old module/class
93
+ @cache[m] ||= create_package_or_class(m)
94
+ end
95
+ def create_package_or_class(m)
96
+ method = m.to_s
97
+ if class?(method)
98
+ Rjb::import("#{self}.#{method}")
99
+ else
100
+ JavaPackage.new(method, self)
101
+ end
102
+ end
103
+
104
+ def to_s
105
+ if @parent_pack
106
+ "#{@parent_pack.to_s}.#@pack_name"
107
+ else
108
+ "#@pack_name"
109
+ end
110
+ end
111
+
112
+ def class?(a)
113
+ first_letter = a[0,1]
114
+ first_letter >= 'A' && first_letter <= 'Z'
115
+ end
116
+
117
+ @@cache = {}
118
+ def self.new(pack_name, parent_pack = nil)
119
+ @@cache[pack_name] ||= super
120
+ end
121
+ end
122
+
123
+ module RjbConf
124
+ # make them as singleton
125
+ ORG = JavaPackage.new('org')
126
+ JAVA = JavaPackage.new('java')
127
+ end
128
+
129
+ def org
130
+ RjbConf::ORG
131
+ end
132
+
133
+ def java
134
+ RjbConf::JAVA
135
+ end
data/test/exttest.rb ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/local/env ruby -Ku
2
+ # encoding: utf-8
3
+ # $Id:$
4
+
5
+ begin
6
+ require 'rjb'
7
+ rescue LoadError
8
+ require 'rubygems'
9
+ require 'rjb'
10
+ end
11
+
12
+ if Rjb::VERSION < '1.2.2'
13
+ puts "Rjb #{Rjb::VERSION} does not support rjbextension. exit"
14
+ exit 0
15
+ end
16
+
17
+ require 'rjbextension'
18
+ require 'test/unit'
19
+
20
+ puts "start RJB(#{Rjb::VERSION}) test"
21
+ class ExtTestRjb < Test::Unit::TestCase
22
+
23
+ def jp
24
+ JavaPackage.new('jp')
25
+ end
26
+
27
+ def test_require_extension
28
+ require 'rjbtest.jar'
29
+ load_jvm
30
+
31
+ base = jp.co.infoseek.hp.arton.rjb.Base.new
32
+ assert_equal('hello', base.instance_var)
33
+ end
34
+ end
data/test/m.rb ADDED
@@ -0,0 +1,20 @@
1
+ puts RUBY_VERSION
2
+ class X
3
+ module Y
4
+ def hello
5
+ puts 'hello'
6
+ end
7
+ end
8
+ def make_proc(&block)
9
+ block
10
+ end
11
+ def test
12
+ Proc.new do
13
+ extend Y
14
+ end
15
+ end
16
+ end
17
+ x = X.new
18
+ a = Object.new
19
+ a.instance_eval &x.test
20
+ a.hello
data/test/rjbtest.jar ADDED
Binary file
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 109 2010-05-11 13:04:25Z arton $
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
- assert(it, unbind(it))
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
- assert(0, a.check(cp, 123, 123))
278
- assert(5, a.check(cp, 81, 76))
279
- assert(-5, a.check(cp, 76, 81))
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
@@ -286,6 +286,7 @@ class TestRjb < Test::Unit::TestCase
286
286
  @jInteger.parseInt('blabla')
287
287
  flunk('no exception')
288
288
  rescue NumberFormatException => e
289
+ assert_nil(e.cause)
289
290
  # OK
290
291
  end
291
292
  end
@@ -658,7 +659,7 @@ class TestRjb < Test::Unit::TestCase
658
659
  end
659
660
  def test_extend
660
661
  @jString.class_eval do
661
- include TestMixin
662
+ include TestRjb::TestMixin
662
663
  end
663
664
  s = @jString.new
664
665
  assert_equal('hello world', s.test_hello('world'))
@@ -666,7 +667,7 @@ class TestRjb < Test::Unit::TestCase
666
667
  def test_extend_with_factory
667
668
  point = import('java.awt.Point')
668
669
  point.class_eval do
669
- include TestMixin
670
+ include TestRjb::TestMixin
670
671
  end
671
672
  p = point.new(11, 12)
672
673
  assert_equal(11, p.x)
@@ -682,6 +683,10 @@ class TestRjb < Test::Unit::TestCase
682
683
  sig = @jString.sigs('indexOf').sort
683
684
  assert_equal(expected, sig)
684
685
  end
686
+ def test_fetch_method_without_signature
687
+ sig =
688
+ assert_equal([nil], @jString.sigs('toString'))
689
+ end
685
690
  def test_fetch_static_method_signature
686
691
  expected = ['Ljava.lang.String;[Ljava.lang.Object;',
687
692
  'Ljava.util.Locale;Ljava.lang.String;[Ljava.lang.Object;']
@@ -693,5 +698,37 @@ class TestRjb < Test::Unit::TestCase
693
698
  sig = @jInteger.ctor_sigs.sort
694
699
  assert_equal(expected, sig)
695
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
696
733
  end
697
734
 
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rjb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ hash: 15
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 2
9
+ - 8
10
+ version: 1.2.8
5
11
  platform: x86-mswin32-60
6
12
  authors:
7
13
  - arton
@@ -9,7 +15,7 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-05-11 00:00:00 +09:00
18
+ date: 2010-09-17 00:00:00 +09:00
13
19
  default_executable:
14
20
  dependencies: []
15
21
 
@@ -37,8 +43,11 @@ files:
37
43
  - ext/depend
38
44
  - data/rjb/jp/co/infoseek/hp/arton/rjb/RBridge.class
39
45
  - lib/rjb.rb
46
+ - lib/rjbextension.rb
40
47
  - samples/filechooser.rb
48
+ - test/exttest.rb
41
49
  - test/gctest.rb
50
+ - test/m.rb
42
51
  - test/test.rb
43
52
  - test/tx.rb
44
53
  - test/Base.class
@@ -52,6 +61,7 @@ files:
52
61
  - test/JTest.class
53
62
  - test/Test$TestTypes.class
54
63
  - test/Test.class
64
+ - test/rjbtest.jar
55
65
  - COPYING
56
66
  - ChangeLog
57
67
  - readme.sj
@@ -67,23 +77,31 @@ rdoc_options: []
67
77
  require_paths:
68
78
  - lib
69
79
  required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
70
81
  requirements:
71
82
  - - ">="
72
83
  - !ruby/object:Gem::Version
84
+ hash: 51
85
+ segments:
86
+ - 1
87
+ - 8
88
+ - 2
73
89
  version: 1.8.2
74
- version:
75
90
  required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
76
92
  requirements:
77
93
  - - ">="
78
94
  - !ruby/object:Gem::Version
95
+ hash: 3
96
+ segments:
97
+ - 0
79
98
  version: "0"
80
- version:
81
99
  requirements:
82
100
  - none
83
101
  - JDK 5.0
84
102
  - " VC6 version of Ruby"
85
103
  rubyforge_project:
86
- rubygems_version: 1.3.5
104
+ rubygems_version: 1.3.7
87
105
  signing_key:
88
106
  specification_version: 3
89
107
  summary: Ruby Java bridge