rjb 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,12 @@
1
+ Sat Oct 6 arton
2
+ *ext/rjb.c
3
+ RJB_VERSION -> 1.4.2
4
+ *test/osx_jvmcheck.rb
5
+ display vendor and version of JRE for OSX load test
6
+ *test/osx_loadtest.rb
7
+ add Oracle JVM support test for OSX
8
+ *lib/rjb.rb
9
+ add Oracle JVM support for OSX
1
10
  Sun Aug 19 arton
2
11
  *ext/rjb.c
3
12
  export bound object's original ruby object as @wrapped
@@ -1,8 +1,9 @@
1
- #ifndef EXTCONF_H
2
- #define EXTCONF_H
3
- #define HAVE_JNI_H 1
4
- #define HAVE_DL_H 1
5
- #define HAVE_SETLOCALE 1
6
- #define HAVE_GETENV 1
7
- #define RJB_RUBY_VERSION_CODE 187
8
- #endif
1
+ #ifndef EXTCONF_H
2
+ #define EXTCONF_H
3
+ #define HAVE_JNI_H 1
4
+ #define HAVE_RUBY_DL_H 1
5
+ #define HAVE_NL_LANGINFO 1
6
+ #define HAVE_SETLOCALE 1
7
+ #define HAVE_GETENV 1
8
+ #define RJB_RUBY_VERSION_CODE 193
9
+ #endif
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,2010,2011 arton
3
+ * Copyright(c) 2004,2005,2006,2007,2008,2009,2010,2011,2012 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 191 2012-08-18 15:04:18Z arton $
15
+ * $Id: rjb.c 194 2012-10-06 06:01:31Z arton $
16
16
  */
17
17
 
18
- #define RJB_VERSION "1.4.1"
18
+ #define RJB_VERSION "1.4.2"
19
19
 
20
20
  #include "ruby.h"
21
21
  #include "extconf.h"
@@ -889,8 +889,8 @@ static jarray r2barray(JNIEnv* jenv, VALUE v, const char* cls)
889
889
  jarray ary = NULL;
890
890
  if (TYPE(v) == T_STRING)
