rjb 1.2.9-x86-mswin32-60 → 1.3.0-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,22 @@
1
+ Sat Oct 23 arton
2
+ *ext/rjb.c
3
+ RJV_VERSION -> 1.3.0
4
+ add loaded? class method.
5
+ add add_classpath method (add jars without invoking load method)
6
+ *ext/load.c
7
+ OSX default jvm name changes to "JavaVM"
8
+ *ext/extconf.rb
9
+ OSX javahome set to /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
10
+ *lib/rjbextension.rb
11
+ use Rjb::add_classpath method instead of Kernel's class vars.
12
+ *test/test.rb, test/exttest.rb
13
+ fix add_jar test, previous version load them from jp directory.
14
+ Tue Sep 22 arton
15
+ *ext/rjb.c
16
+ RJV_VERSION -> 1.2.10
17
+ add add_jars method. add_jar and add_jars can take an array of jars.
18
+ *test/test.rb
19
+ add calling add_jar with an array test.
1
20
  Tue Sep 21 arton
2
21
  *ext/rjb.h
3
22
  export ClassLoader methods
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 139 2010-09-21 17:32:57Z arton $
15
+ * $Id: load.c 148 2010-10-23 08:38:44Z arton $
16
16
  */
17
17
 
18
18
  #include <stdlib.h>
@@ -45,7 +45,7 @@
45
45
  #endif
46
46
  #define CLASSPATH_SEP ';'
47
47
  #elif defined(__APPLE__) && defined(__MACH__)
48
- static char* JVMDLL = "%s/Libraries/libjvm_compat.dylib";
48
+ static char* JVMDLL = "%s/JavaVM";
49
49
  #define DIRSEPARATOR '/'
50
50
  #define CLASSPATH_SEP ':'
51
51
  #define HOME_NAME "/Home"
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 139 2010-09-21 17:32:57Z arton $
15
+ * $Id: rjb.c 147 2010-10-23 05:10:33Z arton $
16
16
  */
17
17
 
18
- #define RJB_VERSION "1.2.9"
18
+ #define RJB_VERSION "1.3.0"
19
19
 
20
20
  #include "ruby.h"
21
21
  #include "extconf.h"
@@ -83,6 +83,7 @@ static VALUE rjbi;
83
83
  static VALUE rjbb;
84
84
 
85
85
  static ID user_initialize;
86
+ static ID cvar_classpath;
86
87
 
87
88
  VALUE rjb_loaded_classes;
88
89
  static VALUE proxies;
@@ -1679,9 +1680,12 @@ static VALUE rjb_s_load(int argc, VALUE* argv, VALUE self)
1679
1680
  JNIEnv* jenv;
1680
1681
  JavaVMInitArgs vm_args;
1681
1682
  jint res;
1683
+ VALUE classpath;
1682
1684
  VALUE user_path;
1683
1685
  VALUE vm_argv;
1684
1686
  char* userpath;
1687
+ ID stradd = rb_intern("<<");
1688
+ ID pathsep = rb_intern("PATH_SEPARATOR");
1685
1689
  int i;
1686
1690
  jclass jmethod;
1687
1691
  jclass jfield;
@@ -1698,12 +1702,19 @@ static VALUE rjb_s_load(int argc, VALUE* argv, VALUE self)
1698
1702
  if (!NIL_P(user_path))
1699
1703
  {
1700
1704
  Check_Type(user_path, T_STRING);
1701
- userpath = StringValueCStr(user_path);
1702
1705
  }
1703
1706
  else
1704
1707
  {
1705
- userpath = ".";
1708
+ user_path = rb_str_new2(".");
1706
1709
  }
1710
+ classpath = rb_cvar_get(rjb, cvar_classpath);
1711
+ for (i = 0; i < RARRAY_LEN(classpath); i++)
1712
+ {
1713
+ rb_funcall(user_path, stradd, 1, rb_const_get(rb_cFile, pathsep));
1714
+ rb_funcall(user_path, stradd, 1, rb_ary_entry(classpath, 0));
1715
+ }
1716
+ userpath = StringValueCStr(user_path);
1717
+
1707
1718
  if (!NIL_P(vm_argv))
