rjb 1.2.8-x86-mswin32-60 → 1.2.9-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,20 @@
1
+ Tue Sep 21 arton
2
+ *ext/rjb.h
3
+ export ClassLoader methods
4
+ *ext/load.c
5
+ move ClassLoader interaction codes into rjb.c
6
+ *ext/rjb.c
7
+ RJV_VERSION -> 1.2.9
8
+ add add_jar method.
9
+ loading classes throgh URLClassLoader if the user add Jars
10
+ *lib/rjb.rb
11
+ change MODIFIER module into a constant. Because it implys Rjb::import.
12
+ change Config -> RbConfig for 1.9
13
+ *test/test.rb
14
+ add Rjb::add_jar test
15
+ *test/JarTest.java
16
+ *test/jartest.jar
17
+ add for Rjb::add_jar test
1
18
  Fri Sep 17 arton
2
19
  *test/test.rb
3
20
  sort arguments order for test_java_methods (the order is implement dependent)
data/ext/load.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: load.c 124 2010-06-08 18:24:45Z arton $
15
+ * $Id: load.c 139 2010-09-21 17:32:57Z arton $
16
16
  */
17
17
 
18
18
  #include <stdlib.h>
@@ -210,10 +210,6 @@ static int load_bridge(JNIEnv* jenv)
210
210
  char* bridge;
211
211
  int len;
212
212
  FILE* f;
213
- jclass loader = (*jenv)->FindClass(jenv, "java/lang/ClassLoader");
214
- jmethodID getSysLoader = (*jenv)->GetStaticMethodID(jenv, loader,
215
- "getSystemClassLoader", "()Ljava/lang/ClassLoader;");
216
- jobject iloader = (*jenv)->CallStaticObjectMethod(jenv, loader, getSysLoader);
217
213
  #if defined(RUBINIUS)
218
214
  VALUE v = rb_const_get(rb_cObject, rb_intern("RjbConf"));
219
215
  v = rb_const_get(v, rb_intern("BRIDGE_FILE"));
@@ -241,7 +237,7 @@ static int load_bridge(JNIEnv* jenv)
241
237
  len = fread(buff, 1, sizeof(buff), f);
242
238
  fclose(f);
243
239
  rjb_rbridge = (*jenv)->DefineClass(jenv,
244
- "jp/co/infoseek/hp/arton/rjb/RBridge", iloader, buff, len);
240
+ "jp/co/infoseek/hp/arton/rjb/RBridge", get_systemloader(jenv), buff, len);
245
241
  if (rjb_rbridge == NULL)
