ruboto 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/Gemfile.lock +9 -9
  2. data/README.md +2 -0
  3. data/Rakefile +71 -7
  4. data/assets/Rakefile +2 -407
  5. data/assets/libs/dexmaker20120305.jar +0 -0
  6. data/assets/rakelib/ruboto.rake +428 -0
  7. data/assets/samples/sample_broadcast_receiver.rb +7 -3
  8. data/assets/samples/sample_broadcast_receiver_test.rb +47 -1
  9. data/assets/src/RubotoActivity.java +6 -2
  10. data/assets/src/org/ruboto/EntryPointActivity.java +2 -2
  11. data/assets/src/org/ruboto/Script.java +91 -24
  12. data/assets/src/org/ruboto/test/ActivityTest.java +27 -24
  13. data/assets/src/org/ruboto/test/InstrumentationTestRunner.java +42 -8
  14. data/assets/src/ruboto/activity.rb +1 -1
  15. data/assets/src/ruboto/base.rb +17 -6
  16. data/assets/src/ruboto/generate.rb +458 -0
  17. data/assets/src/ruboto/legacy.rb +9 -12
  18. data/assets/src/ruboto/widget.rb +9 -1
  19. data/lib/java_class_gen/android_api.xml +1 -1
  20. data/lib/ruboto.rb +1 -2
  21. data/lib/ruboto/commands/base.rb +19 -4
  22. data/lib/ruboto/sdk_versions.rb +12 -0
  23. data/lib/ruboto/util/build.rb +10 -11
  24. data/lib/ruboto/util/update.rb +150 -51
  25. data/lib/ruboto/util/verify.rb +6 -4
  26. data/lib/ruboto/util/xml_element.rb +2 -2
  27. data/lib/ruboto/version.rb +1 -1
  28. data/test/activity/option_menu_activity.rb +5 -1
  29. data/test/activity/psych_activity.rb +11 -6
  30. data/test/activity/stack_activity_test.rb +13 -5
  31. data/test/app_test_methods.rb +4 -3
  32. data/test/broadcast_receiver_test.rb +86 -0
  33. data/test/minimal_app_test.rb +27 -19
  34. data/test/rake_test.rb +13 -2
  35. data/test/ruboto_gen_test.rb +17 -3
  36. data/test/ruboto_update_test.rb +24 -2
  37. data/test/service_test.rb +1 -1
  38. data/test/test_helper.rb +134 -62
  39. data/test/update_test_methods.rb +40 -14
  40. data/test/updated_example_test_methods.rb +41 -0
  41. metadata +12 -6
@@ -10,9 +10,10 @@ module Ruboto
10
10
  #
11
11
 
12
12
  def verify_manifest
13
+ return @manifest if @manifest
13
14
  abort "cannot find your AndroidManifest.xml to extract info from it. Make sure you're in the root directory of your app" unless
14
15
  File.exists? 'AndroidManifest.xml'
15
- @manifest ||= REXML::Document.new(File.read('AndroidManifest.xml')).root
16
+ @manifest = REXML::Document.new(File.read('AndroidManifest.xml')).root
16
17
  end
17
18
 
18
19
  def save_manifest
@@ -54,10 +55,11 @@ module Ruboto
54
55
  end
55
56
 
56
57
  def verify_target_sdk
58
+ return @target_sdk if @target_sdk
57
59
  verify_sdk_versions
58
- @target_sdk ||= @uses_sdk.attribute('android:targetSdkVersion').value
59
- abort "you must specify a target sdk level in the manifest (e.g., <uses-sdk android:minSdkVersion='3' android:targetSdkVersion='8' />)" unless @target_sdk
60
- @target_sdk
60
+ target_sdk_attr ||= @uses_sdk.attribute('android:targetSdkVersion').value
61
+ abort "you must specify a target sdk level in the manifest (e.g., <uses-sdk android:minSdkVersion='3' android:targetSdkVersion='8' />)" unless target_sdk_attr
62
+ @target_sdk = target_sdk_attr.to_i
61
63
  end
62
64
 
63
65
  def verify_strings
@@ -185,7 +185,7 @@ module Ruboto
185
185
  (attribute("return") ? attribute("return") : "void"),
186
186
  attribute("name"), parameters,
187
187
  if_else(
188
- "callbackProcs[#{constant_string}] != null",
188
+ "callbackProcs != null && callbackProcs[#{constant_string}] != null",
189
189
  [super_string] + ruby_call,
190
190
  [super_return]
191
191
  )
@@ -197,4 +197,4 @@ module Ruboto
197
197
  end
198
198
  end
199
199
  end
200
- end
200
+ end
@@ -1,3 +1,3 @@
1
1
  module Ruboto
2
- VERSION = '0.5.4'
2
+ VERSION = '0.6.0'
3
3
  end
@@ -1,4 +1,8 @@
1
- require 'ruboto'
1
+ require 'ruboto/activity'
2
+ require 'ruboto/widget'
3
+ require 'ruboto/legacy'
4
+ require 'ruboto/menu'
5
+ require 'ruboto/util/toast'
2
6
 
