ruboto 0.5.2 → 0.5.3
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/Gemfile.lock +5 -5
- data/README.md +2 -2
- data/Rakefile +5 -6
- data/assets/Rakefile +32 -11
- data/assets/res/drawable/get_ruboto_core.png +0 -0
- data/assets/res/layout/get_ruboto_core.xml +1 -1
- data/assets/samples/sample_activity.rb +13 -11
- data/assets/samples/sample_broadcast_receiver.rb +6 -3
- data/assets/samples/sample_service.rb +10 -7
- data/assets/src/InheritingActivity.java +1 -186
- data/assets/src/RubotoActivity.java +9 -11
- data/assets/src/RubotoBroadcastReceiver.java +34 -27
- data/assets/src/RubotoService.java +9 -2
- data/assets/src/org/ruboto/EntryPointActivity.java +194 -0
- data/assets/src/org/ruboto/Script.java +29 -15
- data/assets/src/org/ruboto/test/InstrumentationTestRunner.java +17 -16
- data/assets/src/ruboto.rb +11 -608
- data/assets/src/ruboto/activity.rb +84 -0
- data/assets/src/ruboto/base.rb +88 -0
- data/assets/src/ruboto/broadcast_receiver.rb +31 -0
- data/assets/src/ruboto/legacy.rb +223 -0
- data/assets/src/ruboto/menu.rb +89 -0
- data/assets/src/ruboto/preference.rb +78 -0
- data/assets/src/ruboto/service.rb +74 -0
- data/assets/src/ruboto/util/stack.rb +34 -0
- data/assets/src/ruboto/util/toast.rb +18 -0
- data/assets/src/ruboto/widget.rb +188 -0
- data/assets/test/{assets/scripts → src}/test_helper.rb +4 -0
- data/bin/ruboto +7 -0
- data/lib/ruboto/commands/base.rb +4 -18
- data/lib/ruboto/util/build.rb +1 -2
- data/lib/ruboto/util/update.rb +77 -70
- data/lib/ruboto/version.rb +1 -1
- data/test/activity/psych_activity.rb +25 -0
- data/test/activity/psych_activity_test.rb +16 -0
- data/test/activity/stack_activity_test.rb +1 -1
- data/test/app_test_methods.rb +8 -4
- data/test/minimal_app_test.rb +6 -3
- data/test/rake_test.rb +1 -1
- data/test/ruboto_gen_test.rb +10 -1
- data/test/test_helper.rb +3 -5
- data/test/update_test_methods.rb +2 -2
- metadata +20 -8
- data/test/ruboto_gen_with_psych_test.rb +0 -16
- data/test/ruboto_update_with_psych_test.rb +0 -18
@@ -75,6 +75,7 @@ THE_CONSTANTS
|
|
75
75
|
|
76
76
|
// This causes JRuby to initialize and takes while
|
77
77
|
protected void prepareJRuby() {
|
78
|
+
Script.put("$context", this);
|
78
79
|
Script.put("$activity", this);
|
79
80
|
Script.put("$bundle", args[0]);
|
80
81
|
}
|
@@ -82,18 +83,15 @@ THE_CONSTANTS
|
|
82
83
|
protected void loadScript() {
|
83
84
|
try {
|
84
85
|
if (scriptName != null) {
|
85
|
-
|
86
|
-
|
87
|
-
setRemoteVariable(configBundle.getString("Remote Variable"));
|
88
|
-
if (configBundle.getBoolean("Define Remote Variable")) {
|
89
|
-
Script.put(remoteVariable, this);
|
90
|
-
}
|
91
|
-
if (configBundle.getString("Initialize Script") != null) {
|
92
|
-
Script.execute(configBundle.getString("Initialize Script"));
|
93
|
-
}
|
94
|
-
Script.execute(getRemoteVariableCall("on_create($bundle)"));
|
86
|
+
Script.setScriptFilename(getClass().getClassLoader().getResource(scriptName).getPath());
|
87
|
+
Script.execute(new Script(scriptName).getContents());
|
95
88
|
} else {
|
96
|
-
|
89
|
+
// TODO: Why doesn't this work?
|
90
|
+
// Script.callMethod(this, "initialize_ruboto");
|
91
|
+
Script.execute("$activity.initialize_ruboto");
|
92
|
+
// TODO: Why doesn't this work?
|
93
|
+
// Script.callMethod(this, "on_create", args[0]);
|
94
|
+
Script.execute("$activity.on_create($bundle)");
|
97
95
|
}
|
98
96
|
} catch(IOException e){
|
99
97
|
e.printStackTrace();
|
@@ -2,50 +2,57 @@ package THE_PACKAGE;
|
|
2
2
|
|
3
3
|
import java.io.IOException;
|
4
4
|
|
5
|
-
public
|
6
|
-
private String scriptName;
|
7
|
-
private
|
8
|
-
|
9
|
-
THE_CONSTANTS
|
10
|
-
|
11
|
-
private Object[] callbackProcs = new Object[CONSTANTS_COUNT];
|
5
|
+
public class THE_RUBOTO_CLASS THE_ACTION THE_ANDROID_CLASS {
|
6
|
+
private String scriptName = null;
|
7
|
+
private boolean initialized = false;
|
12
8
|
|
13
9
|
public void setCallbackProc(int id, Object obj) {
|
14
|
-
|
10
|
+
// Error: no callbacks
|
11
|
+
throw new RuntimeException("RubotoBroadcastReceiver does not accept callbacks");
|
15
12
|
}
|
16
13
|
|
17
|
-
public THE_RUBOTO_CLASS setRemoteVariable(String var) {
|
18
|
-
remoteVariable = ((var == null) ? "" : (var + "."));
|
19
|
-
return this;
|
20
|
-
}
|
21
|
-
|
22
14
|
public void setScriptName(String name){
|
23
15
|
scriptName = name;
|
24
16
|
}
|
25
17
|
|
26
|
-
public THE_RUBOTO_CLASS(
|
27
|
-
|
28
|
-
|
29
|
-
|
18
|
+
public THE_RUBOTO_CLASS() {
|
19
|
+
this(null);
|
20
|
+
}
|
21
|
+
|
22
|
+
public THE_RUBOTO_CLASS(String name) {
|
23
|
+
super();
|
24
|
+
|
25
|
+
if (name != null) {
|
26
|
+
setScriptName(name);
|
27
|
+
|
28
|
+
if (Script.isInitialized()) {
|
29
|
+
loadScript();
|
30
|
+
}
|
30
31
|
}
|
31
32
|
}
|
32
33
|
|
33
34
|
protected void loadScript() {
|
34
35
|
Script.put("$broadcast_receiver", this);
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
if (scriptName != null) {
|
37
|
+
try {
|
38
|
+
new Script(scriptName).execute();
|
39
|
+
} catch(IOException e) {
|
40
|
+
throw new RuntimeException("IOException loading broadcast receiver script", e);
|
41
|
+
}
|
39
42
|
}
|
40
43
|
}
|
41
44
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
THE_METHODS
|
45
|
+
public void onReceive(android.content.Context context, android.content.Intent intent) {
|
46
|
+
Script.put("$context", context);
|
47
|
+
Script.put("$broadcast_receiver", this);
|
48
|
+
Script.put("$intent", intent);
|
48
49
|
|
50
|
+
try {
|
51
|
+
Script.execute("$broadcast_receiver.on_receive($context, $intent)");
|
52
|
+
} catch(Exception e) {
|
53
|
+
e.printStackTrace();
|
54
|
+
}
|
55
|
+
}
|
49
56
|
}
|
50
57
|
|
51
58
|
|
@@ -4,7 +4,7 @@ import org.ruboto.Script;
|
|
4
4
|
import java.io.IOException;
|
5
5
|
import android.app.ProgressDialog;
|
6
6
|
|
7
|
-
public
|
7
|
+
public class THE_RUBOTO_CLASS THE_ACTION THE_ANDROID_CLASS {
|
8
8
|
private String scriptName;
|
9
9
|
private String remoteVariable = "";
|
10
10
|
public Object[] args;
|
@@ -38,9 +38,16 @@ THE_CONSTANTS
|
|
38
38
|
super.onCreate();
|
39
39
|
|
40
40
|
if (Script.setUpJRuby(this)) {
|
41
|
+
Script.defineGlobalVariable("$context", this);
|
41
42
|
Script.defineGlobalVariable("$service", this);
|
43
|
+
|
42
44
|
try {
|
43
|
-
|
45
|
+
if (scriptName != null) {
|
46
|
+
new Script(scriptName).execute();
|
47
|
+
} else {
|
48
|
+
Script.execute("$service.initialize_ruboto");
|
49
|
+
Script.execute("$service.on_create");
|
50
|
+
}
|
44
51
|
} catch(IOException e) {
|
45
52
|
e.printStackTrace();
|
46
53
|
}
|
@@ -0,0 +1,194 @@
|
|
1
|
+
package org.ruboto;
|
2
|
+
|
3
|
+
import java.io.File;
|
4
|
+
import java.io.IOException;
|
5
|
+
|
6
|
+
import org.ruboto.Script;
|
7
|
+
|
8
|
+
import android.app.ProgressDialog;
|
9
|
+
import android.content.BroadcastReceiver;
|
10
|
+
import android.content.Context;
|
11
|
+
import android.content.DialogInterface;
|
12
|
+
import android.content.DialogInterface.OnCancelListener;
|
13
|
+
import android.content.Intent;
|
14
|
+
import android.content.IntentFilter;
|
15
|
+
import android.net.Uri;
|
16
|
+
import android.os.Bundle;
|
17
|
+
import android.os.Handler;
|
18
|
+
import android.util.Log;
|
19
|
+
import android.view.View;
|
20
|
+
import android.widget.TextView;
|
21
|
+
import android.widget.Toast;
|
22
|
+
|
23
|
+
public class EntryPointActivity extends org.ruboto.RubotoActivity {
|
24
|
+
private int splash = 0;
|
25
|
+
private ProgressDialog loadingDialog;
|
26
|
+
private boolean dialogCancelled = false;
|
27
|
+
private BroadcastReceiver receiver;
|
28
|
+
private boolean appStarted = false;
|
29
|
+
|
30
|
+
public void onCreate(Bundle bundle) {
|
31
|
+
Log.d("RUBOTO", "onCreate: ");
|
32
|
+
|
33
|
+
try {
|
34
|
+
splash = Class.forName(getPackageName() + ".R$layout").getField("splash").getInt(null);
|
35
|
+
} catch (Exception e) {
|
36
|
+
splash = -1;
|
37
|
+
}
|
38
|
+
|
39
|
+
if (Script.isInitialized()) {
|
40
|
+
appStarted = true;
|
41
|
+
}
|
42
|
+
super.onCreate(bundle);
|
43
|
+
}
|
44
|
+
|
45
|
+
public void onResume() {
|
46
|
+
Log.d("RUBOTO", "onResume: ");
|
47
|
+
|
48
|
+
if(appStarted) {
|
49
|
+
Log.d("RUBOTO", "onResume: App already started!");
|
50
|
+
super.onResume();
|
51
|
+
return;
|
52
|
+
}
|
53
|
+
|
54
|
+
Log.d("RUBOTO", "onResume: Checking JRuby");
|
55
|
+
if (Script.isInitialized()) {
|
56
|
+
Log.d("RUBOTO", "Already initialized");
|
57
|
+
fireRubotoActivity();
|
58
|
+
} else {
|
59
|
+
Log.d("RUBOTO", "Not initialized");
|
60
|
+
showProgress();
|
61
|
+
receiver = new BroadcastReceiver(){
|
62
|
+
public void onReceive(Context context, Intent intent) {
|
63
|
+
Log.i("RUBOTO", "received broadcast: " + intent);
|
64
|
+
Log.i("RUBOTO", "URI: " + intent.getData());
|
65
|
+
if (intent.getData().toString().equals("package:org.ruboto.core")) {
|
66
|
+
Toast.makeText(context,"Ruboto Core is now installed.",Toast.LENGTH_SHORT).show();
|
67
|
+
if (receiver != null) {
|
68
|
+
unregisterReceiver(receiver);
|
69
|
+
receiver = null;
|
70
|
+
}
|
71
|
+
showProgress();
|
72
|
+
initJRuby(false);
|
73
|
+
}
|
74
|
+
}
|
75
|
+
};
|
76
|
+
IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
|
77
|
+
filter.addDataScheme("package");
|
78
|
+
registerReceiver(receiver, filter);
|
79
|
+
initJRuby(true);
|
80
|
+
super.onResume();
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
public void onPause() {
|
85
|
+
Log.d("RUBOTO", "onPause: ");
|
86
|
+
|
87
|
+
if (receiver != null) {
|
88
|
+
unregisterReceiver(receiver);
|
89
|
+
receiver = null;
|
90
|
+
}
|
91
|
+
super.onPause();
|
92
|
+
}
|
93
|
+
|
94
|
+
public void onDestroy() {
|
95
|
+
Log.d("RUBOTO", "onDestroy: ");
|
96
|
+
|
97
|
+
super.onDestroy();
|
98
|
+
if (dialogCancelled) {
|
99
|
+
System.runFinalizersOnExit(true);
|
100
|
+
System.exit(0);
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
private void initJRuby(final boolean firstTime) {
|
105
|
+
new Thread(new Runnable() {
|
106
|
+
public void run() {
|
107
|
+
final boolean jrubyOk = Script.setUpJRuby(EntryPointActivity.this);
|
108
|
+
if (jrubyOk) {
|
109
|
+
Log.d("RUBOTO", "onResume: JRuby OK");
|
110
|
+
prepareJRuby();
|
111
|
+
runOnUiThread(new Runnable() {
|
112
|
+
public void run() {
|
113
|
+
fireRubotoActivity();
|
114
|
+
}
|
115
|
+
});
|
116
|
+
} else {
|
117
|
+
runOnUiThread(new Runnable() {
|
118
|
+
public void run() {
|
119
|
+
if (firstTime) {
|
120
|
+
Log.d("RUBOTO", "onResume: Checking JRuby - IN UI thread");
|
121
|
+
try {
|
122
|
+
setContentView(Class.forName(getPackageName() + ".R$layout").getField("get_ruboto_core").getInt(null));
|
123
|
+
} catch (Exception e) {
|
124
|
+
}
|
125
|
+
} else {
|
126
|
+
Toast.makeText(EntryPointActivity.this,"Failed to initialize Ruboto Core.",Toast.LENGTH_SHORT).show();
|
127
|
+
try {
|
128
|
+
TextView textView = (TextView) findViewById(Class.forName(getPackageName() + ".R$id").getField("text").getInt(null));
|
129
|
+
textView.setText("Woops! Ruboto Core was installed, but it failed to initialize properly! I am not sure how to proceed from here. If you can, please file an error report at http://ruboto.org/");
|
130
|
+
} catch (Exception e) {
|
131
|
+
}
|
132
|
+
}
|
133
|
+
hideProgress();
|
134
|
+
}
|
135
|
+
});
|
136
|
+
}
|
137
|
+
}
|
138
|
+
}).start();
|
139
|
+
}
|
140
|
+
|
141
|
+
private static final String RUBOTO_APK = "RubotoCore-release.apk";
|
142
|
+
private static final String RUBOTO_URL = "https://github.com/downloads/ruboto/ruboto/" + RUBOTO_APK;
|
143
|
+
|
144
|
+
// Called when the button is pressed.
|
145
|
+
public void getRubotoCore(View view) {
|
146
|
+
try {
|
147
|
+
startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("market://details?id=org.ruboto.core")));
|
148
|
+
} catch (android.content.ActivityNotFoundException anfe) {
|
149
|
+
try {
|
150
|
+
TextView textView = (TextView) findViewById(Class.forName(getPackageName() + ".R$id").getField("text").getInt(null));
|
151
|
+
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(RUBOTO_URL));
|
152
|
+
startActivity(intent);
|
153
|
+
} catch (Exception e) {}
|
154
|
+
}
|
155
|
+
}
|
156
|
+
|
157
|
+
private void fireRubotoActivity() {
|
158
|
+
if(appStarted) return;
|
159
|
+
appStarted = true;
|
160
|
+
Log.i("RUBOTO", "Starting activity");
|
161
|
+
loadScript();
|
162
|
+
onStart();
|
163
|
+
super.onResume();
|
164
|
+
hideProgress();
|
165
|
+
}
|
166
|
+
|
167
|
+
private void showProgress() {
|
168
|
+
if (loadingDialog == null) {
|
169
|
+
Log.i("RUBOTO", "Showing progress");
|
170
|
+
if (splash > 0) {
|
171
|
+
requestWindowFeature(android.view.Window.FEATURE_NO_TITLE);
|
172
|
+
setContentView(splash);
|
173
|
+
} else {
|
174
|
+
loadingDialog = ProgressDialog.show(this, null, "Starting...", true, true);
|
175
|
+
loadingDialog.setCanceledOnTouchOutside(false);
|
176
|
+
loadingDialog.setOnCancelListener(new OnCancelListener() {
|
177
|
+
public void onCancel(DialogInterface dialog) {
|
178
|
+
dialogCancelled = true;
|
179
|
+
finish();
|
180
|
+
}
|
181
|
+
});
|
182
|
+
}
|
183
|
+
}
|
184
|
+
}
|
185
|
+
|
186
|
+
private void hideProgress() {
|
187
|
+
if (loadingDialog != null) {
|
188
|
+
Log.d("RUBOTO", "Hide progress");
|
189
|
+
loadingDialog.dismiss();
|
190
|
+
loadingDialog = null;
|
191
|
+
}
|
192
|
+
}
|
193
|
+
|
194
|
+
}
|
@@ -169,11 +169,8 @@ public class Script {
|
|
169
169
|
callScriptingContainerMethod(Void.class, "setCurrentDirectory", defaultCurrentDir);
|
170
170
|
|
171
171
|
if (out != null) {
|
172
|
-
// callScriptingContainerMethod(Void.class, "setOutput", out);
|
173
172
|
Method setOutputMethod = ruby.getClass().getMethod("setOutput", PrintStream.class);
|
174
173
|
setOutputMethod.invoke(ruby, out);
|
175
|
-
|
176
|
-
// callScriptingContainerMethod(Void.class, "setError", out);
|
177
174
|
Method setErrorMethod = ruby.getClass().getMethod("setError", PrintStream.class);
|
178
175
|
setErrorMethod.invoke(ruby, out);
|
179
176
|
}
|
@@ -229,15 +226,10 @@ public class Script {
|
|
229
226
|
} catch (RuntimeException re) {
|
230
227
|
re.printStackTrace();
|
231
228
|
} catch (IllegalAccessException e) {
|
232
|
-
// TODO Auto-generated catch block
|
233
229
|
e.printStackTrace();
|
234
230
|
} catch (InvocationTargetException e) {
|
235
|
-
|
236
|
-
e.printStackTrace();
|
237
|
-
} catch (NullPointerException npe) {
|
238
|
-
}
|
231
|
+
printStackTrace(e);
|
239
232
|
} catch (NoSuchMethodException e) {
|
240
|
-
// TODO Auto-generated catch block
|
241
233
|
e.printStackTrace();
|
242
234
|
}
|
243
235
|
return null;
|
@@ -330,7 +322,7 @@ public class Script {
|
|
330
322
|
if (new File(scriptsDir).exists()) {
|
331
323
|
Log.i(TAG, "Found extra scripts dir: " + scriptsDir);
|
332
324
|
setDir(scriptsDir);
|
333
|
-
exec("$:.unshift '" + scriptsDir + "' ; $:.uniq!
|
325
|
+
exec("$:.unshift '" + scriptsDir + "' ; $:.uniq!");
|
334
326
|
return true;
|
335
327
|
} else {
|
336
328
|
Log.i(TAG, "Extra scripts dir not present: " + scriptsDir);
|
@@ -495,7 +487,6 @@ public class Script {
|
|
495
487
|
}
|
496
488
|
|
497
489
|
public static void callMethod(Object receiver, String methodName, Object[] args) {
|
498
|
-
// callScriptingContainerMethod(Void.class, "callMethod", receiver, methodName, args);
|
499
490
|
try {
|
500
491
|
Method callMethodMethod = ruby.getClass().getMethod("callMethod", Object.class, String.class, Object[].class);
|
501
492
|
callMethodMethod.invoke(ruby, receiver, methodName, args);
|
@@ -504,7 +495,7 @@ public class Script {
|
|
504
495
|
} catch (IllegalAccessException iae) {
|
505
496
|
throw new RuntimeException(iae);
|
506
497
|
} catch (java.lang.reflect.InvocationTargetException ite) {
|
507
|
-
|
498
|
+
printStackTrace(ite);
|
508
499
|
}
|
509
500
|
}
|
510
501
|
|
@@ -518,7 +509,6 @@ public class Script {
|
|
518
509
|
|
519
510
|
@SuppressWarnings("unchecked")
|
520
511
|
public static <T> T callMethod(Object receiver, String methodName, Object[] args, Class<T> returnType) {
|
521
|
-
// return callScriptingContainerMethod(returnType, "callMethod", receiver, methodName, args, returnType);
|
522
512
|
try {
|
523
513
|
Method callMethodMethod = ruby.getClass().getMethod("callMethod", Object.class, String.class, Object[].class, Class.class);
|
524
514
|
return (T) callMethodMethod.invoke(ruby, receiver, methodName, args, returnType);
|
@@ -527,8 +517,9 @@ public class Script {
|
|
527
517
|
} catch (IllegalAccessException iae) {
|
528
518
|
throw new RuntimeException(iae);
|
529
519
|
} catch (java.lang.reflect.InvocationTargetException ite) {
|
530
|
-
|
520
|
+
printStackTrace(ite);
|
531
521
|
}
|
522
|
+
return null;
|
532
523
|
}
|
533
524
|
|
534
525
|
public static <T> T callMethod(Object receiver, String methodName,
|
@@ -541,5 +532,28 @@ public class Script {
|
|
541
532
|
return callMethod(receiver, methodName, new Object[]{}, returnType);
|
542
533
|
}
|
543
534
|
|
544
|
-
|
535
|
+
private static void printStackTrace(Throwable t) {
|
536
|
+
PrintStream out;
|
537
|
+
try {
|
538
|
+
Method getOutputMethod = ruby.getClass().getMethod("getOutput");
|
539
|
+
out = (PrintStream) getOutputMethod.invoke(ruby);
|
540
|
+
} catch (java.lang.NoSuchMethodException nsme) {
|
541
|
+
throw new RuntimeException("ScriptingContainer#getOutput method not found.", nsme);
|
542
|
+
} catch (java.lang.IllegalAccessException iae) {
|
543
|
+
throw new RuntimeException("ScriptingContainer#getOutput method not accessable.", iae);
|
544
|
+
} catch (java.lang.reflect.InvocationTargetException ite) {
|
545
|
+
throw new RuntimeException("ScriptingContainer#getOutput failed.", ite);
|
546
|
+
}
|
545
547
|
|
548
|
+
// TODO(uwe): Simplify this when Issue #144 is resolved
|
549
|
+
try {
|
550
|
+
t.printStackTrace(out);
|
551
|
+
} catch (NullPointerException npe) {
|
552
|
+
// TODO(uwe): printStackTrace should not fail
|
553
|
+
for (java.lang.StackTraceElement ste : t.getStackTrace()) {
|
554
|
+
out.append(ste.toString() + "\n");
|
555
|
+
}
|
556
|
+
}
|
557
|
+
}
|
558
|
+
|
559
|
+
}
|
@@ -23,6 +23,8 @@ import junit.framework.Test;
|
|
23
23
|
import junit.framework.TestCase;
|
24
24
|
import junit.framework.TestSuite;
|
25
25
|
import org.ruboto.Script;
|
26
|
+
import java.util.Set;
|
27
|
+
import java.util.HashSet;
|
26
28
|
|
27
29
|
public class InstrumentationTestRunner extends android.test.InstrumentationTestRunner {
|
28
30
|
private Class activityClass;
|
@@ -39,23 +41,25 @@ public class InstrumentationTestRunner extends android.test.InstrumentationTestR
|
|
39
41
|
Script.defineGlobalVariable("$test", this);
|
40
42
|
Script.defineGlobalVariable("$suite", suite);
|
41
43
|
|
42
|
-
// TODO(uwe): Why doesn't this work?
|
43
|
-
// Script.copyScriptsIfNeeded(getContext());
|
44
|
-
|
45
44
|
loadScript("test_helper.rb");
|
46
45
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
46
|
+
String test_apk_path = getContext().getPackageManager().getApplicationInfo(getContext().getPackageName(), 0).sourceDir;
|
47
|
+
JarFile jar = new JarFile(test_apk_path);
|
48
|
+
Enumeration<JarEntry> entries = jar.entries();
|
49
|
+
while(entries.hasMoreElements()) {
|
50
|
+
JarEntry entry = entries.nextElement();
|
51
|
+
String name = entry.getName();
|
52
|
+
if (name.indexOf("/") >= 0 || !name.endsWith(".rb")) {
|
53
|
+
continue;
|
54
|
+
}
|
55
|
+
if (name.equals("test_helper.rb")) continue;
|
56
|
+
loadScript(name);
|
55
57
|
}
|
56
58
|
} else {
|
57
59
|
addError(suite, new RuntimeException("Ruboto Core platform is missing"));
|
58
60
|
}
|
61
|
+
} catch (android.content.pm.PackageManager.NameNotFoundException e) {
|
62
|
+
addError(suite, e);
|
59
63
|
} catch (IOException e) {
|
60
64
|
addError(suite, e);
|
61
65
|
} catch (RuntimeException e) {
|
@@ -98,10 +102,8 @@ public class InstrumentationTestRunner extends android.test.InstrumentationTestR
|
|
98
102
|
}
|
99
103
|
|
100
104
|
private void loadScript(String f) throws IOException {
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
InputStream is = getContext().getResources().getAssets().open("scripts/" + f);
|
105
|
+
Log.d(getClass().getName(), "Loading test script: " + f);
|
106
|
+
InputStream is = getClass().getClassLoader().getResourceAsStream(f);
|
105
107
|
BufferedReader buffer = new BufferedReader(new InputStreamReader(is));
|
106
108
|
StringBuilder source = new StringBuilder();
|
107
109
|
while (true) {
|
@@ -111,7 +113,6 @@ public class InstrumentationTestRunner extends android.test.InstrumentationTestR
|
|
111
113
|
}
|
112
114
|
buffer.close();
|
113
115
|
|
114
|
-
Log.d(getClass().getName(), "Loading test script: " + f);
|
115
116
|
String oldFilename = Script.getScriptFilename();
|
116
117
|
Script.setScriptFilename(f);
|
117
118
|
Script.put("$script_code", source.toString());
|