1708
1719
  {
1709
1720
  Check_Type(vm_argv, T_ARRAY);
@@ -1772,7 +1783,7 @@ static VALUE rjb_s_load(int argc, VALUE* argv, VALUE self)
1772
1783
 
1773
1784
  jklass = import_class(jenv, j_class, rb_str_new2("java.lang.Class"));
1774
1785
  rb_define_method(rb_singleton_class(jklass), "forName", rjb_class_forname, -1);
1775
- rb_define_method(rb_singleton_class(jklass), "for_name", rjb_class_forname, -1);
1786
+ rb_define_alias(rb_singleton_class(jklass), "for_name", "forName");
1776
1787
  rb_gc_register_address(&jklass);
1777
1788
 
1778
1789
  return Qnil;
@@ -1813,6 +1824,11 @@ jobject get_systemloader(JNIEnv* jenv)
1813
1824
  return (*jenv)->CallStaticObjectMethod(jenv, j_classloader, get_system_classloader);
1814
1825
  }
1815
1826
 
1827
+ static jobject get_class_loader(JNIEnv* jenv)
1828
+ {
1829
+ return (url_loader) ? url_loader : get_systemloader(jenv);
1830
+ }
1831
+
1816
1832
  /*
1817
1833
  * unload Java Virtual Machine
1818
1834
  *
@@ -1848,6 +1864,11 @@ static VALUE rjb_s_unload(int argc, VALUE* argv, VALUE self)
1848
1864
  return INT2NUM(result);
1849
1865
  }
1850
1866
 
1867
+ static VALUE rjb_s_loaded(VALUE self)
1868
+ {
1869
+ return (rjb_jvm) ? Qtrue : Qfalse;
1870
+ }
1871
+
1851
1872
  /*
1852
1873
  * return all classes that were already loaded.
1853
1874
  * this method simply returns the global hash,
@@ -1859,7 +1880,7 @@ static VALUE rjb_s_classes(VALUE self)
1859
1880
  }
1860
1881
 
1861
1882
  /**
1862
- * For JRuby conpatible optsion
1883
+ * For JRuby conpatible option
1863
1884
  */
1864
1885
  static VALUE rjb_s_set_pconversion(VALUE self, VALUE val)
1865
1886
  {
@@ -1868,7 +1889,7 @@ static VALUE rjb_s_set_pconversion(VALUE self, VALUE val)
1868
1889
  }
1869
1890
 
1870
1891
  /**
1871
- * For JRuby conpatible optsion
1892
+ * For JRuby conpatible option
1872
1893
  */
1873
1894
  static VALUE rjb_s_get_pconversion(VALUE self)
1874
1895
  {
@@ -2026,7 +2047,7 @@ static VALUE import_class(JNIEnv* jenv, jclass jcls, VALUE clsname)
2026
2047
  static VALUE rjb_i_prepare_proxy(VALUE self)
2027
2048
  {
2028
2049
  return rb_funcall(self, rb_intern("instance_eval"), 1,
2029
- rb_str_new2("instance_eval &" USER_INITIALIZE));
2050
+ rb_str_new2("instance_eval(&" USER_INITIALIZE ")"));
2030
2051
  }
2031
2052
 
2032
2053
  static VALUE register_instance(JNIEnv* jenv, VALUE klass, struct jv_data* org, jobject obj)
@@ -2204,6 +2225,7 @@ jclass rjb_find_class_by_name(JNIEnv* jenv, const char* name)
2204
2225
  strcpy(binname, name);
2205
2226
  v.l = (*jenv)->NewStringUTF(jenv, jniname2java(binname));
2206
2227
  cls = (*jenv)->CallObjectMethod(jenv, url_loader, rjb_load_class, v);
2228
+ (*jenv)->DeleteLocalRef(jenv, v.l);
2207
2229
  }
2208
2230
  else
2209
2231
  {
@@ -2376,6 +2398,7 @@ static void register_class(VALUE self, VALUE clsname)
2376
2398
  rb_define_singleton_method(self, "sigs", rjb_get_signatures, 1);
2377
2399
  rb_define_singleton_method(self, "static_sigs", rjb_get_static_signatures, 1);
2378
2400
  rb_define_singleton_method(self, "ctor_sigs", rjb_get_ctor_signatures, 0);
2401
+ rb_ivar_set(self, user_initialize, Qnil);
2379
2402
  /*
2380
2403
  * the hash was frozen, so it need to call st_ func directly.
2381
2404
  */
@@ -2391,30 +2414,15 @@ static void register_class(VALUE self, VALUE clsname)
2391
2414
  #endif
2392
2415
  }
