diff --git a/examples/inspectConvert.py b/examples/inspectConvert.py deleted file mode 100644 index 4331103d7..000000000 --- a/examples/inspectConvert.py +++ /dev/null @@ -1,139 +0,0 @@ -import jpype -from jpype.types import * -from jpype import java -import pandas - -jpype.startJVM() - - -def canConvert(cls, obj): - return cls.__javaclass__.canConvertToJava(obj) - - -def runTest(cases, types, abbrev=lambda x: x): - columns = ['Name', 'Type'] - columns.extend([abbrev(str(t.class_.getName())) for t in types]) - rows = [] - for name, case in cases: - m = {} - q = str(type(case)).replace('', '') - if 'jpype' in q: - q = "Java " + abbrev(q.replace('jpype._jclass.', '')) - else: - q = "Py " + q - - m['Name'] = abbrev(name) - m['Type'] = abbrev(q) - for t in types: - c1 = abbrev(str(t.class_.getName())) - r = canConvert(t, case) - if r == "exact": - m[c1] = 'X' - if r == "implicit": - m[c1] = 'I' - if r == "explicit": - m[c1] = 'E' - if r == "none": - m[c1] = '' - rows.append(m) - out = pandas.DataFrame(rows, columns=columns) - return out - - -cases1 = [ - ("None", None), - ("True", True), - ("False", False), - ("int(1)", int(1)), - ("int(2)", int(2)), - ("float(12.3)", float(12.3)), - - ("JBoolean(True)", JBoolean(True)), - ("JChar(1)", JChar(1)), - ("JShort(1)", JShort(1)), - ("JInt(1)", JInt(1)), - ("JLong(1)", JLong(1)), - ("JFloat(2.1)", JFloat(2.1)), - ("JDouble(3.5)", JDouble(3.5)), - - ("java.lang.Boolean(True)", java.lang.Boolean(True)), - ("java.lang.Character(1)", java.lang.Character(1)), - ("java.lang.Short(1)", java.lang.Short(1)), - ("java.lang.Integer(1)", java.lang.Integer(1)), - ("java.lang.Long(1)", java.lang.Long(1)), - ("java.lang.Float(2.1)", java.lang.Float(2.1)), - ("java.lang.Double(3.5)", java.lang.Double(3.5)), - ("java.lang.Integer(1)", java.lang.Integer(1)), - ("JObject(1)", JObject(1)), - ("JObject(1.1)", JObject(1.1)), - ("JObject(1, JInt)", JObject(1, JInt)), -] - -cases2 = [ - ("bytes('c')", bytes('c', 'utf8')), - ("str('c')", str('c')), - ("str('abc')", str('abc')), - ("JString('b')", JString('b')), - ("JObject('a')", JObject('a')), - ("java.lang.Object", java.lang.Object), - ("java.lang.Object.class_", java.lang.Object.class_), - ("java.lang.Object()", java.lang.Object()), - ("JObject()", JObject()), - ("JObject(1, JObject)", JObject(1, JObject)), - ("JObject(None, JObject)", JObject(None, JObject)), - ("java.lang.Throwable", java.lang.Throwable('d')), - ("java.lang.Exception", java.lang.Exception('d')), - ('java.lang.Byte(1)', java.lang.Byte(1)), - ('JObject(java.lang.Byte(1),java.lang.Number)', - JObject(java.lang.Byte(1), java.lang.Number)), - ("dict()", dict()), - ("list()", list()), - ("[1,2]", [1, 2]), - ("[.1,.2]", [.1, .2]), - ('JArray(JInt)([1,2,3])', JArray(JInt)([1, 2, 3])), -] - -types1 = [ - JBoolean, - JChar, - JShort, - JInt, - JLong, - JFloat, - JDouble, - java.lang.Character, - java.lang.Byte, - java.lang.Short, - java.lang.Integer, - java.lang.Long, - java.lang.Float, - java.lang.Double, - java.lang.Object, - # java.lang.Class, - # java.lang.String, - # java.lang.Exception, - # JArray(JInt) -] - -types2 = [ - JChar, - java.lang.String, - java.lang.Object, - java.lang.Number, - java.lang.Class, - java.lang.Exception, - JArray(JInt), - JArray(JDouble) -] - - -def abbrev(s): - return s.replace("java.lang.", "j.l.") - - -print("Primitives and Boxed") -print(runTest(cases1, types1, abbrev=abbrev)) -print() - -print("Objects and casts") -print(runTest(cases2, types2, abbrev=abbrev)) diff --git a/examples/jms/README.TXT b/examples/jms/README.TXT index 787e157cd..a7772b57a 100644 --- a/examples/jms/README.TXT +++ b/examples/jms/README.TXT @@ -37,4 +37,4 @@ BTW, I don't detect any noticable slowdown in the python versions from the Java versions (probably because of the strightforward conversion of python strings to Java Strings). -============================================================================= \ No newline at end of file +============================================================================= diff --git a/examples/stubs/README b/examples/stubs/README deleted file mode 100644 index f89fb668a..000000000 --- a/examples/stubs/README +++ /dev/null @@ -1,2 +0,0 @@ -These are out of date testing codes used during the development of jpype. -Most of this functionality has be transformed into a formal test already. diff --git a/examples/stubs/buf_leak_test.py b/examples/stubs/buf_leak_test.py deleted file mode 100644 index 27df5e217..000000000 --- a/examples/stubs/buf_leak_test.py +++ /dev/null @@ -1,28 +0,0 @@ -from jpype import * -import time - -remote_pack = "c:/tools/netbeean-remote-pack" - -profiler_options = [ - "-agentpath:%s/lib/deployed/jdk15/windows/profilerinterface.dll=%s/lib,5140" % (remote_pack, remote_pack) -] - -options = [ - '-verbose:gc', - '-Xmx16m', -] # + profiler_options - -startJVM(getDefaultJVMPath(), *options) - - -class MyStr(str): - def __del__(self): - print('string got deleted') - - -while True: - buf = java.lang.String('5' * 1024 * 1024 * 5) - del buf - buf = nio.convertToDirectBuffer(MyStr('5' * 1024 * 1024)) - del buf -# time.sleep(1) diff --git a/examples/stubs/buf_leak_test3.py b/examples/stubs/buf_leak_test3.py deleted file mode 100644 index c55e150a8..000000000 --- a/examples/stubs/buf_leak_test3.py +++ /dev/null @@ -1,56 +0,0 @@ -from jpype import * -import time - -remote_pack = "c:/tools/netbeean-remote-pack" - -profiler_options = [ - "-agentpath:%s/lib/deployed/jdk15/windows/profilerinterface.dll=%s/lib,5140" % (remote_pack, remote_pack) -] - - -options = [ - # '-verbose:gc', - '-Xmx64m', - '-Djava.class.path=classes' -] # + profiler_options - -cnt = 0 - -# setUsePythonThreadForDeamon(True) -startJVM(getDefaultJVMPath(), *options) - - -class MyStr(str): - def __init__(self, val): - str.__init__(self, val) - global cnt - cnt += 1 - print 'created string', cnt - - def __del__(self): - global cnt - cnt -= 1 - print 'deleted string', cnt - - -receive = JClass("jpype.nio.NioReceive") - -while True: - # everything runs great with this line uncommented - #p = JString('5' * 1024 * 1024) - - # with this line uncommented, the python strings aren't GC'd - p = java.lang.StringBuffer(MyStr('5' * 1024 * 1024)) - - # with this line uncommented, the JVM throws an OutOfMemoryError (not GC'ing the proxied java objects?), - # but the python strings are being GC'd - #p = java.lang.StringBuffer(JString(MyStr('5' * 1024 * 1024))) - - # - # forget the direct buffer for now.... - # - buf = nio.convertToDirectBuffer(MyStr('5' * 1024 * 1024 * 5)) - try: - receive.receiveBufferWithException(buf) - except: - pass diff --git a/examples/stubs/bulletproof.py b/examples/stubs/bulletproof.py deleted file mode 100644 index cfdbeceb0..000000000 --- a/examples/stubs/bulletproof.py +++ /dev/null @@ -1,66 +0,0 @@ -# This is an outdated test that hit each entry point in the -# _jpype module and tested if the module response properly to -# an attempt to call without the jvm running. We can't -# run this in our testbench as it requires that the -# jvm is not running. -import unittest -import jpype -import _jpype - - -class TestJpypeModule(unittest.TestCase): - def setUp(self): - self.methods = { - 'attach': [tuple(["none"]), RuntimeError], - 'attachThreadAsDaemon': [tuple(), RuntimeError], - 'attachThreadToJVM': [tuple(), RuntimeError], - 'convertToDirectBuffer': [tuple(), RuntimeError], - 'convertToJValue': [tuple(["a", 1]), RuntimeError], - 'createProxy': [tuple(['a', (1, 2)]), AttributeError], - 'detachThreadFromJVM': [tuple(), RuntimeError], - 'dumpJVMStats': [tuple(), None], - 'findArrayClass': [tuple('double[]'), RuntimeError], - 'findClass': [tuple('java.lang.String'), RuntimeError], - 'getArrayItem': [tuple([None, 1]), TypeError], - 'getArrayLength': [tuple([None]), TypeError], - 'getArraySlice': [tuple([None, 1, 2]), TypeError], - 'isStarted': [tuple(), None], - 'isThreadAttachedToJVM': [tuple(), RuntimeError], - 'newArray': [tuple([None, 1]), TypeError], - 'setArrayItem': [tuple([None, 1, 2]), TypeError], - 'setArraySlice': [tuple([None, 1, 2, 3]), TypeError], - 'setConvertStringObjects': [tuple(), RuntimeError], - 'setGetClassMethod': [tuple([None]), None], - 'setGetJavaArrayClassMethod': [tuple([None]), None], - 'setJavaArrayClass': [tuple([None]), None], - 'setJavaExceptionClass': [tuple([None]), None], - 'setJavaLangObjectClass': [tuple([None]), None], - 'setProxyClass': [tuple([None]), None], - 'setSpecialConstructorKey': [tuple([None]), None], - 'setStringWrapperClass': [tuple([None]), None], - 'setWrapperClass': [tuple([None]), None], - 'shutdown': [tuple(), RuntimeError], - 'startReferenceQueue': [tuple([1]), RuntimeError], - 'startup': [tuple([None, tuple([None]), None]), TypeError], - 'stopReferenceQueue': [tuple(), RuntimeError], - 'synchronized': [tuple(), None], - } - - def testEntryPoints(self): - for n, c in self.methods.items(): - print('====', n) - method = getattr(_jpype, n) - args = c[0] - expect = c[1] - if expect == None: - method(*args) - else: - self.assertRaises(expect, method, *args) - - -# This is a special test suite that checks to see that every entry point to the private -# module will safely fail rather than segfaulting. It can't be run with other tests -# as the jvm must not be loaded. -# -# To test use -# nosetests test.bulletproof diff --git a/examples/stubs/convtest.py b/examples/stubs/convtest.py deleted file mode 100644 index 87c28a1b0..000000000 --- a/examples/stubs/convtest.py +++ /dev/null @@ -1,125 +0,0 @@ -# ***************************************************************************** -# Copyright 2004-2008 Steve Menard -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# ***************************************************************************** - -import jpype -import array -import time -import os - - -def generateStringData(aSize): - return ''.join(['a'] * aSize) - - -DATA_SIZE = 5 * 1024 * 1024 # 5 MB - - -def runBaseline(data): - print 'Running baseline test : converting a python string->array.array->JArray(JByte). size = ', len(data) / 1024.0, 'kb' - print ' Start time (no optimize) on my machine is 3.56 seconds.' - start = time.time() - - #darr = array.array('b', DATA) - arr_cls = jpype.JArray(jpype.JByte) - java_arr = arr_cls(DATA) - - end = time.time() - - print ' test run in', (end - start), 'seconds.' - - -def runStringToByteBuffer(data): - print 'Running String conversion to byte buffer. size = ', len(data) / 1024.0, 'kb' - start = time.time() - - bb = jpype.nio.convertToDirectBuffer(data) - - end = time.time() - - print ' test run in', (end - start), 'seconds.' - - jpype.JPackage("jpype").nio.NioReceive.receiveBuffer(bb) - - -def runStringToByteArray(data): - print 'Running String conversion to byte array. size = ', len(data) / 1024.0, 'kb' - start = time.time() - - arr_cls = jpype.JArray(jpype.JByte) - java_arr = arr_cls(data) - - end = time.time() - - print ' test run in', (end - start), 'seconds.' - - -root = os.path.abspath(os.path.dirname(__file__)) -jpype.startJVM(jpype.getDefaultJVMPath(), "-ea", "-Xmx5M", "-verbose:gc", "-Djava.class.path=./classes%s%s%sclasses" % (os.pathsep, root, os.sep)) - -DELETED = False - - -class MyStr(str): - def __del__(self): - global DELETED - print 'string got deleted' - DELETED = True - - -def testStringMemory(): - print 'with keeping the data' - data = MyStr('5' * 1024) - print data - buf = jpype.nio.convertToDirectBuffer(data) -# print buf.get() -# print buf.get() -# print buf.get() - - print 'now deleting the data' - del data -# print buf.get() -# print buf.get() -# print buf.get() -# print buf.get() - - print 'now deleting the buffer itself' - del buf - print 'now waiting for the string to get deleted' - while not DELETED: - time.sleep(1) - - print '.', - jpype.JPackage("jpype").nio.NioReceive.allocSomeMemory() - - -testStringMemory() - -# for i in range(1,5) : - -# DATA = generateStringData(DATA_SIZE*i) -# runBaseline(DATA) -# runStringToByteBuffer(DATA) -# runStringToByteArray(DATA) - -# expressly delete data to test the GC ... -#del DATA -# for i in range(3) : -# print 'GC', i -# jpype.JClass("java.lang.System").gc(); -# time.sleep(15) - -jpype.shutdownJVM() diff --git a/examples/stubs/findjvm.py b/examples/stubs/findjvm.py deleted file mode 100644 index 95fe73e0d..000000000 --- a/examples/stubs/findjvm.py +++ /dev/null @@ -1,21 +0,0 @@ -# ***************************************************************************** -# Copyright 2004-2008 Steve Menard -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# ***************************************************************************** -import jpype -import os.path - -jvmlib = jpype.getDefaultJVMPath() -print os.path.dirname(os.path.dirname(jvmlib)) diff --git a/examples/stubs/java_dom.py b/examples/stubs/java_dom.py deleted file mode 100644 index 7baa01fed..000000000 --- a/examples/stubs/java_dom.py +++ /dev/null @@ -1,58 +0,0 @@ -# ***************************************************************************** -# Copyright 2004-2008 Steve Menard -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# ***************************************************************************** -from os import path -import time -from jpype import * - -startJVM(getDefaultJVMPath(), "-ea") - -# XML test -Element = JPackage("org").w3c.dom.Element - - -def output(el, prefix=""): - if not isinstance(el, Element): - return - - # print prefix, "<", el.getTagName(), - - atts = el.getAttributes() - for i in range(atts.getLength()): - a = atts.item(i) - # print a.getNodeName(), '="%s"' % a.getNodeValue(), - # print '>' - - nl = el.getChildNodes() - for i in range(nl.getLength()): - output(nl.item(i), prefix + " ") - - # print prefix, "" - - -t = time.time() -count = 30 -for i in range(count): - build = javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder() - doc = build.parse(path.join(path.dirname(__file__), "sample", "big.xml")) - - el = doc.getDocumentElement() - output(el) - -t2 = time.time() -print(count, "iterations in", t2 - t, "seconds") - -shutdownJVM() diff --git a/examples/stubs/java_sax.py b/examples/stubs/java_sax.py deleted file mode 100644 index b0212f690..000000000 --- a/examples/stubs/java_sax.py +++ /dev/null @@ -1,76 +0,0 @@ -# ***************************************************************************** -# Copyright 2004-2008 Steve Menard -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# ***************************************************************************** -from os import path -import time -from jpype import * - -root = path.abspath(path.dirname(__file__)) -startJVM(getDefaultJVMPath(), "-ea", - "-Djava.class.path=%s" % path.join(root, "classes")) - -# XML test -Element = JPackage("org").w3c.dom.Element - - -class ContentHandler(object): - def characters(self, ch, start, length): - pass - - def endDocument(self): - pass - - def endElement(self, namespaceURI, localName, qName): - pass - - def endPrefixMapping(self, prefix): - pass - - def ignorableWhitespace(self, ch, start, length): - pass - - def processingInstruction(self, target, data): - pass - - def setDocumentLocator(self, locator): - pass - - def skippedEntity(self, name): - pass - - def startDocument(self, ): - pass - - def startElement(self, namespaceURI, localName, qName, atts): - pass - - def startPrefixMapping(self, prefix, uri): - pass - - -t = time.time() -count = 30 -for i in range(count): - DelegateHandler = JPackage("jpype.xml").DelegateHandler - dh = DelegateHandler(None, None, JProxy("org.xml.sax.ContentHandler", inst=ContentHandler()), None) - - build = javax.xml.parsers.SAXParserFactory.newInstance().newSAXParser() - build.parse(path.join(root, "sample", "big.xml"), dh) - -t2 = time.time() -print count, "iterations in", t2 - t, "seconds" - -shutdownJVM() diff --git a/examples/stubs/lists_and_maps.py b/examples/stubs/lists_and_maps.py deleted file mode 100644 index 8cff951fe..000000000 --- a/examples/stubs/lists_and_maps.py +++ /dev/null @@ -1,31 +0,0 @@ -from jpype import * -import time - - -startJVM(getDefaultJVMPath()) -# startJVM("c:/tools/jdk1.4.2/jre/bin/server/jvm.dll") - -arr = java.util.ArrayList() - -# no matching overloads found for this line: -arr.addAll([str(x) for x in xrange(50)]) - -print arr - -hmap = java.util.HashMap() - -# no matching overloads found for this line: -hmap.putAll({5: 6, 7: 8, 'hello': 'there'}) - -print hmap - -# for x in xrange(5): -# # this works: -# hmap.put(str(x), str(x)) -# # but this doesn't: -# hmap.put(str(x), x) -# -# -# this throws: AttributeError: 'java.util.HashMap' object has no attribute 'iterator' -# for x in hmap: -# print x, hmap[x] diff --git a/examples/stubs/python_dom.py b/examples/stubs/python_dom.py deleted file mode 100644 index 991055148..000000000 --- a/examples/stubs/python_dom.py +++ /dev/null @@ -1,50 +0,0 @@ -# ***************************************************************************** -# Copyright 2004-2008 Steve Menard -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# ***************************************************************************** -from os import path -import time -from xml.dom import minidom - - -def output(el, prefix=""): - if el.nodeType != el.ELEMENT_NODE: - return - - # print prefix, "<", el.tagName, - - atts = el.attributes - for i in range(atts.length): - a = atts.item(i) - # print a.nodeName, '="%s"' % a.nodeValue, - # print '>' - - nl = el.childNodes - for i in range(nl.length): - output(nl.item(i), prefix + " ") - - # print prefix, "" - - -t = time.time() -count = 30 -for i in range(count): - doc = minidom.parse(path.join(path.dirname(__file__), "sample", "big.xml")) - - el = doc.documentElement - output(el) - -t2 = time.time() -print count, "iterations in", t2 - t, "seconds" diff --git a/examples/stubs/test_awt.py b/examples/stubs/test_awt.py deleted file mode 100644 index d085dff8b..000000000 --- a/examples/stubs/test_awt.py +++ /dev/null @@ -1,17 +0,0 @@ -from jpype import * -import time - - -def run(): - print('Thread started') - try: - print(repr(java.awt.Frame)) - javax.swing.JFrame("Test Frame").setVisible(True) - shutdownGuiEnvironment() - except JException as ex: - print(ex) - - -startJVM(getDefaultJVMPath()) - -setupGuiEnvironment(run) diff --git a/examples/stubs/test_jarray_fixes.py b/examples/stubs/test_jarray_fixes.py deleted file mode 100644 index 0f8f409b8..000000000 --- a/examples/stubs/test_jarray_fixes.py +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env python -""" -Checks for memory leak in the JVM when pushing array data from Python to Java. -""" - -import pytest -import jpype - -#!!! These settings are finely tuned !!! -#!!! DO NOT fiddle with them unless you know what you are doing !!! - -# Size of array to be copied. -ARRAY_SIZE = 4000000 - -# Number of iterations to run. -# - raise this value to increase efficacy of the memory leak test. -ITERATIONS = 10 - -# Maximum size of JVM heap. -# - sets a cap to allow memory leak detection. -MAX_JVM_HEAP_SIZE_BYTES = 128647168 - - -def setup_module(module): - # Module-level setup. - if not jpype.isJVMStarted(): - jvm_args = [ - '-Xmx%dM' % (MAX_JVM_HEAP_SIZE_BYTES // 1000 ** 2), - ] - jpype.startJVM(jpype.getDefaultJVMPath(), *jvm_args) - module.JavaDoubleArray = jpype.JArray(jpype.JDouble, 1) - - -def test_memory_leak_fix(): - """ - This test raises java.lang.VirtualMachineErrorPyRaisable - (java.lang.OutOfMemoryError: Java heap space) if the memory leak - is present. - - """ - # Check memory settings. - rt = jpype.java.lang.Runtime.getRuntime() - assert rt.maxMemory() == MAX_JVM_HEAP_SIZE_BYTES - - # Perform leak test. - for i in xrange(ITERATIONS): - print('iteration:', i) - py_list1 = [float(f) for f in xrange(ARRAY_SIZE)] - j_array1 = JavaDoubleArray(py_list1) - py_list2 = j_array1[:] - assert py_list1 == py_list2 - - -def test_jarray_basic_slicing_fix(): - jl1 = JavaDoubleArray([1., 2., 3.]) - assert list(jl1) == [1., 2., 3.] - assert list(jl1[0:-1]) == [1., 2.] - assert list(jl1[0:1]) == [1.] - - -def test_jarray_slice_copy_fix(): - jl1 = JavaDoubleArray([1., 2., 3.]) - pl1 = jl1[:] - assert list(jl1) == pl1 - - -def test_jarray_slice_assignment_fix(): - jl2 = JavaDoubleArray([1., 2., 3.]) - jl2[:] = [4., 5., 6.] - assert list(jl2) == [4., 5., 6.] diff --git a/examples/stubs/testlucene.py b/examples/stubs/testlucene.py deleted file mode 100644 index 611b28796..000000000 --- a/examples/stubs/testlucene.py +++ /dev/null @@ -1,33 +0,0 @@ -from os import path -import shutil -import tempfile -from jpype import * - -lucene_jar = path.join("..", "build", "lucene-1.4.3.jar") -if not path.isfile(lucene_jar): - raise IOError, "Please provide %s" % path.abspath(lucene_jar) -startJVM(getDefaultJVMPath(), '-Djava.class.path=%s' % lucene_jar) - -QueryParser = JClass("org.apache.lucene.queryParser.QueryParser") -IndexSearcher = JClass("org.apache.lucene.search.IndexSearcher") -IndexReader = JClass("org.apache.lucene.index.IndexReader") -StandardAnalyzer = JClass("org.apache.lucene.analysis.standard.StandardAnalyzer") -FSDirectory = JClass("org.apache.lucene.store.FSDirectory") -IndexWriter = JClass("org.apache.lucene.index.IndexWriter") -SimpleAnalyzer = JClass("org.apache.lucene.analysis.SimpleAnalyzer") - -tmppath = tempfile.mkdtemp() -IndexWriter(tmppath, SimpleAnalyzer(), True).close() - -directory = FSDirectory.getDirectory(tmppath, False) -reader = IndexReader.open(directory) -searcher = IndexSearcher(reader) -queryparser = QueryParser.parse("wenger", "contents", StandardAnalyzer()) -print queryparser.rewrite -print queryparser.rewrite.matchReport(reader) -qp = queryparser.rewrite(reader) -print qp -print searcher.search.matchReport(qp) -hits = searcher.search(qp) - -shutil.rmtree(tmppath)