ruboto 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +35 -11
- data/assets/rakelib/ruboto.rake +2 -0
- data/assets/samples/sample_activity.rb +1 -0
- data/assets/samples/sample_class.rb +2 -0
- data/assets/samples/sample_class_test.rb +1 -0
- data/assets/src/InheritingActivity.java +1 -1
- data/assets/src/InheritingBroadcastReceiver.java +2 -1
- data/assets/src/InheritingClass.java +15 -7
- data/assets/src/InheritingService.java +1 -2
- data/assets/src/RubotoActivity.java +20 -110
- data/assets/src/RubotoBroadcastReceiver.java +16 -62
- data/assets/src/RubotoService.java +13 -89
- data/assets/src/org/ruboto/EntryPointActivity.java +1 -1
- data/assets/src/org/ruboto/JRubyAdapter.java +23 -23
- data/assets/src/org/ruboto/RubotoComponent.java +8 -0
- data/assets/src/org/ruboto/Script.java +10 -5
- data/assets/src/org/ruboto/ScriptInfo.java +53 -0
- data/assets/src/org/ruboto/ScriptLoader.java +143 -0
- data/assets/src/org/ruboto/test/ActivityTest.java +15 -8
- data/assets/src/org/ruboto/test/InstrumentationTestRunner.java +11 -6
- data/assets/src/ruboto/activity.rb +43 -17
- data/assets/src/ruboto/base.rb +7 -1
- data/assets/src/ruboto/generate.rb +6 -2
- data/assets/src/ruboto/legacy.rb +1 -1
- data/assets/src/ruboto/menu.rb +4 -4
- data/assets/src/ruboto/widget.rb +4 -11
- data/lib/ruboto/commands/base.rb +21 -7
- data/lib/ruboto/util/build.rb +6 -3
- data/lib/ruboto/util/code_formatting.rb +2 -2
- data/lib/ruboto/util/update.rb +58 -58
- data/lib/ruboto/util/xml_element.rb +14 -11
- data/lib/ruboto/version.rb +2 -1
- data/test/activity/generate_activity.rb +35 -0
- data/test/activity/generate_activity_test.rb +17 -0
- data/test/activity/image_button_activity.rb +1 -0
- data/test/activity/image_button_and_button_activity.rb +1 -0
- data/test/activity/margins_activity.rb +1 -0
- data/test/activity/navigation_activity.rb +20 -5
- data/test/activity/navigation_activity_test.rb +43 -4
- data/test/activity/option_menu_activity.rb +1 -0
- data/test/activity/psych_activity.rb +2 -1
- data/test/activity/stack_activity.rb +1 -0
- data/test/activity/stack_activity_test.rb +11 -5
- data/test/block_def_activity/margins_activity.rb +2 -1
- data/test/block_def_activity/psych_activity.rb +1 -1
- data/test/block_def_activity/stack_activity_test.rb +1 -1
- data/test/handle_activity/psych_activity.rb +1 -1
- data/test/handle_activity/stack_activity_test.rb +17 -9
- data/test/minimal_app_test.rb +2 -2
- data/test/rake_test.rb +1 -1
- data/test/ruboto_gen_test.rb +162 -34
- data/test/service_test.rb +1 -2
- data/test/sqldroid_test.rb +87 -0
- data/test/test_helper.rb +19 -12
- data/test/update_test_methods.rb +29 -44
- data/test/view_constants_test.rb +1 -2
- metadata +12 -4
@@ -17,14 +17,16 @@ import org.ruboto.JRubyAdapter;
|
|
17
17
|
|
18
18
|
public class ActivityTest extends ActivityInstrumentationTestCase2 {
|
19
19
|
private final Object setup;
|
20
|
+
private final Object teardown;
|
20
21
|
private final Object block;
|
21
22
|
private final String filename;
|
22
23
|
private final boolean onUiThread;
|
23
24
|
|
24
|
-
public ActivityTest(Class activityClass, String filename, Object setup, String name, boolean onUiThread, Object block) {
|
25
|
+
public ActivityTest(Class activityClass, String filename, Object setup, Object teardown, String name, boolean onUiThread, Object block) {
|
25
26
|
super(activityClass.getPackage().getName(), activityClass);
|
26
27
|
this.filename = filename;
|
27
28
|
this.setup = setup;
|
29
|
+
this.teardown = teardown;
|
28
30
|
setName(filename + "#" + name);
|
29
31
|
this.onUiThread = onUiThread;
|
30
32
|
this.block = block;
|
@@ -38,16 +40,21 @@ public class ActivityTest extends ActivityInstrumentationTestCase2 {
|
|
38
40
|
Log.i(getClass().getName(), "Activity OK");
|
39
41
|
Runnable testRunnable = new Runnable() {
|
40
42
|
public void run() {
|
41
|
-
|
43
|
+
if (setup != null) {
|
44
|
+
Log.i(getClass().getName(), "calling setup");
|
45
|
+
JRubyAdapter.setScriptFilename(filename);
|
46
|
+
JRubyAdapter.runRubyMethod(setup, "call", activity);
|
47
|
+
Log.i(getClass().getName(), "setup ok");
|
48
|
+
}
|
42
49
|
|
43
|
-
Log.i(getClass().getName(), "calling setup");
|
44
|
-
JRubyAdapter.setScriptFilename(filename);
|
45
|
-
JRubyAdapter.runRubyMethod(setup, "call", activity);
|
46
|
-
Log.i(getClass().getName(), "setup ok");
|
47
|
-
|
48
50
|
JRubyAdapter.setScriptFilename(filename);
|
49
51
|
JRubyAdapter.runRubyMethod(block, "call", activity);
|
50
|
-
|
52
|
+
|
53
|
+
if (teardown != null) {
|
54
|
+
Log.i(getClass().getName(), "calling teardown");
|
55
|
+
JRubyAdapter.runRubyMethod(teardown, "call", activity);
|
56
|
+
Log.i(getClass().getName(), "teardown ok");
|
57
|
+
}
|
51
58
|
}
|
52
59
|
};
|
53
60
|
if (onUiThread) {
|
@@ -31,6 +31,7 @@ import java.util.HashSet;
|
|
31
31
|
public class InstrumentationTestRunner extends android.test.InstrumentationTestRunner {
|
32
32
|
private Class activityClass;
|
33
33
|
private Object setup;
|
34
|
+
private Object teardown;
|
34
35
|
private TestSuite suite;
|
35
36
|
|
36
37
|
public TestSuite getAllTests() {
|
@@ -99,6 +100,7 @@ public class InstrumentationTestRunner extends android.test.InstrumentationTestR
|
|
99
100
|
if (name.equals("test_helper.rb")) continue;
|
100
101
|
loadStep = "Load " + name;
|
101
102
|
loadScript(name);
|
103
|
+
setup = teardown = null;
|
102
104
|
}
|
103
105
|
} else {
|
104
106
|
addError(suite, loadStep, new RuntimeException("Ruboto Core platform is missing"));
|
@@ -121,6 +123,10 @@ public class InstrumentationTestRunner extends android.test.InstrumentationTestR
|
|
121
123
|
this.setup = block;
|
122
124
|
}
|
123
125
|
|
126
|
+
public void teardown(Object block) {
|
127
|
+
this.teardown = block;
|
128
|
+
}
|
129
|
+
|
124
130
|
public void test(String name, Object block) {
|
125
131
|
test(name, null, block);
|
126
132
|
}
|
@@ -134,7 +140,7 @@ public class InstrumentationTestRunner extends android.test.InstrumentationTestR
|
|
134
140
|
|
135
141
|
boolean runOnUiThread = options == null || options.get("ui") == "true";
|
136
142
|
|
137
|
-
Test test = new ActivityTest(activityClass, JRubyAdapter.getScriptFilename(), setup, name, runOnUiThread, block);
|
143
|
+
Test test = new ActivityTest(activityClass, JRubyAdapter.getScriptFilename(), setup, teardown, name, runOnUiThread, block);
|
138
144
|
suite.addTest(test);
|
139
145
|
Log.d(getClass().getName(), "Made test instance: " + test);
|
140
146
|
}
|
@@ -166,21 +172,20 @@ public class InstrumentationTestRunner extends android.test.InstrumentationTestR
|
|
166
172
|
source.append(line).append("\n");
|
167
173
|
}
|
168
174
|
buffer.close();
|
175
|
+
JRubyAdapter.setScriptFilename(f);
|
169
176
|
|
170
177
|
// FIXME(uwe): Simplify when we stop supporting JRuby < 1.7.0
|
171
178
|
if (JRubyAdapter.isJRubyPreOneSeven()) {
|
172
179
|
JRubyAdapter.put("$test", this);
|
173
180
|
JRubyAdapter.put("$script_code", source.toString());
|
174
|
-
JRubyAdapter.
|
181
|
+
JRubyAdapter.put("$filename", f);
|
182
|
+
JRubyAdapter.runScriptlet("$test.instance_eval($script_code, $filename)");
|
175
183
|
} else {
|
176
|
-
String oldFilename = JRubyAdapter.getScriptFilename();
|
177
|
-
JRubyAdapter.setScriptFilename(f);
|
178
184
|
if (f.equals("test_helper.rb")) {
|
179
185
|
JRubyAdapter.runScriptlet(source.toString());
|
180
186
|
} else {
|
181
|
-
JRubyAdapter.runRubyMethod(this, "instance_eval", source.toString());
|
187
|
+
JRubyAdapter.runRubyMethod(this, "instance_eval", source.toString(), f);
|
182
188
|
}
|
183
|
-
JRubyAdapter.setScriptFilename(oldFilename);
|
184
189
|
}
|
185
190
|
Log.d(getClass().getName(), "Test script " + f + " loaded");
|
186
191
|
}
|
@@ -32,27 +32,57 @@ module Ruboto
|
|
32
32
|
start_ruboto_activity(remote_variable, RubotoDialog, theme, &block)
|
33
33
|
end
|
34
34
|
|
35
|
-
def start_ruboto_activity(global_variable_name = '$activity', klass=RubotoActivity, theme=nil, &block)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
def start_ruboto_activity(global_variable_name = '$activity', klass=RubotoActivity, theme=nil, options = nil, &block)
|
36
|
+
# FIXME(uwe): Translate old positional signature to new options-based signature.
|
37
|
+
# FIXME(uwe): Remove when we stop supporting Ruboto 0.8.0 or older.
|
38
|
+
if options.nil?
|
39
|
+
if global_variable_name.is_a?(Hash)
|
40
|
+
options = global_variable_name
|
41
|
+
else
|
42
|
+
options = {}
|
43
|
+
end
|
44
|
+
global_variable_name = nil
|
45
|
+
end
|
46
|
+
|
47
|
+
# FIXME(uwe): Used for block-based definition of main activity.
|
48
|
+
# FIXME(uwe): Remove when we stop supporting Ruboto 0.8.0 or older.
|
49
|
+
puts "start_ruboto_activity self: #{self.inspect}"
|
50
|
+
if @ruboto_java_class and not @ruboto_java_class_initialized
|
51
|
+
@ruboto_java_class_initialized = true
|
52
|
+
puts "Block based main activity definition"
|
53
|
+
instance_eval &block if block
|
54
|
+
setup_ruboto_callbacks
|
55
|
+
on_create nil
|
56
|
+
else
|
57
|
+
puts "Class based main activity definition"
|
58
|
+
class_name = options[:class_name] || "#{klass.name.split('::').last}_#{source_descriptor(block)[0].split("/").last.gsub(/[.]+/, '_')}_#{source_descriptor(block)[1]}"
|
59
|
+
if !Object.const_defined?(class_name)
|
60
|
+
Object.const_set(class_name, Class.new(&block))
|
61
|
+
else
|
62
|
+
Object.const_get(class_name).class_eval(&block)
|
63
|
+
end
|
40
64
|
b = Java::android.os.Bundle.new
|
41
65
|
b.putInt("Theme", theme) if theme
|
42
|
-
|
43
|
-
i =
|
66
|
+
b.putString("ClassName", class_name)
|
67
|
+
i = android.content.Intent.new
|
44
68
|
i.setClass self, klass.java_class
|
45
69
|
i.putExtra("RubotoActivity Config", b)
|
46
|
-
|
47
|
-
self.startActivity i
|
48
|
-
else
|
49
|
-
initialize_ruboto
|
50
|
-
on_create nil
|
70
|
+
startActivity i
|
51
71
|
end
|
52
|
-
|
53
72
|
self
|
54
73
|
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def source_descriptor(proc)
|
78
|
+
if md = /^#<Proc:0x[0-9A-Fa-f]+@(.+):(\d+)(?: \(lambda\))?>$/.match(proc.inspect)
|
79
|
+
filename, line = md.captures
|
80
|
+
return filename, line.to_i
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
55
84
|
end
|
85
|
+
|
56
86
|
end
|
57
87
|
|
58
88
|
java_import "android.content.Context"
|
@@ -76,10 +106,6 @@ end
|
|
76
106
|
def ruboto_configure_activity(klass)
|
77
107
|
klass.class_eval do
|
78
108
|
include Ruboto::Activity
|
79
|
-
|
80
|
-
# Can't be moved into the module
|
81
|
-
def on_create(bundle)
|
82
|
-
end
|
83
109
|
end
|
84
110
|
end
|
85
111
|
|
data/assets/src/ruboto/base.rb
CHANGED
@@ -22,6 +22,12 @@ module Kernel
|
|
22
22
|
def android
|
23
23
|
JavaUtilities.get_package_module_dot_format('android')
|
24
24
|
end
|
25
|
+
|
26
|
+
alias :old_method_missing :method_missing
|
27
|
+
def method_missing(method, *args, &block)
|
28
|
+
return @ruboto_java_instance.send(method, *args, &block) if @ruboto_java_instance && @ruboto_java_instance.respond_to?(method)
|
29
|
+
old_method_missing(method, *args, &block)
|
30
|
+
end
|
25
31
|
end
|
26
32
|
|
27
33
|
java_import "android.R"
|
@@ -54,7 +60,7 @@ module Ruboto
|
|
54
60
|
ruboto_callback_methods.each do |i|
|
55
61
|
begin
|
56
62
|
# FIXME(uwe): Remove to_sym conversion when we stop supporting Ruby 1.8 mode
|
57
|
-
setCallbackProc((self.class.constants.map(&:to_sym).include?(i.to_s.sub(/^on_/, "CB_").upcase.to_sym) && self.class.const_get(i.to_s.sub(/^on_/, "CB_").upcase)) || (self.class.constants.map(&:to_sym).include?("CB_#{i}".upcase.to_sym) && self.class.const_get("CB_#{i}".upcase)), method(i))
|
63
|
+
scriptInfo.setCallbackProc((self.class.constants.map(&:to_sym).include?(i.to_s.sub(/^on_/, "CB_").upcase.to_sym) && self.class.const_get(i.to_s.sub(/^on_/, "CB_").upcase)) || (self.class.constants.map(&:to_sym).include?("CB_#{i}".upcase.to_sym) && self.class.const_get("CB_#{i}".upcase)), method(i))
|
58
64
|
rescue
|
59
65
|
end
|
60
66
|
end
|
@@ -43,11 +43,15 @@ class TypeId
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def self.convert_type(type)
|
46
|
-
# TODO: Handling arrays
|
47
46
|
rv = @@convert_hash[type]
|
48
47
|
unless rv
|
49
48
|
rv = type.split("[")
|
50
|
-
|
49
|
+
unless rv[-1].length == 1
|
50
|
+
rv[-1] = rv[-1].gsub('.', '/')
|
51
|
+
unless rv[-1] =~ /^L.*;$/
|
52
|
+
rv[-1] = "L#{rv[-1]};"
|
53
|
+
end
|
54
|
+
end
|
51
55
|
rv = get(rv.join("["))
|
52
56
|
end
|
53
57
|
rv
|
data/assets/src/ruboto/legacy.rb
CHANGED
@@ -17,7 +17,7 @@ module Ruboto
|
|
17
17
|
module Callbacks
|
18
18
|
def method_missing(name, *args, &block)
|
19
19
|
if name.to_s =~ /^handle_(.*)/ && self.class.respond_to?(:const_get) && (const = self.class.const_get("CB_#{$1.upcase}"))
|
20
|
-
setCallbackProc(const, block)
|
20
|
+
scriptInfo.setCallbackProc(const, block)
|
21
21
|
self
|
22
22
|
else
|
23
23
|
super
|
data/assets/src/ruboto/menu.rb
CHANGED
@@ -30,7 +30,7 @@ module Ruboto
|
|
30
30
|
@menu = args[0]
|
31
31
|
instance_eval { block.call(*args) } if block
|
32
32
|
end
|
33
|
-
setCallbackProc(self.class.const_get("CB_CREATE_OPTIONS_MENU"), p)
|
33
|
+
scriptInfo.setCallbackProc(self.class.const_get("CB_CREATE_OPTIONS_MENU"), p)
|
34
34
|
|
35
35
|
p = Proc.new do |num, menu_item|
|
36
36
|
# handles a problem where this is called for context items
|
@@ -43,7 +43,7 @@ module Ruboto
|
|
43
43
|
false
|
44
44
|
end
|
45
45
|
end
|
46
|
-
setCallbackProc(self.class.const_get("CB_MENU_ITEM_SELECTED"), p)
|
46
|
+
scriptInfo.setCallbackProc(self.class.const_get("CB_MENU_ITEM_SELECTED"), p)
|
47
47
|
end
|
48
48
|
|
49
49
|
#
|
@@ -65,7 +65,7 @@ module Ruboto
|
|
65
65
|
@context_menu = args[0]
|
66
66
|
instance_eval { block.call(*args) } if block
|
67
67
|
end
|
68
|
-
setCallbackProc(self.class.const_get("CB_CREATE_CONTEXT_MENU"), p)
|
68
|
+
scriptInfo.setCallbackProc(self.class.const_get("CB_CREATE_CONTEXT_MENU"), p)
|
69
69
|
|
70
70
|
p = Proc.new do |menu_item|
|
71
71
|
if menu_item.on_click
|
@@ -81,7 +81,7 @@ module Ruboto
|
|
81
81
|
false
|
82
82
|
end
|
83
83
|
end
|
84
|
-
setCallbackProc(self.class.const_get("CB_CONTEXT_ITEM_SELECTED"), p)
|
84
|
+
scriptInfo.setCallbackProc(self.class.const_get("CB_CONTEXT_ITEM_SELECTED"), p)
|
85
85
|
end
|
86
86
|
end
|
87
87
|
end
|
data/assets/src/ruboto/widget.rb
CHANGED
@@ -157,19 +157,12 @@ end
|
|
157
157
|
|
158
158
|
def setup_list_view
|
159
159
|
Java::android.widget.ListView.class_eval do
|
160
|
-
attr_reader :adapter, :adapter_list
|
161
|
-
|
162
160
|
def configure(context, params = {})
|
163
|
-
if params.
|
164
|
-
|
165
|
-
|
161
|
+
if list = params.delete(:list)
|
162
|
+
adapter_list = Java::java.util.ArrayList.new
|
163
|
+
adapter_list.addAll(list)
|
166
164
|
item_layout = params.delete(:item_layout) || R::layout::simple_list_item_1
|
167
|
-
|
168
|
-
setAdapter @adapter
|
169
|
-
params.delete :list
|
170
|
-
end
|
171
|
-
if params.has_key? :adapter
|
172
|
-
@adapter = params[:adapter]
|
165
|
+
params[:adapter] = Java::android.widget.ArrayAdapter.new(context, item_layout, adapter_list)
|
173
166
|
end
|
174
167
|
super(context, params)
|
175
168
|
end
|
data/lib/ruboto/commands/base.rb
CHANGED
@@ -95,9 +95,9 @@ module Ruboto
|
|
95
95
|
update_assets
|
96
96
|
update_ruboto true
|
97
97
|
update_icons true
|
98
|
-
update_classes true
|
98
|
+
update_classes nil, true
|
99
99
|
update_jruby true if params['with-jruby'].value
|
100
|
-
|
100
|
+
update_dexmaker true unless params['with-jruby'].value
|
101
101
|
update_core_classes "exclude"
|
102
102
|
|
103
103
|
log_action("Generating the default Activity and script") do
|
@@ -116,9 +116,7 @@ module Ruboto
|
|
116
116
|
include Ruboto::Util::Verify
|
117
117
|
|
118
118
|
def run
|
119
|
-
|
120
|
-
update_jruby true
|
121
|
-
end
|
119
|
+
update_jruby true
|
122
120
|
end
|
123
121
|
end
|
124
122
|
|
@@ -217,6 +215,7 @@ module Ruboto
|
|
217
215
|
}
|
218
216
|
|
219
217
|
def run
|
218
|
+
generate_inheriting_file 'Class', params['name'].value
|
220
219
|
generate_subclass_or_interface(
|
221
220
|
%w(class name package method_base method_include method_exclude implements force).inject({}) {|h, i| h[i.to_sym] = params[i].value; h})
|
222
221
|
end
|
@@ -248,6 +247,9 @@ module Ruboto
|
|
248
247
|
}
|
249
248
|
|
250
249
|
def run
|
250
|
+
# FIXME(uwe): DEPRECATED! Remove before Ruboto version 1.0.0.
|
251
|
+
puts "\nThe use of \"ruboto gen interface\" has been deprecated. Please use\n\n ruboto gen subclass\n\ninstead.\n\n"
|
252
|
+
generate_inheriting_file 'Class', params['name'].value
|
251
253
|
generate_subclass_or_interface %w(interface name package force).inject({}) {|h, i| h[i.to_sym] = params[i].value; h}
|
252
254
|
end
|
253
255
|
end
|
@@ -330,6 +332,7 @@ module Ruboto
|
|
330
332
|
|
331
333
|
argument("what") {
|
332
334
|
required
|
335
|
+
# FIXME(uwe): Deprecated "ruboto update ruboto" in Ruboto 0.8.1. Remove september 2013.
|
333
336
|
validate {|i| %w(jruby app ruboto).include?(i)}
|
334
337
|
description "What do you want to update: 'app', 'jruby', or 'ruboto'"
|
335
338
|
}
|
@@ -342,11 +345,20 @@ module Ruboto
|
|
342
345
|
case params['what'].value
|
343
346
|
when "app" then
|
344
347
|
force = params['force'].value
|
348
|
+
old_version = read_ruboto_version
|
349
|
+
if Gem::Version.new(old_version) < Gem::Version.new(Ruboto::UPDATE_VERSION_LIMIT)
|
350
|
+
puts "Detected old Ruboto version: #{old_version}"
|
351
|
+
puts "Will use Ruboto #{Ruboto::UPDATE_VERSION_LIMIT} to update it first."
|
352
|
+
`gem query -i -n ruboto -v #{Ruboto::UPDATE_VERSION_LIMIT}`
|
353
|
+
system "gem install ruboto -v #{Ruboto::UPDATE_VERSION_LIMIT}" unless $? == 0
|
354
|
+
system "ruboto _#{Ruboto::UPDATE_VERSION_LIMIT}_ update app"
|
355
|
+
end
|
345
356
|
update_android
|
346
357
|
update_test force
|
347
358
|
update_assets
|
348
359
|
update_ruboto force
|
349
|
-
update_classes force
|
360
|
+
update_classes old_version, force
|
361
|
+
update_dexmaker force
|
350
362
|
update_jruby force
|
351
363
|
update_manifest nil, nil, force
|
352
364
|
update_icons force
|
@@ -354,7 +366,9 @@ module Ruboto
|
|
354
366
|
update_bundle
|
355
367
|
when "jruby" then
|
356
368
|
update_jruby(params['force'].value) || abort
|
369
|
+
# FIXME(uwe): Deprecated in Ruboto 0.8.1. Remove september 2013.
|
357
370
|
when "ruboto" then
|
371
|
+
puts "\nThe 'ruboto update ruboto' command has been deprecated. Use\n\n ruboto update app\n\ninstead.\n\n"
|
358
372
|
update_ruboto(params['force'].value) || abort
|
359
373
|
end
|
360
374
|
end
|
@@ -372,7 +386,7 @@ module Ruboto
|
|
372
386
|
else
|
373
387
|
gem_spec = Gem.searcher.find('ruboto')
|
374
388
|
end
|
375
|
-
#
|
389
|
+
# EMXIF
|
376
390
|
|
377
391
|
version = gem_spec.version.version
|
378
392
|
|
data/lib/ruboto/util/build.rb
CHANGED
@@ -115,12 +115,15 @@ module Ruboto
|
|
115
115
|
# Remove any duplicate constants (use *args handle multiple parameter lists)
|
116
116
|
constants = methods.map(&:constant_string).uniq
|
117
117
|
|
118
|
+
params[:implements] = params[:implements].split(",").push('org.ruboto.RubotoComponent').join(",")
|
119
|
+
|
120
|
+
action = class_desc.name == "class" ? "extends" : "implements"
|
118
121
|
build_file params[:template], params[:package], params[:name], {
|
119
122
|
"THE_METHOD_BASE" => params[:method_base].to_s,
|
120
123
|
"THE_PACKAGE" => params[:package],
|
121
|
-
"THE_ACTION" =>
|
124
|
+
"THE_ACTION" => action,
|
122
125
|
"THE_ANDROID_CLASS" => (params[:class] || params[:interface]) +
|
123
|
-
(params[:implements] == "" ? "" : (" implements " + params[:implements].split(",").join(", "))),
|
126
|
+
(params[:implements] == "" ? "" : ((action != 'implements' ? " implements " : ', ') + params[:implements].split(",").join(", "))),
|
124
127
|
"THE_RUBOTO_CLASS" => params[:name],
|
125
128
|
"THE_CONSTANTS" => constants.map { |i| "public static final int #{i} = #{constants.index(i)};" }.indent.join("\n"),
|
126
129
|
"CONSTANTS_COUNT" => methods.count.to_s,
|
@@ -160,7 +163,7 @@ module Ruboto
|
|
160
163
|
# generate_inheriting_file:
|
161
164
|
# Builds a script based subclass of Activity, Service, or BroadcastReceiver
|
162
165
|
#
|
163
|
-
def generate_inheriting_file(klass, name, package, script_name = "#{underscore(name)}.rb")
|
166
|
+
def generate_inheriting_file(klass, name, package = verify_package, script_name = "#{underscore(name)}.rb")
|
164
167
|
dest = '.'
|
165
168
|
file = File.expand_path File.join(dest, "src/#{package.gsub('.', '/')}", "#{name}.java")
|
166
169
|
text = File.read(File.join(Ruboto::ASSETS, "src/Inheriting#{klass}.java"))
|
@@ -5,8 +5,8 @@ module Ruboto
|
|
5
5
|
#
|
6
6
|
# Methods for formatting code
|
7
7
|
#
|
8
|
-
def method_call(return_type
|
9
|
-
["public #{"#{return_type} " unless return_type.nil? || return_type.empty?}#{method_name}(" + parameters.map{|i| "#{i[1]} #{i[0]}"}.join(", ") + ") {",
|
8
|
+
def method_call(return_type, method_name, parameters=[], exceptions=nil, body_clause=[])
|
9
|
+
["public #{"#{return_type} " unless return_type.nil? || return_type.empty?}#{method_name}(" + parameters.map{|i| "#{i[1]} #{i[0]}"}.join(", ") + ") #{" throws #{exceptions.join(', ')}" if exceptions && exceptions.any?}{",
|
10
10
|
body_clause.indent, "}"]
|
11
11
|
end
|
12
12
|
|
data/lib/ruboto/util/update.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'ruboto/version'
|
2
|
+
|
1
3
|
module Ruboto
|
2
4
|
module Util
|
3
5
|
module Update
|
@@ -23,7 +25,7 @@ module Ruboto
|
|
23
25
|
puts "Forcing generation of new build.xml since upgrading a project generated with Android SDK 13 or older."
|
24
26
|
FileUtils.rm_f build_xml_file
|
25
27
|
end
|
26
|
-
#
|
28
|
+
# EMXIF
|
27
29
|
|
28
30
|
# FIXME(uwe): Simplify when we stop supporting upgrading apps from Android SDK <= 13
|
29
31
|
prop_file = File.exists?(new_prop_file) ? new_prop_file : old_prop_file
|
@@ -34,7 +36,7 @@ module Ruboto
|
|
34
36
|
File.open(prop_file, 'w') { |f| f << project_property_file.gsub(version_regexp, "\\1#{MINIMUM_SUPPORTED_SDK_LEVEL}") }
|
35
37
|
end
|
36
38
|
end
|
37
|
-
#
|
39
|
+
# EMXIF
|
38
40
|
|
39
41
|
system "android update project -p #{root} -n #{name}"
|
40
42
|
raise "android update project failed with return code #{$?}" unless $? == 0
|
@@ -52,7 +54,7 @@ module Ruboto
|
|
52
54
|
# FIXME(uwe): Remove build.xml file to force regeneration.
|
53
55
|
# FIXME(uwe): Needed when updating apps from Android SDK <= 13 to 14
|
54
56
|
FileUtils.rm_f "#{root}/test/build.xml"
|
55
|
-
|
57
|
+
# EMXIF
|
56
58
|
|
57
59
|
puts "\nUpdating Android test project #{name} in #{root}/test..."
|
58
60
|
system "android update test-project -m #{root} -p #{root}/test"
|
@@ -85,7 +87,7 @@ module Ruboto
|
|
85
87
|
prop_file = %w{ant.properties build.properties}.find { |f| File.exists?(f) }
|
86
88
|
prop_lines = File.readlines(prop_file)
|
87
89
|
File.open(prop_file, 'a') { |f| f << instrumentation_property } unless prop_lines.include?(instrumentation_property)
|
88
|
-
#
|
90
|
+
# EMXIF
|
89
91
|
|
90
92
|
ant_setup_line = /^(\s*<\/project>)/
|
91
93
|
run_tests_override = <<-EOF
|
@@ -134,22 +136,18 @@ module Ruboto
|
|
134
136
|
|
135
137
|
EOF
|
136
138
|
ant_script = File.read('build.xml')
|
137
|
-
# TODO(uwe): Old patches without delimiter. Remove when we stop supporting upgrading from ruboto-core 0.2.0 and older.
|
138
|
-
ant_script.gsub!(/\s*<macrodef name="run-tests-helper">.*?<\/macrodef>\s*/m, '')
|
139
|
-
ant_script.gsub!(/\s*<target name="run-tests-quick".*?<\/target>\s*/m, '')
|
140
|
-
# TODO end
|
141
139
|
ant_script.gsub!(/\s*<!-- BEGIN added by ruboto(?:-core)? -->.*?<!-- END added by ruboto(?:-core)? -->\s*/m, '')
|
142
140
|
raise "Bad ANT script" unless ant_script.gsub!(ant_setup_line, "#{run_tests_override}\n\n\\1")
|
143
141
|
File.open('build.xml', 'w') { |f| f << ant_script }
|
144
142
|
|
145
|
-
# FIXME(uwe): Remove when we stop supporting update from Ruboto
|
143
|
+
# FIXME(uwe): Remove when we stop supporting update from Ruboto < 0.5.3
|
146
144
|
if File.directory? 'assets/scripts'
|
147
145
|
log_action 'Moving test scripts to the "src" directory.' do
|
148
146
|
FileUtils.mv Dir['assets/scripts/*'], 'src'
|
149
147
|
FileUtils.rm_rf 'assets/scripts'
|
150
148
|
end
|
151
149
|
end
|
152
|
-
#
|
150
|
+
# EMXIF
|
153
151
|
end
|
154
152
|
end
|
155
153
|
|
@@ -190,9 +188,9 @@ module Ruboto
|
|
190
188
|
log_action("Copying #{JRubyJars::stdlib_jar_path} to libs") { copier.copy_from_absolute_path JRubyJars::stdlib_jar_path, "libs" }
|
191
189
|
|
192
190
|
# FIXME(uwe): Try keeping the class count low to enable installation on Android 2.3 devices
|
193
|
-
unless new_jruby_version =~ /^1.7.0/ && verify_target_sdk < 15
|
191
|
+
# unless new_jruby_version =~ /^1.7.0/ && verify_target_sdk < 15
|
194
192
|
log_action("Copying dexmaker.jar to libs") { copier.copy 'libs' }
|
195
|
-
end
|
193
|
+
# end
|
196
194
|
|
197
195
|
reconfigure_jruby_libs(new_jruby_version)
|
198
196
|
|
@@ -200,14 +198,32 @@ module Ruboto
|
|
200
198
|
true
|
201
199
|
end
|
202
200
|
|
201
|
+
def update_dexmaker(force=nil)
|
202
|
+
jar_file = Dir.glob("libs/dexmaker*.jar")[0]
|
203
|
+
|
204
|
+
# FIXME(uwe): Skip copying dexmaker to apps using RubotoCore when we include dexmaker.jar in RubotoCore
|
205
|
+
# return false if !jar_file && !force
|
206
|
+
|
207
|
+
copier = AssetCopier.new Ruboto::ASSETS, File.expand_path(".")
|
208
|
+
# FIXME(uwe): Skip copying dexmaker to apps using RubotoCore when we include dexmaker.jar in RubotoCore
|
209
|
+
# log_action("Removing #{jar_file}") { File.delete *Dir.glob("libs/dexmaker*.jar") } if jar_file
|
210
|
+
|
211
|
+
# FIXME(uwe): Try keeping the class count low to enable installation on Android 2.3 devices
|
212
|
+
# FIXME(uwe): Skip copying dexmaker to apps using RubotoCore when we include dexmaker.jar in RubotoCore
|
213
|
+
# if verify_target_sdk < 15
|
214
|
+
log_action("Copying dexmaker.jar to libs") { copier.copy 'libs/dexmaker*.jar' }
|
215
|
+
# end
|
216
|
+
# EMXIF
|
217
|
+
end
|
218
|
+
|
203
219
|
def update_assets
|
204
220
|
puts "\nCopying files:"
|
205
221
|
|
206
|
-
# FIXME(uwe): Remove when we stop supporting updating from Ruboto
|
222
|
+
# FIXME(uwe): Remove when we stop supporting updating from Ruboto < 0.6.0
|
207
223
|
if File.exists?('Rakefile') && !File.exists?('rakelib/ruboto.rake')
|
208
224
|
FileUtils.rm 'Rakefile'
|
209
225
|
end
|
210
|
-
#
|
226
|
+
# EMXIF
|
211
227
|
|
212
228
|
weak_copier = Ruboto::Util::AssetCopier.new Ruboto::ASSETS, '.', false
|
213
229
|
%w{.gitignore Rakefile}.each { |f| log_action(f) { weak_copier.copy f } }
|
@@ -216,15 +232,6 @@ module Ruboto
|
|
216
232
|
%w{assets rakelib res/layout test}.each do |f|
|
217
233
|
log_action(f) { copier.copy f }
|
218
234
|
end
|
219
|
-
|
220
|
-
# FIXME(uwe): Remove when we stop supporting upgrades from ruboto-core 0.3.3 and older
|
221
|
-
old_scripts_dir = 'assets/scripts'
|
222
|
-
if File.exists? old_scripts_dir
|
223
|
-
FileUtils.mv Dir["#{old_scripts_dir}/*"], SCRIPTS_DIR
|
224
|
-
FileUtils.rm_rf old_scripts_dir
|
225
|
-
end
|
226
|
-
# FIXME end
|
227
|
-
|
228
235
|
end
|
229
236
|
|
230
237
|
def update_icons(force = nil)
|
@@ -248,7 +255,7 @@ module Ruboto
|
|
248
255
|
end
|
249
256
|
end
|
250
257
|
|
251
|
-
def update_classes(force = nil)
|
258
|
+
def update_classes(old_version, force = nil)
|
252
259
|
copier = Ruboto::Util::AssetCopier.new Ruboto::ASSETS, '.'
|
253
260
|
log_action("Ruboto java classes") { copier.copy "src/org/ruboto/*.java" }
|
254
261
|
log_action("Ruboto java test classes") { copier.copy "src/org/ruboto/test/*.java", "test" }
|
@@ -261,37 +268,31 @@ module Ruboto
|
|
261
268
|
puts "Regenerating #{class_name} #{subclass_name}"
|
262
269
|
generate_inheriting_file(class_name, subclass_name, verify_package)
|
263
270
|
|
264
|
-
# FIXME(uwe): Remove when we stop supporting upgrading from ruboto
|
265
|
-
if
|
271
|
+
# FIXME(uwe): Remove when we stop supporting upgrading from ruboto 0.7.0 and ruboto 0.8.0
|
272
|
+
if (old_version == '0.7.0' || old_version == '0.8.0')
|
273
|
+
puts "Ruboto version #{old_version.inspect} detected."
|
266
274
|
script_file = File.expand_path("#{SCRIPTS_DIR}/#{underscore(subclass_name)}.rb")
|
275
|
+
puts "Adding explicit super call in #{script_file}"
|
267
276
|
script_content = File.read(script_file)
|
268
|
-
|
269
|
-
|
270
|
-
script_content !~ /class \w+\s+include Ruboto::BroadcastReceiver/ &&
|
271
|
-
script_content !~ /^\s*class #{subclass_name}\s/
|
272
|
-
puts "Putting receiver script in a block in #{script_file}"
|
273
|
-
script_content.gsub! '$broadcast_context', 'context'
|
274
|
-
File.open(script_file, 'w') do |of|
|
275
|
-
of.puts "class #{subclass_name}
|
276
|
-
def on_receive(context, intent)"
|
277
|
-
of << script_content
|
278
|
-
of.puts ' end\nend'
|
279
|
-
end
|
280
|
-
end
|
277
|
+
script_content.gsub! /^(\s*)(def on_(?:create\(bundle\)|start|resume|pause|destroy)\n)/, "\\1\\2\\1 super\n"
|
278
|
+
File.open(script_file, 'w'){|of| of << script_content}
|
281
279
|
end
|
282
|
-
#
|
283
|
-
|
280
|
+
# EMXIF
|
281
|
+
|
282
|
+
elsif source_code =~ /^\/\/ Generated Ruboto subclass with method base "(.*?)".*^\s*package\s+(\S+?)\s*;.*public\s+class\s+(\S+?)\s+extends\s+(.*?)\s*(?:implements\s+org.ruboto.RubotoComponent\s*)?\{/m
|
284
283
|
method_base, package, subclass_name, class_name = $1, $2, $3, $4
|
285
284
|
puts "Regenerating subclass #{package}.#{subclass_name}"
|
285
|
+
generate_inheriting_file 'Class', subclass_name
|
286
286
|
generate_subclass_or_interface(:package => package, :template => 'InheritingClass', :class => class_name,
|
287
287
|
:name => subclass_name, :method_base => method_base, :force => force)
|
288
288
|
# FIXME(uwe): Remove when we stop updating from Ruboto 0.7.0 and older
|
289
289
|
elsif source_code =~ /^\s*package\s+(\S+?)\s*;.*public\s+class\s+(\S+?)\s+extends\s+(.*?)\s\{.*^\s*private Object\[\] callbackProcs = new Object\[\d+\];/m
|
290
290
|
package, subclass_name, class_name = $1, $2, $3
|
291
291
|
puts "Regenerating subclass #{package}.#{subclass_name}"
|
292
|
+
generate_inheriting_file 'Class', subclass_name
|
292
293
|
generate_subclass_or_interface(:package => package, :template => 'InheritingClass', :class => class_name,
|
293
294
|
:name => subclass_name, :method_base => 'on', :force => force)
|
294
|
-
#
|
295
|
+
# EMXIF
|
295
296
|
end
|
296
297
|
end
|
297
298
|
end
|
@@ -348,11 +349,16 @@ module Ruboto
|
|
348
349
|
# FIXME(uwe): Remove when we stop supporting updating from Ruboto 0.5.5 and older.
|
349
350
|
FileUtils.rm_rf 'src/org/ruboto/callbacks'
|
350
351
|
FileUtils.rm_f 'src/org/ruboto/RubotoView.java'
|
351
|
-
#
|
352
|
+
# EMXIF
|
352
353
|
|
353
354
|
generate_core_classes(:class => "all", :method_base => "on", :method_include => "", :method_exclude => "", :force => force, :implements => "")
|
354
355
|
end
|
355
356
|
|
357
|
+
def read_ruboto_version
|
358
|
+
version_file = File.expand_path("./#{SCRIPTS_DIR}/ruboto/version.rb")
|
359
|
+
File.read(version_file).slice(/^\s*VERSION = '(.*?)'/, 1) if File.exists?(version_file)
|
360
|
+
end
|
361
|
+
|
356
362
|
def update_ruboto(force=nil)
|
357
363
|
log_action("Copying ruboto.rb") do
|
358
364
|
from = File.expand_path(Ruboto::GEM_ROOT + "/assets/#{SCRIPTS_DIR}/ruboto.rb")
|
@@ -366,15 +372,8 @@ module Ruboto
|
|
366
372
|
FileUtils.cp from, to
|
367
373
|
end
|
368
374
|
log_action("Copying additional ruboto script components") do
|
369
|
-
Dir.glob(Ruboto::GEM_ROOT + "/assets/#{SCRIPTS_DIR}/ruboto
|
370
|
-
|
371
|
-
to = File.expand_path("./#{SCRIPTS_DIR}/ruboto/#{File.basename(i)}")
|
372
|
-
FileUtils.mkdir_p File.dirname(to)
|
373
|
-
FileUtils.cp from, to
|
374
|
-
end
|
375
|
-
Dir.glob(Ruboto::GEM_ROOT + "/assets/#{SCRIPTS_DIR}/ruboto/util/*.rb").each do |i|
|
376
|
-
from = File.expand_path(i)
|
377
|
-
to = File.expand_path("./#{SCRIPTS_DIR}/ruboto/util/#{File.basename(i)}")
|
375
|
+
Dir.glob(Ruboto::GEM_ROOT + "/assets/#{SCRIPTS_DIR}/ruboto/**/*.rb").each do |from|
|
376
|
+
to = File.expand_path("./#{from.slice /#{SCRIPTS_DIR}\/ruboto\/.*\.rb/}")
|
378
377
|
FileUtils.mkdir_p File.dirname(to)
|
379
378
|
FileUtils.cp from, to
|
380
379
|
end
|
@@ -424,16 +423,17 @@ module Ruboto
|
|
424
423
|
'org/jruby/ext/ffi/jffi',
|
425
424
|
'org/jruby/ext/openssl', # TODO(uwe): Issue #154 Add back when we add jruby-openssl.
|
426
425
|
|
427
|
-
#
|
428
|
-
'org/jruby/ir
|
426
|
+
# FIXME(uwe): IR is the future. We should try using it.
|
427
|
+
# 'org/jruby/ir',
|
428
|
+
# 'org/jruby/ir/dataflow',
|
429
429
|
# 'org/jruby/ir/instructions',
|
430
430
|
# 'org/jruby/ir/interpreter',
|
431
431
|
# 'org/jruby/ir/operands',
|
432
432
|
# 'org/jruby/ir/passes',
|
433
|
-
'org/jruby/ir/representations',
|
433
|
+
# 'org/jruby/ir/representations',
|
434
434
|
# 'org/jruby/ir/targets',
|
435
|
-
'org/jruby/ir/transformations',
|
436
|
-
'org/jruby/ir/util',
|
435
|
+
# 'org/jruby/ir/transformations',
|
436
|
+
# 'org/jruby/ir/util',
|
437
437
|
|
438
438
|
'org/jruby/javasupport/bsf',
|
439
439
|
'org/jruby/runtime/invokedynamic',
|
@@ -458,7 +458,7 @@ module Ruboto
|
|
458
458
|
'org/jruby/embed/jsr223', 'org/jruby/embed/osgi', 'org/jruby/ext/ffi', 'org/jruby/javasupport/bsf',
|
459
459
|
'org/jruby/runtime/invokedynamic',
|
460
460
|
]
|
461
|
-
#
|
461
|
+
# ODOT
|
462
462
|
end
|
463
463
|
|
464
464
|
excluded_core_packages.each do |i|
|