2393
2416
 
2394
- /*
2395
- * Rjb::add_jar(jarname)
2396
- */
2397
- static VALUE rjb_s_add_jar(VALUE self, VALUE jarname)
2417
+ static jobject conv_jarname_to_url(JNIEnv* jenv, VALUE jarname)
2398
2418
  {
2399
- JNIEnv* jenv;
2419
+ jvalue arg;
2420
+ jobject url;
2421
+ size_t len;
2400
2422
  char* jarp;
2401
2423
  char* urlp;
2402
- size_t len;
2403
- jvalue urlarg;
2404
- jvalue args[2];
2405
- jobject url;
2406
-
2424
+
2407
2425
  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
2426
  jarp = StringValueCStr(jarname);
2419
2427
  urlp = ALLOCA_N(char, strlen(jarp) + 32);
2420
2428
  if (strncmp(jarp, "http:", 5) && strncmp(jarp, "https:", 6))
@@ -2443,22 +2451,73 @@ static VALUE rjb_s_add_jar(VALUE self, VALUE jarname)
2443
2451
  }
2444
2452
  }
2445
2453
  #endif
2446
- urlarg.l = (*jenv)->NewStringUTF(jenv, urlp);
2447
- rjb_check_exception(jenv, 0);
2448
- url = (*jenv)->NewObject(jenv, j_url, url_new, urlarg);
2454
+ arg.l = (*jenv)->NewStringUTF(jenv, urlp);
2449
2455
  rjb_check_exception(jenv, 0);
2450
- args[0].l = (*jenv)->NewObjectArray(jenv, 1, j_url, url);
2456
+ url = (*jenv)->NewObject(jenv, j_url, url_new, arg);
2457
+ rjb_check_exception(jenv, 0);
2458
+ return url;
2459
+ }
2460
+
2461
+ /*
2462
+ * Rjb::add_classpath(jarname)
2463
+ */
2464
+ static VALUE rjb_s_add_classpath(VALUE self, VALUE jarname)
2465
+ {
2466
+ VALUE cpath = rb_cvar_get(self, cvar_classpath);
2467
+ SafeStringValue(jarname);
2468
+ rb_ary_push(cpath, jarname);
2469
+ return cpath;
2470
+ }
2471
+
2472
+ /*
2473
+ * Rjb::add_jar(jarname)
2474
+ */
2475
+ static VALUE rjb_s_add_jar(VALUE self, VALUE jarname)
2476
+ {
2477
+ size_t i;
2478
+ JNIEnv* jenv;
2479
+ size_t count;
2480
+ jvalue args[2];
2481
+
2482
+ if (rb_type(jarname) != T_ARRAY)
2483
+ {
2484
+ SafeStringValue(jarname);
2485
+ count = 0;
2486
+ }
2487
+ else
2488
+ {
2489
+ count = RARRAY_LEN(jarname);
2490
+ }
2491
+ jenv = rjb_prelude();
2492
+ if (!j_url_loader)
2493
+ {
2494
+ j_url_loader = (*jenv)->NewGlobalRef(jenv,
2495
+ (*jenv)->FindClass(jenv, "java/net/URLClassLoader"));
2496
+ RJB_LOAD_METHOD(rjb_load_class, j_url_loader, "loadClass",
2497
+ "(Ljava/lang/String;)Ljava/lang/Class;");
2498
+ RJB_LOAD_METHOD(url_loader_new, j_url_loader, "<init>",
2499
+ "([Ljava/net/URL;Ljava/lang/ClassLoader;)V");
2500
+ }
2501
+ args[0].l = (*jenv)->NewObjectArray(jenv, (count == 0) ? 1 : count, j_url, NULL);
2451
2502
  rjb_check_exception(jenv, 0);
2452
- if (url_loader)
2503
+ if (!count)
2453
2504
  {
2454
- args[1].l = url_loader;
2505
+ (*jenv)->SetObjectArrayElement(jenv, args[0].l, 0,
2506
+ conv_jarname_to_url(jenv, jarname));
2455
2507
  }
2456
2508
  else
2457
2509
  {
2458
- args[1].l = get_systemloader(jenv);
2510
+ for (i = 0; i < count; i++) {
2511
+ (*jenv)->SetObjectArrayElement(jenv, args[0].l, i,
2512
+ conv_jarname_to_url(jenv, rb_ary_entry(jarname, i)));
2513
+ }
2459
2514
  }
2515
+ rjb_check_exception(jenv, 0);
2516
+ args[1].l = get_class_loader(jenv);
2460
2517
  url_loader = (*jenv)->NewObjectA(jenv, j_url_loader, url_loader_new, args);
2461
2518
  rjb_check_exception(jenv, 0);
2519
+ (*jenv)->NewGlobalRef(jenv, url_loader);
2520
+ (*jenv)->DeleteLocalRef(jenv, args[0].l);
2462
2521
  return Qtrue;
2463
2522
  }
