ruboto 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/README.md +13 -49
  2. data/Rakefile +26 -26
  3. data/assets/rakelib/ruboto.rake +29 -9
  4. data/assets/res/drawable-hdpi/{icon.png → ic_launcher.png} +0 -0
  5. data/assets/res/drawable-ldpi/{icon.png → ic_launcher.png} +0 -0
  6. data/assets/res/drawable-mdpi/{icon.png → ic_launcher.png} +0 -0
  7. data/assets/samples/sample_activity.rb +19 -9
  8. data/assets/samples/sample_broadcast_receiver.rb +3 -1
  9. data/assets/samples/sample_service.rb +9 -9
  10. data/assets/src/InheritingActivity.java +1 -1
  11. data/assets/src/InheritingBroadcastReceiver.java +4 -4
  12. data/assets/src/InheritingClass.java +1 -1
  13. data/assets/src/InheritingService.java +2 -1
  14. data/assets/src/RubotoActivity.java +26 -17
  15. data/assets/src/RubotoBroadcastReceiver.java +32 -11
  16. data/assets/src/RubotoService.java +23 -13
  17. data/assets/src/org/ruboto/EntryPointActivity.java +18 -26
  18. data/assets/src/org/ruboto/JRubyAdapter.java +468 -0
  19. data/assets/src/org/ruboto/Log.java +22 -0
  20. data/assets/src/org/ruboto/Script.java +113 -587
  21. data/assets/src/org/ruboto/test/ActivityTest.java +7 -7
  22. data/assets/src/org/ruboto/test/InstrumentationTestRunner.java +27 -12
  23. data/assets/src/ruboto.rb +1 -1
  24. data/assets/src/ruboto/activity.rb +10 -1
  25. data/assets/src/ruboto/base.rb +0 -12
  26. data/assets/src/ruboto/broadcast_receiver.rb +12 -0
  27. data/assets/src/ruboto/menu.rb +0 -1
  28. data/assets/src/ruboto/package.rb +11 -0
  29. data/assets/src/ruboto/service.rb +9 -0
  30. data/lib/ruboto/commands/base.rb +1 -1
  31. data/lib/ruboto/util/build.rb +1 -1
  32. data/lib/ruboto/util/update.rb +35 -27
  33. data/lib/ruboto/util/xml_element.rb +25 -12
  34. data/lib/ruboto/version.rb +2 -2
  35. data/test/activity/image_button_activity.rb +14 -11
  36. data/test/activity/image_button_activity_test.rb +2 -6
  37. data/test/activity/image_button_and_button_activity.rb +15 -17
  38. data/test/activity/image_button_and_button_activity_test.rb +4 -8
  39. data/test/activity/option_menu_activity.rb +17 -12
  40. data/test/activity/option_menu_activity_test.rb +1 -4
  41. data/test/activity/psych_activity.rb +20 -13
  42. data/test/activity/psych_activity_test.rb +3 -1
  43. data/test/activity/stack_activity.rb +17 -14
  44. data/test/activity/stack_activity_test.rb +13 -12
  45. data/test/app_test_methods.rb +25 -19
  46. data/test/block_def_activity/image_button_activity.rb +23 -0
  47. data/test/block_def_activity/image_button_activity_test.rb +21 -0
  48. data/test/block_def_activity/image_button_and_button_activity.rb +20 -0
  49. data/test/block_def_activity/image_button_and_button_activity_test.rb +27 -0
  50. data/test/block_def_activity/option_menu_activity.rb +26 -0
  51. data/test/block_def_activity/option_menu_activity_test.rb +18 -0
  52. data/test/block_def_activity/psych_activity.rb +35 -0
  53. data/test/block_def_activity/psych_activity_test.rb +16 -0
  54. data/test/block_def_activity/stack_activity.rb +25 -0
  55. data/test/block_def_activity/stack_activity_test.rb +31 -0
  56. data/test/broadcast_receiver_test.rb +2 -2
  57. data/test/handle_activity/image_button_activity.rb +21 -0
  58. data/test/handle_activity/image_button_activity_test.rb +21 -0
  59. data/test/handle_activity/image_button_and_button_activity.rb +24 -0
  60. data/test/handle_activity/image_button_and_button_activity_test.rb +27 -0
  61. data/test/handle_activity/option_menu_activity.rb +21 -0
  62. data/test/handle_activity/option_menu_activity_test.rb +20 -0
  63. data/test/handle_activity/psych_activity.rb +31 -0
  64. data/test/handle_activity/psych_activity_test.rb +16 -0
  65. data/test/handle_activity/stack_activity.rb +21 -0
  66. data/test/handle_activity/stack_activity_test.rb +32 -0
  67. data/test/minimal_app_test.rb +4 -4
  68. data/test/rake_test.rb +15 -1
  69. data/test/ruboto_gen_test.rb +7 -4
  70. data/test/service_test.rb +110 -21
  71. data/test/test_helper.rb +17 -14
  72. data/test/updated_example_test_methods.rb +5 -14
  73. metadata +30 -7