3
7
  ruboto_import_widgets :ImageButton, :LinearLayout, :TextView
4
8
 
@@ -1,9 +1,14 @@
1
- require 'jruby'
2
- require 'rbconfig'
3
- org.jruby.ext.psych.PsychLibrary.new.load(JRuby.runtime, false)
4
- $LOADED_FEATURES << 'psych.so'
5
- $LOAD_PATH << File.join(Config::CONFIG['libdir'], 'ruby/1.9')
6
- require 'psych.rb'
1
+ # TODO(uwe): Remove when we stop supporting Ruby 1.8 mode
2
+ if RUBY_VERSION < "1.9"
3
+ require 'jruby'
4
+ require 'rbconfig'
5
+ org.jruby.ext.psych.PsychLibrary.new.load(JRuby.runtime, false)
6
+ $LOADED_FEATURES << 'psych.so'
7
+ $LOAD_PATH << File.join(Config::CONFIG['libdir'], 'ruby/1.9')
8
+ end
9
+ # TODO end
10
+
11
+ with_large_stack{require 'psych.rb'}
7
12
 
8
13
  Psych::Parser
9
14
  Psych::Handler
@@ -11,11 +11,19 @@ setup do |activity|
11
11
  end
12
12
 
13
13
  test('stack depth') do |activity|
14
- os_offset = {13 => 1}[android.os.Build::VERSION::SDK_INT].to_i
15
- jruby_offset = {
16
- '1.5.6' => [-2, -5, -6, -8],
17
- }[org.jruby.runtime.Constants::VERSION] || [0,0,0,0]
18
- version_message ="ANDROID: #{android.os.Build::VERSION::SDK_INT}, JRuby: #{org.jruby.runtime.Constants::VERSION}"
14
+ os_offset = {13 => 1, 15 => 1}[android.os.Build::VERSION::SDK_INT].to_i
15
+ if org.ruboto.Script.uses_platform_apk?
16
+ jruby_offset = {
17
+ '0.4.7' => [0, 0, 0, 0],
18
+ '0.4.8.dev' => [0, -1, -1, -1],
19
+ }[org.ruboto.Script.platform_version_name] || [0, 0, 0, 0]
20
+ else
21
+ jruby_offset = {
22
+ '1.5.6' => [-2, -5, -6, -8],
23
+ '1.7.0.dev' => [0, -1, -1, -1],
24
+ }[org.jruby.runtime.Constants::VERSION] || [0, 0, 0, 0]
25
+ end
26
+ version_message ="ANDROID: #{android.os.Build::VERSION::SDK_INT}, PLATFORM: #{org.ruboto.Script.uses_platform_apk ? org.ruboto.Script.platform_version_name : 'STANDALONE'}, JRuby: #{org.jruby.runtime.Constants::VERSION}"
19
27
  assert_equal 44 + os_offset + jruby_offset[0], activity.find_view_by_id(42).text.to_i, version_message
20
28
  assert_equal 68 + os_offset + jruby_offset[1], activity.find_view_by_id(43).text.to_i, version_message
21
29
  assert_equal 77 + os_offset + jruby_offset[2], activity.find_view_by_id(44).text.to_i, version_message
@@ -5,18 +5,19 @@ module AppTestMethods
5
5
 
6
6
  def test_activity_tests
7
7
  # TODO(uwe): Remove check when we stop supporting jruby-jars 1.5.6
8
- if ON_JRUBY_JARS_1_5_6
8
+ if Test::Unit::TestCase::ON_JRUBY_JARS_1_5_6
9
9
  puts "Skipping YAML tests on jruby-jars-1.5.6"
10
10
  else
11
11
  assert_code 'YamlLoads', "with_large_stack{require 'yaml'}"
12
12
  end
13
13
 
14
- assert_code 'ReadSourceFile', "File.read(__FILE__)"
14
+ assert_code 'ReadSourceFile', 'File.read(__FILE__)'
15
15
  assert_code 'DirListsFilesInApk', 'Dir["#{File.dirname(__FILE__)}/*"].each{|f| raise "File #{f.inspect} not found" unless File.exists?(f)}'
16
+ assert_code 'RepeatRubotoImport', 'ruboto_import :TextView ; ruboto_import :TextView'
16
17
 
17
18
  Dir[File.expand_path('activity/*_test.rb', File.dirname(__FILE__))].each do |test_src|
18
19
  # TODO(uwe): Remove check when we stop supporting jruby-jars 1.5.6
19
- next if ON_JRUBY_JARS_1_5_6 && test_src =~ /psych_activity_test.rb$/
20
+ next if Test::Unit::TestCase::ON_JRUBY_JARS_1_5_6 && test_src =~ /psych_activity_test.rb$/
20
21
 
21
22
  snake_name = test_src.chomp('_test.rb')
