Permalink
Browse files

more verbose verbosity

  • Loading branch information...
1 parent e2dc932 commit 0591a1feda08517c0933d43b501468ae7a324956 @jdf committed Oct 17, 2010
Showing with 74 additions and 35 deletions.
  1. +37 −28 runtime/src/jycessing/PAppletJythonDriver.java
  2. +37 −7 runtime/src/jycessing/Runner.java
@@ -15,6 +15,16 @@
*/
package jycessing;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
+import java.io.File;
+import java.lang.Thread.UncaughtExceptionHandler;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.HashSet;
+import java.util.concurrent.CountDownLatch;
+import java.util.regex.Pattern;
+
import org.python.core.CompileMode;
import org.python.core.CompilerFlags;
import org.python.core.Py;
@@ -31,15 +41,6 @@
import processing.core.PConstants;
import processing.core.PImage;
-import java.awt.event.ComponentAdapter;
-import java.awt.event.ComponentEvent;
-import java.io.File;
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.HashSet;
-import java.util.concurrent.CountDownLatch;
-import java.util.regex.Pattern;
-
/**
*
* @author Jonathan Feinberg <jdf@pobox.com>
@@ -81,10 +82,9 @@
private void interpretSketch() {
try {
Py.setSystemState(interp.getSystemState());
- Py.exec(
- Py.compile_flags(programText, pySketchPath,
- CompileMode.exec, new CompilerFlags()),
- interp.getLocals(), null);
+ Py.exec(Py.compile_flags(programText, pySketchPath,
+ CompileMode.exec, new CompilerFlags()), interp.getLocals(),
+ null);
Py.flushLine();
} catch (Throwable t) {
checkForRendererChangeException(t);
@@ -97,13 +97,12 @@ private void interpretSketch() {
}
public PAppletJythonDriver(final InteractiveConsole interp,
- final String sketchPath,
- final String programText) {
+ final String sketchPath, final String programText) {
this.programText = programText;
this.pySketchPath = sketchPath;
this.sketchPath = new File(sketchPath).getParent();
this.isStaticMode = !ACTIVE_METHOD_DEF.matcher(programText).find();
- this.builtins = (PyStringMap) interp.getSystemState().getBuiltins();
+ this.builtins = (PyStringMap)interp.getSystemState().getBuiltins();
this.interp = interp;
initializeStatics(builtins);
setSet();
@@ -112,8 +111,7 @@ public PAppletJythonDriver(final InteractiveConsole interp,
builtins.__setitem__("this", Py.java2py(this));
builtins.__setitem__("exit", new PyObject() {
@Override
- public PyObject __call__(final PyObject[] args,
- final String[] kws) {
+ public PyObject __call__(final PyObject[] args, final String[] kws) {
finishedLatch.countDown();
return Py.None;
}
@@ -145,6 +143,19 @@ public void componentHidden(final ComponentEvent e) {
});
}
+ @Override
+ public void start() {
+ // I want to quit on runtime exceptions.
+ // Processing just sits there by default.
+ Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
+ public void uncaughtException(Thread t, Throwable e) {
+ e.printStackTrace(System.err);
+ System.exit(-1);
+ }
+ });
+ super.start();
+ }
+
public void blockUntilFinished() throws InterruptedException {
finishedLatch.await();
}
@@ -164,8 +175,7 @@ private void setSet() {
}
@Override
- public PyObject __call__(final PyObject[] args,
- final String[] kws) {
+ public PyObject __call__(final PyObject[] args, final String[] kws) {
switch (args.length) {
default:
return super.__call__(args, kws);
@@ -177,15 +187,14 @@ public PyObject __call__(final PyObject[] args,
final PyObject c = args[2];
final PyType tc = c.getType();
if (tx == PyInteger.TYPE && ty == PyInteger.TYPE
- && tc == PyInteger.TYPE) {
+ && tc == PyInteger.TYPE) {
set(x.asInt(), y.asInt(), c.asInt());
return Py.None;
} else if (tx == PyInteger.TYPE && ty == PyInteger.TYPE
- && tc.getProxyType() != null
- && tc.getProxyType() == PImage.class) {
- set(x.asInt(), y.asInt(),
- (processing.core.PImage) c.__tojava__(
- processing.core.PImage.class));
+ && tc.getProxyType() != null
+ && tc.getProxyType() == PImage.class) {
+ set(x.asInt(), y.asInt(), (processing.core.PImage)c
+ .__tojava__(processing.core.PImage.class));
return Py.None;
} else {
return super.__call__(args, kws);
@@ -218,7 +227,7 @@ private void checkForRendererChangeException(final Throwable t) {
// to signal a change to the rendering context, so we unwrap
// the Python exception to extract the signal, and pass it
// up the stack.
- throw (RendererChangeException) t.getCause();
+ throw (RendererChangeException)t.getCause();
}
}
@@ -229,7 +238,7 @@ private void checkForRendererChangeException(final Throwable t) {
*/
@Override
public void size(final int iwidth, final int iheight,
- final String irenderer, final String ipath) {
+ final String irenderer, final String ipath) {
super.size(iwidth, iheight, irenderer, ipath);
setFields();
}
@@ -25,10 +25,12 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
+import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
+import java.net.URLDecoder;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -128,29 +130,52 @@ private static void addLibraryPath(final String newPath) throws Exception {
* library path respectively.
*/
private static void searchForExtraStuff(final File dir) throws Exception {
+ if (dir == null) {
+ throw new IllegalArgumentException("null dir");
+ }
+
+ if (VERBOSE) {
+ System.err.println("Searching: " + dir);
+ }
+
final File[] dlls = dir.listFiles(new FilenameFilter() {
public boolean accept(final File dir, final String name) {
return name.matches("^.+\\.(so|dll|jnilib)$");
}
});
if (dlls != null && dlls.length > 0) {
addLibraryPath(dir.getAbsolutePath());
+ } else if (VERBOSE) {
+ System.err.println("No DLLs in " + dir);
}
+
final File[] jars = dir.listFiles(new FilenameFilter() {
public boolean accept(final File dir, final String name) {
return name.matches("^.+\\.jar$");
}
});
- for (final File jar : jars) {
- addJar(jar.toURI().toURL());
+ if (!(jars == null || jars.length == 0)) {
+ for (final File jar : jars) {
+ addJar(jar.toURI().toURL());
+ }
+ } else if (VERBOSE) {
+ System.err.println("No JARs in " + dir);
}
+
final File[] dirs = dir.listFiles(new FileFilter() {
public boolean accept(final File f) {
+ if (VERBOSE) {
+ System.err.println("Looking at " + f);
+ }
return f.isDirectory() && f.getName().charAt(0) != '.';
}
});
- for (final File d : dirs) {
- searchForExtraStuff(d);
+ if (!(dirs == null || dirs.length == 0)) {
+ for (final File d : dirs) {
+ searchForExtraStuff(d);
+ }
+ } else if (VERBOSE) {
+ System.err.println("No dirs in " + dir);
}
}
@@ -187,8 +212,14 @@ public static void main(final String[] args) throws Exception {
.compile("file:(.+?)/bin/jycessing/buildnumber.properties");
private static File getLibrariesDir() {
- final String propsResource = Runner.class.getResource(
- "buildnumber.properties").toString();
+ String propsResource;
+ try {
+ propsResource = URLDecoder.decode(
+ Runner.class.getResource("buildnumber.properties")
+ .toString(), "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException("Impossible: " + e);
+ }
{
final Matcher m = JAR_RESOURCE.matcher(propsResource);
if (m.matches()) {
@@ -271,6 +302,5 @@ public static void runSketch(final String[] args, final String sketchPath,
}
interp.cleanup();
}
-
}
}

0 comments on commit 0591a1f

Please sign in to comment.