From 9bd899e371067ce56987a3afe33c58d6c68324ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juancarlo=20A=C3=B1ez?= Date: Sat, 25 Aug 2012 10:24:48 -0430 Subject: [PATCH] Allow for '*' wildcards in CLASSPATH+(some tipos). --- jnius/jnius_export_class.pxi | 4 ++-- jnius/jnius_jvm_desktop.pxi | 30 +++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/jnius/jnius_export_class.pxi b/jnius/jnius_export_class.pxi index 1f00ec2..25b0ce7 100644 --- a/jnius/jnius_export_class.pxi +++ b/jnius/jnius_export_class.pxi @@ -48,12 +48,12 @@ class MetaJavaClass(type): jcs.j_env = get_jnienv() if jcs.j_env == NULL: - raise JavaException('Unable to get the Android JNI Environment') + raise JavaException('Unable to get the JNI Environment') jcs.j_cls = jcs.j_env[0].FindClass(jcs.j_env, __javaclass__) if jcs.j_cls == NULL: - raise JavaException('Unable to found the class' + raise JavaException('Unable to find the class' ' {0}'.format(__javaclass__)) classDict['__cls_storage'] = jcs diff --git a/jnius/jnius_jvm_desktop.pxi b/jnius/jnius_jvm_desktop.pxi index 53d0eb0..7b30670 100644 --- a/jnius/jnius_jvm_desktop.pxi +++ b/jnius/jnius_jvm_desktop.pxi @@ -16,15 +16,39 @@ cdef extern from "jni.h": cdef JNIEnv *default_env = NULL +def classpath(): + import platform + from glob import glob + from os import environ + from os.path import realpath + + if 'CLASSPATH' not in environ: + return realpath('.') + cp = environ.get('CLASSPATH') + if platform.system() == 'Windows': + split_char = ';' + else: + split_char = ':' + pre_paths = cp.split(split_char) + # deal with wildcards + paths = [] + for path in pre_paths: + if not path.endswith('*'): + paths.append(path) + else: + paths.extend(glob(path + '.jar')) + paths.extend(glob(path + '.JAR')) + result = split_char.join(paths) + return result + + cdef void create_jnienv(): cdef JavaVM* jvm cdef JavaVMInitArgs args cdef JavaVMOption options[1] cdef bytes py_bytes - from os import environ - from os.path import realpath - cp = environ.get('CLASSPATH') or realpath('.') + cp = classpath() py_bytes = ('-Djava.class.path={0}'.format(cp)) options[0].optionString = py_bytes options[0].extraInfo = NULL