rjb 1.4.9 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ChangeLog +12 -0
- data/ext/riconv.c +20 -8
- data/ext/rjb.c +91 -46
- data/lib/rjb/extension.rb +128 -0
- data/lib/rjb/list.rb +37 -0
- data/test/Base.class +0 -0
- data/test/CallbackTest$Callback.class +0 -0
- data/test/CallbackTest.class +0 -0
- data/test/ExtBase.class +0 -0
- data/test/IBase.class +0 -0
- data/test/JTest.class +0 -0
- data/test/Test$TestTypes.class +0 -0
- data/test/Test.class +0 -0
- data/test/Two.class +0 -0
- data/test/TwoCaller.class +0 -0
- data/test/jp/co/infoseek/hp/arton/rjb/CallbackTest$Callback.class +0 -0
- data/test/jp/co/infoseek/hp/arton/rjb/CallbackTest.class +0 -0
- data/test/jp/co/infoseek/hp/arton/rjb/IBase.class +0 -0
- data/test/jp/co/infoseek/hp/arton/rjb/JTest.class +0 -0
- data/test/jp/co/infoseek/hp/arton/rjb/Test$TestTypes.class +0 -0
- data/test/jp/co/infoseek/hp/arton/rjb/Test.class +0 -0
- data/test/rjbtest.jar +0 -0
- data/test/test.rb +24 -4
- metadata +39 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d6d253c1e5df6889eb04285aeaff937351317c9
|
4
|
+
data.tar.gz: b4bb1f5f967729a3b0571656346311ca0f2eb895
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d27f2f4b4bad8f7f6e5da58c2fc723d95281043232f285e7946e2684fbd701f986b7ce50187ce467452f7cdc41a2c51b9ec3229ab66ef3fd83d3734463da092
|
7
|
+
data.tar.gz: fe5118788283e6615c6ba533414cb246988b8686e17474b571bdaccbf36494803084ca7fe3fafe303d67d8703869dc24d998a2dc1e24dae3c2a21e9c123acc8d
|
data/ChangeLog
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
Sat Sep 20 2014 arton
|
2
|
+
*ext/rjb.c
|
3
|
+
RJB_VERSION -> 1.5.0
|
4
|
+
fix ctor_sigs with non argment ctor (represented by '')
|
5
|
+
select preferable constructor
|
6
|
+
*ext/riconv.c
|
7
|
+
restruct encoding function
|
8
|
+
*test/test.rb
|
9
|
+
add constructor selection test (Ljava.lang.String; vs [B)
|
10
|
+
Wed Jan 15 2014 arton
|
11
|
+
*rjb.rake
|
12
|
+
add lib/rjb/*.rb into gem
|
1
13
|
Fri Jan 4 2014 arton
|
2
14
|
*test/Test.java
|
3
15
|
*test/rjbtest.jar
|
data/ext/riconv.c
CHANGED
@@ -169,6 +169,16 @@ static void check_kcode()
|
|
169
169
|
}
|
170
170
|
#endif
|
171
171
|
|
172
|
+
#if defined(DEBUG)
|
173
|
+
static void debug_out(VALUE v)
|
174
|
+
{
|
175
|
+
char* p = StringValuePtr(v);
|
176
|
+
printf("-- %d, %d, %s\n", rb_num2long(rb_funcall(v, rb_intern("size"), 0)),
|
177
|
+
strlen(p), p);
|
178
|
+
fflush(stdout);
|
179
|
+
}
|
180
|
+
#endif
|
181
|
+
|
172
182
|
VALUE exticonv_local_to_utf8(VALUE local_string)
|
173
183
|
{
|
174
184
|
#if RJB_RUBY_VERSION_CODE < 190
|
@@ -182,16 +192,18 @@ VALUE exticonv_local_to_utf8(VALUE local_string)
|
|
182
192
|
return local_string;
|
183
193
|
}
|
184
194
|
#else
|
185
|
-
VALUE rb_cEncoding, encoding,
|
195
|
+
VALUE rb_cEncoding, encoding, utf8;
|
186
196
|
rb_cEncoding = rb_const_get(rb_cObject, rb_intern("Encoding"));
|
187
|
-
sjis = rb_const_get(rb_cEncoding, rb_intern("SHIFT_JIS"));
|
188
|
-
eucjp = rb_const_get(rb_cEncoding, rb_intern("EUC_JP"));
|
189
|
-
iso2022jp = rb_const_get(rb_cEncoding, rb_intern("ISO_2022_JP"));
|
190
197
|
encoding = rb_funcall(local_string, rb_intern("encoding"), 0);
|
191
|
-
|
192
|
-
if (encoding
|
198
|
+
utf8 = rb_const_get(rb_cEncoding, rb_intern("UTF_8"));
|
199
|
+
if (encoding != utf8)
|
193
200
|
{
|
194
|
-
|
201
|
+
VALUE ret = rb_funcall(local_string, rb_intern("encode"), 2, utf8, encoding);
|
202
|
+
#if defined(DEBUG)
|
203
|
+
debug_out(local_string);
|
204
|
+
debug_out(ret);
|
205
|
+
#endif
|
206
|
+
return ret;
|
195
207
|
}
|
196
208
|
else
|
197
209
|
{
|
@@ -213,6 +225,6 @@ VALUE exticonv_utf8_to_local(VALUE utf8_string)
|
|
213
225
|
return utf8_string;
|
214
226
|
}
|
215
227
|
#else
|
216
|
-
return rb_funcall(utf8_string, rb_intern("force_encoding"), 1,
|
228
|
+
return rb_funcall(utf8_string, rb_intern("force_encoding"), 1, rb_const_get(rb_cEncoding, rb_intern("UTF_8")));
|
217
229
|
#endif
|
218
230
|
}
|
data/ext/rjb.c
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
* $Id: rjb.c 199 2012-12-17 13:31:18Z arton $
|
16
16
|
*/
|
17
17
|
|
18
|
-
#define RJB_VERSION "1.
|
18
|
+
#define RJB_VERSION "1.5.0"
|
19
19
|
|
20
20
|
#include "ruby.h"
|
21
21
|
#include "extconf.h"
|
@@ -846,7 +846,7 @@ static void rv2jobject(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, in
|
|
846
846
|
#endif
|
847
847
|
case T_OBJECT:
|
848
848
|
default:
|
849
|
-
#if DEBUG
|
849
|
+
#if defined(DEBUG)
|
850
850
|
fprintf(stderr, "rtype:%d, sig=%s\n", TYPE(val), psig);
|
851
851
|
fflush(stderr);
|
852
852
|
#endif
|
@@ -2131,6 +2131,10 @@ static VALUE register_instance(JNIEnv* jenv, VALUE klass, struct jv_data* org, j
|
|
2131
2131
|
* temporary signature check
|
2132
2132
|
* return !0 if found
|
2133
2133
|
*/
|
2134
|
+
#define NOTFOUND 0
|
2135
|
+
#define SATISFIED 1
|
2136
|
+
#define SOSO 2
|
2137
|
+
#define PREFERABLE 3
|
2134
2138
|
static int check_rtype(JNIEnv* jenv, VALUE* pv, char* p)
|
2135
2139
|
{
|
2136
2140
|
char* pcls = NULL;
|
@@ -2146,18 +2150,30 @@ static int check_rtype(JNIEnv* jenv, VALUE* pv, char* p)
|
|
2146
2150
|
}
|
2147
2151
|
if (pcls && !strcmp("java.lang.Object", pcls))
|
2148
2152
|
{
|
2149
|
-
return
|
2153
|
+
return SATISFIED;
|
2150
2154
|
}
|
2151
2155
|
switch (TYPE(*pv))
|
2152
2156
|
{
|
2153
2157
|
case T_FIXNUM:
|
2154
|
-
|
2158
|
+
if (strchr("IJ", *p)) return SOSO;
|
2159
|
+
return strchr("BCDFS", *p) != NULL;
|
2155
2160
|
case T_BIGNUM:
|
2156
2161
|
return strchr("BCDFIJS", *p) != NULL;
|
2157
2162
|
case T_FLOAT:
|
2158
|
-
|
2163
|
+
if (*p == 'D') return SOSO;
|
2164
|
+
if (*p == 'F') return SATISFIED;
|
2165
|
+
return NOTFOUND;
|
2159
2166
|
case T_STRING:
|
2160
|
-
|
2167
|
+
if (pcls && (!strcmp("java.lang.String", pcls)
|
2168
|
+
|| !strcmp("java.lang.CharSequence", pcls)))
|
2169
|
+
{
|
2170
|
+
return PREFERABLE;
|
2171
|
+
}
|
2172
|
+
else if (*p == '[' && *(p + 1) == 'B')
|
2173
|
+
{
|
2174
|
+
return SATISFIED;
|
2175
|
+
}
|
2176
|
+
return NOTFOUND;
|
2161
2177
|
case T_TRUE:
|
2162
2178
|
case T_FALSE:
|
2163
2179
|
return *p == 'Z';
|
@@ -2170,15 +2186,15 @@ static int check_rtype(JNIEnv* jenv, VALUE* pv, char* p)
|
|
2170
2186
|
jclass cls;
|
2171
2187
|
struct jvi_data* ptr;
|
2172
2188
|
int result = 0;
|
2173
|
-
if (!strcmp("java.lang.String", pcls)) return
|
2189
|
+
if (!strcmp("java.lang.String", pcls)) return SATISFIED;
|
2174
2190
|
Data_Get_Struct(*pv, struct jvi_data, ptr);
|
2175
2191
|
RJB_FIND_CLASS(cls, java2jniname(pcls));
|
2176
2192
|
if (cls)
|
2177
|
-
|
2193
|
+
{
|
2178
2194
|
result = (cls && (*jenv)->IsInstanceOf(jenv, ptr->obj, cls));
|
2179
2195
|
(*jenv)->DeleteLocalRef(jenv, cls);
|
2180
2196
|
}
|
2181
|
-
return result;
|
2197
|
+
return (result) ? PREFERABLE : NOTFOUND;
|
2182
2198
|
} else if (pcls) {
|
2183
2199
|
VALUE blockobj = rb_class_new_instance(1, pv, rjba);
|
2184
2200
|
*pv = rjb_s_bind(rjbb, blockobj, rb_str_new2(pcls));
|
@@ -2189,9 +2205,9 @@ static int check_rtype(JNIEnv* jenv, VALUE* pv, char* p)
|
|
2189
2205
|
default:
|
2190
2206
|
if (pcls || *p == '[')
|
2191
2207
|
{
|
2192
|
-
return
|
2208
|
+
return SATISFIED;
|
2193
2209
|
}
|
2194
|
-
return
|
2210
|
+
return NOTFOUND;
|
2195
2211
|
}
|
2196
2212
|
}
|
2197
2213
|
|
@@ -2235,7 +2251,10 @@ static VALUE rjb_newinstance(int argc, VALUE* argv, VALUE self)
|
|
2235
2251
|
VALUE ret = Qnil;
|
2236
2252
|
struct jv_data* ptr;
|
2237
2253
|
struct cls_constructor** pc;
|
2254
|
+
struct cls_constructor** found_pc = NULL;
|
2238
2255
|
int found = 0;
|
2256
|
+
int weight = 0;
|
2257
|
+
int cweight;
|
2239
2258
|
JNIEnv* jenv = rjb_prelude();
|
2240
2259
|
|
2241
2260
|
Data_Get_Struct(self, struct jv_data, ptr);
|
@@ -2246,28 +2265,39 @@ static VALUE rjb_newinstance(int argc, VALUE* argv, VALUE self)
|
|
2246
2265
|
char* psig;
|
2247
2266
|
for (pc = ptr->constructors; *pc; pc++)
|
2248
2267
|
{
|
2268
|
+
found = 0;
|
2249
2269
|
if ((*pc)->arg_count == argc)
|
2250
2270
|
{
|
2251
|
-
|
2271
|
+
found = 1;
|
2272
|
+
cweight = 0;
|
2252
2273
|
psig = (*pc)->method_signature;
|
2253
2274
|
for (i = 0; i < argc; i++)
|
2254
2275
|
{
|
2255
|
-
|
2276
|
+
int w = check_rtype(jenv, argv + i, psig);
|
2277
|
+
if (!w)
|
2256
2278
|
{
|
2257
2279
|
found = 0;
|
2258
2280
|
break;
|
2259
2281
|
}
|
2282
|
+
cweight += w;
|
2260
2283
|
psig = next_sig(psig);
|
2261
2284
|
}
|
2262
|
-
if (found)
|
2263
|
-
{
|
2264
|
-
ret = createinstance(jenv, argc, argv, self, *pc);
|
2265
|
-
break;
|
2266
|
-
}
|
2267
2285
|
}
|
2286
|
+
if (found)
|
2287
|
+
{
|
2288
|
+
if (cweight > weight || weight == 0)
|
2289
|
+
{
|
2290
|
+
found_pc = pc;
|
2291
|
+
weight = cweight;
|
2292
|
+
}
|
2293
|
+
}
|
2268
2294
|
}
|
2295
|
+
if (found_pc)
|
2296
|
+
{
|
2297
|
+
ret = createinstance(jenv, argc, argv, self, *found_pc);
|
2298
|
+
}
|
2269
2299
|
}
|
2270
|
-
if (!
|
2300
|
+
if (!found_pc) {
|
2271
2301
|
rb_raise(rb_eRuntimeError, "Constructor not found");
|
2272
2302
|
}
|
2273
2303
|
return ret;
|
@@ -2364,7 +2394,8 @@ static VALUE rjb_get_ctor_signatures(VALUE self)
|
|
2364
2394
|
{
|
2365
2395
|
for (pc = ptr->constructors; *pc; pc++)
|
2366
2396
|
{
|
2367
|
-
|
2397
|
+
const char* sig = (*pc)->method_signature;
|
2398
|
+
rb_ary_push(ret, rb_str_new2(sig ? sig : ""));
|
2368
2399
|
}
|
2369
2400
|
}
|
2370
2401
|
return ret;
|
@@ -2861,11 +2892,13 @@ static void setter(JNIEnv* jenv, struct cls_field* pf, struct jvi_data* ptr, VA
|
|
2861
2892
|
static VALUE invoke(JNIEnv* jenv, struct cls_method* pm, struct jvi_data* ptr,
|
2862
2893
|
int argc, VALUE* argv, const char* sig)
|
2863
2894
|
{
|
2864
|
-
int i, found;
|
2895
|
+
int i, found, cweight;
|
2865
2896
|
jvalue jv;
|
2866
2897
|
jvalue* args;
|
2867
2898
|
char* psig;
|
2868
2899
|
struct cls_method* orgpm = pm;
|
2900
|
+
struct cls_method* prefer_pm = NULL;
|
2901
|
+
int weight = 0;
|
2869
2902
|
|
2870
2903
|
if (rb_block_given_p())
|
2871
2904
|
{
|
@@ -2876,8 +2909,9 @@ static VALUE invoke(JNIEnv* jenv, struct cls_method* pm, struct jvi_data* ptr,
|
|
2876
2909
|
argv = pargs;
|
2877
2910
|
}
|
2878
2911
|
|
2879
|
-
for (
|
2912
|
+
for (; pm; pm = pm->next)
|
2880
2913
|
{
|
2914
|
+
found = 0;
|
2881
2915
|
if (argc == pm->basic.arg_count)
|
2882
2916
|
{
|
2883
2917
|
if (sig && pm->basic.method_signature)
|
@@ -2885,27 +2919,38 @@ static VALUE invoke(JNIEnv* jenv, struct cls_method* pm, struct jvi_data* ptr,
|
|
2885
2919
|
if (!strcmp(sig, pm->basic.method_signature))
|
2886
2920
|
{
|
2887
2921
|
found = 1;
|
2922
|
+
prefer_pm = pm;
|
2888
2923
|
break;
|
2889
2924
|
}
|
2890
2925
|
}
|
2891
2926
|
else
|
2892
2927
|
{
|
2893
|
-
psig = pm->basic.method_signature;
|
2894
2928
|
found = 1;
|
2929
|
+
cweight = 0;
|
2930
|
+
psig = pm->basic.method_signature;
|
2895
2931
|
for (i = 0; i < argc; i++)
|
2896
2932
|
{
|
2897
|
-
|
2933
|
+
int w = check_rtype(jenv, argv + i, psig);
|
2934
|
+
if (!w)
|
2898
2935
|
{
|
2899
2936
|
found = 0;
|
2900
2937
|
break;
|
2901
2938
|
}
|
2939
|
+
cweight += w;
|
2902
2940
|
psig = next_sig(psig);
|
2903
2941
|
}
|
2904
|
-
if (found) break;
|
2905
2942
|
}
|
2906
2943
|
}
|
2944
|
+
if (found)
|
2945
|
+
{
|
2946
|
+
if (cweight > weight || weight == 0)
|
2947
|
+
{
|
2948
|
+
prefer_pm = pm;
|
2949
|
+
weight = cweight;
|
2950
|
+
}
|
2951
|
+
}
|
2907
2952
|
}
|
2908
|
-
if (!
|
2953
|
+
if (!prefer_pm)
|
2909
2954
|
{
|
2910
2955
|
const char* tname = rb_id2name(orgpm->name);
|
2911
2956
|
if (sig)
|
@@ -2918,71 +2963,71 @@ static VALUE invoke(JNIEnv* jenv, struct cls_method* pm, struct jvi_data* ptr,
|
|
2918
2963
|
}
|
2919
2964
|
}
|
2920
2965
|
args = (argc) ? ALLOCA_N(jvalue, argc) : NULL;
|
2921
|
-
psig =
|
2966
|
+
psig = prefer_pm->basic.method_signature;
|
2922
2967
|
for (i = 0; i < argc; i++)
|
2923
2968
|
{
|
2924
|
-
R2J pr2j = *(
|
2969
|
+
R2J pr2j = *(prefer_pm->basic.arg_convert + i);
|
2925
2970
|
pr2j(jenv, argv[i], args + i, psig, 0);
|
2926
2971
|
psig = next_sig(psig);
|
2927
2972
|
}
|
2928
|
-
switch (
|
2973
|
+
switch (prefer_pm->basic.result_signature)
|
2929
2974
|
{
|
2930
2975
|
case 'D':
|
2931
2976
|
{
|
2932
|
-
INVOKEAD voked = *(INVOKEAD*)(((char*)*jenv) +
|
2933
|
-
jv.d = voked(jenv, ptr->obj,
|
2977
|
+
INVOKEAD voked = *(INVOKEAD*)(((char*)*jenv) + prefer_pm->method);
|
2978
|
+
jv.d = voked(jenv, ptr->obj, prefer_pm->basic.id, args);
|
2934
2979
|
}
|
2935
2980
|
break;
|
2936
2981
|
case 'Z':
|
2937
2982
|
case 'B':
|
2938
2983
|
{
|
2939
|
-
INVOKEAZ vokez = *(INVOKEAZ*)(((char*)*jenv) +
|
2940
|
-
jv.z = vokez(jenv, ptr->obj,
|
2984
|
+
INVOKEAZ vokez = *(INVOKEAZ*)(((char*)*jenv) + prefer_pm->method);
|
2985
|
+
jv.z = vokez(jenv, ptr->obj, prefer_pm->basic.id, args);
|
2941
2986
|
}
|
2942
2987
|
break;
|
2943
2988
|
case 'F':
|
2944
2989
|
{
|
2945
|
-
INVOKEAF vokef = *(INVOKEAF*)(((char*)*jenv) +
|
2946
|
-
jv.f = vokef(jenv, ptr->obj,
|
2990
|
+
INVOKEAF vokef = *(INVOKEAF*)(((char*)*jenv) + prefer_pm->method);
|
2991
|
+
jv.f = vokef(jenv, ptr->obj, prefer_pm->basic.id, args);
|
2947
2992
|
}
|
2948
2993
|
break;
|
2949
2994
|
case 'C':
|
2950
2995
|
case 'S':
|
2951
2996
|
{
|
2952
|
-
INVOKEAS vokes = *(INVOKEAS*)(((char*)*jenv) +
|
2953
|
-
jv.s = vokes(jenv, ptr->obj,
|
2997
|
+
INVOKEAS vokes = *(INVOKEAS*)(((char*)*jenv) + prefer_pm->method);
|
2998
|
+
jv.s = vokes(jenv, ptr->obj, prefer_pm->basic.id, args);
|
2954
2999
|
}
|
2955
3000
|
break;
|
2956
3001
|
#if HAVE_LONG_LONG
|
2957
3002
|
case 'J':
|
2958
3003
|
{
|
2959
|
-
INVOKEAL vokel = *(INVOKEAL*)(((char*)*jenv) +
|
2960
|
-
jv.j = vokel(jenv, ptr->obj,
|
3004
|
+
INVOKEAL vokel = *(INVOKEAL*)(((char*)*jenv) + prefer_pm->method);
|
3005
|
+
jv.j = vokel(jenv, ptr->obj, prefer_pm->basic.id, args);
|
2961
3006
|
}
|
2962
3007
|
break;
|
2963
3008
|
#endif
|
2964
3009
|
default:
|
2965
3010
|
{
|
2966
|
-
INVOKEA voke = *(INVOKEA*)(((char*)*jenv) +
|
2967
|
-
jv.l = voke(jenv, ptr->obj,
|
3011
|
+
INVOKEA voke = *(INVOKEA*)(((char*)*jenv) + prefer_pm->method);
|
3012
|
+
jv.l = voke(jenv, ptr->obj, prefer_pm->basic.id, args);
|
2968
3013
|
}
|
2969
3014
|
break;
|
2970
3015
|
}
|
2971
3016
|
rjb_check_exception(jenv, 1);
|
2972
|
-
psig =
|
3017
|
+
psig = prefer_pm->basic.method_signature;
|
2973
3018
|
for (i = 0; i < argc; i++)
|
2974
3019
|
{
|
2975
|
-
R2J pr2j = *(
|
3020
|
+
R2J pr2j = *(prefer_pm->basic.arg_convert + i);
|
2976
3021
|
pr2j(jenv, argv[i], args + i, psig, 1);
|
2977
3022
|
psig = next_sig(psig);
|
2978
3023
|
}
|
2979
|
-
if (
|
3024
|
+
if (prefer_pm->basic.result_arraydepth)
|
2980
3025
|
{
|
2981
|
-
return ja2r(
|
3026
|
+
return ja2r(prefer_pm->result_convert, jenv, jv, prefer_pm->basic.result_arraydepth);
|
2982
3027
|
}
|
2983
3028
|
else
|
2984
3029
|
{
|
2985
|
-
return
|
3030
|
+
return prefer_pm->result_convert(jenv, jv);
|
2986
3031
|
}
|
2987
3032
|
}
|
2988
3033
|
|
@@ -0,0 +1,128 @@
|
|
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 147 2010-10-23 05:10:33Z 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
|
+
if Rjb::loaded?
|
63
|
+
Rjb::add_jar abs_path
|
64
|
+
else
|
65
|
+
Rjb::add_classpath abs_path
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def load_jvm(jargs = [])
|
70
|
+
return if Rjb::loaded?
|
71
|
+
classpath = ENV['CLASSPATH'] ||= ''
|
72
|
+
Rjb::load(classpath, jargs)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class JavaPackage
|
77
|
+
|
78
|
+
def initialize(pack_name, parent_pack = nil)
|
79
|
+
@pack_name = pack_name
|
80
|
+
@parent_pack = parent_pack
|
81
|
+
@cache = {}
|
82
|
+
end
|
83
|
+
|
84
|
+
def method_missing(m, *args)
|
85
|
+
# return if possible old module/class
|
86
|
+
@cache[m] ||= create_package_or_class(m)
|
87
|
+
end
|
88
|
+
def create_package_or_class(m)
|
89
|
+
method = m.to_s
|
90
|
+
if class?(method)
|
91
|
+
Rjb::import("#{self}.#{method}")
|
92
|
+
else
|
93
|
+
JavaPackage.new(method, self)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def to_s
|
98
|
+
if @parent_pack
|
99
|
+
"#{@parent_pack.to_s}.#@pack_name"
|
100
|
+
else
|
101
|
+
"#@pack_name"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def class?(a)
|
106
|
+
first_letter = a[0,1]
|
107
|
+
first_letter >= 'A' && first_letter <= 'Z'
|
108
|
+
end
|
109
|
+
|
110
|
+
@@cache = {}
|
111
|
+
def self.new(pack_name, parent_pack = nil)
|
112
|
+
@@cache[pack_name] ||= super
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
module RjbConf
|
117
|
+
# make them as singleton
|
118
|
+
ORG = JavaPackage.new('org')
|
119
|
+
JAVA = JavaPackage.new('java')
|
120
|
+
end
|
121
|
+
|
122
|
+
def org
|
123
|
+
RjbConf::ORG
|
124
|
+
end
|
125
|
+
|
126
|
+
def java
|
127
|
+
RjbConf::JAVA
|
128
|
+
end
|
data/lib/rjb/list.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
=begin
|
3
|
+
Copyright(c) 2012 arton
|
4
|
+
=end
|
5
|
+
|
6
|
+
require 'rjb'
|
7
|
+
|
8
|
+
module Rjb
|
9
|
+
JIterable = import('java.lang.Iterable')
|
10
|
+
JIterator = import('java.util.Iterator')
|
11
|
+
module Iterable
|
12
|
+
def each
|
13
|
+
it = iterator
|
14
|
+
while it.has_next
|
15
|
+
yield it.next
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
module Iterator
|
20
|
+
def each
|
21
|
+
while has_next
|
22
|
+
yield self.next
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
class Rjb_JavaProxy
|
27
|
+
def initialize_proxy
|
28
|
+
if JIterable.isInstance(self)
|
29
|
+
include Iterable
|
30
|
+
include Enumerable
|
31
|
+
elsif JIterator.isInstance(self)
|
32
|
+
include Iterator
|
33
|
+
include Enumerable
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/test/Base.class
ADDED
Binary file
|
Binary file
|
Binary file
|
data/test/ExtBase.class
ADDED
Binary file
|
data/test/IBase.class
ADDED
Binary file
|
data/test/JTest.class
ADDED
Binary file
|
data/test/Test$TestTypes.class
CHANGED
Binary file
|
data/test/Test.class
CHANGED
Binary file
|
data/test/Two.class
CHANGED
Binary file
|
data/test/TwoCaller.class
CHANGED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/test/rjbtest.jar
CHANGED
Binary file
|
data/test/test.rb
CHANGED
@@ -147,25 +147,25 @@ class TestRjb < Test::Unit::TestCase
|
|
147
147
|
if Object::const_defined?(:Encoding)
|
148
148
|
test = import('jp.co.infoseek.hp.arton.rjb.Test').new
|
149
149
|
euc_kj = "\xb4\xc1\xbb\xfa\xa5\xc6\xa5\xad\xa5\xb9\xa5\xc8".force_encoding Encoding::EUC_JP
|
150
|
-
s = @jString.
|
150
|
+
s = @jString.new_with_sig('Ljava.lang.String;', euc_kj)
|
151
151
|
assert_equal(s.toString().encoding, Encoding::UTF_8)
|
152
152
|
assert(test.isSameString(s))
|
153
153
|
assert(test.isSameString(euc_kj))
|
154
154
|
assert_equal(s.toString().encode(Encoding::EUC_JP), euc_kj)
|
155
155
|
sjis_kj = "\x8a\xbf\x8e\x9a\x83\x65\x83\x4c\x83\x58\x83\x67".force_encoding Encoding::SHIFT_JIS
|
156
|
-
s = @jString.
|
156
|
+
s = @jString.new_with_sig('Ljava.lang.String;', sjis_kj)
|
157
157
|
assert_equal(s.toString().encoding, Encoding::UTF_8)
|
158
158
|
assert(test.isSameString(s))
|
159
159
|
assert(test.isSameString(sjis_kj))
|
160
160
|
assert_equal(s.toString().encode(Encoding::SHIFT_JIS), sjis_kj)
|
161
161
|
utf8_kj = "\xE6\xBC\xA2\xE5\xAD\x97\xE3\x83\x86\xE3\x82\xAD\xE3\x82\xB9\xE3\x83\x88".force_encoding Encoding::UTF_8
|
162
|
-
s = @jString.
|
162
|
+
s = @jString.new_with_sig('Ljava.lang.String;', utf8_kj)
|
163
163
|
assert_equal(s.toString().encoding, Encoding::UTF_8)
|
164
164
|
assert(test.isSameString(s))
|
165
165
|
assert(test.isSameString(utf8_kj))
|
166
166
|
assert_equal(s.toString().encode(Encoding::UTF_8), utf8_kj)
|
167
167
|
iso2022jp_kj = "\x1b\x24\x42\x34\x41\x3b\x7a\x25\x46\x25\x2d\x25\x39\x25\x48\x1b\x28\x42".force_encoding Encoding::ISO_2022_JP
|
168
|
-
s = @jString.
|
168
|
+
s = @jString.new_with_sig('Ljava.lang.String;', iso2022jp_kj)
|
169
169
|
assert_equal(s.toString().encoding, Encoding::UTF_8)
|
170
170
|
assert(test.isSameString(s))
|
171
171
|
assert(test.isSameString(iso2022jp_kj))
|
@@ -899,5 +899,25 @@ class TestRjb < Test::Unit::TestCase
|
|
899
899
|
assert_equal '[Ljava.lang.Integer;', ret[1]
|
900
900
|
assert_equal '[Ljava.net.URI;', ret[2]
|
901
901
|
end
|
902
|
+
def test_auto_constructor_selection
|
903
|
+
skip 'no encoding' unless Object::const_defined?(:Encoding)
|
904
|
+
sys = import('java.lang.System')
|
905
|
+
encoding = sys.property('file.encoding')
|
906
|
+
s = @jString.new("\x8a\xbf\x8e\x9a\x83\x65\x83\x4c\x83\x58\x83\x67".force_encoding Encoding::SHIFT_JIS)
|
907
|
+
e = @jString.new("\xb4\xc1\xbb\xfa\xa5\xc6\xa5\xad\xa5\xb9\xa5\xc8".force_encoding Encoding::EUC_JP)
|
908
|
+
u = @jString.new("\xE6\xBC\xA2\xE5\xAD\x97\xE3\x83\x86\xE3\x82\xAD\xE3\x82\xB9\xE3\x83\x88".force_encoding Encoding::UTF_8)
|
909
|
+
if encoding == 'MS932'
|
910
|
+
s1 = @jString.new("\x8a\xbf\x8e\x9a\x83\x65\x83\x4c\x83\x58\x83\x67".bytes)
|
911
|
+
elsif encoding.upcase == 'EUC-JP'
|
912
|
+
s1 = @jString.new("\xb4\xc1\xbb\xfa\xa5\xc6\xa5\xad\xa5\xb9\xa5\xc8".bytes)
|
913
|
+
elsif encoding.upcase == 'UTF-8'
|
914
|
+
s1 = @jString.new("\xE6\xBC\xA2\xE5\xAD\x97\xE3\x83\x86\xE3\x82\xAD\xE3\x82\xB9\xE3\x83\x88".bytes)
|
915
|
+
else
|
916
|
+
skip 'no checkable encoding'
|
917
|
+
end
|
918
|
+
assert_equal s1.toString, s.toString
|
919
|
+
assert_equal s1.toString, e.toString
|
920
|
+
assert_equal s1.toString, u.toString
|
921
|
+
end
|
902
922
|
end
|
903
923
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rjb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- arton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
RJB is a bridge program that connect between Ruby and Java with Java Native Interface.
|
@@ -18,52 +18,62 @@ extensions:
|
|
18
18
|
- ext/extconf.rb
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
|
-
- COPYING
|
22
|
-
- ChangeLog
|
23
|
-
- data/rjb/jp/co/infoseek/hp/arton/rjb/RBridge.class
|
24
21
|
- ext/RBridge.java
|
25
|
-
- ext/
|
22
|
+
- ext/load.c
|
23
|
+
- ext/riconv.c
|
24
|
+
- ext/rjb.c
|
25
|
+
- ext/rjbexception.c
|
26
26
|
- ext/extconf.h
|
27
|
-
- ext/extconf.rb
|
28
27
|
- ext/jniwrap.h
|
29
28
|
- ext/jp_co_infoseek_hp_arton_rjb_RBridge.h
|
30
|
-
- ext/load.c
|
31
|
-
- ext/riconv.c
|
32
29
|
- ext/riconv.h
|
33
|
-
- ext/rjb.c
|
34
30
|
- ext/rjb.h
|
35
|
-
- ext/
|
31
|
+
- ext/depend
|
32
|
+
- data/rjb/jp/co/infoseek/hp/arton/rjb/RBridge.class
|
36
33
|
- lib/rjb.rb
|
37
34
|
- lib/rjbextension.rb
|
38
|
-
-
|
39
|
-
-
|
35
|
+
- lib/rjb/extension.rb
|
36
|
+
- lib/rjb/list.rb
|
40
37
|
- samples/filechooser.rb
|
41
38
|
- samples/unzip.rb
|
42
|
-
- test/Test$TestTypes.class
|
43
|
-
- test/Test.class
|
44
|
-
- test/Two.class
|
45
|
-
- test/TwoCaller.class
|
46
39
|
- test/exttest.rb
|
47
40
|
- test/gctest.rb
|
48
|
-
- test/jartest.jar
|
49
41
|
- test/jartest.rb
|
50
|
-
- test/jartest2.jar
|
51
42
|
- test/jartest2.rb
|
52
43
|
- test/jartest3.rb
|
53
|
-
- test/jp/co/infoseek/hp/arton/rjb/CallbackTest$Callback.class
|
54
|
-
- test/jp/co/infoseek/hp/arton/rjb/CallbackTest.class
|
55
|
-
- test/jp/co/infoseek/hp/arton/rjb/IBase.class
|
56
|
-
- test/jp/co/infoseek/hp/arton/rjb/Test$TestTypes.class
|
57
|
-
- test/jp/co/infoseek/hp/arton/rjb/Test.class
|
58
44
|
- test/listtest.rb
|
59
45
|
- test/osx_jvmcheck.rb
|
60
|
-
- test/rjbtest.jar
|
61
46
|
- test/test.rb
|
62
47
|
- test/test_osxjvm.rb
|
63
48
|
- test/test_osxload.rb
|
64
49
|
- test/test_unload.rb
|
50
|
+
- test/Base.class
|
51
|
+
- test/CallbackTest$Callback.class
|
52
|
+
- test/CallbackTest.class
|
53
|
+
- test/ExtBase.class
|
54
|
+
- test/IBase.class
|
55
|
+
- test/JTest.class
|
56
|
+
- test/Test$TestTypes.class
|
57
|
+
- test/Test.class
|
58
|
+
- test/Two.class
|
59
|
+
- test/TwoCaller.class
|
60
|
+
- test/jp/co/infoseek/hp/arton/rjb/CallbackTest$Callback.class
|
61
|
+
- test/jp/co/infoseek/hp/arton/rjb/CallbackTest.class
|
62
|
+
- test/jp/co/infoseek/hp/arton/rjb/IBase.class
|
63
|
+
- test/jp/co/infoseek/hp/arton/rjb/JTest.class
|
64
|
+
- test/jp/co/infoseek/hp/arton/rjb/Test$TestTypes.class
|
65
|
+
- test/jp/co/infoseek/hp/arton/rjb/Test.class
|
66
|
+
- test/jartest.jar
|
67
|
+
- test/jartest2.jar
|
68
|
+
- test/rjbtest.jar
|
69
|
+
- COPYING
|
70
|
+
- ChangeLog
|
71
|
+
- readme.sj
|
72
|
+
- readme.txt
|
73
|
+
- ext/extconf.rb
|
65
74
|
homepage: http://rjb.rubyforge.org/
|
66
|
-
licenses:
|
75
|
+
licenses:
|
76
|
+
- LGPL
|
67
77
|
metadata: {}
|
68
78
|
post_install_message:
|
69
79
|
rdoc_options: []
|
@@ -71,19 +81,19 @@ require_paths:
|
|
71
81
|
- lib
|
72
82
|
required_ruby_version: !ruby/object:Gem::Requirement
|
73
83
|
requirements:
|
74
|
-
- -
|
84
|
+
- - '>='
|
75
85
|
- !ruby/object:Gem::Version
|
76
86
|
version: 1.8.2
|
77
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
88
|
requirements:
|
79
|
-
- -
|
89
|
+
- - '>='
|
80
90
|
- !ruby/object:Gem::Version
|
81
91
|
version: '0'
|
82
92
|
requirements:
|
83
93
|
- none
|
84
94
|
- JDK 5.0
|
85
95
|
rubyforge_project: rjb
|
86
|
-
rubygems_version: 2.2
|
96
|
+
rubygems_version: 2.0.2
|
87
97
|
signing_key:
|
88
98
|
specification_version: 4
|
89
99
|
summary: Ruby Java bridge
|