ruboto 0.11.0 → 0.12.0.rc.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 +1 -1
  2. data/README.md +7 -5
  3. data/Rakefile +3 -4
  4. data/assets/rakelib/ruboto.rake +138 -87
  5. data/assets/samples/sample_broadcast_receiver.rb +1 -1
  6. data/assets/src/InheritingActivity.java +0 -6
  7. data/assets/src/RubotoActivity.java +4 -1
  8. data/assets/src/RubotoBroadcastReceiver.java +2 -11
  9. data/assets/src/RubotoService.java +6 -52
  10. data/assets/src/org/ruboto/EntryPointActivity.java +276 -36
  11. data/assets/src/org/ruboto/JRubyAdapter.java +5 -152
  12. data/assets/src/org/ruboto/Script.java +1 -1
  13. data/assets/src/org/ruboto/ScriptLoader.java +26 -44
  14. data/assets/src/org/ruboto/test/InstrumentationTestRunner.java +4 -21
  15. data/bin/ruboto +0 -6
  16. data/lib/ruboto/commands/base.rb +58 -48
  17. data/lib/ruboto/sdk_locations.rb +23 -0
  18. data/lib/ruboto/sdk_versions.rb +1 -19
  19. data/lib/ruboto/util/build.rb +32 -32
  20. data/lib/ruboto/util/setup.rb +240 -0
  21. data/lib/ruboto/util/update.rb +12 -25
  22. data/lib/ruboto/util/verify.rb +7 -4
  23. data/lib/ruboto/util/xml_element.rb +62 -76
  24. data/lib/ruboto/version.rb +1 -1
  25. data/test/activity/image_button_activity_test.rb +2 -2
  26. data/test/activity/image_button_and_button_activity_test.rb +2 -2
  27. data/test/activity/json_activity.rb +1 -1
  28. data/test/activity/navigation_activity.rb +12 -12
  29. data/test/activity/navigation_activity_test.rb +7 -7
  30. data/test/activity/option_menu_activity.rb +0 -1
  31. data/test/activity/option_menu_activity_test.rb +2 -2
  32. data/test/activity/stack_activity_test.rb +10 -20
  33. data/test/app_test_methods.rb +0 -4
  34. data/test/broadcast_receiver_test.rb +16 -6
  35. data/test/minimal_app_test.rb +4 -12
  36. data/test/rake_test.rb +37 -23
  37. data/test/ruboto_gen_test.rb +12 -15
  38. data/test/sqldroid_test.rb +3 -6
  39. data/test/test_helper.rb +2 -0
  40. data/test/update_test_methods.rb +9 -9
  41. metadata +7 -11