22
23
  activity_name = File.basename(snake_name).split('_').map { |s| "#{s[0..0].upcase}#{s[1..-1]}" }.join
@@ -0,0 +1,86 @@
1
+ require File.expand_path("test_helper", File.dirname(__FILE__))
2
+ require 'fileutils'
3
+
4
+ class BroadcastReceiverTest < Test::Unit::TestCase
5
+ SRC_DIR ="#{APP_DIR}/src"
6
+
7
+ def setup
8
+ generate_app
9
+ end
10
+
11
+ def teardown
12
+ cleanup_app
13
+ end
14
+
15
+ def test_generated_broadcast_receiver
16
+ action_name ='org.ruboto.example.click_broadcast'
17
+ message = 'Broadcast received!'
18
+ Dir.chdir APP_DIR do
19
+ activity_filename = 'src/ruboto_test_app_activity.rb'
20
+ activity_content = File.read(activity_filename)
21
+
22
+ assert activity_content.sub!(/ def on_create\(bundle\)\n/, <<EOF)
23
+ def on_create(bundle)
24
+ @receiver = $package.ClickReceiver.new
25
+ filter = android.content.IntentFilter.new('#{action_name}')
26
+ Thread.start do
27
+ begin
28
+ android.os.Looper.prepare
29
+ registerReceiver(@receiver, filter, nil, android.os.Handler.new)
30
+ android.os.Looper.loop
31
+ rescue
32
+ puts "Exception starting receiver"
33
+ puts $!.message
34
+ puts $!.backtrace.join("\n")
35
+ end
36
+ end
37
+ EOF
38
+
39
+ assert activity_content.sub!(/ @handle_click = proc do \|view\|\n.*? end\n/m, <<EOF)
40
+ @handle_click = proc do |view|
41
+ intent = android.content.Intent.new
42
+ intent.set_action '#{action_name}'
43
+ send_broadcast(intent)
44
+ end
45
+ EOF
46
+ File.open(activity_filename, 'w') { |f| f << activity_content }
47
+
48
+ system "#{RUBOTO_CMD} gen class BroadcastReceiver --name ClickReceiver"
49
+ FileUtils.rm 'test/src/click_receiver_test.rb'
50
+ receiver_filename = 'src/click_receiver.rb'
51
+ receiver_content = File.read(receiver_filename)
52
+
53
+ assert receiver_content.sub!(/ def on_receive\(context, intent\)\n.*? end\n/m, <<EOF)
54
+ def on_receive(context, intent)
55
+ Log.d "RUBOTO TEST", "Changing UI text"
56
+ context.run_on_ui_thread{$activity.find_view_by_id(42).text = '#{message}'}
57
+ Log.d "RUBOTO TEST", "UI text changed OK!"
58
+ rescue
59
+ Log.e "RUBOTO TEST", "Exception changing UI text: \#{$!.message}"
60
+ Log.e "RUBOTO TEST", $!.message
61
+ Log.e "RUBOTO TEST", $!.backtrace.join("\n")
62
+ end
63
+ EOF
64
+ File.open(receiver_filename, 'w') { |f| f << receiver_content }
65
+
66
+ test_filename = 'test/src/ruboto_test_app_activity_test.rb'
67
+ test_content = File.read(test_filename)
68
+
69
+ assert test_content.sub!(/'button changes text'/, "'button changes text', :ui => false")
70
+ assert test_content.sub!(/ button.performClick/, <<EOF)
71
+ clicked_at = nil
72
+ activity.run_on_ui_thread do
73
+ button.performClick
74
+ clicked_at = Time.now
75
+ end
76
+
77
+ sleep 0.1 until clicked_at && (@text_view.text == '#{message}' || (Time.now - clicked_at) > 10)
78
+ EOF
79
+ assert test_content.sub!(/What hath Matz wrought!/, message)
80
+ File.open(test_filename, 'w') { |f| f << test_content }
81
+ end
82
+
83
+ run_app_tests
84
+ end
85
+
86
+ end
@@ -1,26 +1,34 @@
1
1
  require File.expand_path("test_helper", File.dirname(__FILE__))
2
- require 'bigdecimal'
3
2
 
