From: <cg...@us...> - 2009-08-23 19:48:03
|
Revision: 6713 http://jython.svn.sourceforge.net/jython/?rev=6713&view=rev Author: cgroves Date: 2009-08-23 19:47:55 +0000 (Sun, 23 Aug 2009) Log Message: ----------- Roll back 6532-6534 and 6548 to keep __javaname__ and sys.javaproxy_dir from going out with 2.5.1. __javaname__ just went away in favor of a naming proxymaker on the customizable-proxymaker branch, and sys.javaproxy_dir doesn't make sense without named proxies. I'll need to re-commit 6533, 6534 and 6548 when I merge customizable-proxymaker to trunk. Modified Paths: -------------- trunk/jython/Lib/test/test_java_subclasses.py trunk/jython/NEWS trunk/jython/src/org/python/compiler/Module.java trunk/jython/src/org/python/core/MakeProxies.java trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/PyJavaType.java trunk/jython/src/org/python/core/PySystemState.java trunk/jython/src/org/python/core/PyType.java trunk/jython/src/org/python/core/util/StringUtil.java trunk/jython/src/org/python/expose/generate/ExposeTask.java trunk/jython/src/org/python/util/GlobMatchingTask.java trunk/jython/src/org/python/util/JycompileAntTask.java Removed Paths: ------------- trunk/jython/Lib/test/import_as_java_class.py trunk/jython/Lib/test/static_proxy.py trunk/jython/src/org/python/util/CompileProxiesTask.java trunk/jython/src/org/python/util/FileNameMatchingTask.java Deleted: trunk/jython/Lib/test/import_as_java_class.py =================================================================== --- trunk/jython/Lib/test/import_as_java_class.py 2009-08-23 19:05:32 UTC (rev 6712) +++ trunk/jython/Lib/test/import_as_java_class.py 2009-08-23 19:47:55 UTC (rev 6713) @@ -1,7 +0,0 @@ -# Part of test_java_subclasses.StaticProxyCompilationTest -from java.lang import Class - -# Grab the proxy class statically compiled by the containing test -cls = Class.forName("test.static_proxy.RunnableImpl") -# Instantiating the proxy class should import the module containing it and create the Python side -assert cls.newInstance().meth() == 78 Deleted: trunk/jython/Lib/test/static_proxy.py =================================================================== --- trunk/jython/Lib/test/static_proxy.py 2009-08-23 19:05:32 UTC (rev 6712) +++ trunk/jython/Lib/test/static_proxy.py 2009-08-23 19:47:55 UTC (rev 6713) @@ -1,11 +0,0 @@ -# Part of test_java_subclasses.StaticProxyCompilationTest. This needs to be its own module -# so the statically compiled proxy can import it. -from java.lang import Runnable - -class RunnableImpl(Runnable): - __javaname__ = "test.static_proxy.RunnableImpl" - def run(self): - pass - - def meth(self): - return 78 Modified: trunk/jython/Lib/test/test_java_subclasses.py =================================================================== --- trunk/jython/Lib/test/test_java_subclasses.py 2009-08-23 19:05:32 UTC (rev 6712) +++ trunk/jython/Lib/test/test_java_subclasses.py 2009-08-23 19:47:55 UTC (rev 6713) @@ -1,8 +1,6 @@ '''Tests subclassing Java classes in Python''' import os import sys -import tempfile -import subprocess import unittest from test import test_support @@ -323,56 +321,10 @@ self.assertEquals(len(called), 1) -class SettingJavaClassNameTest(unittest.TestCase): - def test_setting_name(self): - class Fixedname(Runnable): - __javaname__ = 'name.set.in.Python' - def run(self): - pass - self.assertEquals('name.set.in.Python', Fixedname().getClass().name) - try: - class NumberPackageName(Runnable): - __javaname__ = 'ok.7.ok' - def run(self): - pass - self.fail("Shouldn't be able to set a package name that starts with a digit") - except TypeError: - pass - try: - class LiteralPackageName(Runnable): - __javaname__ = 'ok.true.ok' - def run(self): - pass - self.fail("Shouldn't be able to use a Java literal as a package name") - except TypeError: - pass - -class StaticProxyCompilationTest(unittest.TestCase): - def setUp(self): - self.orig_proxy_dir = sys.javaproxy_dir - sys.javaproxy_dir = tempfile.mkdtemp() - - def tearDown(self): - sys.javaproxy_dir = self.orig_proxy_dir - - def test_proxies_without_classloader(self): - # importing with proxy_dir set compiles RunnableImpl there - import static_proxy - - # Use the existing environment with the proxy dir added on the classpath - env = dict(os.environ) - env["CLASSPATH"] = sys.javaproxy_dir - script = test_support.findfile("import_as_java_class.py") - self.assertEquals(subprocess.call([sys.executable, "-J-Dpython.cachedir.skip=true", - script], env=env), - 0) - def test_main(): test_support.run_unittest(InterfaceTest, TableModelTest, AutoSuperTest, PythonSubclassesTest, AbstractOnSyspathTest, - ContextClassloaderTest, - SettingJavaClassNameTest, - StaticProxyCompilationTest) + ContextClassloaderTest) Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2009-08-23 19:05:32 UTC (rev 6712) +++ trunk/jython/NEWS 2009-08-23 19:47:55 UTC (rev 6713) @@ -4,8 +4,6 @@ New Features - Upgraded to ANTLR 3.1.3 - [ 1859477 ] Dynamically loaded ServletFilters like PyServlet - - Setting __javaname__ in classes subclassing Java classes or implementing Java interfaces sets - the name of the produced proxy class. - Built in JSR 223 scripting engine, with LiveTribe JSR 223 implementation for JDK 5 - Jython "-J-classpath cp_args_here" now works as expected for unix shell. Bugs Fixed Modified: trunk/jython/src/org/python/compiler/Module.java =================================================================== --- trunk/jython/src/org/python/compiler/Module.java 2009-08-23 19:05:32 UTC (rev 6712) +++ trunk/jython/src/org/python/compiler/Module.java 2009-08-23 19:47:55 UTC (rev 6713) @@ -12,11 +12,6 @@ import org.objectweb.asm.Label; import org.objectweb.asm.Opcodes; -import org.objectweb.asm.Type; -import org.python.antlr.ParseException; -import org.python.antlr.PythonTree; -import org.python.antlr.ast.Suite; -import org.python.antlr.base.mod; import org.python.core.CodeBootstrap; import org.python.core.CodeFlag; import org.python.core.CodeLoader; @@ -24,7 +19,11 @@ import org.python.core.Py; import org.python.core.PyException; import org.python.core.PyRunnableBootstrap; -import org.python.core.util.StringUtil; +import org.objectweb.asm.Type; +import org.python.antlr.ParseException; +import org.python.antlr.PythonTree; +import org.python.antlr.ast.Suite; +import org.python.antlr.base.mod; class PyIntegerConstant extends Constant implements ClassConstants, Opcodes { @@ -366,7 +365,20 @@ } List<PyCodeConstant> codes; + private boolean isJavaIdentifier(String s) { + char[] chars = s.toCharArray(); + if (chars.length == 0) + return false; + if (!Character.isJavaIdentifierStart(chars[0])) + return false; + for(int i=1; i<chars.length; i++) { + if (!Character.isJavaIdentifierPart(chars[i])) + return false; + } + return true; + } + //XXX: this can probably go away now that we can probably just copy the list. private List<String> toNameAr(List<String> names,boolean nullok) { int sz = names.size(); @@ -411,7 +423,7 @@ code.id = codes.size(); //Better names in the future? - if (StringUtil.isJavaIdentifier(name)) + if (isJavaIdentifier(name)) code.fname = name+"$"+code.id; else code.fname = "f$"+code.id; @@ -537,7 +549,7 @@ c.invokestatic("org/python/core/Py", "runMain", "(" + bootstrap + $strArr + ")V"); c.return_(); } - + public void addBootstrap() throws IOException { Code c = classfile.addMethod(CodeLoader.GET_BOOTSTRAP_METHOD_NAME, "()" + Type.getDescriptor(CodeBootstrap.class), @@ -643,7 +655,7 @@ String name, String filename, boolean linenumbers, boolean printResults, CompilerFlags cflags) - throws Exception + throws Exception { compile(node, ostream, name, filename, linenumbers, printResults, cflags, org.python.core.imp.NO_MTIME); } Modified: trunk/jython/src/org/python/core/MakeProxies.java =================================================================== --- trunk/jython/src/org/python/core/MakeProxies.java 2009-08-23 19:05:32 UTC (rev 6712) +++ trunk/jython/src/org/python/core/MakeProxies.java 2009-08-23 19:47:55 UTC (rev 6713) @@ -8,7 +8,6 @@ import org.python.compiler.AdapterMaker; import org.python.compiler.JavaMaker; -import org.python.core.util.StringUtil; class MakeProxies { @@ -52,28 +51,13 @@ List<Class<?>> vinterfaces, String className, String proxyName, PyObject dict) { Class<?>[] interfaces = vinterfaces.toArray(new Class<?>[vinterfaces.size()]); - String fullProxyName; - PyObject customProxyName = dict.__finditem__("__javaname__"); - if (customProxyName != null) { - fullProxyName = Py.tojava(customProxyName, String.class); - if (!StringUtil.isJavaClassName(fullProxyName)) { - throw Py.TypeError(fullProxyName + " isn't a valid Java class name. Classes " + - "must be valid Java identifiers: " + - "http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#40625"); - } - Class<?> proxy = Py.findClass(fullProxyName); - if (proxy != null) { - return proxy; - } - } else { - fullProxyName = proxyPrefix + proxyName + "$" + proxyNumber++; - } + String fullProxyName = proxyPrefix + proxyName + "$" + proxyNumber++; String pythonModuleName; PyObject mn = dict.__finditem__("__module__"); if (mn == null) { pythonModuleName = "foo"; } else { - pythonModuleName = Py.tojava(mn, String.class); + pythonModuleName = (String) mn.__tojava__(String.class); } JavaMaker jm = new JavaMaker(superclass, interfaces, @@ -84,11 +68,7 @@ try { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); jm.build(bytes); - if (customProxyName != null) { - Py.saveClassFile(fullProxyName, bytes, Py.getSystemState().javaproxy_dir); - } else { - Py.saveClassFile(fullProxyName, bytes); - } + Py.saveClassFile(fullProxyName, bytes); return makeClass(superclass, vinterfaces, jm.myClass, bytes); } catch (Exception exc) { Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2009-08-23 19:05:32 UTC (rev 6712) +++ trunk/jython/src/org/python/core/Py.java 2009-08-23 19:47:55 UTC (rev 6713) @@ -839,9 +839,8 @@ public static void initProxy(PyProxy proxy, String module, String pyclass, Object[] args) { - if (proxy._getPyInstance() != null) { + if (proxy._getPyInstance() != null) return; - } ThreadState ts = getThreadState(); PyObject instance = ts.getInitializingProxy(); if (instance != null) { @@ -1781,17 +1780,12 @@ } public static void saveClassFile(String name, ByteArrayOutputStream bytestream) { - saveClassFile(name, bytestream, Options.proxyDebugDirectory); - } - - public static void saveClassFile(String name, ByteArrayOutputStream baos, String dirname) { + String dirname = Options.proxyDebugDirectory; if (dirname == null) { return; } - saveClassFile(name, baos.toByteArray(), dirname); - } - public static void saveClassFile(String name, byte[] bytes, String dirname) { + byte[] bytes = bytestream.toByteArray(); File dir = new File(dirname); File file = makeFilename(name, dir); new File(file.getParent()).mkdirs(); Modified: trunk/jython/src/org/python/core/PyJavaType.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaType.java 2009-08-23 19:05:32 UTC (rev 6712) +++ trunk/jython/src/org/python/core/PyJavaType.java 2009-08-23 19:47:55 UTC (rev 6713) @@ -186,7 +186,7 @@ underlying_class = forClass; computeLinearMro(baseClass); } else { - needsInners.add(this); + needsInners.add(this); javaProxy = forClass; objtype = PyType.fromClassSkippingInners(Class.class, needsInners); // Wrapped Java types fill in their mro first using all of their interfaces then their Modified: trunk/jython/src/org/python/core/PySystemState.java =================================================================== --- trunk/jython/src/org/python/core/PySystemState.java 2009-08-23 19:05:32 UTC (rev 6712) +++ trunk/jython/src/org/python/core/PySystemState.java 2009-08-23 19:47:55 UTC (rev 6713) @@ -40,7 +40,6 @@ public static final String PYTHON_CACHEDIR_SKIP = "python.cachedir.skip"; public static final String PYTHON_CONSOLE_ENCODING = "python.console.encoding"; protected static final String CACHEDIR_DEFAULT_NAME = "cachedir"; - public static final String PYTHON_JAVAPROXYDIR = "python.javaproxydir"; public static final String JYTHON_JAR = "jython.jar"; public static final String JYTHON_DEV_JAR = "jython-dev.jar"; @@ -139,13 +138,6 @@ public PyObject last_type = Py.None; public PyObject last_traceback = Py.None; - private static String defaultJavaProxyDir; - - /** - * The directory where named Java proxies are written. - */ - public String javaproxy_dir; - public PyObject __name__ = new PyString("sys"); public PyObject __dict__; @@ -197,8 +189,6 @@ __dict__.invoke("update", getType().fastGetDict()); __dict__.__setitem__("displayhook", __displayhook__); __dict__.__setitem__("excepthook", __excepthook__); - - javaproxy_dir = defaultJavaProxyDir; } void reload() throws PyIgnoreMethodTag { @@ -867,8 +857,6 @@ // other initializations initBuiltins(registry); initStaticFields(); - defaultJavaProxyDir = registry.getProperty(PYTHON_JAVAPROXYDIR); - // Initialize the path (and add system defaults) defaultPath = initPath(registry, standalone, jarFileName); defaultArgv = initArgv(argv); Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2009-08-23 19:05:32 UTC (rev 6712) +++ trunk/jython/src/org/python/core/PyType.java 2009-08-23 19:47:55 UTC (rev 6713) @@ -579,9 +579,11 @@ if (module != null) { proxyName = module.toString() + "$" + proxyName; } - javaProxy = MakeProxies.makeProxy(baseProxyClass, interfaces, name, proxyName, dict); + Class<?> proxyClass = MakeProxies.makeProxy(baseProxyClass, interfaces, name, proxyName, + dict); + javaProxy = proxyClass; - PyType proxyType = PyType.fromClass((Class<?>)javaProxy); + PyType proxyType = PyType.fromClass(proxyClass); List<PyObject> cleanedBases = Generic.list(); boolean addedProxyType = false; for (PyObject base : bases) { Modified: trunk/jython/src/org/python/core/util/StringUtil.java =================================================================== --- trunk/jython/src/org/python/core/util/StringUtil.java 2009-08-23 19:05:32 UTC (rev 6712) +++ trunk/jython/src/org/python/core/util/StringUtil.java 2009-08-23 19:47:55 UTC (rev 6713) @@ -3,10 +3,8 @@ import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; -import java.util.Set; import org.python.core.Py; -import org.python.util.Generic; /** * String Utility methods. @@ -86,47 +84,4 @@ chars[0] = Character.toLowerCase(c0); return new String(chars); } - - /** - * Returns true if each segment of <code>name</code> produced by splitting it on '.' is a valid - * Java identifier. - */ - public static boolean isJavaClassName(String name) { - for (String segment : name.split("\\.")) { - if (!isJavaIdentifier(segment)) { - return false; - } - } - return true; - } - - /** - * Returns true if ident is a valid Java identifier as defined by - * http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#40625 - */ - public static boolean isJavaIdentifier(String ident) { - if (ident.length() == 0 || JAVA_LITERALS.contains(ident)) { - return false; - } - int cp = ident.codePointAt(0); - if (!Character.isJavaIdentifierStart(cp)) { - return false; - } - for (int i = Character.charCount(cp); i < ident.length(); i += Character.charCount(cp)) { - cp = ident.codePointAt(i); - if (!Character.isJavaIdentifierPart(cp)) { - return false; - } - } - return true; - } - - // True false and null are just literals, the rest are keywords - private static final Set<String> JAVA_LITERALS = Generic.set("abstract", "continue", "for", - "new", "switch", "assert", "default", "goto", "package", "synchronized", "boolean", "do", - "if", "private", "this", "break", "double", "implements", "protected", "throw", "byte", - "else", "import", "public", "throws", "case", "enum", "instanceof", "return", "transient", - "catch", "extends", "int", "short", "try", "char", "final", "interface", "static", "void", - "class", "finally", "long", "strictfp", "volatile", "const", "float", "native", "super", - "while", "true", "false", "null"); } Modified: trunk/jython/src/org/python/expose/generate/ExposeTask.java =================================================================== --- trunk/jython/src/org/python/expose/generate/ExposeTask.java 2009-08-23 19:05:32 UTC (rev 6712) +++ trunk/jython/src/org/python/expose/generate/ExposeTask.java 2009-08-23 19:47:55 UTC (rev 6713) @@ -8,8 +8,8 @@ import org.apache.tools.ant.BuildException; import org.objectweb.asm.ClassWriter; +import org.python.core.Py; import org.python.core.Options; -import org.python.core.Py; import org.python.util.GlobMatchingTask; public class ExposeTask extends GlobMatchingTask { Deleted: trunk/jython/src/org/python/util/CompileProxiesTask.java =================================================================== --- trunk/jython/src/org/python/util/CompileProxiesTask.java 2009-08-23 19:05:32 UTC (rev 6712) +++ trunk/jython/src/org/python/util/CompileProxiesTask.java 2009-08-23 19:47:55 UTC (rev 6713) @@ -1,68 +0,0 @@ -package org.python.util; - -import java.io.File; -import java.util.List; -import java.util.Properties; -import java.util.Set; - -import org.apache.tools.ant.BuildException; -import org.python.core.Py; -import org.python.core.PySystemState; - -/** - * Compiles the Java proxies for Python classes in the Python modules in a given directory tree to - * another directory. - */ -public class CompileProxiesTask extends JycompileAntTask { - - @Override - public void process(Set<File> toCompile) throws BuildException { - // Run our superclass' compile first to check that everything has valid syntax before - // attempting to import it and to keep the imports from generating class files in the source - // directory - super.process(toCompile); - Properties props = new Properties(); - props.setProperty(PySystemState.PYTHON_CACHEDIR_SKIP, "true"); - PySystemState.initialize(props, null); - PySystemState sys = Py.getSystemState(); - // Part 2 of not spewing compilation in the source directory: import our compiled files - sys.path.insert(0, Py.newString(destDir.getAbsolutePath())); - sys.javaproxy_dir = destDir.getAbsolutePath(); - PythonInterpreter interp = new PythonInterpreter(); - for (String module : compiledModuleNames) { - try { - interp.exec("import " + module); - } catch (RuntimeException t) { - // We didn't get to import any of these files, so their compiled form can't hang - // around or we won't pick them up as needing compilation next time. - for (File f : compiledModuleFiles) { - f.delete(); - } - throw t; - } - // This module was successfully imported, so its compiled file can hang around - compiledModuleFiles.remove(0); - } - } - - @Override - protected void compile(File src, File compiled, String moduleName) { - try { - super.compile(src, compiled, moduleName); - } catch (BuildException ex) { - // This depends on the modtime of the source being newer than that of the compiled file - // to decide to do the import in process, so even though these files compiled properly, - // they need to be deleted to allow them to be imported in process next time around. - for (File f : compiledModuleFiles) { - f.delete(); - } - throw ex; - } - compiledModuleNames.add(moduleName); - compiledModuleFiles.add(compiled); - } - - private List<String> compiledModuleNames = Generic.list(); - - private List<File> compiledModuleFiles = Generic.list(); -} Deleted: trunk/jython/src/org/python/util/FileNameMatchingTask.java =================================================================== --- trunk/jython/src/org/python/util/FileNameMatchingTask.java 2009-08-23 19:05:32 UTC (rev 6712) +++ trunk/jython/src/org/python/util/FileNameMatchingTask.java 2009-08-23 19:47:55 UTC (rev 6713) @@ -1,95 +0,0 @@ -package org.python.util; - -import java.io.File; -import java.util.Set; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.taskdefs.MatchingTask; -import org.apache.tools.ant.types.Path; -import org.apache.tools.ant.util.FileNameMapper; -import org.apache.tools.ant.util.SourceFileScanner; - -public abstract class FileNameMatchingTask extends MatchingTask { - - private Path src; - - protected File destDir; - - private Set<File> toProcess = Generic.set(); - - /** - * Set the source directories to find the class files to be exposed. - */ - public void setSrcdir(Path srcDir) { - if (src == null) { - src = srcDir; - } else { - src.append(srcDir); - } - } - - /** - * Gets the source dirs to find the class files to be exposed. - */ - public Path getSrcdir() { - return src; - } - - /** - * Set the destination directory into which the Java source files should be compiled. - * - * @param destDir - * the destination director - */ - public void setDestdir(File destDir) { - this.destDir = destDir; - } - - /** - * Gets the destination directory into which the java source files should be compiled. - * - * @return the destination directory - */ - public File getDestdir() { - return destDir; - } - - @Override - public void execute() throws BuildException { - checkParameters(); - toProcess.clear(); - for (String srcEntry : src.list()) { - File srcDir = getProject().resolveFile(srcEntry); - if (!srcDir.exists()) { - throw new BuildException("srcdir '" + srcDir.getPath() + "' does not exist!", - getLocation()); - } - String[] files = getDirectoryScanner(srcDir).getIncludedFiles(); - scanDir(srcDir, destDir != null ? destDir : srcDir, files); - } - process(toProcess); - } - - protected abstract void process(Set<File> matches); - - protected abstract FileNameMapper createMapper(); - - protected void scanDir(File srcDir, File destDir, String[] files) { - SourceFileScanner sfs = new SourceFileScanner(this); - for (File file : sfs.restrictAsFiles(files, srcDir, destDir, createMapper())) { - toProcess.add(file); - } - } - /** - * Check that all required attributes have been set and nothing silly has been entered. - */ - protected void checkParameters() throws BuildException { - if (src == null || src.size() == 0) { - throw new BuildException("srcdir attribute must be set!", getLocation()); - } - if (destDir != null && !destDir.isDirectory()) { - throw new BuildException("destination directory '" + destDir + "' does not exist " - + "or is not a directory", getLocation()); - } - } -} \ No newline at end of file Modified: trunk/jython/src/org/python/util/GlobMatchingTask.java =================================================================== --- trunk/jython/src/org/python/util/GlobMatchingTask.java 2009-08-23 19:05:32 UTC (rev 6712) +++ trunk/jython/src/org/python/util/GlobMatchingTask.java 2009-08-23 19:47:55 UTC (rev 6713) @@ -1,19 +1,101 @@ package org.python.util; -import org.apache.tools.ant.util.FileNameMapper; +import java.io.File; +import java.util.Set; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.taskdefs.MatchingTask; +import org.apache.tools.ant.types.Path; import org.apache.tools.ant.util.GlobPatternMapper; +import org.apache.tools.ant.util.SourceFileScanner; -public abstract class GlobMatchingTask extends FileNameMatchingTask { +public abstract class GlobMatchingTask extends MatchingTask { + private Path src; + + protected File destDir; + + private Set<File> toExpose = Generic.set(); + + /** + * Set the source directories to find the class files to be exposed. + */ + public void setSrcdir(Path srcDir) { + if (src == null) { + src = srcDir; + } else { + src.append(srcDir); + } + } + + /** + * Gets the source dirs to find the class files to be exposed. + */ + public Path getSrcdir() { + return src; + } + + /** + * Set the destination directory into which the Java source files should be compiled. + * + * @param destDir + * the destination director + */ + public void setDestdir(File destDir) { + this.destDir = destDir; + } + + /** + * Gets the destination directory into which the java source files should be compiled. + * + * @return the destination directory + */ + public File getDestdir() { + return destDir; + } + @Override - protected FileNameMapper createMapper() { - FileNameMapper mapper = new GlobPatternMapper(); - mapper.setFrom(getFrom()); - mapper.setTo(getTo()); - return mapper; + public void execute() throws BuildException { + checkParameters(); + toExpose.clear(); + for (String srcEntry : src.list()) { + File srcDir = getProject().resolveFile(srcEntry); + if (!srcDir.exists()) { + throw new BuildException("srcdir '" + srcDir.getPath() + "' does not exist!", + getLocation()); + } + String[] files = getDirectoryScanner(srcDir).getIncludedFiles(); + scanDir(srcDir, destDir != null ? destDir : srcDir, files); + } + process(toExpose); } + protected abstract void process(Set<File> matches); + protected abstract String getFrom(); protected abstract String getTo(); -} + + protected void scanDir(File srcDir, File destDir, String[] files) { + GlobPatternMapper m = new GlobPatternMapper(); + m.setFrom(getFrom()); + m.setTo(getTo()); + SourceFileScanner sfs = new SourceFileScanner(this); + for (File file : sfs.restrictAsFiles(files, srcDir, destDir, m)) { + toExpose.add(file); + } + } + + /** + * Check that all required attributes have been set and nothing silly has been entered. + */ + protected void checkParameters() throws BuildException { + if (src == null || src.size() == 0) { + throw new BuildException("srcdir attribute must be set!", getLocation()); + } + if (destDir != null && !destDir.isDirectory()) { + throw new BuildException("destination directory '" + destDir + "' does not exist " + + "or is not a directory", getLocation()); + } + } +} \ No newline at end of file Modified: trunk/jython/src/org/python/util/JycompileAntTask.java =================================================================== --- trunk/jython/src/org/python/util/JycompileAntTask.java 2009-08-23 19:05:32 UTC (rev 6712) +++ trunk/jython/src/org/python/util/JycompileAntTask.java 2009-08-23 19:47:55 UTC (rev 6713) @@ -59,12 +59,10 @@ imp.cacheCompiledSource(src.getAbsolutePath(), compiled.getAbsolutePath(), bytes); } - @Override protected String getFrom() { return "*.py"; } - @Override protected String getTo() { return "*$py.class"; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |