Permalink
Browse files

* Issue #6 Port to Ruboto Core

* Changed exception handling to log the exception to the given output stream rather than throw a RuntimeException.
  • Loading branch information...
donv committed Jan 3, 2012
1 parent 9b503d3 commit f2d0b13f66ccea6b6020852e1a0cb1842415d1ea
Showing with 35 additions and 18 deletions.
  1. +6 −3 Rakefile
  2. BIN res/drawable/get_ruboto_core.png
  3. +1 −1 res/layout/get_ruboto_core.xml
  4. +28 −14 src/org/ruboto/Script.java
View
@@ -1,5 +1,5 @@
if `ant -version` !~ /version (\d+)\.(\d+)\.(\d+)/ || $1.to_i < 1 || ($1.to_i == 1 && $2.to_i < 8)
- puts "ANT version 1.8.1 or later required. Version found: #{$1}.#{$2}.#{$3}"
+ puts "ANT version 1.8.0 or later required. Version found: #{$1}.#{$2}.#{$3}"
exit 1
end
@@ -77,21 +77,24 @@ namespace :install do
end
end
+desc 'Build APK for release'
task :release => RELEASE_APK_FILE
file RELEASE_APK_FILE => APK_DEPENDENCIES do |t|
build_apk(t, true)
end
+desc 'Tag this working copy with the current version'
task :tag => :release do
unless `git branch` =~ /^\* master$/
puts "You must be on the master branch to release!"
exit!
end
- sh "git commit --allow-empty -a -m 'Release #{version}'"
+ # sh "git commit --allow-empty -a -m 'Release #{version}'"
+ output = `git status --porcelain`
+ raise "Workspace not clean!\n#{output}" unless output.empty?
sh "git tag #{version}"
sh "git push origin master --tags"
- #sh "gem push pkg/#{name}-#{version}.gem"
end
task :sign => :release do
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -12,7 +12,7 @@
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
- android:src="@drawable/icon"
+ android:src="@drawable/get_ruboto_core"
android:layout_weight="1"
android:scaleType="fitCenter"
android:onClick="getRubotoCore"
View
@@ -169,11 +169,8 @@ public static synchronized boolean setUpJRuby(Context appContext, PrintStream ou
callScriptingContainerMethod(Void.class, "setCurrentDirectory", defaultCurrentDir);
if (out != null) {
- // callScriptingContainerMethod(Void.class, "setOutput", out);
Method setOutputMethod = ruby.getClass().getMethod("setOutput", PrintStream.class);
setOutputMethod.invoke(ruby, out);
-
- // callScriptingContainerMethod(Void.class, "setError", out);
Method setErrorMethod = ruby.getClass().getMethod("setError", PrintStream.class);
setErrorMethod.invoke(ruby, out);
}
@@ -229,15 +226,10 @@ private static void handleInitException(Exception e) {
} catch (RuntimeException re) {
re.printStackTrace();
} catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
- try {
- e.printStackTrace();
- } catch (NullPointerException npe) {
- }
+ printStackTrace(e);
} catch (NoSuchMethodException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
return null;
@@ -495,7 +487,6 @@ public String execute() throws IOException {
}
public static void callMethod(Object receiver, String methodName, Object[] args) {
- // callScriptingContainerMethod(Void.class, "callMethod", receiver, methodName, args);
try {
Method callMethodMethod = ruby.getClass().getMethod("callMethod", Object.class, String.class, Object[].class);
callMethodMethod.invoke(ruby, receiver, methodName, args);
@@ -504,7 +495,7 @@ public static void callMethod(Object receiver, String methodName, Object[] args)
} catch (IllegalAccessException iae) {
throw new RuntimeException(iae);
} catch (java.lang.reflect.InvocationTargetException ite) {
- throw (RuntimeException)(ite.getCause());
+ printStackTrace(ite);
}
}
@@ -518,7 +509,6 @@ public static void callMethod(Object object, String methodName) {
@SuppressWarnings("unchecked")
public static <T> T callMethod(Object receiver, String methodName, Object[] args, Class<T> returnType) {
- // return callScriptingContainerMethod(returnType, "callMethod", receiver, methodName, args, returnType);
try {
Method callMethodMethod = ruby.getClass().getMethod("callMethod", Object.class, String.class, Object[].class, Class.class);
return (T) callMethodMethod.invoke(ruby, receiver, methodName, args, returnType);
@@ -527,8 +517,9 @@ public static void callMethod(Object object, String methodName) {
} catch (IllegalAccessException iae) {
throw new RuntimeException(iae);
} catch (java.lang.reflect.InvocationTargetException ite) {
- throw (RuntimeException) ite.getCause();
+ printStackTrace(ite);
}
+ return null;
}
public static <T> T callMethod(Object receiver, String methodName,
@@ -541,5 +532,28 @@ public static void callMethod(Object object, String methodName) {
return callMethod(receiver, methodName, new Object[]{}, returnType);
}
-}
+ private static void printStackTrace(Throwable t) {
+ PrintStream out;
+ try {
+ Method getOutputMethod = ruby.getClass().getMethod("getOutput");
+ out = (PrintStream) getOutputMethod.invoke(ruby);
+ } catch (java.lang.NoSuchMethodException nsme) {
+ throw new RuntimeException("ScriptingContainer#getOutput method not found.", nsme);
+ } catch (java.lang.IllegalAccessException iae) {
+ throw new RuntimeException("ScriptingContainer#getOutput method not accessable.", iae);
+ } catch (java.lang.reflect.InvocationTargetException ite) {
+ throw new RuntimeException("ScriptingContainer#getOutput failed.", ite);
+ }
+ // TODO(uwe): Simplify this when Issue #144 is resolved
+ try {
+ t.printStackTrace(out);
+ } catch (NullPointerException npe) {
+ // TODO(uwe): printStackTrace should not fail
+ for (java.lang.StackTraceElement ste : t.getStackTrace()) {
+ out.append(ste.toString() + "\n");
+ }
+ }
+ }
+
+}

0 comments on commit f2d0b13

Please sign in to comment.