lucene-pylucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From va...@apache.org
Subject svn commit: r945445 - in /lucene/pylucene/branches/branch_3x/jcc: CHANGES jcc/sources/JCCEnv.cpp jcc/sources/JCCEnv.h jcc/sources/jcc.cpp
Date Tue, 18 May 2010 01:04:03 GMT
Author: vajda
Date: Tue May 18 01:04:02 2010
New Revision: 945445

URL: http://svn.apache.org/viewvc?rev=945445&view=rev
Log:
added read-only env.classpath property

Modified:
    lucene/pylucene/branches/branch_3x/jcc/CHANGES
    lucene/pylucene/branches/branch_3x/jcc/jcc/sources/JCCEnv.cpp
    lucene/pylucene/branches/branch_3x/jcc/jcc/sources/JCCEnv.h
    lucene/pylucene/branches/branch_3x/jcc/jcc/sources/jcc.cpp

Modified: lucene/pylucene/branches/branch_3x/jcc/CHANGES
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/branch_3x/jcc/CHANGES?rev=945445&r1=945444&r2=945445&view=diff
==============================================================================
--- lucene/pylucene/branches/branch_3x/jcc/CHANGES (original)
+++ lucene/pylucene/branches/branch_3x/jcc/CHANGES Tue May 18 01:04:02 2010
@@ -18,6 +18,7 @@ Version 2.5 ->
  - added JCC_VERSION string to modules using JCC
  - added support for --resources
  - added support for --import
+ - added read-only env.classpath property
  - 
 
 Version 2.4 -> 2.5

Modified: lucene/pylucene/branches/branch_3x/jcc/jcc/sources/JCCEnv.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/branch_3x/jcc/jcc/sources/JCCEnv.cpp?rev=945445&r1=945444&r2=945445&view=diff
==============================================================================
--- lucene/pylucene/branches/branch_3x/jcc/jcc/sources/JCCEnv.cpp (original)
+++ lucene/pylucene/branches/branch_3x/jcc/jcc/sources/JCCEnv.cpp Tue May 18 01:04:02 2010
@@ -709,6 +709,52 @@ void JCCEnv::setClassPath(const char *cl
     free(path);
 }
 
+char *JCCEnv::getClassPath()
+{
+    JNIEnv *vm_env = get_vm_env();
+    jclass _ucl = (jclass) vm_env->FindClass("java/net/URLClassLoader");
+    jclass _url = (jclass) vm_env->FindClass("java/net/URL");
+    jmethodID mid = vm_env->GetStaticMethodID(_ucl, "getSystemClassLoader",
+                                              "()Ljava/lang/ClassLoader;");
+    jobject classLoader = vm_env->CallStaticObjectMethod(_ucl, mid);
+    jmethodID gu = vm_env->GetMethodID(_ucl, "getURLs", "()[Ljava/net/URL;");
+    jmethodID gp = vm_env->GetMethodID(_url, "getPath", "()Ljava/lang/String;");
+#ifdef WINDOWS
+    char *pathsep = ";";
+#else
+    char *pathsep = ":";
+#endif
+    jobjectArray array = (jobjectArray)
+        vm_env->CallObjectMethod(classLoader, gu);
+    int count = array ? vm_env->GetArrayLength(array) : 0;
+    int first = 1, total = 0;
+    char *classpath = NULL;
+    
+    for (int i = 0; i < count; i++) {
+        jobject url = vm_env->GetObjectArrayElement(array, i);
+        jstring path = (jstring) vm_env->CallObjectMethod(url, gp);
+        const char *chars = vm_env->GetStringUTFChars(path, NULL);
+        int size = vm_env->GetStringUTFLength(path);
+
+        total += size + 1;
+        if (classpath == NULL)
+            classpath = (char *) calloc(total, 1);
+        else
+            classpath = (char *) realloc(classpath, total);
+        if (classpath == NULL)
+            return NULL;
+
+        if (first)
+            first = 0;
+        else
+            strcat(classpath, pathsep);
+
+        strcat(classpath, chars);
+    }
+
+    return classpath;
+}
+
 jstring JCCEnv::fromUTF(const char *bytes) const
 {
     jstring str = get_vm_env()->NewStringUTF(bytes);

Modified: lucene/pylucene/branches/branch_3x/jcc/jcc/sources/JCCEnv.h
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/branch_3x/jcc/jcc/sources/JCCEnv.h?rev=945445&r1=945444&r2=945445&view=diff
==============================================================================
--- lucene/pylucene/branches/branch_3x/jcc/jcc/sources/JCCEnv.h (original)
+++ lucene/pylucene/branches/branch_3x/jcc/jcc/sources/JCCEnv.h Tue May 18 01:04:02 2010
@@ -286,6 +286,7 @@ public:
     }
 
     virtual void setClassPath(const char *classPath);
+    virtual char *getClassPath();
 
     virtual jstring fromUTF(const char *bytes) const;
     virtual char *toUTF(jstring str) const;

Modified: lucene/pylucene/branches/branch_3x/jcc/jcc/sources/jcc.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/branch_3x/jcc/jcc/sources/jcc.cpp?rev=945445&r1=945444&r2=945445&view=diff
==============================================================================
--- lucene/pylucene/branches/branch_3x/jcc/jcc/sources/jcc.cpp (original)
+++ lucene/pylucene/branches/branch_3x/jcc/jcc/sources/jcc.cpp Tue May 18 01:04:02 2010
@@ -49,10 +49,12 @@ static PyObject *t_jccenv__addClassPath(
 
 static PyObject *t_jccenv__get_jni_version(PyObject *self, void *data);
 static PyObject *t_jccenv__get_java_version(PyObject *self, void *data);
+static PyObject *t_jccenv__get_classpath(PyObject *self, void *data);
 
 static PyGetSetDef t_jccenv_properties[] = {
     { "jni_version", (getter) t_jccenv__get_jni_version, NULL, NULL, NULL },
     { "java_version", (getter) t_jccenv__get_java_version, NULL, NULL, NULL },
+    { "classpath", (getter) t_jccenv__get_classpath, NULL, NULL, NULL },
     { NULL, NULL, NULL, NULL, NULL }
 };
 
@@ -293,6 +295,21 @@ static PyObject *t_jccenv__get_java_vers
     return env->fromJString(env->getJavaVersion(), 1);
 }
 
+static PyObject *t_jccenv__get_classpath(PyObject *self, void *data)
+{
+    char *classpath = env->getClassPath();
+
+    if (classpath)
+    {
+        PyObject *result = PyString_FromString(classpath);
+
+        free(classpath);
+        return result;
+    }
+
+    Py_RETURN_NONE;
+}
+
 _DLL_EXPORT PyObject *getVMEnv(PyObject *self)
 {
     if (env->vm != NULL)



Mime
View raw message