246
242
  {
247
243
  rjb_check_exception(jenv, 1);
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 131 2010-09-16 15:53:33Z arton $
15
+ * $Id: rjb.c 139 2010-09-21 17:32:57Z arton $
16
16
  */
17
17
 
18
- #define RJB_VERSION "1.2.8"
18
+ #define RJB_VERSION "1.2.9"
19
19
 
20
20
  #include "ruby.h"
21
21
  #include "extconf.h"
@@ -43,10 +43,10 @@
43
43
  #define ACC_TRANSIENT 0x0080
44
44
 
45
45
  #define RJB_FIND_CLASS(var, name) \
46
- var = (*jenv)->FindClass(jenv, name); \
46
+ var = rjb_find_class_by_name(jenv, name); \
47
47
  rjb_check_exception(jenv, 1)
48
48
  #define RJB_HOLD_CLASS(var, name) \
49
- var = (*jenv)->FindClass(jenv, name); \
49
+ var = rjb_find_class_by_name(jenv, name); \
50
50
  rjb_check_exception(jenv, 1); \
51
51
  var = (*jenv)->NewGlobalRef(jenv, var)
52
52
  #define RJB_LOAD_METHOD(var, obj, name, sig) \
@@ -89,6 +89,7 @@ static VALUE proxies;
89
89
  JavaVM* rjb_jvm;
90
90
  jclass rjb_rbridge;
91
91
  jmethodID rjb_register_bridge;
92
+ jmethodID rjb_load_class;
92
93
  static JNIEnv* main_jenv;
93
94
  static VALUE primitive_conversion = Qfalse;
94
95
 
@@ -117,6 +118,16 @@ static jclass j_string;
117
118
  static jmethodID str_tostring;
118
119
  /* Object global reference */
119
120
  static jclass j_object;
121
+ /* ClassLoader */
122
+ static jclass j_classloader;
123
+ static jmethodID get_system_classloader;
124
+ /* URLClassLoader */
125
+ static jclass j_url_loader;
126
+ static jobject url_loader;
127
+ static jmethodID url_loader_new;
128
+ /* URL global reference */
129
+ static jclass j_url;
130
+ static jmethodID url_new;
120
131
 
121
132
  enum PrimitiveType {
122
133
  PRM_INT = 0,
@@ -171,20 +182,18 @@ static char* java2jniname(char* jnicls)
171
182
  return jnicls;
172
183
  }
173
184
 
174
- #if 0
175
- static char* jni2javaname(char* jnicls)
185
+ static char* jniname2java(char* jniname)
176
186
  {
177
187
  char* p;
178
- for (p = jnicls; *p; p++)
188
+ for (p = jniname; *p; p++)
179
189
  {
180
190
  if (*p == '/')
181
191
  {
182
192
  *p = '.';
183
193
  }
184
194
  }
185
- return jnicls;
195
+ return jniname;
186
196
  }
187
- #endif
188
197
 
189
198
  static char* next_sig(char* p)
190
199
  {
@@ -1716,26 +1725,37 @@ static VALUE rjb_s_load(int argc, VALUE* argv, VALUE self)
1716
1725
  RJB_LOAD_METHOD(method_getName, jmethod, "getName", "()Ljava/lang/String;");
1717
1726
  RJB_LOAD_METHOD(getParameterTypes, jmethod, "getParameterTypes", "()[Ljava/lang/Class;");
1718
1727
  RJB_LOAD_METHOD(getReturnType, jmethod, "getReturnType", "()Ljava/lang/Class;");
1719
-
1728
+ rjb_check_exception(jenv, 1);
1729
+
1720
1730
  RJB_FIND_CLASS(jfield, "java/lang/reflect/Field");
1721
1731
  RJB_LOAD_METHOD(field_getModifiers, jfield, "getModifiers", "()I");
1722
1732
  RJB_LOAD_METHOD(field_getName, jfield, "getName", "()Ljava/lang/String;");
1723
1733
  RJB_LOAD_METHOD(field_getType, jfield, "getType", "()Ljava/lang/Class;");
1724
-
1734
+ rjb_check_exception(jenv, 1);
1735
+
1725
1736
  RJB_HOLD_CLASS(j_class, "java/lang/Class");
1726
1737
  RJB_LOAD_METHOD(rjb_class_getName, j_class, "getName", "()Ljava/lang/String;");
1727
-
1738
+ rjb_check_exception(jenv, 1);
1739
+
1728
1740
  RJB_HOLD_CLASS(rjb_j_throwable, "java/lang/Throwable");
1729
1741
  RJB_LOAD_METHOD(rjb_throwable_getMessage, rjb_j_throwable, "getMessage", "()Ljava/lang/String;");
1742
+ rjb_check_exception(jenv, 1);
1730
1743
 
1731
1744
  RJB_HOLD_CLASS(j_string, "java/lang/String");
1732
1745
  RJB_LOAD_METHOD(str_tostring, j_string, "toString", "()Ljava/lang/String;");
1746
+ rjb_check_exception(jenv, 1);
1733
1747
 
1734
1748
  RJB_HOLD_CLASS(j_object, "java/lang/Object");
1749
+ rjb_check_exception(jenv, 1);
1750
+
1751
+ RJB_HOLD_CLASS(j_url, "java/net/URL");
1752
+ RJB_LOAD_METHOD(url_new, j_url, "<init>", "(Ljava/lang/String;)V");
1753
+ rjb_check_exception(jenv, 1);
1735
1754
 
1736
1755
  for (i = PRM_INT; i < PRM_LAST; i++)
1737
1756
  {
1738
- jclass klass = (*jenv)->FindClass(jenv, jpcvt[i].classname);
1757
+ jclass klass;
1758
+ RJB_FIND_CLASS(klass, jpcvt[i].classname);
1739
1759
  if (i == PRM_BOOLEAN)
1740
1760
  {
1741
1761
  RJB_LOAD_STATIC_METHOD(jpcvt[i].ctr_id, klass, "valueOf", jpcvt[i].ctrsig);
@@ -1781,6 +1801,18 @@ JNIEnv* rjb_prelude()
1781
1801
  return jenv;
1782
1802
  }
1783
1803
 
1804
+ jobject get_systemloader(JNIEnv* jenv)
1805
+ {
1806
+ if (!j_classloader)
1807
+ {
1808
+ RJB_HOLD_CLASS(j_classloader, "java/lang/ClassLoader");
1809
+ RJB_LOAD_STATIC_METHOD(get_system_classloader, j_classloader,
1810
+ "getSystemClassLoader", "()Ljava/lang/ClassLoader;");
1811
+ rjb_check_exception(jenv, 1);
1812
+ }
1813
+ return (*jenv)->CallStaticObjectMethod(jenv, j_classloader, get_system_classloader);
1814
+ }
1815
+
1784
1816
  /*
1785
1817
  * unload Java Virtual Machine
1786
1818
  *
@@ -2061,7 +2093,7 @@ static int check_rtype(JNIEnv* jenv, VALUE v, char* p)
2061
2093
  int result = 0;
2062
2094
  if (!strcmp("java.lang.String", pcls)) return 1;
2063
2095
  Data_Get_Struct(v, struct jvi_data, ptr);
2064
- cls = (*jenv)->FindClass(jenv, java2jniname(pcls));
2096
+ RJB_FIND_CLASS(cls, java2jniname(pcls));
2065
2097
  if (cls)
2066
2098
  {
2067
2099
  result = (cls && (*jenv)->IsInstanceOf(jenv, ptr->obj, cls));
@@ -2159,6 +2191,27 @@ static VALUE rjb_newinstance(int argc, VALUE* argv, VALUE self)
2159
2191
  return ret;
2160
2192
  }
2161
2193
 
2194
+ /*
2195
+ * find java class using added classloader
2196
+ */
2197
+ jclass rjb_find_class_by_name(JNIEnv* jenv, const char* name)
2198
+ {
2199
+ jclass cls;
2200
+ if (url_loader)
2201
+ {
2202
+ jvalue v;
2203
+ char* binname = ALLOCA_N(char, strlen(name) + 32);
2204
+ strcpy(binname, name);
2205
+ v.l = (*jenv)->NewStringUTF(jenv, jniname2java(binname));
2206
+ cls = (*jenv)->CallObjectMethod(jenv, url_loader, rjb_load_class, v);
2207
+ }
2208
+ else
2209
+ {
2210
+ cls = (*jenv)->FindClass(jenv, name);
2211
+ }
2212
+ return cls;
2213
+ }
2214
+
2162
2215
  /*
2163
2216
  * find java class from classname
2164
2217
  */
@@ -2167,10 +2220,11 @@ jclass rjb_find_class(JNIEnv* jenv, VALUE name)
2167
2220
  char* cname;
2168
2221
  char* jnicls;
2169
2222
 
2223
+ Check_Type(name, T_STRING);
2170
2224
  cname = StringValueCStr(name);
2171
2225
  jnicls = ALLOCA_N(char, strlen(cname) + 1);
2172
2226
  strcpy(jnicls, cname);
2173
- return (*jenv)->FindClass(jenv, java2jniname(jnicls));
2227
+ return rjb_find_class_by_name(jenv, java2jniname(jnicls));
2174
2228
  }
2175
2229
 
2176
2230
  /*
@@ -2337,6 +2391,77 @@ static void register_class(VALUE self, VALUE clsname)
2337
2391
  #endif
2338
2392
  }
2339
2393
 
2394
+ /*
2395
+ * Rjb::add_jar(jarname)
2396
+ */
2397
+ static VALUE rjb_s_add_jar(VALUE self, VALUE jarname)
2398
+ {
2399
+ JNIEnv* jenv;
2400
+ char* jarp;
2401
+ char* urlp;
2402
+ size_t len;
2403
+ jvalue urlarg;
2404
+ jvalue args[2];
2405
+ jobject url;
2406
+
2407
+ SafeStringValue(jarname);
2408
+ jenv = rjb_prelude();
2409
+ if (!j_url_loader)
2410
+ {
2411
+ j_url_loader = (*jenv)->NewGlobalRef(jenv,
2412
+ (*jenv)->FindClass(jenv, "java/net/URLClassLoader"));
2413
+ RJB_LOAD_METHOD(rjb_load_class, j_url_loader, "loadClass",
2414
+ "(Ljava/lang/String;)Ljava/lang/Class;");
2415
+ RJB_LOAD_METHOD(url_loader_new, j_url_loader, "<init>",
2416
+ "([Ljava/net/URL;Ljava/lang/ClassLoader;)V");
2417
+ }
2418
+ jarp = StringValueCStr(jarname);
2419
+ urlp = ALLOCA_N(char, strlen(jarp) + 32);
2420
+ if (strncmp(jarp, "http:", 5) && strncmp(jarp, "https:", 6))
2421
+ {
2422
+ #if defined(DOSISH)
2423
+ if (strlen(jarp) > 1 && jarp[1] == ':')
2424
+ {
2425
+ sprintf(urlp, "file:///%s", jarp);
2426
+ }
2427
+ else
2428
+ #endif
2429
+ {
2430
+ sprintf(urlp, "file://%s", jarp);
2431
+ }
2432
+ }
2433
+ else
2434
+ {
2435
+ strcpy(urlp, jarp);
2436
+ }
2437
+ #if defined(DOSISH)
2438
+ for (len = 0; len < strlen(urlp); len++)
2439
+ {
2440
+ if (urlp[len] == '\\')
2441
+ {
2442
+ urlp[len] = '/';
2443
+ }
2444
+ }
2445
+ #endif
2446
+ urlarg.l = (*jenv)->NewStringUTF(jenv, urlp);
2447
+ rjb_check_exception(jenv, 0);
2448
+ url = (*jenv)->NewObject(jenv, j_url, url_new, urlarg);
2449
+ rjb_check_exception(jenv, 0);
2450
+ args[0].l = (*jenv)->NewObjectArray(jenv, 1, j_url, url);
2451
+ rjb_check_exception(jenv, 0);
2452
+ if (url_loader)
2453
+ {
2454
+ args[1].l = url_loader;
2455
+ }
2456
+ else
2457
+ {
2458
+ args[1].l = get_systemloader(jenv);
2459
+ }
2460
+ url_loader = (*jenv)->NewObjectA(jenv, j_url_loader, url_loader_new, args);
2461
+ rjb_check_exception(jenv, 0);
2462
+ return Qtrue;
2463
+ }
2464
+
2340
2465
  /*
2341
2466
  * return class name
2342
2467
  */
@@ -2897,6 +3022,7 @@ void Init_rjbcore()
2897
3022
  rb_define_module_function(rjb, "throw", rjb_s_throw, -1);
2898
3023
  rb_define_module_function(rjb, "primitive_conversion=", rjb_s_set_pconversion, 1);
2899
3024
  rb_define_module_function(rjb, "primitive_conversion", rjb_s_get_pconversion, 0);
3025
+ rb_define_module_function(rjb, "add_jar", rjb_s_add_jar, 1);
2900
3026
  rb_define_const(rjb, "VERSION", rb_str_new2(RJB_VERSION));
2901
3027
 
2902
3028
  /* Java class object */
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 126 2010-07-22 13:58:15Z arton $
15
+ * $Id: rjb.h 139 2010-09-21 17:32:57Z arton $
16
16
  * $Log: rjb.h,v $
17
17
  * Revision 1.1 2005/01/16 17:36:10 arton
18
18
  * Initial revision
@@ -74,6 +74,8 @@ extern void rjb_release_string(JNIEnv *jenv, jstring str, const char* chrs);
74
74
  extern VALUE rjb_load_vm_default();
75
75
  extern VALUE rjb_safe_funcall(VALUE args);
76
76
  extern VALUE jv2rv(JNIEnv* jenv, jvalue val);
77
+ extern jobject get_systemloader(JNIEnv* jenv);
78
+ extern jclass rjb_find_class_by_name(JNIEnv* jenv, const char* name);
77
79
 
78
80
  /* in rjbexception.c */
79
81
  extern VALUE rjb_get_exception_class(JNIEnv* jenv, jstring str);
data/lib/rjb.rb CHANGED
@@ -9,7 +9,7 @@ module RjbConf
9
9
  if File.exist?(dir)
10
10
  datadir = dir
11
11
  else
12
- datadir = Config::CONFIG['datadir']
12
+ datadir = RbConfig::CONFIG['datadir']
13
13
  end
14
14
  BRIDGE_FILE = File.join(datadir, 'rjb', 'jp', 'co', 'infoseek', 'hp',
15
15
  'arton', 'rjb', 'RBridge.class')
@@ -21,7 +21,14 @@ end
21
21
  require 'rjbcore'
22
22
 
23
23
  module Rjb
24
- MODIFIER = import('java.lang.reflect.Modifier')
24
+ module MODIFIER
25
+ def self.STATIC
26
+ 8
27
+ end
28
+ def self.PUBLIC
29
+ 1
30
+ end
31
+ end
25
32
 
26
33
  module JMethod
27
34
  def instance_method?(m)
Binary file
Binary file
@@ -1,6 +1,6 @@
1
1
  #!/usr/local/env ruby -Ku
2
2
  # encoding: utf-8
3
- # $Id: test.rb 133 2010-09-16 16:01:02Z arton $
3
+ # $Id: test.rb 142 2010-09-21 17:59:30Z arton $
4
4
 
5
5
  begin
6
6
  require 'rjb'
@@ -526,9 +526,9 @@ class TestRjb < Test::Unit::TestCase
526
526
  assert_equal('Hello World !!', a[1][1].toString)
527
527
  end
528
528
 
529
- def test_CallByNullForArraies()
529
+ def test_CallByNullForArrays()
530
530
  test = import('jp.co.infoseek.hp.arton.rjb.Test').new
531
- assert_equal(nil, test.callWithArraies(nil, nil, nil, nil, nil, nil,
531
+ assert_equal(nil, test.callWithArrays(nil, nil, nil, nil, nil, nil,
532
532
  nil, nil))
533
533
  end
534
534
 
@@ -723,12 +723,21 @@ class TestRjb < Test::Unit::TestCase
723
723
  args.split(/,\s*/).sort)
724
724
  end
725
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;])')
726
+ format = @jString.java_methods.find do |m|
727
+ m =~ /^format/
728
+ end
729
+ args = format.match(/\[([^\]]+)\]/)[1]
730
+ assert_equal('Ljava.lang.String;[Ljava.lang.Object;, Ljava.util.Locale;Ljava.lang.String;[Ljava.lang.Object;'.split(/,\s*/).sort, args.split(/,\s*/).sort)
728
731
  end