2464
2523
 
@@ -3015,6 +3074,7 @@ void Init_rjbcore()
3015
3074
  rjb = rb_define_module("Rjb");
3016
3075
  rb_define_module_function(rjb, "load", rjb_s_load, -1);
3017
3076
  rb_define_module_function(rjb, "unload", rjb_s_unload, -1);
3077
+ rb_define_module_function(rjb, "loaded?", rjb_s_loaded, 0);
3018
3078
  rb_define_module_function(rjb, "import", rjb_s_import, 1);
3019
3079
  rb_define_module_function(rjb, "bind", rjb_s_bind, 2);
3020
3080
  rb_define_module_function(rjb, "unbind", rjb_s_unbind, 1);
@@ -3022,8 +3082,12 @@ void Init_rjbcore()
3022
3082
  rb_define_module_function(rjb, "throw", rjb_s_throw, -1);
3023
3083
  rb_define_module_function(rjb, "primitive_conversion=", rjb_s_set_pconversion, 1);
3024
3084
  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);
3085
+ rb_define_module_function(rjb, "add_classpath", rjb_s_add_classpath, 1);
3086
+ rb_define_module_function(rjb, "add_jar", rjb_s_add_jar, 1);
3087
+ rb_define_alias(rjb, "add_jars", "add_jar");
3026
3088
  rb_define_const(rjb, "VERSION", rb_str_new2(RJB_VERSION));
3089
+ rb_define_class_variable(rjb, "@@classpath", rb_ary_new());
3090
+ cvar_classpath = rb_intern("@@classpath");
3027
3091
 
3028
3092
  /* Java class object */
3029
3093
  rjbc = CLASS_NEW(rb_cObject, "Rjb_JavaClass");
data/lib/rjbcore.so CHANGED
Binary file
data/lib/rjbextension.rb CHANGED
@@ -11,7 +11,7 @@ Copyright(c) 2010 arton
11
11
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
12
  Lesser General Public License for more details.
13
13
 
14
- $Id: rjbextension.rb 116 2010-05-30 14:23:07Z arton $
14
+ $Id: rjbextension.rb 147 2010-10-23 05:10:33Z arton $
15
15
 
16
16
  This file is from Andreas Ronge project neo4j
17
17
  http://github.com/andreasronge/neo4j/blob/rjb/lib/rjb_ext.rb
@@ -59,23 +59,16 @@ module Kernel
59
59
  raise unless File.exist?(abs_path)
60
60
 
61
61
  # try to load it using RJB
62
- @@rjb_jars ||= []
63
- @@rjb_jars << abs_path unless @@rjb_jars.include?(abs_path)
64
- # TODO
62
+ if Rjb::loaded?
63
+ Rjb::add_jar abs_path
64
+ else
65
+ Rjb::add_classpath abs_path
66
+ end
65
67
  end
66
68
 
67
- @@jvm_loaded = false
68
-
69
69
  def load_jvm(jargs = [])
70
- # avoid starting the JVM twice
71
- return if @@jvm_loaded
72
-
73
- @@jvm_loaded = true
70
+ return if Rjb::loaded?
74
71
  classpath = ENV['CLASSPATH'] ||= ''
75
- @@rjb_jars.each do |jar|
76
- classpath += File::PATH_SEPARATOR unless classpath.empty?
77
- classpath += jar
78
- end
79
72
  Rjb::load(classpath, jargs)
80
73
  end
81
74
  end
data/test/exttest.rb CHANGED
@@ -16,6 +16,9 @@ end
16
16
 