4
- class MinimalAppTest < Test::Unit::TestCase
5
- def setup
6
- generate_app :excluded_stdlibs => %w{ant cgi digest dl drb ffi irb net optparse racc rbconfig rdoc rexml rinda rss
3
+ if RubotoTest::RUBOTO_PLATFORM == 'STANDALONE'
4
+ require 'bigdecimal'
5
+
6
+ class MinimalAppTest < Test::Unit::TestCase
7
+ def setup
8
+ generate_app :excluded_stdlibs => %w{ant cgi digest dl drb ffi irb net optparse racc rbconfig rdoc rexml rinda rss
7
9
  rubygems runit shell soap test uri webrick win32 wsdl xmlrpc xsd ../1.9}
8
- end
10
+ end
9
11
 
10
- def teardown
11
- cleanup_app
12
- end
12
+ def teardown
13
+ cleanup_app
14
+ end
13
15
 
14
- def test_minimal_apk_is_less_than_3_mb
15
- apk_size = BigDecimal(File.size("#{APP_DIR}/bin/RubotoTestApp-debug.apk").to_s) / (1024 * 1024)
16
- upper_limit = 3.0
17
- lower_limit = upper_limit * 0.85
18
- assert apk_size <= upper_limit, "APK was larger than #{'%.1f' % upper_limit}MB: #{'%.1f' % apk_size.ceil(1)}MB"
19
- assert apk_size >= lower_limit, "APK was smaller than #{'%.1f' % lower_limit}MB: #{'%.1f' % apk_size.floor(1)}MB. You should lower the limit."
20
- end
16
+ def test_minimal_apk_is_less_than_3_mb
17
+ apk_size = BigDecimal(File.size("#{APP_DIR}/bin/RubotoTestApp-debug.apk").to_s) / (1024 * 1024)
18
+ upper_limit = {
19
+ # '1.5.6' => 3.7,
20
+ '1.6.7' => 3.2,
21
+ '1.7.0.dev' => ANDROID_TARGET < 15 ? 3.4 : 3.8, # Without dexmaker for Android < 4.0.3
22
+ }[JRUBY_JARS_VERSION.to_s] || 3.2
23
+ lower_limit = upper_limit * 0.9
24
+ version_message ="JRuby: #{JRUBY_JARS_VERSION}"
25
+ assert apk_size <= upper_limit, "APK was larger than #{'%.1f' % upper_limit}MB: #{'%.1f' % apk_size.ceil(1)}MB. #{version_message}"
26
+ assert apk_size >= lower_limit, "APK was smaller than #{'%.1f' % lower_limit}MB: #{'%.1f' % apk_size.floor(1)}MB. You should lower the limit. #{version_message}"
27
+ end
21
28
 
22
- def test_minimal_apk_succeeds_tests
23
- run_app_tests
24
- end
29
+ def test_minimal_apk_succeeds_tests
30
+ run_app_tests
31
+ end
25
32
 
26
- end
33
+ end
34
+ end
data/test/rake_test.rb CHANGED
@@ -9,7 +9,8 @@ class RakeTest < Test::Unit::TestCase
9
9
  cleanup_app
10
10
  end
11
11
 
12
- if ANDROID_OS == 'android-7'
12
+ # FIXME(uwe): Remove condition when we stop supporting android-7
13
+ if ANDROID_OS == 7
13
14
  puts "Skipping sdcard test since files on sdcard are not removed on android-7 on app uninstall"
14
15
  else
15
16
  def test_that_update_scripts_task_copies_files_to_sdcard_and_are_read_by_activity
@@ -32,9 +33,19 @@ class RakeTest < Test::Unit::TestCase
32
33
  # assert_equal apk_timestamp, File.ctime("bin/#{APP_NAME}-debug.apk"), 'APK should not have been rebuilt'
33
34
  # FIXME end
34
35
 
35
- assert `adb shell ls -d /sdcard/Android/data/#{PACKAGE}/files/scripts`.chomp =~ %r{^/sdcard/Android/data/#{PACKAGE}/files/scripts$}
36
+ assert_match %r{^/sdcard/Android/data/#{PACKAGE}/files/scripts$}, `adb shell ls -d /sdcard/Android/data/#{PACKAGE}/files/scripts`.chomp
36
37
  end
37
38
  end
38
39
  end
39
40
 
41
+ def test_that_apk_is_built_if_only_one_ruby_source_file_has_changed
42
+ Dir.chdir APP_DIR do
43
+ system 'rake install'
44
+ apk_timestamp = File.ctime("bin/#{APP_NAME}-debug.apk")
45
+ FileUtils.touch "src/ruboto_test_app_activity.rb"
46
+ system 'rake install'
47
+ assert_not_equal apk_timestamp, File.ctime("bin/#{APP_NAME}-debug.apk"), 'APK should have been rebuilt'
48
+ end
49
+ end
50
+
40
51
  end
@@ -32,10 +32,24 @@ class RubotoGenTest < Test::Unit::TestCase
32
32
 
33
33
  def test_new_apk_size_is_within_limits
34
34
  apk_size = BigDecimal(File.size("#{APP_DIR}/bin/RubotoTestApp-debug.apk").to_s) / 1024
35
- upper_limit = 54.0
35
+ version = " PLATFORM: #{RUBOTO_PLATFORM}"
36
+ if RUBOTO_PLATFORM == 'STANDALONE'
37
+ upper_limit = {
38
+ '1.6.7' => 5800.0,
39
+ '1.7.0.dev' => 6666.0,
40
+ }[JRUBY_JARS_VERSION.to_s] || 4200.0
41
+ version << ", JRuby: #{JRUBY_JARS_VERSION.to_s}"
42
+ else
43
+ upper_limit = {
44
+ 7 => 56.0,
45
+ 10 => 60.0,
46
+ 15 => 65.0,
47
+ }[ANDROID_TARGET] || 64.0
48
+ version << ", ANDROID_TARGET: #{ANDROID_TARGET}"
49
+ end
36
50
  lower_limit = upper_limit * 0.9
37
- assert apk_size <= upper_limit, "APK was larger than #{'%.1f' % upper_limit}KB: #{'%.1f' % apk_size.ceil(1)}KB"
38
- assert apk_size >= lower_limit, "APK was smaller than #{'%.1f' % lower_limit}KB: #{'%.1f' % apk_size.ceil(1)}KB. You should lower the limit."
51
+ assert apk_size <= upper_limit, "APK was larger than #{'%.1f' % upper_limit}KB: #{'%.1f' % apk_size.ceil(1)}KB.#{version}"
52
+ assert apk_size >= lower_limit, "APK was smaller than #{'%.1f' % lower_limit}KB: #{'%.1f' % apk_size.floor(1)}KB. You should lower the limit.#{version}"
39
53
  end
40
54
 
41
55
  end
@@ -1,5 +1,27 @@
1
- require File.expand_path("update_test_methods", File.dirname(__FILE__))
1
+ require File.expand_path('updated_example_test_methods', File.dirname(__FILE__))
2
+ require File.expand_path('update_test_methods', File.dirname(__FILE__))
2
3
 
3
- class RubotoUpdateTest < Test::Unit::TestCase
4
+ # TODO(uwe): Delete obsolete examples when we stop supporting updating from them.
5
+
6
+ Dir.chdir "#{RubotoTest::PROJECT_DIR}/examples/" do
7
+ Dir["#{RubotoTest::APP_NAME}_*_tools_r*.tgz"].each do |f|
8
+ next unless f =~ /^#{RubotoTest::APP_NAME}_(.*)_tools_r(.*)\.tgz$/
9
+ ruboto_version = $1
10
+ tools_version = $2
11
+ self.class.class_eval <<EOF
12
+ class RubotoUpdatedExample#{ruboto_version.gsub('.', '_')}Tools#{tools_version}Test < Test::Unit::TestCase
13
+ include UpdatedExampleTestMethods
14
+ def setup
15
+ super('#{ruboto_version}', '#{tools_version}')
16
+ end
17
+ end
18
+
19
+ class RubotoUpdate#{ruboto_version.gsub('.', '_')}Tools#{tools_version}Test < Test::Unit::TestCase
4
20
  include UpdateTestMethods
21
+ def setup
22
+ super('#{ruboto_version}', '#{tools_version}')
23
+ end
24
+ end
25
+ EOF
26
+ end
5
27
  end
data/test/service_test.rb CHANGED
@@ -19,7 +19,7 @@ class ServiceTest < Test::Unit::TestCase
19
19
  assert File.exists? service_filename
20
20
  File.open(service_filename, 'w'){|f| f << <<EOF}
21
21
  require 'ruboto'
22
-
22
+
23
23
  $service.handle_create do
24
24
  Thread.start do
25
25
  loop do
data/test/test_helper.rb CHANGED
@@ -1,9 +1,13 @@
1
+ $:.unshift('lib') unless $:.include?('lib')
1
2
  require 'test/unit'
2
3
  require 'rubygems'
3
4
  require 'fileutils'
4
5
  require 'yaml'
6
+ require 'ruboto/sdk_versions'
5
7
 
6
8
  module RubotoTest
9
+ include Ruboto::SdkVersions
10
+
7
11
  PROJECT_DIR = File.expand_path('..', File.dirname(__FILE__))
8
12
  $LOAD_PATH << PROJECT_DIR
9
13
 
@@ -11,21 +15,28 @@ module RubotoTest
11
15
  FileUtils.mkdir_p GEM_PATH
12
16
  ENV['GEM_HOME'] = GEM_PATH
13
17
  ENV['GEM_PATH'] = GEM_PATH
14
- system 'gem install bundler'
15
- system 'bundle'
16
-
17
- PACKAGE = 'org.ruboto.test_app'
18
- APP_NAME = 'RubotoTestApp'
19
- TMP_DIR = File.join PROJECT_DIR, 'tmp'
20
- APP_DIR = File.join TMP_DIR, APP_NAME
21
- ANDROID_TARGET = ENV['ANDROID_TARGET'] || 'android-7'
18
+ ENV['PATH'] = "#{GEM_PATH}/bin:#{ENV['PATH']}"
19
+ Gem.path << GEM_PATH
20
+ Gem.refresh
21
+ `gem query -i -n bundler`
22
+ system 'gem install bundler' unless $? == 0
23
+ system 'bundle --system'
24
+ lib_path = File.expand_path('lib', File.dirname(File.dirname(__FILE__)))
25
+ $LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
26
+ require 'ruboto'
27
+ require 'ruboto/version'
22
28
 
29
+ PACKAGE = 'org.ruboto.test_app'
30
+ APP_NAME = 'RubotoTestApp'
31
+ TMP_DIR = File.join PROJECT_DIR, 'tmp'
32
+ APP_DIR = File.join TMP_DIR, APP_NAME
33
+ ANDROID_TARGET = (ENV['ANDROID_TARGET'] && ENV['ANDROID_TARGET'].slice(/\d+/).to_i) || MINIMUM_SUPPORTED_SDK_LEVEL
23
34
  VERSION_TO_API_LEVEL = {
24
- '2.1' => 'android-7', '2.1-update1' => 'android-7', '2.2' => 'android-8',
25
- '2.3' => 'android-9', '2.3.1' => 'android-9', '2.3.2' => 'android-9',
35
+ '2.1' => 'android-7', '2.1-update1' => 'android-7', '2.2' => 'android-8',
36
+ '2.3' => 'android-9', '2.3.1' => 'android-9', '2.3.2' => 'android-9',
26
37
  '2.3.3' => 'android-10', '2.3.4' => 'android-10',
27
- '3.0' => 'android-11', '3.1' => 'android-12', '3.2' => 'android-13',
28
- '4.0.1' => 'android-14', '4.0.3' => 'android-15',
38
+ '3.0' => 'android-11', '3.1' => 'android-12', '3.2' => 'android-13',
39
+ '4.0.1' => 'android-14', '4.0.3' => 'android-15', '4.0.4' => 'android-15'
29
40
  }
30
41
 
31
42
  def self.version_from_device
@@ -34,7 +45,7 @@ module RubotoTest
34
45
  start = Time.now
35
46
  IO.popen('adb bugreport').each_line do |line|
36
47
  if line =~ /sdk-eng (.*?) .*? .*? test-keys/
37
- version = $1
48
+ version = $1
38
49
  api_level = VERSION_TO_API_LEVEL[version]
39
50
  raise "Unknown version: #{version}" if api_level.nil?
40
51
  puts "Getting version from device/emulator took #{(Time.now - start).to_i}s"
@@ -47,21 +58,44 @@ module RubotoTest
47
58
  raise "Unable to read device/emulator apilevel"
48
59
  end
49
60
 
50
- def install_jruby_jars_gem
51
- system "gem install jruby-jars #{"-v #{ENV['JRUBY_JARS_VERSION']}" if ENV['JRUBY_JARS_VERSION']}"
61
+ def self.install_jruby_jars_gem
62
+ version_requirement = "-v #{ENV['JRUBY_JARS_VERSION']}" if ENV['JRUBY_JARS_VERSION']
63
+ `gem query -i -n jruby-jars #{version_requirement}`
64
+ system "gem install jruby-jars #{version_requirement}" unless $? == 0
52
65
  raise "install of jruby-jars failed with return code #$?" unless $? == 0
53
- system %Q{gem uninstall jruby-jars --all -v "!=#{ENV['JRUBY_JARS_VERSION']}"} if ENV['JRUBY_JARS_VERSION']
66
+ if ENV['JRUBY_JARS_VERSION']
67
+ exclusion_clause = %Q{-v "!=#{ENV['JRUBY_JARS_VERSION']}"}
68
+ `gem query -u -n jruby-jars #{exclusion_clause}`
69
+ system %Q{gem uninstall jruby-jars --all #{exclusion_clause}"} unless $? == 0
70
+ raise "Uninstall of jruby-jars failed with return code #$?" unless $? == 0
71
+ end
54
72
  end
55
73
 
56
- ANDROID_OS = ENV['ANDROID_OS'] || version_from_device
57
- RUBOTO_CMD = "ruby -rubygems -I #{PROJECT_DIR}/lib #{PROJECT_DIR}/bin/ruboto"
74
+ def install_jruby_jars_gem
75
+ RubotoTest::install_jruby_jars_gem
76
+ end
58
77
 
78
+ def uninstall_jruby_jars_gem
79
+ `gem query --no-installed -n jruby-jars`
80
+ system 'gem uninstall jruby-jars --all' if $? != 0
81
+ assert_equal 0, $?, "uninstall of jruby-jars failed with return code #$?"
82
+ end
83
+
84
+ def install_ruboto_gem(version)
85
+ version_requirement = "-v #{version}"
86
+ `gem query -i -n ^ruboto$ #{version_requirement}`
87
+ system "gem install ruboto #{version_requirement}" unless $? == 0
88
+ raise "install of ruboto #{version} failed with return code #$?" unless $? == 0
89
+ end
90
+
91
+ ANDROID_OS = (ENV['ANDROID_OS'] || version_from_device).slice(/\d+/).to_i
59
92
  puts "ANDROID_OS: #{ANDROID_OS}"
60
- end
93
+ puts "ANDROID_TARGET: #{ANDROID_TARGET}"
61
94
 
62
- class Test::Unit::TestCase
63
- include RubotoTest
64
- extend RubotoTest
95
+ RUBOTO_CMD = "ruby -rubygems -I #{PROJECT_DIR}/lib #{PROJECT_DIR}/bin/ruboto"
96
+
97
+ puts "ANDROID_HOME: #{ANDROID_HOME}"
98
+ puts "ANDROID_SDK_TOOLS_REVISION: #{ANDROID_TOOLS_REVISION}"
65
99
 
66
100
  install_jruby_jars_gem
67
101
 
@@ -74,10 +108,19 @@ class Test::Unit::TestCase
74
108
  # FIXME end
75
109
 
76
110
  raise StandardError.new("Can't find Gem specification jruby-jars.") unless gem_spec
77
- JRUBY_JARS_VERSION = gem_spec.version
111
+ JRUBY_JARS_VERSION = gem_spec.version
112
+ puts "JRUBY_JARS_VERSION: #{JRUBY_JARS_VERSION}"
113
+
114
+ RUBOTO_PLATFORM = ENV['RUBOTO_PLATFORM'] || 'CURRENT'
115
+ puts "RUBOTO_PLATFORM: #{RUBOTO_PLATFORM}"
78
116
 
79
117
  # FIXME(uwe): Remove when we stop supporting JRuby 1.5.6
80
118
  ON_JRUBY_JARS_1_5_6 = JRUBY_JARS_VERSION == Gem::Version.new('1.5.6')
119
+ end
120
+
121
+ class Test::Unit::TestCase
122
+ include RubotoTest
123
+ extend RubotoTest
81
124
 
82
125
  alias old_run run
83
126
 
@@ -97,7 +140,8 @@ class Test::Unit::TestCase
97
140
 
98
141
  def mark_test_end(test_name)
99
142
  log
100
- log "Ended test #{test_name}: #{passed? ? 'PASSED' : 'FAILED'} after #{(Time.now - @start_time).to_i}s"
143
+ duration = (Time.now - @start_time).to_i
144
+ log "Ended test #{test_name}: #{passed? ? 'PASSED' : 'FAILED'} after #{duration / 60}:#{'%02d' % (duration % 60)}"
101
145
  log '=' * 80
102
146
  log
103
147
  end
@@ -108,86 +152,114 @@ class Test::Unit::TestCase
108
152
  end
109
153
 
110
154
  def generate_app(options = {})
111
- update = options.delete(:update) || false
155
+ example = options.delete(:example) || false
156
+ update = options.delete(:update) || false
112
157
  excluded_stdlibs = options.delete(:excluded_stdlibs)
158
+ standalone = options.delete(:standalone) || !!excluded_stdlibs || ENV['RUBOTO_PLATFORM'] == 'STANDALONE'
113
159
  raise "Unknown options: #{options.inspect}" unless options.empty?
114
160
  Dir.mkdir TMP_DIR unless File.exists? TMP_DIR
115
161
 
116
- if excluded_stdlibs
117
- system 'rake platform:uninstall'
118
- else
119
- system 'rake platform:install'
120
- end
121
- if $? != 0
122
- FileUtils.rm_rf 'tmp/RubotoCore'
123
- fail 'Error (un)installing RubotoCore'
124
- end
125
-
126
162
  FileUtils.rm_rf APP_DIR if File.exists? APP_DIR
127
- template_dir = "#{APP_DIR}_template_#{$$}#{'_updated' if update}#{"_without_#{excluded_stdlibs.map { |ed| ed.gsub(/[.\/]/, '_') }.join('_')}" if excluded_stdlibs}"
163
+ template_dir = "#{APP_DIR}_template_#{$$}"
164
+ template_dir << "_example_#{example}" if example
165
+ template_dir << '_updated' if update
166
+ template_dir << '_standalone' if standalone
167
+ template_dir << "_without_#{excluded_stdlibs.map { |ed| ed.gsub(/[.\/]/, '_') }.join('_')}" if excluded_stdlibs
128
168
  if File.exists?(template_dir)
129
169
  puts "Copying app from template #{template_dir}"
130
170
  FileUtils.cp_r template_dir, APP_DIR, :preserve => true
131
171
  else
132
172
  install_jruby_jars_gem
133
173
 
134
- if update
174
+ if example
135
175
  Dir.chdir TMP_DIR do
136
- system "tar xzf #{PROJECT_DIR}/examples/RubotoTestApp_0.1.0_jruby_1.6.3.dev.tgz"
137
- end
138
- if ENV['ANDROID_HOME']
139
- android_home = ENV['ANDROID_HOME']
140
- else
141
- android_home = File.dirname(File.dirname(`which adb`))
176
+ system "tar xzf #{PROJECT_DIR}/examples/#{APP_NAME}_#{example}.tgz"
142
177
  end
143
178
  Dir.chdir APP_DIR do
144
- File.open('local.properties', 'w') { |f| f.puts "sdk.dir=#{android_home}" }
145
- File.open('test/local.properties', 'w') { |f| f.puts "sdk.dir=#{android_home}" }
146
- exclude_stdlibs(excluded_stdlibs) if excluded_stdlibs
147
- system "#{RUBOTO_CMD} update app"
148
- assert_equal 0, $?, "update app failed with return code #$?"
179
+ File.open('local.properties', 'w') { |f| f.puts "sdk.dir=#{ANDROID_HOME}" }
180
+ File.open('test/local.properties', 'w') { |f| f.puts "sdk.dir=#{ANDROID_HOME}" }
181
+ if standalone
182
+ exclude_stdlibs(excluded_stdlibs) if excluded_stdlibs
183
+ FileUtils.touch 'libs/jruby-core-x.x.x.jar'
184
+ FileUtils.touch 'libs/jruby-stdlib-x.x.x.jar'
185
+ else
186
+ FileUtils.rm(Dir['libs/{jruby-*.jar,dexmaker*.jar}'])
187
+ end
188
+ update_app if update
149
189
  end
150
190
  else
151
- unless excluded_stdlibs
152
- system 'gem uninstall jruby-jars --all'
153
- assert_equal 0, $?, "uninstall of jruby-jars failed with return code #$?"
154
- end
191
+ uninstall_jruby_jars_gem unless standalone
155
192
  puts "Generating app #{APP_DIR}"
156
- system "#{RUBOTO_CMD} gen app --package #{PACKAGE} --path #{APP_DIR} --name #{APP_NAME} --target #{ANDROID_TARGET}"
193
+ system "#{RUBOTO_CMD} gen app --package #{PACKAGE} --path #{APP_DIR} --name #{APP_NAME} --target android-#{ANDROID_TARGET}"
157
194
  if $? != 0
158
195
  FileUtils.rm_rf APP_DIR
159
196
  raise "gen app failed with return code #$?"
160
197
  end
161
- if excluded_stdlibs
198
+ if standalone
162
199
  Dir.chdir APP_DIR do
163
- exclude_stdlibs(excluded_stdlibs)
200
+ exclude_stdlibs(excluded_stdlibs) if excluded_stdlibs
164
201
  system "#{RUBOTO_CMD} update jruby --force"
165
202
  raise "update jruby failed with return code #$?" if $? != 0
166
203
  end
167
204
  end
168
205
  end
169
- Dir.chdir APP_DIR do
170
- system 'rake debug'
171
- assert_equal 0, $?
206
+
207
+ # FIXME(uwe): Installation with dexmaker fails on Android < 4.0.3 due to complex interface structure
208
+ # Fixme(uwe): Remove when solved
209
+ if standalone && ANDROID_OS < 15
210
+ Dir.chdir APP_DIR do
211
+ puts "Removing dexmaker jar for android-#{ANDROID_OS}"
212
+ FileUtils.rm(Dir['libs/dexmaker*.jar'])
213
+ end
214
+ end
215
+ # FIXME end
216
+
217
+ unless example && !update
218
+ Dir.chdir APP_DIR do
219
+ system 'rake debug'
220
+ assert_equal 0, $?
221
+ end
172
222
  end
173
223
  puts "Storing app as template #{template_dir}"
174
224
  FileUtils.cp_r APP_DIR, template_dir, :preserve => true
175
225
  end
176
226
  end
177
227
 
228
+ def update_app
229
+ system "#{RUBOTO_CMD} update app"
230
+ assert_equal 0, $?, "update app failed with return code #$?"
231
+ end
232
+
178
233
  def cleanup_app
179
234
  # FileUtils.rm_rf APP_DIR if File.exists? APP_DIR
180
235
  end
181
236
 
182
237
  def run_app_tests
183
- if ['android-7', 'android-8'].include? ANDROID_OS
238
+ if [7, 8].include? ANDROID_OS
184
239
  puts "Skipping instrumentation tests on #{ANDROID_OS} since they don't work."
240
+ return
241
+ end
242
+ check_platform_installation(Dir['libs/jruby-core-*.jar'].any?)
243
+ Dir.chdir APP_DIR do
244
+ system 'rake test:quick'
245
+ assert_equal 0, $?, "tests failed with return code #$?"
246
+ end
247
+ end
248
+
249
+ def check_platform_installation(standalone)
250
+ if standalone
251
+ system 'rake platform:uninstall'
185
252
  else
186
- Dir.chdir APP_DIR do
187
- system 'rake test:quick'
188
- assert_equal 0, $?, "tests failed with return code #$?"
253
+ if RUBOTO_PLATFORM == 'CURRENT'
254
+ system "rake platform:current platform:install"
255
+ elsif RUBOTO_PLATFORM == 'MASTER'
256
+ system "rake platform:install"
189
257
  end
190
258
  end
259
+ if $? != 0
260
+ FileUtils.rm_rf 'tmp/RubotoCore'
261
+ fail 'Error (un)installing RubotoCore'
262
+ end
191
263
  end
192
264
 
193
265
  def exclude_stdlibs(excluded_stdlibs)