diff options
author | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2007-11-02 17:15:01 +0000 |
---|---|---|
committer | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2007-11-02 17:15:01 +0000 |
commit | a9d3c7bd1da63565c9fd2937a9121bbe6a02c4bc (patch) | |
tree | 0c30b2309b1dad0a5145ab30fa2a09d86b281e41 | |
parent | 04bb09167da844dc49516342063a3e642afab7ab (diff) | |
download | javassist-a9d3c7bd1da63565c9fd2937a9121bbe6a02c4bc.tar.gz javassist-a9d3c7bd1da63565c9fd2937a9121bbe6a02c4bc.zip |
supported the class path wildcards.
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@413 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
-rw-r--r-- | src/main/javassist/ClassPool.java | 6 | ||||
-rw-r--r-- | src/main/javassist/ClassPoolTail.java | 60 |
2 files changed, 61 insertions, 5 deletions
diff --git a/src/main/javassist/ClassPool.java b/src/main/javassist/ClassPool.java index e7e209a9..3bab74ae 100644 --- a/src/main/javassist/ClassPool.java +++ b/src/main/javassist/ClassPool.java @@ -757,6 +757,9 @@ public class ClassPool { * * @param pathname the path name of the directory or jar file. * It must not end with a path separator ("/"). + * If the path name ends with "/*", then all the + * jar files matching the path name are inserted. + * * @return the inserted class path. * @throws NotFoundException if the jar file is not found. */ @@ -772,6 +775,9 @@ public class ClassPool { * * @param pathname the path name of the directory or jar file. * It must not end with a path separator ("/"). + * If the path name ends with "/*", then all the + * jar files matching the path name are appended. + * * @return the appended class path. * @throws NotFoundException if the jar file is not found. */ diff --git a/src/main/javassist/ClassPoolTail.java b/src/main/javassist/ClassPoolTail.java index fc21c0a3..8b6dfabc 100644 --- a/src/main/javassist/ClassPoolTail.java +++ b/src/main/javassist/ClassPoolTail.java @@ -72,6 +72,51 @@ final class DirClassPath implements ClassPath { } } +final class JarDirClassPath implements ClassPath { + JarClassPath[] jars; + + JarDirClassPath(String dirName) throws NotFoundException { + File[] files = new File(dirName).listFiles(new FilenameFilter() { + public boolean accept(File dir, String name) { + name = name.toLowerCase(); + return name.endsWith(".jar") || name.endsWith(".zip"); + } + }); + + jars = new JarClassPath[files.length]; + for (int i = 0; i < files.length; i++) + jars[i] = new JarClassPath(files[i].getPath()); + } + + public InputStream openClassfile(String classname) throws NotFoundException { + if (jars != null) + for (int i = 0; i < jars.length; i++) { + InputStream is = jars[i].openClassfile(classname); + if (is != null) + return is; + } + + return null; // not found + } + + public URL find(String classname) { + if (jars != null) + for (int i = 0; i < jars.length; i++) { + URL url = jars[i].find(classname); + if (url != null) + return url; + } + + return null; // not found + } + + public void close() { + if (jars != null) + for (int i = 0; i < jars.length; i++) + jars[i].close(); + } +} + final class JarClassPath implements ClassPath { JarFile jarfile; String jarfileURL; @@ -206,11 +251,16 @@ final class ClassPoolTail { private static ClassPath makePathObject(String pathname) throws NotFoundException { - int i = pathname.lastIndexOf('.'); - if (i >= 0) { - String ext = pathname.substring(i).toLowerCase(); - if (ext.equals(".jar") || ext.equals(".zip")) - return new JarClassPath(pathname); + String lower = pathname.toLowerCase(); + if (lower.endsWith(".jar") || lower.endsWith(".zip")) + return new JarClassPath(pathname); + + int len = pathname.length(); + if (len > 2 && pathname.charAt(len - 1) == '*' + && (pathname.charAt(len - 2) == '/' + || pathname.charAt(len - 2) == File.separatorChar)) { + String dir = pathname.substring(0, len - 2); + return new JarDirClassPath(dir); } return new DirClassPath(pathname); |