ruboto-core 0.3.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +3 -3
- data/Rakefile +75 -0
- data/assets/Rakefile +76 -85
- data/assets/res/layout/get_ruboto_core.xml +25 -0
- data/assets/samples/sample_broadcast_receiver.rb +1 -2
- data/assets/src/InheritingActivity.java +181 -5
- data/assets/src/InheritingBroadcastReceiver.java +22 -5
- data/assets/src/InheritingClass.java +4 -13
- data/assets/src/RubotoActivity.java +78 -118
- data/assets/src/RubotoBroadcastReceiver.java +31 -50
- data/assets/src/RubotoService.java +13 -28
- data/assets/src/org/ruboto/Script.java +286 -114
- data/assets/src/org/ruboto/test/ActivityTest.java +25 -26
- data/assets/src/org/ruboto/test/InstrumentationTestRunner.java +28 -29
- data/assets/{assets/scripts → src}/ruboto.rb +13 -8
- data/assets/test/assets/scripts/test_helper.rb +8 -4
- data/lib/ruboto/commands/base.rb +42 -6
- data/lib/ruboto/util/build.rb +25 -18
- data/lib/ruboto/util/update.rb +53 -30
- data/lib/ruboto/util/xml_element.rb +2 -2
- data/lib/ruboto/version.rb +3 -0
- data/test/activity/image_button_activity.rb +1 -1
- data/test/activity/image_button_and_button_activity.rb +1 -1
- data/test/activity/stack_activity.rb +21 -0
- data/test/activity/stack_activity_test.rb +24 -0
- data/test/app_test_methods.rb +25 -32
- data/test/rake_test.rb +15 -17
- data/test/ruboto_gen_test.rb +1 -16
- data/test/ruboto_gen_with_psych_test.rb +16 -0
- data/test/ruboto_update_test.rb +1 -47
- data/test/ruboto_update_with_psych_test.rb +18 -0
- data/test/service_test.rb +4 -2
- data/test/test_helper.rb +32 -22
- data/test/update_test_methods.rb +29 -0
- metadata +13 -22
@@ -22,15 +22,11 @@ import java.util.List;
|
|
22
22
|
import junit.framework.Test;
|
23
23
|
import junit.framework.TestCase;
|
24
24
|
import junit.framework.TestSuite;
|
25
|
-
import org.jruby.exceptions.RaiseException;
|
26
|
-
import org.jruby.javasupport.JavaEmbedUtils;
|
27
|
-
import org.jruby.RubyClass;
|
28
|
-
import org.jruby.runtime.builtin.IRubyObject;
|
29
25
|
import org.ruboto.Script;
|
30
26
|
|
31
27
|
public class InstrumentationTestRunner extends android.test.InstrumentationTestRunner {
|
32
28
|
private Class activityClass;
|
33
|
-
private
|
29
|
+
private Object setup;
|
34
30
|
private TestSuite suite;
|
35
31
|
|
36
32
|
public TestSuite getAllTests() {
|
@@ -38,28 +34,31 @@ public class InstrumentationTestRunner extends android.test.InstrumentationTestR
|
|
38
34
|
suite = new TestSuite("Sweet");
|
39
35
|
|
40
36
|
try {
|
41
|
-
Script.setUpJRuby(getTargetContext())
|
42
|
-
|
43
|
-
|
44
|
-
|
37
|
+
if (Script.setUpJRuby(getTargetContext())) {
|
38
|
+
Script.defineGlobalVariable("$runner", this);
|
39
|
+
Script.defineGlobalVariable("$test", this);
|
40
|
+
Script.defineGlobalVariable("$suite", suite);
|
45
41
|
|
46
|
-
|
47
|
-
|
42
|
+
// TODO(uwe): Why doesn't this work?
|
43
|
+
// Script.copyScriptsIfNeeded(getContext());
|
48
44
|
|
49
|
-
|
45
|
+
loadScript("test_helper.rb");
|
50
46
|
|
51
|
-
|
52
|
-
|
47
|
+
// TODO(uwe): Why doesn't this work?
|
48
|
+
// String[] scripts = new File(Script.scriptsDirName(getContext())).list();
|
53
49
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
50
|
+
String[] scripts = getContext().getResources().getAssets().list("scripts");
|
51
|
+
for (String f : scripts) {
|
52
|
+
if (f.equals("test_helper.rb")) continue;
|
53
|
+
Log.i(getClass().getName(), "Found script: " + f);
|
54
|
+
loadScript(f);
|
55
|
+
}
|
56
|
+
} else {
|
57
|
+
addError(suite, new RuntimeException("Ruboto Core platform is missing"));
|
59
58
|
}
|
60
59
|
} catch (IOException e) {
|
61
60
|
addError(suite, e);
|
62
|
-
} catch (
|
61
|
+
} catch (RuntimeException e) {
|
63
62
|
addError(suite, e);
|
64
63
|
}
|
65
64
|
return suite;
|
@@ -69,15 +68,15 @@ public class InstrumentationTestRunner extends android.test.InstrumentationTestR
|
|
69
68
|
this.activityClass = activityClass;
|
70
69
|
}
|
71
70
|
|
72
|
-
public void setup(
|
71
|
+
public void setup(Object block) {
|
73
72
|
this.setup = block;
|
74
73
|
}
|
75
74
|
|
76
|
-
public void test(String name,
|
75
|
+
public void test(String name, Object block) {
|
77
76
|
if (android.os.Build.VERSION.SDK_INT <= 8) {
|
78
77
|
name ="runTest";
|
79
78
|
}
|
80
|
-
Test test = new ActivityTest(activityClass, Script.
|
79
|
+
Test test = new ActivityTest(activityClass, Script.getScriptFilename(), setup, name, block);
|
81
80
|
suite.addTest(test);
|
82
81
|
Log.d(getClass().getName(), "Made test instance: " + test);
|
83
82
|
}
|
@@ -106,12 +105,12 @@ public class InstrumentationTestRunner extends android.test.InstrumentationTestR
|
|
106
105
|
buffer.close();
|
107
106
|
|
108
107
|
Log.d(getClass().getName(), "Loading test script: " + f);
|
109
|
-
String oldFilename = Script.
|
110
|
-
Script.
|
111
|
-
Script.
|
112
|
-
Script.
|
113
|
-
Script.
|
114
|
-
Script.
|
108
|
+
String oldFilename = Script.getScriptFilename();
|
109
|
+
Script.setScriptFilename(f);
|
110
|
+
Script.put("$script_code", source.toString());
|
111
|
+
Script.setScriptFilename(f);
|
112
|
+
Script.execute("$test.instance_eval($script_code)");
|
113
|
+
Script.setScriptFilename(oldFilename);
|
115
114
|
Log.d(getClass().getName(), "Test script " + f + " loaded");
|
116
115
|
}
|
117
116
|
|
@@ -9,7 +9,8 @@
|
|
9
9
|
#
|
10
10
|
#######################################################
|
11
11
|
|
12
|
-
|
12
|
+
require 'ruboto/version'
|
13
|
+
$RUBOTO_VERSION = 9
|
13
14
|
|
14
15
|
def confirm_ruboto_version(required_version, exact=true)
|
15
16
|
raise "requires $RUBOTO_VERSION=#{required_version} or greater, current version #{$RUBOTO_VERSION}" if $RUBOTO_VERSION < required_version and not exact
|
@@ -44,9 +45,11 @@ class Object
|
|
44
45
|
def with_large_stack(opts = {}, &block)
|
45
46
|
opts = {:size => opts} if opts.is_a? Integer
|
46
47
|
opts = {:name => 'Block with large stack'}.update(opts)
|
48
|
+
exception = nil
|
47
49
|
result = nil
|
48
|
-
t = Thread.with_large_stack(opts, &proc{result = block.call})
|
50
|
+
t = Thread.with_large_stack(opts, &proc{result = block.call rescue exception = $!})
|
49
51
|
t.join
|
52
|
+
raise exception if exception
|
50
53
|
result
|
51
54
|
end
|
52
55
|
end
|
@@ -79,7 +82,7 @@ def setup_activity
|
|
79
82
|
def start_ruboto_activity(remote_variable, klass=RubotoActivity, theme=nil, &block)
|
80
83
|
$activity_init_block = block
|
81
84
|
|
82
|
-
if @initialized or self == $activity
|
85
|
+
if @initialized or (self == $activity && !$activity.kind_of?(RubotoActivity))
|
83
86
|
b = Java::android.os.Bundle.new
|
84
87
|
b.putInt("Theme", theme) if theme
|
85
88
|
b.putString("Remote Variable", remote_variable)
|
@@ -257,17 +260,19 @@ end
|
|
257
260
|
# Ruboto Set up for all app types (Activity, Service, BroadcastReceiver)
|
258
261
|
#
|
259
262
|
|
260
|
-
def ruboto_setup(klass, init_method=
|
263
|
+
def ruboto_setup(klass, init_method = true)
|
261
264
|
# Setup ability to handle callbacks
|
262
265
|
ruboto_allow_handlers(klass)
|
263
266
|
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
+
if init_method
|
268
|
+
klass.class_eval do
|
269
|
+
eval %Q{
|
270
|
+
def handle_create(&block)
|
267
271
|
instance_exec &block
|
268
272
|
#{klass == Java::org.ruboto.RubotoActivity ? "on_create(nil)" : ""}
|
269
273
|
end
|
270
274
|
}
|
275
|
+
end
|
271
276
|
end
|
272
277
|
end
|
273
278
|
|
@@ -613,4 +618,4 @@ ruboto_setup(RubotoService)
|
|
613
618
|
|
614
619
|
# setup broadcast receiver support
|
615
620
|
java_import "org.ruboto.RubotoBroadcastReceiver"
|
616
|
-
ruboto_setup(RubotoBroadcastReceiver,
|
621
|
+
ruboto_setup(RubotoBroadcastReceiver, false)
|
@@ -1,9 +1,13 @@
|
|
1
1
|
require 'java'
|
2
2
|
|
3
|
-
def assert(value, message =
|
4
|
-
raise message unless value
|
3
|
+
def assert(value, message = nil)
|
4
|
+
raise "#{"#{message}\n" if message}#{value.inspect} expected to be true" unless value
|
5
5
|
end
|
6
6
|
|
7
|
-
def assert_equal(expected, actual, message =
|
8
|
-
raise message unless expected == actual
|
7
|
+
def assert_equal(expected, actual, message = nil)
|
8
|
+
raise "#{"#{message}\n" if message}'#{expected}' expected, but got '#{actual}'" unless expected == actual
|
9
|
+
end
|
10
|
+
|
11
|
+
def assert_less_than_or_equal(limit, actual, message = nil)
|
12
|
+
raise "#{"#{message}\n" if message}Expected '#{actual}' to be less than or equal to '#{limit}'" unless actual <= limit
|
9
13
|
end
|
data/lib/ruboto/commands/base.rb
CHANGED
@@ -51,7 +51,10 @@ module Ruboto
|
|
51
51
|
argument :required
|
52
52
|
description "Minimum android version supported. Must begin with 'android-'."
|
53
53
|
}
|
54
|
-
|
54
|
+
option("with-jruby") {
|
55
|
+
description "Generate the JRuby jars jar"
|
56
|
+
cast :boolean
|
57
|
+
}
|
55
58
|
option("with-psych") {
|
56
59
|
description "Generate the Psych YAML parser jar"
|
57
60
|
cast :boolean
|
@@ -76,6 +79,10 @@ module Ruboto
|
|
76
79
|
exit_failure!
|
77
80
|
end
|
78
81
|
Dir.chdir path do
|
82
|
+
FileUtils.rm_f "src/#{package.gsub '.', '/'}/#{activity}.java"
|
83
|
+
puts "Removed file #{"src/#{package.gsub '.', '/'}/#{activity}"}.java"
|
84
|
+
FileUtils.rm_f 'res/layout/main.xml'
|
85
|
+
puts 'Removed file res/layout/main.xml'
|
79
86
|
verify_strings.root.elements['string'].text = name.gsub(/([A-Z]+)([A-Z][a-z])/,'\1 \2').gsub(/([a-z\d])([A-Z])/,'\1 \2')
|
80
87
|
File.open("res/values/strings.xml", 'w') {|f| verify_strings.document.write(f, 4)}
|
81
88
|
end
|
@@ -84,15 +91,16 @@ module Ruboto
|
|
84
91
|
Dir.chdir root do
|
85
92
|
update_test true
|
86
93
|
update_assets
|
94
|
+
update_ruboto true
|
87
95
|
update_icons true
|
88
96
|
update_classes true
|
89
|
-
update_jruby true, params['with-psych'].value
|
97
|
+
update_jruby true, params['with-psych'].value if params['with-jruby'].value || params['with-psych'].value
|
90
98
|
update_build_xml
|
91
99
|
update_manifest min_sdk[/\d+/], target[/\d+/], true
|
92
100
|
update_core_classes "exclude"
|
93
101
|
|
94
102
|
log_action("Generating the default Activity and script") do
|
95
|
-
generate_inheriting_file "Activity", activity, package
|
103
|
+
generate_inheriting_file "Activity", activity, package
|
96
104
|
end
|
97
105
|
end
|
98
106
|
|
@@ -100,6 +108,24 @@ module Ruboto
|
|
100
108
|
end
|
101
109
|
end
|
102
110
|
|
111
|
+
mode "jruby" do
|
112
|
+
include Ruboto::Util::LogAction
|
113
|
+
include Ruboto::Util::Build
|
114
|
+
include Ruboto::Util::Update
|
115
|
+
include Ruboto::Util::Verify
|
116
|
+
|
117
|
+
option("with-psych") {
|
118
|
+
description "Generate the Psych YAML parser jar"
|
119
|
+
cast :boolean
|
120
|
+
}
|
121
|
+
|
122
|
+
def run
|
123
|
+
Dir.chdir root do
|
124
|
+
update_jruby true, params['with-psych'].value
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
103
129
|
mode "class" do
|
104
130
|
include Ruboto::Util::Build
|
105
131
|
include Ruboto::Util::Verify
|
@@ -113,7 +139,7 @@ module Ruboto
|
|
113
139
|
|
114
140
|
option("script_name"){
|
115
141
|
argument :required
|
116
|
-
description "name of the ruby script
|
142
|
+
description "name of the ruby script that this class will execute. Should end in .rb. Optional."
|
117
143
|
}
|
118
144
|
|
119
145
|
option("name"){
|
@@ -314,11 +340,12 @@ module Ruboto
|
|
314
340
|
def run
|
315
341
|
case params['what'].value
|
316
342
|
when "jruby" then
|
317
|
-
update_jruby(params['force'].value) || abort
|
343
|
+
update_jruby(params['force'].value, params['with-psych'].value) || abort
|
318
344
|
when "app" then
|
319
345
|
force = params['force'].value
|
320
346
|
update_test force
|
321
347
|
update_assets
|
348
|
+
update_ruboto force
|
322
349
|
update_icons force
|
323
350
|
update_classes force
|
324
351
|
update_jruby force, params['with-psych'].value
|
@@ -337,7 +364,16 @@ module Ruboto
|
|
337
364
|
|
338
365
|
# just running `ruboto`
|
339
366
|
def run
|
340
|
-
|
367
|
+
# FIXME(uwe): Simplify when we stop supporting rubygems < 1.8.0
|
368
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.8.0')
|
369
|
+
gem_spec = Gem::Specification.find_by_path 'ruboto'
|
370
|
+
else
|
371
|
+
gem_spec = Gem.searcher.find('ruboto')
|
372
|
+
end
|
373
|
+
# FIXME end
|
374
|
+
|
375
|
+
version = gem_spec.version.version
|
376
|
+
|
341
377
|
if params['version'].value
|
342
378
|
puts version
|
343
379
|
else
|
data/lib/ruboto/util/build.rb
CHANGED
@@ -2,6 +2,8 @@ module Ruboto
|
|
2
2
|
module Util
|
3
3
|
module Build
|
4
4
|
include Verify
|
5
|
+
SCRIPTS_DIR = 'src'
|
6
|
+
|
5
7
|
###########################################################################
|
6
8
|
#
|
7
9
|
# Build Subclass or Interface:
|
@@ -101,7 +103,7 @@ module Ruboto
|
|
101
103
|
def generate_subclass_or_interface(params)
|
102
104
|
defaults = {:template => "InheritingClass", :method_base => "all", :method_include => "", :method_exclude => "", :force => nil, :implements => ""}
|
103
105
|
params = defaults.merge(params)
|
104
|
-
params[:package]
|
106
|
+
params[:package] ||= verify_package
|
105
107
|
|
106
108
|
class_desc = get_class_or_interface(params[:class] || params[:interface], params[:force])
|
107
109
|
|
@@ -141,7 +143,7 @@ module Ruboto
|
|
141
143
|
|
142
144
|
hash = {:package => "org.ruboto"}
|
143
145
|
%w(method_base method_include implements force).inject(hash) {|h, i| h[i.to_sym] = params[i.to_sym]; h}
|
144
|
-
hash[:method_exclude] = params[:method_exclude].split(",").push("onCreate").
|
146
|
+
hash[:method_exclude] = params[:method_exclude].split(",").push("onCreate").join(",")
|
145
147
|
|
146
148
|
%w(android.app.Activity android.app.Service android.content.BroadcastReceiver android.view.View).each do |i|
|
147
149
|
name = i.split(".")[-1]
|
@@ -164,30 +166,35 @@ module Ruboto
|
|
164
166
|
# generate_inheriting_file:
|
165
167
|
# Builds a script based subclass of Activity, Service, or BroadcastReceiver
|
166
168
|
#
|
167
|
-
|
168
|
-
|
169
|
-
file = File.expand_path File.join(dest, "src/#{package.gsub('.', '/')}", "#{
|
169
|
+
def generate_inheriting_file(klass, name, package, script_name = "#{underscore(name)}.rb")
|
170
|
+
dest = '.'
|
171
|
+
file = File.expand_path File.join(dest, "src/#{package.gsub('.', '/')}", "#{name}.java")
|
170
172
|
text = File.read(File.join(Ruboto::ASSETS, "src/Inheriting#{klass}.java"))
|
173
|
+
file_existed = File.exists?(file)
|
171
174
|
File.open(file, 'w') do |f|
|
172
175
|
f << text.gsub("THE_PACKAGE", package).gsub("Inheriting#{klass}", name).gsub("start.rb", script_name)
|
173
176
|
end
|
174
|
-
puts "Added file #{file}."
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
177
|
+
puts "#{file_existed ? 'Updated' : 'Added'} file #{file}."
|
178
|
+
|
179
|
+
script_file = File.expand_path("#{SCRIPTS_DIR}/#{script_name}", dest)
|
180
|
+
if !File.exists? script_file
|
181
|
+
sample_source = File.read(File.join(Ruboto::ASSETS, "samples/sample_#{underscore klass}.rb")).gsub("THE_PACKAGE", package).gsub("Sample#{klass}", name).gsub("start.rb", script_name)
|
182
|
+
FileUtils.mkdir_p File.join(dest, SCRIPTS_DIR)
|
183
|
+
File.open script_file, "a" do |f|
|
184
|
+
f << sample_source
|
185
|
+
end
|
186
|
+
puts "Added file #{script_file}."
|
181
187
|
end
|
182
|
-
puts "Added file #{script_file}."
|
183
188
|
|
184
|
-
sample_test_source = File.read(File.join(Ruboto::ASSETS, "samples/sample_#{underscore klass}_test.rb")).gsub("THE_PACKAGE", package).gsub("Sample#{klass}", name)
|
185
|
-
FileUtils.mkdir_p File.join(dest, 'test/assets/scripts')
|
186
189
|
test_file = File.expand_path("test/assets/scripts/#{script_name.chomp('.rb')}_test.rb", dest)
|
187
|
-
File.
|
188
|
-
|
190
|
+
if !File.exists? test_file
|
191
|
+
sample_test_source = File.read(File.join(Ruboto::ASSETS, "samples/sample_#{underscore klass}_test.rb")).gsub("THE_PACKAGE", package).gsub("Sample#{klass}", name)
|
192
|
+
FileUtils.mkdir_p File.join(dest, 'test/assets/scripts')
|
193
|
+
File.open test_file, "a" do |f|
|
194
|
+
f << sample_test_source
|
195
|
+
end
|
196
|
+
puts "Added file #{test_file}."
|
189
197
|
end
|
190
|
-
puts "Added file #{test_file}."
|
191
198
|
end
|
192
199
|
end
|
193
200
|
end
|
data/lib/ruboto/util/update.rb
CHANGED
@@ -8,15 +8,15 @@ module Ruboto
|
|
8
8
|
#
|
9
9
|
def update_test(force = nil)
|
10
10
|
root = Dir.getwd
|
11
|
-
if
|
11
|
+
if !File.exists?("#{root}/test")
|
12
12
|
name = verify_strings.root.elements['string'].text.gsub(' ', '')
|
13
13
|
puts "\nGenerating Android test project #{name} in #{root}..."
|
14
|
-
system
|
14
|
+
system %Q{android create test-project -m "#{root.gsub('"', '\"')}" -n "#{name}Test" -p "#{root.gsub('"', '\"')}/test"}
|
15
15
|
FileUtils.rm_rf File.join(root, 'test', 'src', verify_package.split('.'))
|
16
16
|
puts "Done"
|
17
17
|
else
|
18
|
-
|
19
|
-
|
18
|
+
puts "\nUpdating Android test project #{name} in #{root}..."
|
19
|
+
system "android update test-project -m #{root} -p #{root}/test"
|
20
20
|
end
|
21
21
|
|
22
22
|
Dir.chdir File.join(root, 'test') do
|
@@ -132,9 +132,18 @@ EOF
|
|
132
132
|
puts "\nCopying files:"
|
133
133
|
copier = Ruboto::Util::AssetCopier.new Ruboto::ASSETS, '.'
|
134
134
|
|
135
|
-
%w{.gitignore Rakefile assets test}.each do |f|
|
135
|
+
%w{.gitignore Rakefile assets res/layout test}.each do |f|
|
136
136
|
log_action(f) {copier.copy f}
|
137
137
|
end
|
138
|
+
|
139
|
+
# FIXME(uwe): Remove when we stop supporting upgrades from ruboto-core 0.3.3 and older
|
140
|
+
old_scripts_dir = 'assets/scripts'
|
141
|
+
if File.exists? old_scripts_dir
|
142
|
+
FileUtils.mv Dir["#{old_scripts_dir}/**/*"], SCRIPTS_DIR
|
143
|
+
FileUtils.rm_rf old_scripts_dir
|
144
|
+
end
|
145
|
+
# FIXME end
|
146
|
+
|
138
147
|
end
|
139
148
|
|
140
149
|
def update_icons(force = nil)
|
@@ -149,6 +158,29 @@ EOF
|
|
149
158
|
copier = Ruboto::Util::AssetCopier.new Ruboto::ASSETS, '.'
|
150
159
|
log_action("Ruboto java classes"){copier.copy "src/org/ruboto/*.java"}
|
151
160
|
log_action("Ruboto java test classes"){copier.copy "src/org/ruboto/test/*.java", "test"}
|
161
|
+
Dir["src/#{verify_package.gsub('.', '/')}/*.java"].each do |f|
|
162
|
+
if File.read(f) =~ /public class (.*?) extends org.ruboto.Ruboto(Activity|BroadcastReceiver|Service) \{/
|
163
|
+
subclass_name, class_name = $1, $2
|
164
|
+
puts "Regenerating #{subclass_name}"
|
165
|
+
generate_inheriting_file(class_name, subclass_name, verify_package)
|
166
|
+
|
167
|
+
# FIXME(uwe): Remove when we stop supporting upgrading from ruboto-core 0.3.3 and older
|
168
|
+
if class_name == 'BroadcastReceiver'
|
169
|
+
script_file = File.expand_path("#{SCRIPTS_DIR}/#{underscore(subclass_name)}.rb")
|
170
|
+
script_content = File.read(script_file)
|
171
|
+
if script_content !~ /\$broadcast_receiver.handle_receive do \|context, intent\|/
|
172
|
+
puts "Putting receiver script in a block in #{script_file}"
|
173
|
+
File.open(script_file, 'w') do |of|
|
174
|
+
of.puts '$broadcast_receiver.handle_receive do |context, intent|'
|
175
|
+
of << script_content
|
176
|
+
of.puts 'end'
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
# FIXME end
|
181
|
+
|
182
|
+
end
|
183
|
+
end
|
152
184
|
end
|
153
185
|
|
154
186
|
def update_manifest(min_sdk, target, force = false)
|
@@ -165,12 +197,12 @@ EOF
|
|
165
197
|
if app_element.elements["activity[@android:name='org.ruboto.RubotoActivity']"]
|
166
198
|
puts 'found activity tag'
|
167
199
|
else
|
168
|
-
app_element.add_element 'activity', {"android:name" => "org.ruboto.RubotoActivity"}
|
200
|
+
app_element.add_element 'activity', {"android:name" => "org.ruboto.RubotoActivity", 'android:exported' => 'false'}
|
169
201
|
end
|
170
202
|
if app_element.elements["activity[@android:name='org.ruboto.RubotoDialog']"]
|
171
203
|
puts 'found dialog tag'
|
172
204
|
else
|
173
|
-
app_element.add_element 'activity', {"android:name" => "org.ruboto.RubotoDialog", "android:theme" => "@android:style/Theme.Dialog"}
|
205
|
+
app_element.add_element 'activity', {"android:name" => "org.ruboto.RubotoDialog", 'android:exported' => 'false', "android:theme" => "@android:style/Theme.Dialog"}
|
174
206
|
end
|
175
207
|
if sdk_element
|
176
208
|
sdk_element.attributes["android:minSdkVersion"] = min_sdk
|
@@ -187,28 +219,17 @@ EOF
|
|
187
219
|
end
|
188
220
|
|
189
221
|
def update_ruboto(force=nil)
|
190
|
-
verify_manifest
|
191
|
-
|
192
|
-
from = File.expand_path(Ruboto::GEM_ROOT + "/assets/assets/scripts/ruboto.rb")
|
193
|
-
to = File.expand_path("./assets/scripts/ruboto.rb")
|
194
|
-
|
195
|
-
from_text = File.read(from)
|
196
|
-
to_text = File.read(to) if File.exists?(to)
|
197
|
-
|
198
|
-
unless force
|
199
|
-
puts "New version: #{from_text[/\$RUBOTO_VERSION = (\d+)/, 1]}"
|
200
|
-
puts "Old version: #{to_text ? to_text[/\$RUBOTO_VERSION = (\d+)/, 1] : 'none'}"
|
201
|
-
|
202
|
-
if from_text[/\$RUBOTO_VERSION = (\d+)/, 1] == to_text[/\$RUBOTO_VERSION = (\d+)/, 1]
|
203
|
-
puts "The ruboto.rb version has not changed. Use --force to force update."
|
204
|
-
return false
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
222
|
log_action("Copying ruboto.rb") do
|
209
|
-
File.
|
223
|
+
from = File.expand_path(Ruboto::GEM_ROOT + "/assets/#{SCRIPTS_DIR}/ruboto.rb")
|
224
|
+
to = File.expand_path("./#{SCRIPTS_DIR}/ruboto.rb")
|
225
|
+
FileUtils.cp from, to
|
226
|
+
end
|
227
|
+
log_action("Copying ruboto/version.rb") do
|
228
|
+
from = File.expand_path(Ruboto::GEM_ROOT + "/lib/ruboto/version.rb")
|
229
|
+
to = File.expand_path("./#{SCRIPTS_DIR}/ruboto/version.rb")
|
230
|
+
FileUtils.mkdir_p File.dirname(to)
|
231
|
+
FileUtils.cp from, to
|
210
232
|
end
|
211
|
-
true
|
212
233
|
end
|
213
234
|
|
214
235
|
def reconfigure_jruby_libs(jruby_core_version, with_psych=nil)
|
@@ -222,13 +243,15 @@ EOF
|
|
222
243
|
jruby_core = JRubyJars::core_jar_path.split('/')[-1]
|
223
244
|
Dir.chdir 'libs' do
|
224
245
|
log_action("Removing unneeded classes from #{jruby_core}") do
|
225
|
-
|
226
|
-
Dir.
|
246
|
+
FileUtils.rm_rf 'tmp'
|
247
|
+
Dir.mkdir 'tmp'
|
248
|
+
Dir.chdir 'tmp' do
|
227
249
|
FileUtils.move "../#{jruby_core}", "."
|
228
250
|
`jar -xf #{jruby_core}`
|
229
251
|
File.delete jruby_core
|
230
252
|
excluded_core_packages = [
|
231
|
-
'META-INF', 'cext', 'com/kenai/constantine', 'com/kenai/jffi', 'com/martiansoftware', 'ext', '
|
253
|
+
'META-INF', 'cext', 'com/kenai/constantine', 'com/kenai/jffi', 'com/martiansoftware', 'ext', 'java',
|
254
|
+
'jline', 'jni',
|
232
255
|
'jnr/constants/platform/darwin', 'jnr/constants/platform/fake', 'jnr/constants/platform/freebsd',
|
233
256
|
'jnr/constants/platform/openbsd', 'jnr/constants/platform/sunos', 'jnr/constants/platform/windows',
|
234
257
|
'org/apache', 'org/jruby/ant', 'org/jruby/compiler/ir', 'org/jruby/demo', 'org/jruby/embed/bsf',
|
@@ -176,7 +176,7 @@ module Ruboto
|
|
176
176
|
convert_return = ", #{return_class}.class"
|
177
177
|
end
|
178
178
|
|
179
|
-
rv << "#{return_cast}
|
179
|
+
rv << "#{return_cast}Script.callMethod(callbackProcs[#{constant_string}], \"call\" #{args}#{convert_return});"
|
180
180
|
rv
|
181
181
|
end
|
182
182
|
|
@@ -186,7 +186,7 @@ module Ruboto
|
|
186
186
|
attribute("name"), parameters,
|
187
187
|
if_else(
|
188
188
|
"callbackProcs[#{constant_string}] != null",
|
189
|
-
[super_string] +
|
189
|
+
[super_string] + ruby_call,
|
190
190
|
[super_return]
|
191
191
|
)
|
192
192
|
).indent.join("\n")
|
@@ -3,7 +3,7 @@ require 'ruboto'
|
|
3
3
|
ruboto_import_widgets :ImageButton, :LinearLayout, :TextView
|
4
4
|
|
5
5
|
$activity.handle_create do |bundle|
|
6
|
-
setTitle '
|
6
|
+
setTitle File.basename(__FILE__).chomp('_activity.rb').split('_').map{|s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ')
|
7
7
|
|
8
8
|
setup_content do
|
9
9
|
linear_layout :orientation => LinearLayout::VERTICAL do
|
@@ -3,7 +3,7 @@ require 'ruboto'
|
|
3
3
|
ruboto_import_widgets :Button, :ImageButton, :LinearLayout, :TextView
|
4
4
|
|
5
5
|
$activity.handle_create do |bundle|
|
6
|
-
setTitle '
|
6
|
+
setTitle File.basename(__FILE__).chomp('_activity.rb').split('_').map{|s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ')
|
7
7
|
|
8
8
|
setup_content do
|
9
9
|
linear_layout :orientation => LinearLayout::VERTICAL do
|
@@ -0,0 +1,21 @@
|
|
1
|
+
STACK_DEPTH_SCRIPT = java.lang.Thread.current_thread.stack_trace.length.to_s
|
2
|
+
require 'ruboto'
|
3
|
+
|
4
|
+
ruboto_import_widgets :Button, :LinearLayout, :TextView
|
5
|
+
|
6
|
+
$activity.handle_create do |bundle|
|
7
|
+
STACK_DEPTH_HANDLE_CREATE = java.lang.Thread.current_thread.stack_trace.length.to_s
|
8
|
+
setTitle File.basename(__FILE__).chomp('_activity.rb').split('_').map{|s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ')
|
9
|
+
|
10
|
+
setup_content do
|
11
|
+
STACK_DEPTH_SETUP_CONTENT = java.lang.Thread.current_thread.stack_trace.length.to_s
|
12
|
+
linear_layout :orientation => LinearLayout::VERTICAL do
|
13
|
+
STACK_DEPTH_LINEAR_LAYOUT = java.lang.Thread.current_thread.stack_trace.length.to_s
|
14
|
+
@script_view = text_view :id => 42, :text => STACK_DEPTH_SCRIPT
|
15
|
+
@handle_create_view = text_view :id => 43, :text => STACK_DEPTH_HANDLE_CREATE
|
16
|
+
@setup_content_view = text_view :id => 44, :text => STACK_DEPTH_SETUP_CONTENT
|
17
|
+
@linear_layout_view = text_view :id => 45, :text => STACK_DEPTH_LINEAR_LAYOUT
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
activity org.ruboto.test_app.StackActivity
|
2
|
+
|
3
|
+
setup do |activity|
|
4
|
+
start = Time.now
|
5
|
+
loop do
|
6
|
+
@text_view = activity.findViewById(42)
|
7
|
+
break if @text_view || (Time.now - start > 60)
|
8
|
+
sleep 1
|
9
|
+
end
|
10
|
+
assert @text_view
|
11
|
+
end
|
12
|
+
|
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
|
+
'1.7.0.dev' => [ 0, 2, 5, 5],
|
18
|
+
}[org.jruby.runtime.Constants::VERSION] || [0,0,0,0]
|
19
|
+
version_message ="ANDROID: #{android.os.Build::VERSION::SDK_INT}, JRuby: #{org.jruby.runtime.Constants::VERSION}"
|
20
|
+
assert_equal 44 + os_offset + jruby_offset[0], activity.find_view_by_id(42).text.to_i, version_message
|
21
|
+
assert_equal 68 + os_offset + jruby_offset[1], activity.find_view_by_id(43).text.to_i, version_message
|
22
|
+
assert_equal 77 + os_offset + jruby_offset[2], activity.find_view_by_id(44).text.to_i, version_message
|
23
|
+
assert_equal 96 + os_offset + jruby_offset[3], activity.find_view_by_id(45).text.to_i, version_message
|
24
|
+
end
|