@@ -23,92 +23,6 @@ public class JRubyAdapter {
23
23
  private static String localVariableBehavior = "TRANSIENT";
24
24
  private static String RUBOTO_CORE_VERSION_NAME;
25
25
 
26
- /**
27
- * @deprecated As of Ruboto 0.7.1, replaced by {@link #runRubyMethod(Object receiver, String methodName, Object... args)}
28
- */
29
- @Deprecated public static void callMethod(Object receiver, String methodName, Object[] args) {
30
- runRubyMethod(receiver, methodName, args);
31
- }
32
-
33
- /**
34
- * @deprecated As of Ruboto 0.7.1, replaced by {@link #runRubyMethod(Object receiver, String methodName, Object... args)}
35
- */
36
- @Deprecated public static void callMethod(Object object, String methodName, Object arg) {
37
- runRubyMethod(object, methodName, arg);
38
- }
39
-
40
- /**
41
- * @deprecated As of Ruboto 0.7.1, replaced by {@link #runRubyMethod(Object receiver, String methodName, Object... args)}
42
- */
43
- @Deprecated public static void callMethod(Object object, String methodName) {
44
- runRubyMethod(object, methodName, new Object[] {});
45
- }
46
-
47
- /**
48
- * @deprecated As of Ruboto 0.7.1, replaced by {@link #runRubyMethod(Class<T> returnType, Object receiver, String methodName, Object... args)}
49
- */
50
- @SuppressWarnings("unchecked")
51
- @Deprecated public static <T> T callMethod(Object receiver, String methodName, Object[] args, Class<T> returnType) {
52
- return (T) runRubyMethod(returnType, receiver, methodName, args);
53
- }
54
-
55
- /**
56
- * @deprecated As of Ruboto 0.7.1, replaced by {@link #runRubyMethod(Class<T> returnType, Object receiver, String methodName, Object... args)}
57
- */
58
- @SuppressWarnings("unchecked")
59
- @Deprecated public static <T> T callMethod(Object receiver, String methodName, Object arg, Class<T> returnType) {
60
- return (T) runRubyMethod(returnType, receiver, methodName, arg);
61
- }
62
-
63
- /**
64
- * @deprecated As of Ruboto 0.7.1, replaced by {@link #runRubyMethod(Class<T> returnType, Object receiver, String methodName, Object... args)}
65
- */
66
- @SuppressWarnings("unchecked")
67
- @Deprecated public static <T> T callMethod(Object receiver, String methodName, Class<T> returnType) {
68
- return (T) runRubyMethod(returnType, receiver, methodName);
69
- }
70
-
71
- /**
72
- * @deprecated As of Ruboto 0.7.0, replaced by {@link #put(String name, Object object)}
73
- */
74
- @Deprecated public static void defineGlobalConstant(String name, Object object) {
75
- put(name, object);
76
- }
77
-
78
- /**
79
- * @deprecated As of Ruboto 0.7.0, replaced by {@link #put(String name, Object object)}
80
- */
81
- @Deprecated public static void defineGlobalVariable(String name, Object object) {
82
- put(name, object);
83
- }
84
-
85
- /**
86
- * @deprecated As of Ruboto 0.7.0, replaced by {@link #runScriptlet(String code)}
87
- */
88
- @Deprecated public static Object exec(String code) {
89
- try {
90
- Method runScriptletMethod = ruby.getClass().getMethod("runScriptlet", String.class);
91
- return runScriptletMethod.invoke(ruby, code);
92
- } catch (NoSuchMethodException nsme) {
93
- throw new RuntimeException(nsme);
94
- } catch (IllegalAccessException iae) {
95
- throw new RuntimeException(iae);
96
- } catch (java.lang.reflect.InvocationTargetException ite) {
97
- if (isDebugBuild) {
98
- throw ((RuntimeException) ite.getCause());
99
- } else {
100
- return null;
101
- }
102
- }
103
- }
104
-
105
- /**
106
- * @deprecated As of Ruboto 0.7.0, replaced by {@link #runScriptlet(String code)}
107
- */
108
- @Deprecated public static String execute(String code) {
109
- return (String) runRubyMethod(String.class, exec(code), "inspect");
110
- }
111
-
112
26
  public static Object get(String name) {
113
27
  try {
114
28
  Method getMethod = ruby.getClass().getMethod("get", String.class);
@@ -132,21 +46,8 @@ public class JRubyAdapter {
132
46
 
133
47
  public static Object runRubyMethod(Object receiver, String methodName, Object... args) {
134
48
  try {
135
- // FIXME(uwe): Simplify when we stop supporting JRuby < 1.7.0
136
- if (isJRubyPreOneSeven()) {
137
- if (args.length == 0) {
138
- Method m = ruby.getClass().getMethod("callMethod", Object.class, String.class, Class.class);
139
- // System.out.println("Calling callMethod(" + receiver + ", " + methodName + ", " + Object.class + ")");
140
- return m.invoke(ruby, receiver, methodName, Object.class);
141
- } else {
142
- Method m = ruby.getClass().getMethod("callMethod", Object.class, String.class, Object[].class, Class.class);
143
- // System.out.println("Calling callMethod(" + receiver + ", " + methodName + ", " + args + ", " + Object.class + ")");
144
- return m.invoke(ruby, receiver, methodName, args, Object.class);
145
- }
146
- } else {
147
- Method m = ruby.getClass().getMethod("runRubyMethod", Class.class, Object.class, String.class, Object[].class);
148
- return m.invoke(ruby, Object.class, receiver, methodName, args);
149
- }
49
+ Method m = ruby.getClass().getMethod("runRubyMethod", Class.class, Object.class, String.class, Object[].class);
50
+ return m.invoke(ruby, Object.class, receiver, methodName, args);
150
51
  } catch (NoSuchMethodException nsme) {
151
52
  throw new RuntimeException(nsme);
152
53
  } catch (IllegalAccessException iae) {
@@ -163,19 +64,8 @@ public class JRubyAdapter {
163
64
  @SuppressWarnings("unchecked")
164
65
  public static <T> T runRubyMethod(Class<T> returnType, Object receiver, String methodName, Object... args) {
165
66
  try {
166
- // FIXME(uwe): Simplify when we stop supporting JRuby < 1.7.0
167
- if (isJRubyPreOneSeven()) {
168
- if (args.length == 0) {
169
- Method m = ruby.getClass().getMethod("callMethod", Object.class, String.class, Class.class);
170
- return (T) m.invoke(ruby, receiver, methodName, returnType);
171
- } else {
172
- Method m = ruby.getClass().getMethod("callMethod", Object.class, String.class, Object[].class, Class.class);
173
- return (T) m.invoke(ruby, receiver, methodName, args, returnType);
174
- }
175
- } else {
176
- Method m = ruby.getClass().getMethod("runRubyMethod", Class.class, Object.class, String.class, Object[].class);
177
- return (T) m.invoke(ruby, returnType, receiver, methodName, args);
178
- }
67
+ Method m = ruby.getClass().getMethod("runRubyMethod", Class.class, Object.class, String.class, Object[].class);
68
+ return (T) m.invoke(ruby, returnType, receiver, methodName, args);
179
69
  } catch (NoSuchMethodException nsme) {
180
70
  throw new RuntimeException(nsme);
181
71
  } catch (IllegalAccessException iae) {
@@ -262,11 +152,6 @@ public class JRubyAdapter {
262
152
  System.setProperty("jruby.ji.proxyClassFactory", "org.ruboto.DalvikProxyClassFactory");
263
153
  System.setProperty("jruby.class.cache.path", appContext.getDir("dex", 0).getAbsolutePath());
264
154
 
265
- // Workaround for bug in Android 2.2
266
- // http://code.google.com/p/android/issues/detail?id=9431
267
- // System.setProperty("java.net.preferIPv4Stack", "true");
268
- // System.setProperty("java.net.preferIPv6Addresses", "false");
269
-
270
155
  ClassLoader classLoader;
271
156
  Class<?> scriptingContainerClass;
272
157
  String apkName = null;
@@ -459,16 +344,6 @@ public class JRubyAdapter {
459
344
  ruby = null;
460
345
  }
461
346
 
462
- // FIXME(uwe): Remove when we stop supporting JRuby < 1.7.0
463
- @Deprecated public static boolean isJRubyPreOneSeven() {
464
- return ((String)get("JRUBY_VERSION")).equals("1.7.0.dev") || ((String)get("JRUBY_VERSION")).startsWith("1.6.");
465
- }
466
-
467
- // FIXME(uwe): Remove when we stop supporting JRuby < 1.7.0
468
- @Deprecated public static boolean isJRubyOneSeven() {
469
- return !isJRubyPreOneSeven() && ((String)get("JRUBY_VERSION")).startsWith("1.7.");
470
- }
471
-
472
347
  // FIXME(uwe): Remove when we stop supporting Ruby 1.8
473
348
  @Deprecated public static boolean isRubyOneEight() {
474
349
  return ((String)get("RUBY_VERSION")).startsWith("1.8.");
@@ -496,29 +371,7 @@ public class JRubyAdapter {
496
371
  private static String scriptsDirName(Context context) {
497
372
  File storageDir = null;
498
373
  if (isDebugBuild()) {
499
-
500
- // FIXME(uwe): Simplify this as soon as we drop support for android-7
501
- if (android.os.Build.VERSION.SDK_INT >= 8) {
502
- try {
503
- Method method = context.getClass().getMethod("getExternalFilesDir", String.class);
504
- storageDir = (File) method.invoke(context, (Object) null);
505
- } catch (SecurityException e) {
506
- printStackTrace(e);
507
- } catch (NoSuchMethodException e) {
508
- printStackTrace(e);
509
- } catch (IllegalArgumentException e) {
510
- printStackTrace(e);
511
- } catch (IllegalAccessException e) {
512
- printStackTrace(e);
513
- } catch (InvocationTargetException e) {
514
- printStackTrace(e);
515
- }
516
- } else {
517
- storageDir = new File(Environment.getExternalStorageDirectory(), "Android/data/" + context.getPackageName() + "/files");
518
- Log.e("Calculated path to sdcard the old way: " + storageDir);
519
- }
520
- // FIXME end
521
-
374
+ storageDir = context.getExternalFilesDir(null);
522
375
  if (storageDir == null || (!storageDir.exists() && !storageDir.mkdirs())) {
523
376
  Log.e("Development mode active, but sdcard is not available. Make sure you have added\n<uses-permission android:name='android.permission.WRITE_EXTERNAL_STORAGE' />\nto your AndroidManifest.xml file.");
524
377
  storageDir = context.getFilesDir();
@@ -105,7 +105,7 @@ public class Script {
105
105
  * Instance methods
106
106
  */
107
107
  public String execute() throws IOException {
108
- return JRubyAdapter.execute(getContents());
108
+ return JRubyAdapter.runScriptlet(getContents()).toString();
109
109
  }
110
110
 
111
111
  boolean exists() {
@@ -21,15 +21,16 @@ public class ScriptLoader {
21
21
  return false;
22
22
  }
23
23
 
24
- public static void loadScript(final RubotoComponent component, Object... args) {
24
+ public static void loadScript(final RubotoComponent component) {
25
25
  try {
26
26
  if (component.getScriptInfo().getScriptName() != null) {
27
- System.out.println("Looking for Ruby class: " + component.getScriptInfo().getRubyClassName());
27
+ Log.d("Looking for Ruby class: " + component.getScriptInfo().getRubyClassName());
28
28
  Object rubyClass = JRubyAdapter.get(component.getScriptInfo().getRubyClassName());
29
- System.out.println("Found: " + rubyClass);
29
+ Log.d("Found: " + rubyClass);
30
30
  final Script rubyScript = new Script(component.getScriptInfo().getScriptName());
31
31
  Object rubyInstance;
32
32
  if (rubyScript.exists()) {
33
+ Log.d("Found script.");
33
34
  rubyInstance = component;
34
35
  final String script = rubyScript.getContents();
35
36
  boolean scriptContainsClass = script.matches("(?s).*class "
@@ -38,43 +39,38 @@ public class ScriptLoader {
38
39
  .equals(component.getClass().getSimpleName());
39
40
  if (scriptContainsClass) {
40
41
  if (hasBackingJavaClass) {
42
+ Log.d("hasBackingJavaClass");
41
43
  if (rubyClass != null && !rubyClass.toString().startsWith("Java::")) {
42
- System.out.println("Found Ruby class instead of Java class. Reloading.");
44
+ Log.d("Found Ruby class instead of Java class. Reloading.");
43
45
  rubyClass = null;
44
46
  }
45
47
  } else {
46
- System.out.println("Script defines methods on meta class");
48
+ Log.d("Script defines methods on meta class");
47
49
 
48
- // FIXME(uwe): Simplify when we stop support for RubotoCore 0.4.7
49
- if (JRubyAdapter.isJRubyPreOneSeven() || JRubyAdapter.isRubyOneEight()) {
50
+ // FIXME(uwe): Simplify when we stop support for Ruby 1.8 mode.
51
+ if (JRubyAdapter.isRubyOneEight()) {
50
52
  JRubyAdapter.put("$java_instance", component);
51
53
  rubyClass = JRubyAdapter.runScriptlet("class << $java_instance; self; end");
52
- } else if (JRubyAdapter.isJRubyOneSeven() && JRubyAdapter.isRubyOneNine()) {
54
+ } else if (JRubyAdapter.isRubyOneNine()) {
53
55
  JRubyAdapter.runScriptlet("Java::" + component.getClass().getName() + ".__persistent__ = true");
54
56
  rubyClass = JRubyAdapter.runRubyMethod(component, "singleton_class");
55
57
  } else {
56
- throw new RuntimeException("Unknown JRuby/Ruby version: " + JRubyAdapter.get("JRUBY_VERSION") + "/" + JRubyAdapter.get("RUBY_VERSION"));
58
+ throw new RuntimeException("Unknown Ruby version: " + JRubyAdapter.get("RUBY_VERSION"));
57
59
  }
58
60
  // EMXIF
59
61
 
60
62
  }
61
63
  }
62
64
  if (rubyClass == null || !hasBackingJavaClass) {
63
- System.out.println("Loading script: " + component.getScriptInfo().getScriptName());
65
+ Log.d("Loading script: " + component.getScriptInfo().getScriptName());
64
66
  if (scriptContainsClass) {
65
- System.out.println("Script contains class definition");
67
+ Log.d("Script contains class definition");
66
68
  if (rubyClass == null && hasBackingJavaClass) {
67
- System.out.println("Script has separate Java class");
68
-
69
- // FIXME(uwe): Simplify when we stop support for JRuby < 1.7.0
70
- if (!JRubyAdapter.isJRubyPreOneSeven()) {
71
- JRubyAdapter.runScriptlet("Java::" + component.getClass().getName() + ".__persistent__ = true");
72
- }
73
- // EMXIF
74
-
69
+ Log.d("Script has separate Java class");
70
+ JRubyAdapter.runScriptlet("Java::" + component.getClass().getName() + ".__persistent__ = true");
75
71
  rubyClass = JRubyAdapter.runScriptlet("Java::" + component.getClass().getName());
76
72
  }
77
- System.out.println("Set class: " + rubyClass);
73
+ Log.d("Set class: " + rubyClass);
78
74
  JRubyAdapter.put(component.getScriptInfo().getRubyClassName(), rubyClass);
79
75
  // FIXME(uwe): Collect these threads in a ThreadGroup ?
80
76
  Thread t = new Thread(null, new Runnable(){
@@ -82,7 +78,7 @@ public class ScriptLoader {
82
78
  long loadStart = System.currentTimeMillis();
83
79
  JRubyAdapter.setScriptFilename(rubyScript.getAbsolutePath());
84
80
  JRubyAdapter.runScriptlet(script);
85
- System.out.println("Script load took " + (System.currentTimeMillis() - loadStart) + "ms");
81
+ Log.d("Script load took " + (System.currentTimeMillis() - loadStart) + "ms");
86
82
  }
87
83
  }, "ScriptLoader for " + rubyClass, 128 * 1024);
88
84
  try {
@@ -101,18 +97,14 @@ public class ScriptLoader {
101
97
  }
102
98
  } else if (rubyClass != null) {
103
99
  // We have a predefined Ruby class without corresponding Ruby source file.
104
- System.out.println("Create separate Ruby instance for class: " + rubyClass);
100
+ Log.d("Create separate Ruby instance for class: " + rubyClass);
105
101
  rubyInstance = JRubyAdapter.runRubyMethod(rubyClass, "new");
106
102
  JRubyAdapter.runRubyMethod(rubyInstance, "instance_variable_set", "@ruboto_java_instance", component);
107
103
  } else {
108
104
  // Neither script file nor predefined class
105
+ Log.e("Missing script and class. Either script or predefined class must be present.");
109
106
  throw new RuntimeException("Either script or predefined class must be present.");
110
107
  }
111
- if (rubyClass != null) {
112
- if (component instanceof android.content.Context) {
113
- callOnCreate(rubyInstance, args, component.getScriptInfo().getRubyClassName());
114
- }
115
- }
116
108
  component.getScriptInfo().setRubyInstance(rubyInstance);
117
109
  }
118
110
  } catch(IOException e){
@@ -123,27 +115,17 @@ public class ScriptLoader {
123
115
  }
124
116
  }
125
117
 
126
- private static final void callOnCreate(Object rubyInstance, Object[] args, String rubyClassName) {
127
- System.out.println("Call onCreate on: " + rubyInstance + ", " + JRubyAdapter.get("JRUBY_VERSION"));
128
- // FIXME(uwe): Simplify when we stop support for RubotoCore 0.4.7
129
- if (JRubyAdapter.isJRubyPreOneSeven()) {
130
- if (args.length > 0) {
131
- JRubyAdapter.put("$bundle", args[0]);
132
- }
133
- JRubyAdapter.put("$ruby_instance", rubyInstance);
134
- JRubyAdapter.runScriptlet("$ruby_instance.on_create(" + (args.length > 0 ? "$bundle" : "") + ")");
135
- } else if (JRubyAdapter.isJRubyOneSeven()) {
118
+ public static final void callOnCreate(final RubotoComponent component, Object... args) {
119
+ if (component instanceof android.content.Context) {
120
+ Log.d("Call onCreate on: " + component.getScriptInfo().getRubyInstance());
136
121
  // FIXME(uwe): Simplify when we stop support for snake case aliasing interface callback methods.
137
- if ((Boolean)JRubyAdapter.runScriptlet(rubyClassName + ".instance_methods(false).any?{|m| m.to_sym == :onCreate}")) {
138
- JRubyAdapter.runRubyMethod(rubyInstance, "onCreate", args);
139
- } else if ((Boolean)JRubyAdapter.runScriptlet(rubyClassName + ".instance_methods(false).any?{|m| m.to_sym == :on_create}")) {
140
- JRubyAdapter.runRubyMethod(rubyInstance, "on_create", args);
122
+ if ((Boolean)JRubyAdapter.runScriptlet(component.getScriptInfo().getRubyClassName() + ".instance_methods(false).any?{|m| m.to_sym == :onCreate}")) {
123
+ JRubyAdapter.runRubyMethod(component.getScriptInfo().getRubyInstance(), "onCreate", args);
124
+ } else if ((Boolean)JRubyAdapter.runScriptlet(component.getScriptInfo().getRubyClassName() + ".instance_methods(false).any?{|m| m.to_sym == :on_create}")) {
125
+ JRubyAdapter.runRubyMethod(component.getScriptInfo().getRubyInstance(), "on_create", args);
141
126
  }
142
127
  // EMXIF
143
- } else {
144
- throw new RuntimeException("Unknown JRuby version: " + JRubyAdapter.get("JRUBY_VERSION"));
145
128
  }
146
- // EMXIF
147
129
  }
148
130
 
149
131
  }
@@ -47,9 +47,7 @@ public class InstrumentationTestRunner extends android.test.InstrumentationTestR
47
47
  Thread t = new Thread(null, new Runnable() {
48
48
  public void run() {
49
49
  JRubyLoadedOk.set(JRubyAdapter.setUpJRuby(getTargetContext()));
50
- if (!JRubyAdapter.isJRubyPreOneSeven()) {
51
- JRubyAdapter.runScriptlet("Java::OrgRubotoTest::InstrumentationTestRunner.__persistent__ = true");
52
- }
50
+ JRubyAdapter.runScriptlet("Java::OrgRubotoTest::InstrumentationTestRunner.__persistent__ = true");
53
51
  }
54
52
  }, "Setup JRuby from instrumentation test runner", 64 * 1024);
55
53
  try {
@@ -132,14 +130,7 @@ public class InstrumentationTestRunner extends android.test.InstrumentationTestR
132
130
  }
133
131
 
134
132
  public void test(String name, Map options, Object block) {
135
- // FIXME(uwe): Remove when we stop supporting Android 2.2
136
- if (android.os.Build.VERSION.SDK_INT <= 8) {
137
- name ="runTest";
138
- }
139
- // FIXME end
140
-
141
133
  boolean runOnUiThread = options == null || options.get("ui") == "true";
142
-
143
134
  Test test = new ActivityTest(activityClass, JRubyAdapter.getScriptFilename(), setup, teardown, name, runOnUiThread, block);
144
135
  suite.addTest(test);
145
136
  Log.d(getClass().getName(), "Made test instance: " + test);
@@ -174,18 +165,10 @@ public class InstrumentationTestRunner extends android.test.InstrumentationTestR
174
165
  buffer.close();
175
166
  JRubyAdapter.setScriptFilename(f);
176
167
 
177
- // FIXME(uwe): Simplify when we stop supporting JRuby < 1.7.0
178
- if (JRubyAdapter.isJRubyPreOneSeven()) {
179
- JRubyAdapter.put("$test", this);
180
- JRubyAdapter.put("$script_code", source.toString());
181
- JRubyAdapter.put("$filename", f);
182
- JRubyAdapter.runScriptlet("$test.instance_eval($script_code, $filename)");
168
+ if (f.equals("test_helper.rb")) {
169
+ JRubyAdapter.runScriptlet(source.toString());
183
170
  } else {
184
- if (f.equals("test_helper.rb")) {
185
- JRubyAdapter.runScriptlet(source.toString());
186
- } else {
187
- JRubyAdapter.runRubyMethod(this, "instance_eval", source.toString(), f);
188
- }
171
+ JRubyAdapter.runRubyMethod(this, "instance_eval", source.toString(), f);
189
172
  }
190
173
  Log.d(getClass().getName(), "Test script " + f + " loaded");
191
174
  }
data/bin/ruboto CHANGED
@@ -1,11 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- output = `android list 2>&1`
4
- if $? != 0
5
- puts "Android SDK not in path\n#{output}"
6
- exit 1
7
- end
8
-
9
3
  begin
10
4
  require 'ruboto/commands/base'
11
5
  rescue RuntimeError
@@ -8,7 +8,6 @@ require 'ruboto/util/log_action'
8
8
  require 'ruboto/util/xml_element'
9
9
  require 'ruboto/util/code_formatting'
10
10
  require 'ruboto/util/build'
11
- require 'ruboto/util/update'
12
11
  require 'ruboto/util/verify'
13
12
  require 'ruboto/util/scan_in_api'
14
13
  require 'ruboto/core_ext/array'
@@ -20,35 +19,37 @@ module Ruboto
20
19
  include Ruboto::SdkVersions
21
20
 
22
21
  def self.main
23
- Main {
22
+ Main do
24
23
  mode 'gen' do
24
+ require 'ruboto/util/update'
25
+
25
26
  mode 'app' do
26
27
  include Ruboto::Util::LogAction
27
28
  include Ruboto::Util::Build
28
29
  include Ruboto::Util::Update
29
30
  include Ruboto::Util::Verify
30
31
 
31
- option('package'){
32
+ option('package') {
32
33
  required
33
34
  argument :required
34
35
  description 'Name of package. Must be unique for every app. A common pattern is yourtld.yourdomain.appname (Ex. org.ruboto.irb)'
35
36
  }
36
- option('name'){
37
+ option('name') {
37
38
  argument :required
38
39
  description 'Name of your app. Defaults to the last part of the package name capitalized.'
39
40
  }
40
- option('activity'){
41
+ option('activity') {
41
42
  argument :required
42
43
  description 'Name of your primary Activity. Defaults to the name of the application with Activity appended.'
43
44
  }
44
- option('path'){
45
+ option('path') {
45
46
  argument :required
46
47
  description 'Path to where you want your app. Defaults to the last part of the package name.'
47
48
  }
48
49
  option('target') {
49
50
  argument :required
50
51
  defaults DEFAULT_TARGET_SDK
51
- description "Android version to target. Must begin with 'android-' (e.g., 'android-8' for froyo)"
52
+ description "Android version to target. Must begin with 'android-' (e.g., 'android-10' for gingerbread)"
52
53
  }
53
54
  option('min-sdk') {
54
55
  argument :required
@@ -65,7 +66,7 @@ module Ruboto
65
66
 
66
67
  def run
67
68
  package = params['package'].value
68
- name = params['name'].value || package.split('.').last.split('_').map{|s| s.capitalize}.join
69
+ name = params['name'].value || package.split('.').last.split('_').map { |s| s.capitalize }.join
69
70
  name[0..0] = name[0..0].upcase
70
71
  activity = params['activity'].value || "#{name}Activity"
71
72
  path = params['path'].value || package.split('.').last
@@ -91,8 +92,8 @@ module Ruboto
91
92
  puts "Removed file #{"src/#{package.gsub '.', '/'}/#{activity}"}.java"
92
93
  FileUtils.rm_f 'res/layout/main.xml'
93
94
  puts 'Removed file res/layout/main.xml'
94
- verify_strings.root.elements['string'].text = name.gsub(/([A-Z]+)([A-Z][a-z])/,'\1 \2').gsub(/([a-z\d])([A-Z])/,'\1 \2')
95
- File.open('res/values/strings.xml', 'w') {|f| verify_strings.document.write(f, 4)}
95
+ verify_strings.root.elements['string'].text = name.gsub(/([A-Z]+)([A-Z][a-z])/, '\1 \2').gsub(/([a-z\d])([A-Z])/, '\1 \2')
96
+ File.open('res/values/strings.xml', 'w') { |f| verify_strings.document.write(f, 4) }
96
97
  end
97
98
  puts 'Done'
98
99
 
@@ -131,19 +132,19 @@ module Ruboto
131
132
  include Ruboto::Util::Build
132
133
  include Ruboto::Util::Verify
133
134
 
134
- argument('class'){
135
+ argument('class') {
135
136
  required
136
- alternatives = Dir[File.join(Ruboto::ASSETS, 'src/Inheriting*.java')].map{|f| File.basename(f)[10..-6]} - %w(Class)
137
- description "the Android Class that you want: #{alternatives[0..-2].map{|c| "#{c}, "}}or #{alternatives[-1]}"
138
- validate {|v| alternatives.include? v}
137
+ alternatives = Dir[File.join(Ruboto::ASSETS, 'src/Inheriting*.java')].map { |f| File.basename(f)[10..-6] } - %w(Class)
138
+ description "the Android Class that you want: #{alternatives[0..-2].map { |c| "#{c}, " }}or #{alternatives[-1]}"
139
+ validate { |v| alternatives.include? v }
139
140
  }
140
141
 
141
- option('script_name'){
142
+ option('script_name') {
142
143
  argument :required
143
144
  description 'name of the ruby script that this class will execute. Should end in .rb. Optional.'
144
145
  }
145
146
 
146
- option('name'){
147
+ option('name') {
147
148
  required
148
149
  argument :required
149
150
  description 'name of the class (and file). Should be CamelCase'
@@ -174,83 +175,83 @@ module Ruboto
174
175
  mode 'subclass' do
175
176
  include Ruboto::Util::Build
176
177
 
177
- argument('class'){
178
+ argument('class') {
178
179
  required
179
180
  description 'the Android Class that you want to subclass (e.g., package.Class).'
180
181
  }
181
182
 
182
- option('name'){
183
+ option('name') {
183
184
  required
184
185
  argument :required
185
186
  description 'name of the class (and file). Should be CamelCase'
186
187
  }
187
188
 
188
- option('package'){
189
+ option('package') {
189
190
  argument :required
190
191
  description 'package for the new class (if not specified, uses project package)'
191
192
  }
192
193
 
193
- option('method_base'){
194
+ option('method_base') {
194
195
  required
195
- validate {|i| %w(all on none abstract).include?(i)}
196
+ validate { |i| %w(all on none abstract).include?(i) }
196
197
  argument :required
197
198
  description 'the base set of methods to generate (adjusted with method_include and method_exclude): all, none, abstract, on (e.g., onClick)'
198
199
  }
199
200
 
200
- option('method_include'){
201
+ option('method_include') {
201
202
  argument :required
202
203
  defaults ''
203
204
  description 'additional methods to add to the base list'
204
205
  }
205
206
 
206
- option('method_exclude'){
207
+ option('method_exclude') {
207
208
  argument :required
208
209
  defaults ''
209
210
  description 'methods to remove from the base list'
210
211
  }
211
212
 
212
- option('implements'){
213
+ option('implements') {
213
214
  required
214
215
  argument :required
215
216
  defaults ''
216
217
  description 'comma separated list interfaces to implement'
217
218
  }
218
219
 
219
- option('force'){
220
+ option('force') {
220
221
  argument :required
221
- validate {|i| %w(include exclude).include?(i)}
222
+ validate { |i| %w(include exclude).include?(i) }
222
223
  description "force handling of added and deprecated methods (values: 'include' or 'exclude') unless individually included or excluded"
223
224
  }
224
225
 
225
226
  def run
226
227
  generate_inheriting_file 'Class', params['name'].value
227
228
  generate_subclass_or_interface(
228
- %w(class name package method_base method_include method_exclude implements force).inject({}) {|h, i| h[i.to_sym] = params[i].value; h})
229
+ %w(class name package method_base method_include method_exclude implements force).inject({}) { |h, i| h[i.to_sym] = params[i].value; h })
229
230
  end
230
231
  end
231
232
 
232
233
  mode 'interface' do
233
234
  include Ruboto::Util::Build
234
235
 
235
- argument('interface'){
236
+ argument('interface') {
236
237
  required
237
238
  description 'the Android Interface that you want to implement (e.g., package.Interface).'
238
239
  }
239
240
 
240
- option('name'){
241
+ option('name') {
241
242
  required
242
243
  argument :required
243
244
  description 'name of the class (and file) that will implement the interface. Should be CamelCase'
244
245
  }
245
246
 
246
- option('package'){
247
+ option('package') {
247
248
  argument :required
248
249
  description 'package for the new class (if not specified, uses project package)'
249
250
  }
250
251
 
251
- option('force'){
252
+ option('force') {
252
253
  argument :required
253
- validate {|i| %w(include exclude).include?(i)}
254
+ validate { |i| %w(include exclude).include?(i) }
254
255
  description "force added and deprecated interfaces (values: 'include' or 'exclude')"
255
256
  }
256
257
 
@@ -258,63 +259,63 @@ module Ruboto
258
259
  # FIXME(uwe): DEPRECATED! Remove before Ruboto version 1.0.0.
259
260
  puts "\nThe use of \"ruboto gen interface\" has been deprecated. Please use\n\n ruboto gen subclass\n\ninstead.\n\n"
260
261
  generate_inheriting_file 'Class', params['name'].value
261
- generate_subclass_or_interface %w(interface name package force).inject({}) {|h, i| h[i.to_sym] = params[i].value; h}
262
+ generate_subclass_or_interface %w(interface name package force).inject({}) { |h, i| h[i.to_sym] = params[i].value; h }
262
263
  end
263
264
  end
264
265
 
265
266
  mode 'core' do
266
267
  include Ruboto::Util::Build
267
268
 
268
- argument('class'){
269
+ argument('class') {
269
270
  required
270
- validate {|i| %w(Activity Service BroadcastReceiver View PreferenceActivity TabActivity OnClickListener OnItemClickListener OnItemSelectedListener all).include?(i)}
271
+ validate { |i| %w(Activity Service BroadcastReceiver View PreferenceActivity TabActivity OnClickListener OnItemClickListener OnItemSelectedListener all).include?(i) }
271
272
  description "Activity, Service, BroadcastReceiver, View, OnClickListener, OnItemClickListener, OnItemSelectedListener, or all (default = all); Other activities not included in 'all': PreferenceActivity, TabActivity"
272
273
  }
273
274
 
274
- option('method_base'){
275
+ option('method_base') {
275
276
  required
276
277
  argument :required
277
- validate {|i| %w(all on none).include?(i)}
278
+ validate { |i| %w(all on none).include?(i) }
278
279
  defaults 'on'
279
280
  description 'the base set of methods to generate (adjusted with method_include and method_exclude): all, none, on (e.g., onClick)'
280
281
  }
281
282
 
282
- option('method_include'){
283
+ option('method_include') {
283
284
  required
284
285
  argument :required
285
286
  defaults ''
286
287
  description 'additional methods to add to the base list'
287
288
  }
288
289
 
289
- option('method_exclude'){
290
+ option('method_exclude') {
290
291
  required
291
292
  argument :required
292
293
  defaults ''
293
294
  description 'methods to remove from the base list'
294
295
  }
295
296
 
296
- option('implements'){
297
+ option('implements') {
297
298
  required
298
299
  argument :required
299
300
  defaults ''
300
301
  description "for classes only, interfaces to implement (cannot be used with 'gen core all')"
301
302
  }
302
303
 
303
- option('force'){
304
+ option('force') {
304
305
  argument :required
305
- validate {|i| %w(include exclude).include?(i)}
306
+ validate { |i| %w(include exclude).include?(i) }
306
307
  description "force handling of added and deprecated methods (values: 'include' or 'exclude') unless individually included or excluded"
307
308
  }
308
309
 
309
310
  def run
310
- abort("specify 'implements' only for Activity, Service, BroadcastReceiver, PreferenceActivity, or TabActivity") unless
311
- %w(Activity Service BroadcastReceiver PreferenceActivity TabActivity).include?(params['class'].value) or params['implements'].value == ''
312
- generate_core_classes [:class, :method_base, :method_include, :method_exclude, :implements, :force].inject({}) {|h, i| h[i] = params[i.to_s].value; h}
311
+ abort("specify 'implements' only for Activity, Service, BroadcastReceiver, PreferenceActivity, or TabActivity") unless %w(Activity Service BroadcastReceiver PreferenceActivity TabActivity).include?(params['class'].value) or params['implements'].value == ''
312
+ generate_core_classes [:class, :method_base, :method_include, :method_exclude, :implements, :force].inject({}) { |h, i| h[i] = params[i.to_s].value; h }
313
313
  end
314
314
  end
315
315
  end
316
316
 
317
317
  mode 'update' do
318
+ require 'ruboto/util/update'
318
319
  include Ruboto::Util::LogAction
319
320
  include Ruboto::Util::Update
320
321
  include Ruboto::Util::Verify
@@ -322,7 +323,7 @@ module Ruboto
322
323
  argument('what') {
323
324
  required
324
325
  # FIXME(uwe): Deprecated "ruboto update ruboto" in Ruboto 0.8.1. Remove september 2013.
325
- validate {|i| %w(jruby app ruboto).include?(i)}
326
+ validate { |i| %w(jruby app ruboto).include?(i) }
326
327
  description "What do you want to update: 'app', 'jruby', or 'ruboto'"
327
328
  }
328
329
 
@@ -357,7 +358,7 @@ module Ruboto
357
358
  update_bundle
358
359
  when 'jruby' then
359
360
  update_jruby(params['force'].value, true) || abort
360
- # FIXME(uwe): Deprecated in Ruboto 0.8.1. Remove september 2013.
361
+ # FIXME(uwe): Deprecated in Ruboto 0.8.1. Remove september 2013.
361
362
  when 'ruboto' then
362
363
  puts "\nThe 'ruboto update ruboto' command has been deprecated. Use\n\n ruboto update app\n\ninstead.\n\n"
363
364
  update_ruboto(params['force'].value) || abort
@@ -365,6 +366,15 @@ module Ruboto
365
366
  end
366
367
  end
367
368
 
369
+ mode 'setup' do
370
+ require 'ruboto/util/setup'
371
+ include Ruboto::Util::Setup
372
+
373
+ def run
374
+ setup_ruboto
375
+ end
376
+ end
377
+
368
378
  option 'version' do
369
379
  description 'display ruboto version'
370
380
  end
@@ -391,7 +401,7 @@ module Ruboto
391
401
  }
392
402
  end
393
403
  end
394
- }
404
+ end
395
405
  end
396
406
  end
397
407
  end