729
732
  def test_64fixnum
730
733
  big = @jLong.new_with_sig('J', 1230918239495)
731
734
  assert_equal 1230918239495, big.long_value
732
735
  end
736
+ def test_add_jar
737
+ add_jar(File.expand_path('./jartest.jar'))
738
+ jt = import('jp.co.infoseek.hp.arton.rjb.JarTest')
739
+ assert jt
740
+ assert_equal 'abcd', jt.new.add('ab', 'cd')
741
+ end
733
742
  end
734
743
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rjb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 8
10
- version: 1.2.8
9
+ - 9
10
+ version: 1.2.9
11
11
  platform: x86-mswin32-60
12
12
  authors:
13
13
  - arton
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-17 00:00:00 +09:00
18
+ date: 2010-09-22 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -53,14 +53,14 @@ files:
53
53
  - test/Base.class
54
54
  - test/ExtBase.class
55
55
  - test/IBase.class
56
+ - test/jar/jp/co/infoseek/hp/arton/rjb/JarTest.class
56
57
  - test/jp/co/infoseek/hp/arton/rjb/Base.class
57
58
  - test/jp/co/infoseek/hp/arton/rjb/ExtBase.class
58
59
  - test/jp/co/infoseek/hp/arton/rjb/IBase.class
59
60
  - test/jp/co/infoseek/hp/arton/rjb/Test$TestTypes.class
60
61
  - test/jp/co/infoseek/hp/arton/rjb/Test.class
61
62
  - test/JTest.class
62
- - test/Test$TestTypes.class
63
- - test/Test.class
63
+ - test/jartest.jar
64
64
  - test/rjbtest.jar
65
65
  - COPYING
66
66
  - ChangeLog
Binary file
Binary file