@@ -13,7 +13,7 @@ import junit.framework.AssertionFailedError;
13
13
  import junit.framework.Test;
14
14
  import junit.framework.TestResult;
15
15
  import junit.framework.TestSuite;
16
- import org.ruboto.Script;
16
+ import org.ruboto.JRubyAdapter;
17
17
 
18
18
  public class ActivityTest extends ActivityInstrumentationTestCase2 {
19
19
  private final Object setup;
@@ -38,16 +38,16 @@ public class ActivityTest extends ActivityInstrumentationTestCase2 {
38
38
  Log.i(getClass().getName(), "Activity OK");
39
39
  Runnable testRunnable = new Runnable() {
40
40
  public void run() {
41
- String oldFile = Script.getScriptFilename();
41
+ String oldFile = JRubyAdapter.getScriptFilename();
42
42
 
43
43
  Log.i(getClass().getName(), "calling setup");
44
- Script.setScriptFilename(filename);
45
- Script.callMethod(setup, "call", activity);
44
+ JRubyAdapter.setScriptFilename(filename);
45
+ JRubyAdapter.callMethod(setup, "call", activity);
46
46
  Log.i(getClass().getName(), "setup ok");
47
47
 
48
- Script.setScriptFilename(filename);
49
- Script.callMethod(block, "call", activity);
50
- Script.setScriptFilename(oldFile);
48
+ JRubyAdapter.setScriptFilename(filename);
49
+ JRubyAdapter.callMethod(block, "call", activity);
50
+ JRubyAdapter.setScriptFilename(oldFile);
51
51
  }
52
52
  };
53
53
  if (onUiThread) {
@@ -24,7 +24,7 @@ import java.util.Map;
24
24
  import junit.framework.Test;
25
25
  import junit.framework.TestCase;
26
26
  import junit.framework.TestSuite;
27
- import org.ruboto.Script;
27
+ import org.ruboto.JRubyAdapter;
28
28
  import java.util.Set;
29
29
  import java.util.HashSet;
30
30
 
@@ -45,7 +45,7 @@ public class InstrumentationTestRunner extends android.test.InstrumentationTestR
45
45
  // TODO(uwe): Simplify when we stop support for JRuby 1.7.0 or android-10
46
46
  Thread t = new Thread(null, new Runnable() {
47
47
  public void run() {
48
- JRubyLoadedOk.set(Script.setUpJRuby(getTargetContext()));
48
+ JRubyLoadedOk.set(JRubyAdapter.setUpJRuby(getTargetContext()));
49
49
  }
50
50
  }, "Setup JRuby from instrumentation test runner", 64 * 1024);
51
51
  try {
@@ -59,9 +59,24 @@ public class InstrumentationTestRunner extends android.test.InstrumentationTestR
59
59
 
60
60
  if (JRubyLoadedOk.get()) {
61
61
  loadStep = "Setup global variables";
62
- Script.defineGlobalVariable("$runner", this);
63
- Script.defineGlobalVariable("$test", this);
64
- Script.defineGlobalVariable("$suite", suite);
62
+
63
+ // TODO(uwe): Running with large stack is currently only needed when running with JRuby 1.7.0 and android-10
64
+ // TODO(uwe): Simplify when we stop support for JRuby 1.7.0 or android-10
65
+ Thread t2 = new Thread(null, new Runnable() {
66
+ public void run() {
67
+ JRubyAdapter.put("$runner", InstrumentationTestRunner.this);
68
+ JRubyAdapter.put("$test", InstrumentationTestRunner.this);
69
+ JRubyAdapter.put("$suite", suite);
70
+ }
71
+ }, "Setup JRuby from instrumentation test runner", 64 * 1024);
72
+ try {
73
+ t2.start();
74
+ t2.join();
75
+ } catch(InterruptedException ie) {
76
+ Thread.currentThread().interrupt();
77
+ throw new RuntimeException("Interrupted starting JRuby", ie);
78
+ }
79
+ // TODO end
65
80
 
66
81
  loadStep = "Load test helper";
67
82
  loadScript("test_helper.rb");
@@ -114,7 +129,7 @@ public class InstrumentationTestRunner extends android.test.InstrumentationTestR
114
129
 
115
130
  boolean runOnUiThread = options == null || options.get("ui") == "true";
116
131
 
117
- Test test = new ActivityTest(activityClass, Script.getScriptFilename(), setup, name, runOnUiThread, block);
132
+ Test test = new ActivityTest(activityClass, JRubyAdapter.getScriptFilename(), setup, name, runOnUiThread, block);
118
133
  suite.addTest(test);
119
134
  Log.d(getClass().getName(), "Made test instance: " + test);
120
135
  }
@@ -147,12 +162,12 @@ public class InstrumentationTestRunner extends android.test.InstrumentationTestR
147
162
  }
148
163
  buffer.close();
149
164
 
150
- String oldFilename = Script.getScriptFilename();
151
- Script.setScriptFilename(f);
152
- Script.put("$script_code", source.toString());
153
- Script.setScriptFilename(f);
154
- Script.execute("$test.instance_eval($script_code)");
155
- Script.setScriptFilename(oldFilename);
165
+ String oldFilename = JRubyAdapter.getScriptFilename();
166
+ JRubyAdapter.setScriptFilename(f);
167
+ JRubyAdapter.put("$script_code", source.toString());
168
+ JRubyAdapter.setScriptFilename(f);
169
+ JRubyAdapter.execute("$test.instance_eval($script_code)");
170
+ JRubyAdapter.setScriptFilename(oldFilename);
156
171
  Log.d(getClass().getName(), "Test script " + f + " loaded");
157
172
  }
158
173
 
data/assets/src/ruboto.rb CHANGED
@@ -12,6 +12,7 @@
12
12
  #
13
13
  #######################################################
14
14
 
15
+ require 'ruboto/base'
15
16
  require 'ruboto/activity'
16
17
  require 'ruboto/service'
17
18
  require 'ruboto/broadcast_receiver'
@@ -21,4 +22,3 @@ require 'ruboto/menu'
21
22
  require 'ruboto/util/stack'
22
23
  require 'ruboto/util/toast'
23
24
  require 'ruboto/legacy'
24
-
@@ -1,4 +1,5 @@
1
1
  require 'ruboto/base'
2
+ require 'ruboto/package'
2
3
 
3
4
  #######################################################
4
5
  #
@@ -31,7 +32,7 @@ module Ruboto
31
32
  start_ruboto_activity(remote_variable, RubotoDialog, theme, &block)
32
33
  end
33
34
 
34
- def start_ruboto_activity(global_variable_name, klass=RubotoActivity, theme=nil, &block)
35
+ def start_ruboto_activity(global_variable_name = '$activity', klass=RubotoActivity, theme=nil, &block)
35
36
  $context_init_block = block
36
37
  $new_context_global = global_variable_name
37
38
 
@@ -65,6 +66,14 @@ end
65
66
 
66
67
  module Ruboto
67
68
  module Activity
69
+ def initialize(java_instance)
70
+ @java_instance = java_instance
71
+ end
72
+
73
+ def method_missing(method, *args, &block)
74
+ return @java_instance.send(method, *args, &block) if @java_instance.respond_to?(method)
75
+ super
76
+ end
68
77
  end
69
78
  end
70
79
 
@@ -17,9 +17,6 @@ end
17
17
 
18
18
  require 'java'
19
19
 
20
- $package_name = ($activity || $service || $broadcast_receiver).package_name
21
- $package = eval("Java::#{$package_name}")
22
-
23
20
  # Create convenience method for top-level android package so we do not need to prefix with 'Java::'.
24
21
  module Kernel
25
22
  def android
@@ -28,15 +25,6 @@ module Kernel
28
25
  end
29
26
 
30
27
  java_import "android.R"
31
-
32
- module Ruboto
33
- java_import "#{$package_name}.R"
34
- begin
35
- Id = JavaUtilities.get_proxy_class("#{$package_name}.R$id")
36
- rescue NameError
37
- Java::android.util.Log.d "RUBOTO", "no R$id"
38
- end
39
- end
40
28
  AndroidIds = JavaUtilities.get_proxy_class("android.R$id")
41
29
 
42
30
  #
@@ -29,3 +29,15 @@ RubotoBroadcastReceiver.class_eval do
29
29
  end
30
30
  end
31
31
 
32
+ module Ruboto
33
+ module BroadcastReceiver
34
+ def initialize(java_instance)
35
+ @java_instance = java_instance
36
+ end
37
+
38
+ def method_missing(method, *args, &block)
39
+ return @java_instance.send(method, *args, &block) if @java_instance.respond_to?(method)
40
+ super
41
+ end
42
+ end
43
+ end
@@ -34,7 +34,6 @@ module Ruboto
34
34
 
35
35
  p = Proc.new do |num, menu_item|
36
36
  # handles a problem where this is called for context items
37
- # TODO(uwe): JRUBY-5866 JRuby can't access nested Java class if the class is called 'id'
38
37
  # TODO(uwe): Remove check for SDK version when we stop supporting api level < 11
39
38
  unless @just_processed_context_item == menu_item || (android.os.Build::VERSION::SDK_INT >= 11 && menu_item.item_id == AndroidIds.home)
40
39
  instance_eval &(menu_item.on_click)
@@ -0,0 +1,11 @@
1
+ $package_name = ($activity || $service).package_name
2
+ $package = eval("Java::#{$package_name}")
3
+
4
+ module Ruboto
5
+ java_import "#{$package_name}.R"
6
+ begin
7
+ Id = JavaUtilities.get_proxy_class("#{$package_name}.R$id")
8
+ rescue NameError
9
+ Java::android.util.Log.d "RUBOTO", "no R$id"
10
+ end
11
+ end
@@ -1,4 +1,5 @@
1
1
  require 'ruboto/base'
2
+ require 'ruboto/package'
2
3
 
3
4
  #######################################################
4
5
  #
@@ -53,6 +54,14 @@ end
53
54
 
54
55
  module Ruboto
55
56
  module Service
57
+ def initialize(java_instance)
58
+ @java_instance = java_instance
59
+ end
60
+
61
+ def method_missing(method, *args, &block)
62
+ return @java_instance.send(method, *args, &block) if @java_instance.respond_to?(method)
63
+ super
64
+ end
56
65
  end
57
66
  end
58
67
 
@@ -346,10 +346,10 @@ module Ruboto
346
346
  update_test force
347
347
  update_assets
348
348
  update_ruboto force
349
- update_icons force
350
349
  update_classes force
351
350
  update_jruby force
352
351
  update_manifest nil, nil, force
352
+ update_icons force
353
353
  update_core_classes "exclude"
354
354
  update_bundle
355
355
  when "jruby" then
@@ -165,7 +165,7 @@ module Ruboto
165
165
  text = File.read(File.join(Ruboto::ASSETS, "src/Inheriting#{klass}.java"))
166
166
  file_existed = File.exists?(file)
167
167
  File.open(file, 'w') do |f|
168
- f << text.gsub("THE_PACKAGE", package).gsub("Inheriting#{klass}", name).gsub("start.rb", script_name)
168
+ f << text.gsub("THE_PACKAGE", package).gsub("Sample#{klass}", name).gsub("Inheriting#{klass}", name).gsub("sample_#{underscore(klass)}.rb", script_name)
169
169
  end
170
170
  puts "#{file_existed ? 'Updated' : 'Added'} file #{file}."
171
171
 
@@ -17,15 +17,15 @@ module Ruboto
17
17
  name = REXML::Document.new(File.read(build_xml_file)).root.attributes['name']
18
18
 
19
19
  # FIXME(uwe): Remove build.xml file to force regeneration.
20
- # FIXME(uwe): Needed when updating from Android SDK <= 13 to 14
21
- # FIXME(uwe): Remove when we stop supporting upgrading from Android SDK <= 13
20
+ # FIXME(uwe): Needed when updating apps from Android SDK <= 13 to 14
21
+ # FIXME(uwe): Remove when we stop supporting upgrading apps from Android SDK <= 13
22
22
  if File.read(build_xml_file) !~ /<!-- version-tag: 1 -->/
23
23
  puts "Forcing generation of new build.xml since upgrading a project generated with Android SDK 13 or older."
24
24
  FileUtils.rm_f build_xml_file
25
25
  end
26
26
  # FIXME end
27
27
 
28
- # FIXME(uwe): Simplify when we stop supporting upgrading from Android ASK <= 13
28
+ # FIXME(uwe): Simplify when we stop supporting upgrading apps from Android SDK <= 13
29
29
  prop_file = File.exists?(new_prop_file) ? new_prop_file : old_prop_file
30
30
  version_regexp = /^(target=android-)(\d+)$/
31
31
  if (project_property_file = File.read(prop_file)) =~ version_regexp
@@ -50,7 +50,7 @@ module Ruboto
50
50
  puts "Done"
51
51
  else
52
52
  # FIXME(uwe): Remove build.xml file to force regeneration.
53
- # FIXME(uwe): Needed when updating from Android SDK <=13 to 14
53
+ # FIXME(uwe): Needed when updating apps from Android SDK <= 13 to 14
54
54
  FileUtils.rm_f "#{root}/test/build.xml"
55
55
  # FIXME end
56
56
 
@@ -61,7 +61,7 @@ module Ruboto
61
61
 
62
62
  Dir.chdir File.join(root, 'test') do
63
63
  test_manifest = REXML::Document.new(File.read('AndroidManifest.xml')).root
64
- test_manifest.elements['application'].attributes['android:icon'] = '@drawable/icon'
64
+ test_manifest.elements['application'].attributes['android:icon'] ||= '@drawable/ic_launcher'
65
65
  test_manifest.elements['instrumentation'].attributes['android:name'] = 'org.ruboto.test.InstrumentationTestRunner'
66
66
 
67
67
  # TODO(uwe): Trying to push test scripts for faster test cycle, but failing...
@@ -81,7 +81,7 @@ module Ruboto
81
81
  File.open("AndroidManifest.xml", 'w') { |f| test_manifest.document.write(f, 4) }
82
82
  instrumentation_property = "test.runner=org.ruboto.test.InstrumentationTestRunner\n"
83
83
 
84
- # FIXME(uwe): Cleanup when we stop supporting Android SDK <= 13
84
+ # FIXME(uwe): Cleanup when we stop supporting updating apps generated with Android SDK <= 13
85
85
  prop_file = %w{ant.properties build.properties}.find { |f| File.exists?(f) }
86
86
  prop_lines = File.readlines(prop_file)
87
87
  File.open(prop_file, 'a') { |f| f << instrumentation_property } unless prop_lines.include?(instrumentation_property)
@@ -119,7 +119,7 @@ module Ruboto
119
119
  <contains string="${tests.output}" substring="INSTRUMENTATION_FAILED"/>
120
120
  <contains string="${tests.output}" substring="FAILURES"/>
121
121
  <not>
122
- <matches string="${tests.output}" pattern="OK \\(\\d+ tests\\)" multiline="true"/>
122
+ <matches string="${tests.output}" pattern="OK \\(\\d+ tests?\\)" multiline="true"/>
123
123
  </not>
124
124
  </or>
125
125
  </condition>
@@ -190,7 +190,7 @@ module Ruboto
190
190
  log_action("Copying #{JRubyJars::stdlib_jar_path} to libs") { copier.copy_from_absolute_path JRubyJars::stdlib_jar_path, "libs" }
191
191
 
192
192
  # FIXME(uwe): Try keeping the class count low to enable installation on Android 2.3 devices
193
- unless new_jruby_version == '1.7.0.dev' && verify_target_sdk < 15
193
+ unless new_jruby_version =~ /^1.7.0/ && verify_target_sdk < 15
194
194
  log_action("Copying dexmaker.jar to libs") { copier.copy 'libs' }
195
195
  end
196
196
 
@@ -228,11 +228,23 @@ module Ruboto
228
228
  end
229
229
 
230
230
  def update_icons(force = nil)
231
- copier = Ruboto::Util::AssetCopier.new Ruboto::ASSETS, '.', force
232
- log_action('icons') do
233
- copier.copy 'res/drawable*/icon.png'
234
- copier.copy 'res/drawable/get_ruboto_core.png'
235
- copier.copy 'res/drawable*/icon.png', 'test'
231
+ log_action('Copying icons') do
232
+ Ruboto::Util::AssetCopier.new(Ruboto::ASSETS, '.', force).copy 'res/drawable/get_ruboto_core.png'
233
+ icon_path = verify_manifest.elements['application'].attributes['android:icon']
234
+ test_icon_path = verify_test_manifest.elements['application'].attributes['android:icon']
235
+ Dir["#{Ruboto::ASSETS}/res/drawable*/ic_launcher.png"].each do |f|
236
+ src_dir = f.slice(/res\/drawable.*\//)
237
+ dest_file = icon_path.sub('@drawable/', src_dir) + '.png'
238
+ if force || !File.exists?(dest_file)
239
+ FileUtils.mkdir_p File.dirname(dest_file)
240
+ FileUtils.cp(f, dest_file)
241
+ end
242
+ test_dest_file = 'test/' + test_icon_path.sub('@drawable/', src_dir) + '.png'
243
+ if force || !File.exists?(test_dest_file)
244
+ FileUtils.mkdir_p File.dirname(test_dest_file)
245
+ FileUtils.cp(f, test_dest_file)
246
+ end
247
+ end
236
248
  end
237
249
  end
238
250
 
@@ -251,14 +263,17 @@ module Ruboto
251
263
  script_file = File.expand_path("#{SCRIPTS_DIR}/#{underscore(subclass_name)}.rb")
252
264
  script_content = File.read(script_file)
253
265
  if script_content !~ /\$broadcast_receiver.handle_receive do \|context, intent\|/ &&
254
- script_content !~ /RubotoBroadcastReceiver.new_with_callbacks/
266
+ script_content !~ /RubotoBroadcastReceiver.new_with_callbacks/ &&
267
+ script_content !~ /class \w+\s+include Ruboto::BroadcastReceiver/
255
268
  puts "Putting receiver script in a block in #{script_file}"
256
269
  script_content.gsub! '$broadcast_context', 'context'
257
270
  File.open(script_file, 'w') do |of|
258
- of.puts 'RubotoBroadcastReceiver.new_with_callbacks do
259
- def on_receive(context, intent)'
271
+ of.puts "class #{subclass_name}
272
+ include Ruboto::BroadcastReceiver
273
+
274
+ def on_receive(context, intent)"
260
275
  of << script_content
261
- of.puts 'end'
276
+ of.puts ' end\nend'
262
277
  end
263
278
  end
264
279
  end
@@ -287,7 +302,7 @@ module Ruboto
287
302
  end
288
303
 
289
304
  app_element = verify_manifest.elements['application']
290
- app_element.attributes['android:icon'] ||= '@drawable/icon'
305
+ app_element.attributes['android:icon'] ||= '@drawable/ic_launcher'
291
306
 
292
307
  if min_sdk.to_i >= 11
293
308
  app_element.attributes['android:hardwareAccelerated'] ||= 'true'
@@ -431,13 +446,6 @@ module Ruboto
431
446
  'org/jruby/runtime/invokedynamic',
432
447
  ]
433
448
  # TODO end
434
-
435
- # TODO(uwe): Remove when we stop supporting jruby-jars-1.6.2
436
- if jruby_core_version == '1.6.2'
437
- print 'Retaining FFI for JRuby 1.6.2...'
438
- excluded_core_packages.delete('org/jruby/ext/ffi')
439
- end
440
- # TODO end
441
449
  end
442
450
 
443
451
  excluded_core_packages.each do |i|
@@ -447,7 +455,7 @@ module Ruboto
447
455
  # FIXME(uwe): Add a Ruboto.yml config for this if it works
448
456
  # Reduces the installation footprint, but also reduces performance and stack usage
449
457
  # FIXME(uwe): Measure the performance change
450
- if false && jruby_core_version == '1.7.0.dev' && Dir.chdir('../..'){verify_target_sdk < 15}
458
+ if false && jruby_core_version =~ /^1.7.0/ && Dir.chdir('../..'){verify_target_sdk < 15}
451
459
  invokers = Dir['**/*${INVOKER$*,POPULATOR}.class']
452
460
  log_action("Removing invokers & populators(#{invokers.size})") do
453
461
  FileUtils.rm invokers
@@ -489,7 +497,7 @@ module Ruboto
489
497
  # TODO(uwe): Simplify when we stop supporting JRuby < 1.7.0
490
498
  raise "Unrecognized JRuby stdlib jar: #{jruby_stdlib}" unless jruby_stdlib =~ /jruby-stdlib-(.*).jar/
491
499
  jruby_version = Gem::Version.new($1)
492
- if Gem::Requirement.new('< 1.7.0.dev') =~ jruby_version
500
+ if Gem::Requirement.new('< 1.7.0.preview1') =~ jruby_version
493
501
  lib_dirs = ['1.8', '1.9', 'site_ruby/1.8', 'site_ruby/1.9', 'site_ruby/shared']
494
502
  else
495
503
  lib_dirs = ['1.8', '1.9', 'shared']
@@ -151,9 +151,7 @@ module Ruboto
151
151
  rv ? "return #{rv}" : default_return
152
152
  end
153
153
 
154
- def ruby_call
155
- rv = []
156
-
154
+ def ruby_call(on_ruby_instance = false, camelize = false)
157
155
  params = parameters
158
156
  args = ""
159
157
  if params.size > 1
@@ -176,19 +174,34 @@ module Ruboto
176
174
  convert_return = ", #{return_class}.class"
177
175
  end
178
176
 
179
- rv << "#{return_cast}Script.callMethod(callbackProcs[#{constant_string}], \"call\" #{args}#{convert_return});"
180
- rv
177
+ if on_ruby_instance
178
+ ["#{return_cast}JRubyAdapter.callMethod(rubyInstance, \"#{camelize ? attribute("name") : snake_case_attribute}\" #{args}#{convert_return});"]
179
+ else
180
+ ["#{return_cast}JRubyAdapter.callMethod(callbackProcs[#{constant_string}], \"call\" #{args}#{convert_return});"]
181
+ end
182
+ end
183
+
184
+ def snake_case_attribute
185
+ attribute("name").gsub(/[A-Z]/) { |i| "_#{i}" }.downcase
181
186
  end
182
187
 
183
188
  def method_definition
184
189
  method_call(
185
- (attribute("return") ? attribute("return") : "void"),
186
- attribute("name"), parameters,
187
- if_else(
188
- "callbackProcs != null && callbackProcs[#{constant_string}] != null",
189
- [super_string] + ruby_call,
190
- [super_return]
191
- )
190
+ (attribute("return") ? attribute("return") : "void"),
191
+ attribute("name"), parameters,
192
+ if_else(
193
+ "rubyInstance != null && JRubyAdapter.callMethod(rubyInstance, \"respond_to?\" , new Object[]{\""+ snake_case_attribute + "\"}, Boolean.class)",
194
+ [super_string] + ruby_call(true),
195
+ if_else(
196
+ "rubyInstance != null && JRubyAdapter.callMethod(rubyInstance, \"respond_to?\" , new Object[]{\""+ attribute("name") +"\"}, Boolean.class)",
197
+ [super_string] + ruby_call(true, true),
198
+ if_else(
199
+ "callbackProcs != null && callbackProcs[#{constant_string}] != null",
200
+ [super_string] + ruby_call,
201
+ [super_return]
202
+ )
203
+ )
204
+ )
192
205
  ).indent.join("\n")
193
206
  end
194
207