891
891
  {
892
- ary = (*jenv)->NewByteArray(jenv, RSTRING_LEN(v));
893
- (*jenv)->SetByteArrayRegion(jenv, ary, 0, RSTRING_LEN(v),
892
+ ary = (*jenv)->NewByteArray(jenv, (jint)RSTRING_LEN(v));
893
+ (*jenv)->SetByteArrayRegion(jenv, ary, 0, (jint)RSTRING_LEN(v),
894
894
  (const jbyte*)RSTRING_PTR(v));
895
895
  }
896
896
  else if (TYPE(v) == T_ARRAY)
@@ -898,7 +898,7 @@ static jarray r2barray(JNIEnv* jenv, VALUE v, const char* cls)
898
898
  int i;
899
899
  jbyte* pb;
900
900
  check_fixnumarray(v);
901
- ary = (*jenv)->NewByteArray(jenv, RARRAY_LEN(v));
901
+ ary = (*jenv)->NewByteArray(jenv, (jint)RARRAY_LEN(v));
902
902
  pb = (*jenv)->GetByteArrayElements(jenv, ary, NULL);
903
903
  for (i = 0; i < RARRAY_LEN(v); i++)
904
904
  {
@@ -921,7 +921,7 @@ static jarray r2carray(JNIEnv* jenv, VALUE v, const char* cls)
921
921
  int i;
922
922
  jchar* pb;
923
923
  check_fixnumarray(v);
924
- ary = (*jenv)->NewCharArray(jenv, RARRAY_LEN(v));
924
+ ary = (*jenv)->NewCharArray(jenv, (jint)RARRAY_LEN(v));
925
925
  pb = (*jenv)->GetCharArrayElements(jenv, ary, NULL);
926
926
  for (i = 0; i < RARRAY_LEN(v); i++)
927
927
  {
@@ -940,7 +940,7 @@ static jarray r2darray(JNIEnv* jenv, VALUE v, const char* cls)
940
940
  {
941
941
  int i;
942
942
  jdouble* pb;
943
- ary = (*jenv)->NewDoubleArray(jenv, RARRAY_LEN(v));
943
+ ary = (*jenv)->NewDoubleArray(jenv, (jint)RARRAY_LEN(v));
944
944
  pb = (*jenv)->GetDoubleArrayElements(jenv, ary, NULL);
945
945
  for (i = 0; i < RARRAY_LEN(v); i++)
946
946
  {
@@ -959,7 +959,7 @@ static jarray r2farray(JNIEnv* jenv, VALUE v, const char* cls)
959
959
  {
960
960
  int i;
961
961
  jfloat* pb;
962
- ary = (*jenv)->NewFloatArray(jenv, RARRAY_LEN(v));
962
+ ary = (*jenv)->NewFloatArray(jenv, (jint)RARRAY_LEN(v));
963
963
  pb = (*jenv)->GetFloatArrayElements(jenv, ary, NULL);
964
964
  for (i = 0; i < RARRAY_LEN(v); i++)
965
965
  {
@@ -979,7 +979,7 @@ static jarray r2iarray(JNIEnv* jenv, VALUE v, const char* cls)
979
979
  int i;
980
980
  jint* pb;
981
981
  check_fixnumarray(v);
982
- ary = (*jenv)->NewIntArray(jenv, RARRAY_LEN(v));
982
+ ary = (*jenv)->NewIntArray(jenv, (jint)RARRAY_LEN(v));
983
983
  pb = (*jenv)->GetIntArrayElements(jenv, ary, NULL);
984
984
  for (i = 0; i < RARRAY_LEN(v); i++)
985
985
  {
@@ -998,7 +998,7 @@ static jarray r2larray(JNIEnv* jenv, VALUE v, const char* cls)
998
998
  {
999
999
  int i;
1000
1000
  jlong* pb;
1001
- ary = (*jenv)->NewLongArray(jenv, RARRAY_LEN(v));
1001
+ ary = (*jenv)->NewLongArray(jenv, (jint)RARRAY_LEN(v));
1002
1002
  pb = (*jenv)->GetLongArrayElements(jenv, ary, NULL);
1003
1003
  for (i = 0; i < RARRAY_LEN(v); i++)
1004
1004
  {
@@ -1022,7 +1022,7 @@ static jarray r2sarray(JNIEnv* jenv, VALUE v, const char* cls)
1022
1022
  int i;
1023
1023
  jshort* pb;
1024
1024
  check_fixnumarray(v);
1025
- ary = (*jenv)->NewShortArray(jenv, RARRAY_LEN(v));
1025
+ ary = (*jenv)->NewShortArray(jenv, (jint)RARRAY_LEN(v));
1026
1026
  pb = (*jenv)->GetShortArrayElements(jenv, ary, NULL);
1027
1027
  for (i = 0; i < RARRAY_LEN(v); i++)
1028
1028
  {
@@ -1041,7 +1041,7 @@ static jarray r2boolarray(JNIEnv* jenv, VALUE v, const char* cls)
1041
1041
  {
1042
1042
  int i;
1043
1043
  jboolean* pb;
1044
- ary = (*jenv)->NewBooleanArray(jenv, RARRAY_LEN(v));
1044
+ ary = (*jenv)->NewBooleanArray(jenv, (jint)RARRAY_LEN(v));
1045
1045
  pb = (*jenv)->GetBooleanArrayElements(jenv, ary, NULL);
1046
1046
  for (i = 0; i < RARRAY_LEN(v); i++)
1047
1047
  {
@@ -1066,7 +1066,7 @@ static jarray r2objarray(JNIEnv* jenv, VALUE v, const char* cls)
1066
1066
  if (TYPE(v) == T_ARRAY)
1067
1067
  {
1068
1068
  int i;
1069
- ary = (*jenv)->NewObjectArray(jenv, RARRAY_LEN(v), j_object, NULL);
1069
+ ary = (*jenv)->NewObjectArray(jenv, (jint)RARRAY_LEN(v), j_object, NULL);
1070
1070
  rjb_check_exception(jenv, 0);
1071
1071
  for (i = 0; i < RARRAY_LEN(v); i++)
1072
1072
  {
@@ -1153,7 +1153,7 @@ static void rv2jarray(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, int
1153
1153
  }
1154
1154
  else
1155
1155
  {
1156
- size_t i;
1156
+ jint i;
1157
1157
  jarray ja = NULL;
1158
1158
  if (NIL_P(val))
1159
1159
  {
@@ -1164,19 +1164,19 @@ static void rv2jarray(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, int
1164
1164
  if (TYPE(val) != T_ARRAY) {
1165
1165
  rb_raise(rb_eRuntimeError, "array's rank unmatch");
1166
1166
  }
1167
- ja = (*jenv)->NewObjectArray(jenv, RARRAY_LEN(val), j_object, NULL);
1167
+ ja = (*jenv)->NewObjectArray(jenv, (jint)RARRAY_LEN(val), j_object, NULL);
1168
1168
  rjb_check_exception(jenv, 0);
1169
- for (i = 0; i < RARRAY_LEN(val); i++)
1169
+ for (i = 0; i < (jint)RARRAY_LEN(val); i++)
1170
1170
  {
1171
1171
  jvalue jv;
1172
1172
  rv2jarray(jenv, RARRAY_PTR(val)[i], &jv, psig + 1, 0);
1173
- (*jenv)->SetObjectArrayElement(jenv, ja, i, jv.l);
1173
+ (*jenv)->SetObjectArrayElement(jenv, ja, (jint)i, jv.l);
1174
1174
  }
1175
1175
  }
1176
1176
  else
1177
1177
  {
1178
1178
  R2JARRAY r2a = r2objarray;
1179
- for (i = 0; i < COUNTOF(jcvt); i++)
1179
+ for (i = 0; i < (jint)COUNTOF(jcvt); i++)
1180
1180
  {
1181
1181
  if (*(psig + 1) == jcvt[i].jntype[0])
1182
1182
  {
@@ -1205,7 +1205,7 @@ static R2J get_r2j(JNIEnv* jenv, jobject o, int* siglen, char* sigp)
1205
1205
  if (siglen)
1206
1206
  {
1207
1207
  len = strlen(cname);
1208
- *siglen += len;
1208
+ *siglen += (int)len;
1209
1209
  strcpy(sigp, cname);
1210
1210
  }
1211
1211
  result = rv2jarray;
@@ -1218,7 +1218,7 @@ static R2J get_r2j(JNIEnv* jenv, jobject o, int* siglen, char* sigp)
1218
1218
  {
1219
1219
  if (siglen)
1220
1220
  {
1221
- *siglen += strlen(jcvt[i].jntype);
1221
+ *siglen += (int)strlen(jcvt[i].jntype);
1222
1222
  strcpy(sigp, jcvt[i].jntype);
1223
1223
  }
1224
1224
  result = jcvt[i].r2j;
@@ -2568,7 +2568,7 @@ static VALUE rjb_s_add_jar(VALUE self, VALUE jarname)
2568
2568
  }
2569
2569
  if (!url_loader)
2570
2570
  {
2571
- args[0].l = (*jenv)->NewObjectArray(jenv, (count == 0) ? 1 : count, j_url, NULL);
2571
+ args[0].l = (*jenv)->NewObjectArray(jenv, (jsize)((count == 0) ? 1 : count), j_url, NULL);
2572
2572
  rjb_check_exception(jenv, 0);
2573
2573
  if (!count)
2574
2574
  {
@@ -2578,7 +2578,7 @@ static VALUE rjb_s_add_jar(VALUE self, VALUE jarname)
2578
2578
  else
2579
2579
  {
2580
2580
  for (i = 0; i < count; i++) {
2581
- (*jenv)->SetObjectArrayElement(jenv, args[0].l, i,
2581
+ (*jenv)->SetObjectArrayElement(jenv, args[0].l, (jint)i,
2582
2582
  conv_jarname_to_url(jenv, rb_ary_entry(jarname, i)));
2583
2583
  }
2584
2584
  }
data/lib/rjb.rb CHANGED
@@ -1,10 +1,23 @@
1
1
  =begin
2
- Copyright(c) 2006-2010 arton
2
+ Copyright(c) 2006-2010,2012 arton
3
3
  =end
4
4
 
5
5
  require 'rbconfig'
6
6
 
7
7
  module RjbConf
8
+ if /darwin/ =~ RUBY_PLATFORM
9
+ if ENV['JVM_LIB'].nil? || ENV['JVM_LIB'] == ''
10
+ if ENV['JAVA_HOME'].nil? || ENV['JAVA_HOME'] == ''
11
+ jvms = Dir.glob("#{`/usr/libexec/java_home`.strip}/**/libjvm.dylib")
12
+ else
13
+ jvms = Dir.glob("#{ENV['JAVA_HOME']}/**/libjvm.dylib")
14
+ end
15
+ if jvms.size > 0
16
+ ENV['JVM_LIB'] = jvms[0]
17
+ end
18
+ end
19
+ end
20
+
8
21
  dir = File.join(File.dirname(File.dirname(__FILE__)), 'data')
9
22
  if File.exist?(dir)
10
23
  datadir = dir
@@ -0,0 +1,9 @@
1
+ # coding: utf-8
2
+ begin
3
+ require 'rjb'
4
+ rescue LoadError
5
+ require 'rubygems'
6
+ require 'rjb'
7
+ end
8
+ S = Rjb::import('java.lang.System')
9
+ puts "#{S.property('java.vendor')} #{S.property('java.version')}"
@@ -0,0 +1,64 @@
1
+ # coding: utf-8
2
+
3
+ require 'rbconfig'
4
+ require 'test/unit'
5
+
6
+ class TestOSXLoad < Test::Unit::TestCase
7
+ def setup
8
+ ENV['JAVA_HOME'] = ''
9
+ ENV['JVM_LIB'] = ''
10
+ @testprog = File.dirname($0) + File::SEPARATOR + 'osx_jvmcheck.rb'
11
+ end
12
+
13
+ def test_no_java_home
14
+ skip "no meaning test except for OSX" unless /darwin/ =~ RUBY_PLATFORM
15
+
16
+ javahome = `/usr/libexec/java_home`
17
+ if javahome =~ /jdk1\.[7-8]\.0/
18
+ vendor = /Oracle/
19
+ version = /1\.[7-8]\.0/
20
+ else
21
+ vendor = /Apple/
22
+ version = /1\.[4-6]\.0/
23
+ end
24
+ test = `#{RbConfig.ruby} #{@testprog}`
25
+ assert test =~ vendor, expected(vendor, test)
26
+ assert test =~ version, expected(version, test)
27
+ end
28
+
29
+ def test_apple_jvm
30
+ skip "no meaning test except for OSX" unless /darwin/ =~ RUBY_PLATFORM
31
+
32
+ test_specific_jvm('/System/Library/Frameworks/JavaVM.framework/Home',
33
+ /Apple/)
34
+ end
35
+
36
+ def test_oracle_jvm
37
+ skip "no meaning test except for OSX" unless /darwin/ =~ RUBY_PLATFORM
38
+
39
+ test_specific_jvm('/Library/Java/JavaVirtualMachines/***/Contents/Home',
40
+ /Oracle/)
41
+ end
42
+
43
+ def test_withjvmlib
44
+ skip "no meaning test except for OSX" unless /darwin/ =~ RUBY_PLATFORM
45
+
46
+ ENV['JVM_LIB'] = '/usr/lib/libc.dylib'
47
+ test = `#{RbConfig.ruby} #{@testprog}`.strip
48
+ assert test == '', "no exception but #{test}"
49
+ end
50
+
51
+ private
52
+ def test_specific_jvm(path, vendor)
53
+ jvms = Dir.glob(path)
54
+ skip "no #{vendor.inspect} jvm" if jvms.size == 0
55
+ ENV['JAVA_HOME'] = jvms[0]
56
+ test = `#{RbConfig.ruby} #{@testprog}`.strip
57
+ assert test =~ vendor, expected(vendor, test)
58
+ end
59
+
60
+ def expected(test, target)
61
+ "expected #{test.inspect} but #{target}"
62
+ end
63
+ end
64
+
metadata CHANGED
@@ -1,29 +1,26 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rjb
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.2
4
5
  prerelease:
5
- version: 1.4.1
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - arton
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2012-08-18 00:00:00 Z
12
+ date: 2012-10-06 00:00:00.000000000 Z
14
13
  dependencies: []
14
+ description: ! 'RJB is a bridge program that connect between Ruby and Java with Java
15
+ Native Interface.
15
16
 
16
- description: |
17
- RJB is a bridge program that connect between Ruby and Java with Java Native Interface.
18
-
17
+ '
19
18
  email: artonx@gmail.com
20
19
  executables: []
21
-
22
- extensions:
20
+ extensions:
23
21
  - ext/extconf.rb
24
22
  extra_rdoc_files: []
25
-
26
- files:
23
+ files:
27
24
  - ext/RBridge.java
28
25
  - ext/rjbexception.c
29
26
  - ext/rjb.c
@@ -45,6 +42,8 @@ files:
45
42
  - test/test_osxjvm.rb
46
43
  - test/test.rb
47
44
  - test/exttest.rb
45
+ - test/test_osxload.rb
46
+ - test/osx_jvmcheck.rb
48
47
  - test/jartest2.rb
49
48
  - test/jartest3.rb
50
49
  - test/test_unload.rb
@@ -66,25 +65,23 @@ files:
66
65
  - ext/extconf.rb
67
66
  homepage: http://rjb.rubyforge.org/
68
67
  licenses: []
69
-
70
68
  post_install_message:
71
69
  rdoc_options: []
72
-
73
- require_paths:
70
+ require_paths:
74
71
  - lib
75
- required_ruby_version: !ruby/object:Gem::Requirement
72
+ required_ruby_version: !ruby/object:Gem::Requirement
76
73
  none: false
77
- requirements:
78
- - - ">="
79
- - !ruby/object:Gem::Version
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
80
77
  version: 1.8.2
81
- required_rubygems_version: !ruby/object:Gem::Requirement
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
79
  none: false
83
- requirements:
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- version: "0"
87
- requirements:
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements:
88
85
  - none
89
86
  - JDK 5.0
90
87
  rubyforge_project: rjb
@@ -92,5 +89,5 @@ rubygems_version: 1.8.23
92
89
  signing_key:
93
90
  specification_version: 3
94
91
  summary: Ruby Java bridge
95
- test_files:
92
+ test_files:
96
93
  - test/test.rb