summaryrefslogtreecommitdiff
authorJosh Kropf <josh@slashdev.ca>2010-02-01 04:23:19 (GMT)
committer Josh Kropf <josh@slashdev.ca>2010-02-01 04:23:19 (GMT)
commitc8d01bc1b0b2fe34cfd45a08d66c499222caf423 (patch) (side-by-side diff)
tree4082b6911755450485730187a44eb49226c8a2a7
parent6094d7e6bb100c7cd6d49713ed4043ce6df700ac (diff)
downloadjavapp-master.zip
javapp-master.tar.gz
javapp-master.tar.bz2
updated jython runtime to 2.5.1HEADmaster
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--build.xml33
-rw-r--r--deps/build.xml3
-rw-r--r--deps/jython_installer-2.2.1.jarbin4663097 -> 0 bytes
-rw-r--r--deps/jython_installer-2.5.1.jarbin0 -> 15338930 bytes
-rw-r--r--src/java/ca/slashdev/javapp/JavaPp.java44
-rw-r--r--src/python/javapp.py3
6 files changed, 55 insertions, 28 deletions
diff --git a/build.xml b/build.xml
index c8a8d76..807acb4 100644
--- a/build.xml
+++ b/build.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="javapp" default="build">
<property name="jython.jar" location="deps/jython/jython.jar" />
- <property name="version" value="0.4" />
+ <property name="version" value="0.5" />
<path id="build.classpath">
<pathelement location="${jython.jar}" />
@@ -12,31 +12,43 @@
<fileset file="javapp.jar" />
</path>
- <!--<filelist id="python_lib_files" dir="deps/jython/Lib">
- <file name="re.py"/>
+ <filelist id="python_lib_files" dir="deps/jython/Lib">
+ <file name="codecs.py"/>
<file name="copy.py"/>
<file name="copy_reg.py"/>
- <file name="sys.py"/>
+ <file name="encodings/__init__.py"/>
+ <file name="encodings/ascii.py"/>
+ <file name="encodings/utf_8.py"/>
+ <file name="re.py"/>
+ <file name="repr.py"/>
<file name="sre_compile.py"/>
<file name="sre_constants.py"/>
<file name="sre_parse.py"/>
<file name="StringIO.py"/>
<file name="string.py"/>
<file name="types.py"/>
- </filelist>-->
+ </filelist>
+
+ <fileset id="jython_files" dir="deps/jython.jar">
+ <include name="com/**" />
+ <include name="org/**" />
+ </fileset>
<target name="build">
<mkdir dir="build" />
<copy todir="build/Lib">
- <!--<filelist refid="python_lib_files" />-->
- <fileset dir="deps/jython/Lib" includes="*.py" />
+ <filelist refid="python_lib_files" />
+ <!--<fileset dir="deps/jython/Lib">
+ <include name="**/*.py" />
+ <exclude name="test/**" />
+ </fileset>-->
<fileset dir="deps/plex" includes="Plex/*.py" />
<fileset dir="src/python" includes="*.py" />
</copy>
<copy todir="build">
- <fileset dir="deps/jython.jar" />
+ <fileset refid="jython_files" />
</copy>
<javac srcdir="src/java" destdir="build" source="1.5" target="1.5"
@@ -49,13 +61,13 @@
</target>
<target name="clean">
- <delete dir="javapp.jar" />
+ <delete file="javapp.jar" />
<delete dir="build" />
<delete dir="test/output" />
</target>
<target name="install" depends="build">
- <copy file="javapp.jar" todir="${ant.library.dir}" />
+ <copy file="javapp.jar" todir="${user.home}/.ant/lib" />
</target>
<target name="package" depends="build">
@@ -74,6 +86,7 @@
<fileset dir="test/input" />
<property name="pee" value="poo" />
<property name="num" value="9999" />
+ <property name="copy" value="© 2010" />
</javapp>
</target>
diff --git a/deps/build.xml b/deps/build.xml
index 4715c41..78560d4 100644
--- a/deps/build.xml
+++ b/deps/build.xml
@@ -1,12 +1,13 @@
<project name="javapp dependencies" default="extract">
<target name="extract">
- <unzip dest="jython" src="jython_installer-2.2.1.jar" />
+ <unzip dest="jython" src="jython_installer-2.5.1.jar" />
<unjar dest="jython.jar" src="jython/jython.jar" />
<unzip dest="plex" src="plex-1.1.5.zip" />
</target>
<target name="clean">
<delete dir="jython" />
+ <delete dir="jython.jar" />
<delete dir="plex" />
</target>
</project>
diff --git a/deps/jython_installer-2.2.1.jar b/deps/jython_installer-2.2.1.jar
deleted file mode 100644
index 1bf3ed4..0000000
--- a/deps/jython_installer-2.2.1.jar
+++ b/dev/null
Binary files differ
diff --git a/deps/jython_installer-2.5.1.jar b/deps/jython_installer-2.5.1.jar
new file mode 100644
index 0000000..e6edf57
--- a/dev/null
+++ b/deps/jython_installer-2.5.1.jar
Binary files differ
diff --git a/src/java/ca/slashdev/javapp/JavaPp.java b/src/java/ca/slashdev/javapp/JavaPp.java
index e82aacc..9aecc69 100644
--- a/src/java/ca/slashdev/javapp/JavaPp.java
+++ b/src/java/ca/slashdev/javapp/JavaPp.java
@@ -23,6 +23,8 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.util.Hashtable;
import java.util.Properties;
@@ -31,21 +33,27 @@ import org.python.core.PyDictionary;
import org.python.core.PyException;
import org.python.core.PyFile;
import org.python.core.PyObject;
-import org.python.util.PythonInterpreter;
+import org.python.core.PySystemState;
+import org.python.core.io.StreamIO;
public class JavaPp {
- private PythonInterpreter py;
+ private PyObject func;
+ private PyDictionary env;
+ private PyObject prefix;
public JavaPp(String prefix, Hashtable<Object, Object> env) {
Properties props = new Properties();
props.setProperty("python.home", "javapp.jar");
props.setProperty("python.cachedir.skip", "true");
- PythonInterpreter.initialize(System.getProperties(), props, new String[] {""});
-
- py = new PythonInterpreter();
- py.exec("from javapp import process");
+ PySystemState.initialize(System.getProperties(), props);
+ PySystemState sys = new PySystemState();
+
+ PyObject importer = sys.getBuiltins().__getitem__(Py.newString("__import__"));
+ PyObject module = importer.__call__(Py.newString("javapp"));
+ func = module.__getattr__("process");
+
Hashtable<PyObject, PyObject> table = new Hashtable<PyObject, PyObject>();
PyObject pkey, pval;
String val;
@@ -57,36 +65,38 @@ public class JavaPp {
try {
// first attempt to parse number as integer
- pval = Py.java2py(Integer.parseInt(val));
+ pval = Py.newInteger(Integer.parseInt(val));
} catch (NumberFormatException ie) {
try {
// if not integer, try double
- pval = Py.java2py(Double.parseDouble(val));
+ pval = Py.newFloat(Double.parseDouble(val));
} catch (NumberFormatException de) {
- // if neither integer or double, let jython decide
- pval = Py.java2py(val);
+ // if neither integer or double, use string
+ pval = Py.newString(val);
}
}
table.put(pkey, pval);
}
- py.set("env", new PyDictionary(table));
- py.set("prefix", prefix);
+ this.env = new PyDictionary(table);
+ this.prefix = Py.newString(prefix);
}
public void process(File input, File output) throws IOException, JavaPpException {
- FileInputStream in = null;
- FileOutputStream out = null;
+ InputStream in = null;
+ OutputStream out = null;
try {
in = new FileInputStream(input);
out = new FileOutputStream(output);
- py.set("infile", new PyFile(in, input.getName()));
- py.set("outfile", new PyFile(out));
+ // Plex will fail if input file is not in universal newline mode
+ PyFile infile = new PyFile(new StreamIO(in, false), input.getName(), "rU", -1);
- py.exec("process(infile, outfile, infile.name, env, prefix)");
+ func.__call__(new PyObject[] {
+ infile, new PyFile(out), infile.name, env, prefix
+ });
} catch (PyException e) {
throw new JavaPpException(e);
} finally {
diff --git a/src/python/javapp.py b/src/python/javapp.py
index 799dfbf..45ce73b 100644
--- a/src/python/javapp.py
+++ b/src/python/javapp.py
@@ -182,7 +182,10 @@ def process(input, output, filename = "", env = {}, prefix = "#"):
if token is None:
break
+
output.write(token)
+
+ output.flush()
#if __name__ == '__main__':
# import sys