17
17
  require 'rjbextension'
18
18
  require 'test/unit'
19
+ require 'fileutils'
20
+
21
+ FileUtils.rm_f 'jp/co/infoseek/hp/arton/rjb/Base.class'
19
22
 
20
23
  puts "start RJB(#{Rjb::VERSION}) test"
21
24
  class ExtTestRjb < Test::Unit::TestCase
@@ -25,9 +28,11 @@ class ExtTestRjb < Test::Unit::TestCase
25
28
  end
26
29
 
27
30
  def test_require_extension
31
+ assert !Rjb::loaded?
32
+ $LOAD_PATH << '.'
28
33
  require 'rjbtest.jar'
29
- load_jvm
30
-
34
+ Rjb::load
35
+ assert Rjb::loaded?
31
36
  base = jp.co.infoseek.hp.arton.rjb.Base.new
32
37
  assert_equal('hello', base.instance_var)
33
38
  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 142 2010-09-21 17:59:30Z arton $
3
+ # $Id: test.rb 147 2010-10-23 05:10:33Z arton $
4
4
 
5
5
  begin
6
6
  require 'rjb'
@@ -9,12 +9,17 @@ rescue LoadError
9
9
  require 'rjb'
10
10
  end
11
11
  require 'test/unit'
12
+ require 'fileutils'
13
+
14
+ FileUtils.rm_f 'jp/co/infoseek/hp/arton/rjb/Base.class'
15
+ FileUtils.rm_f 'jp/co/infoseek/hp/arton/rjb/ExtBase.class'
12
16
 
13
17
  puts "start RJB(#{Rjb::VERSION}) test"
14
18
  class TestRjb < Test::Unit::TestCase
15
19
  include Rjb
16
20
  def setup
17
- load('.')
21
+ Rjb::load('.')
22
+ Rjb::add_jar(File.expand_path('rjbtest.jar'))
18
23
  Rjb::primitive_conversion = false
19
24
 
20
25
  @jString = import('java.lang.String')
@@ -463,10 +468,8 @@ class TestRjb < Test::Unit::TestCase
463
468
  bs = import('jp.co.infoseek.hp.arton.rjb.Base')
464
469
  b = cls.forName('jp.co.infoseek.hp.arton.rjb.Base')
465
470
  assert_equal(bs, b)
466
- # class java's Class#forName and convert result to imported class
471
+ # check class that was loaded from classpath
467
472
  loader = Rjb::import('java.lang.ClassLoader')
468
- b = cls.forName('jp.co.infoseek.hp.arton.rjb.Base', true, loader.getSystemClassLoader)
469
- assert_equal(bs, b)
470
473
  b = cls.forName('jp.co.infoseek.hp.arton.rjb.IBase', true, loader.getSystemClassLoader)
471
474
  assert(b.isInterface)
472
475
  end
@@ -739,5 +742,13 @@ class TestRjb < Test::Unit::TestCase
739
742
  assert jt
740
743
  assert_equal 'abcd', jt.new.add('ab', 'cd')
741
744
  end
745
+ def test_add_jars
746
+ arg = ['./jartest.jar', './jartest.jar'].map do |e|
747
+ File.expand_path(e)
748
+ end
749
+ add_jar(arg)
750
+ jt = import('jp.co.infoseek.hp.arton.rjb.JarTest')
751
+ assert_equal 'abcd', jt.new.add('ab', 'cd')
752
+ end
742
753
  end
743
754
 
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: 13
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 2
9
- - 9
10
- version: 1.2.9
8
+ - 3
9
+ - 0
10
+ version: 1.3.0
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-22 00:00:00 +09:00
18
+ date: 2010-10-23 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -54,8 +54,6 @@ files:
54
54
  - test/ExtBase.class
55
55
  - test/IBase.class
56
56
  - test/jar/jp/co/infoseek/hp/arton/rjb/JarTest.class
57
- - test/jp/co/infoseek/hp/arton/rjb/Base.class
58
- - test/jp/co/infoseek/hp/arton/rjb/ExtBase.class
59
57
  - test/jp/co/infoseek/hp/arton/rjb/IBase.class
60
58
  - test/jp/co/infoseek/hp/arton/rjb/Test$TestTypes.class
61
59
  - test/jp/co/infoseek/hp/arton/rjb/Test.class