From: <cg...@us...> - 2009-01-21 20:47:33
|
Revision: 5953 http://jython.svn.sourceforge.net/jython/?rev=5953&view=rev Author: cgroves Date: 2009-01-21 20:47:19 +0000 (Wed, 21 Jan 2009) Log Message: ----------- Break out the compile method for use in subclasses Modified Paths: -------------- trunk/jython/src/org/python/util/JycompileAntTask.java Modified: trunk/jython/src/org/python/util/JycompileAntTask.java =================================================================== --- trunk/jython/src/org/python/util/JycompileAntTask.java 2009-01-21 05:02:29 UTC (rev 5952) +++ trunk/jython/src/org/python/util/JycompileAntTask.java 2009-01-21 20:47:19 UTC (rev 5953) @@ -10,6 +10,10 @@ import org.python.core.imp; import org.python.modules._py_compile; +/** + * Compiles all python files in a directory to bytecode, and writes them to another directory, + * possibly the same one. + */ public class JycompileAntTask extends GlobMatchingTask { @Override @@ -31,21 +35,30 @@ compiledFilePath += "/__init__"; } File compiled = new File(destDir, compiledFilePath + "$py.class"); - byte[] bytes; - try { - bytes = imp.compileSource(name, src); - } catch (PyException pye) { - pye.printStackTrace(); - throw new BuildException("Compile failed; see the compiler error output for details."); - } - File dir = compiled.getParentFile(); - if (!dir.exists() && !compiled.getParentFile().mkdirs()) { - throw new BuildException("Unable to make directory for compiled file: " + compiled); - } - imp.cacheCompiledSource(src.getAbsolutePath(), compiled.getAbsolutePath(), bytes); + compile(src, compiled, name); } } + /** + * Compiles the python file <code>src</code> to bytecode filling in <code>moduleName</code> as + * its name, and stores it in <code>compiled</code>. This is called by process for every file + * that's compiled, so subclasses can override this method to affect or track the compilation. + */ + protected void compile(File src, File compiled, String moduleName) { + byte[] bytes; + try { + bytes = imp.compileSource(moduleName, src); + } catch (PyException pye) { + pye.printStackTrace(); + throw new BuildException("Compile failed; see the compiler error output for details."); + } + File dir = compiled.getParentFile(); + if (!dir.exists() && !compiled.getParentFile().mkdirs()) { + throw new BuildException("Unable to make directory for compiled file: " + compiled); + } + imp.cacheCompiledSource(src.getAbsolutePath(), compiled.getAbsolutePath(), bytes); + } + protected String getFrom() { return "*.py"; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |