6 * A ClassPathEntry that represents a directory in which classes are
7 * stored. This is scanned recursively for classes at load time.
9 * Copyright (C) 2001, 2002, 2003 Eric D. Friedman (eric@hfriedman.rdsl.lmi.net)
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 * Created: Tue Aug 14 19:46:52 2001
27 * @author Eric D. Friedman
28 * @version $Id: ClassPathDir.java,v 1.4 2003/10/20 03:55:49 paulk Exp $
31 class ClassPathDir extends ClassPathEntry {
32 private File directory;
35 * Create an instance of ClassPathDir representing
36 * <code>directory</code>
38 * @param directory a <code>File</code> value
39 * @return a <code>ClassPathDir</code> value
41 ClassPathDir (File directory) {
43 this.directory = directory;
47 * Perform a recursive scan of the directory and set the loaded
52 addRecursively(directory,directory);
57 * Search for classes in <code>directory</code> rooted at
58 * <code>rootDir</code>
60 * @param directory a <code>File</code> value
61 * @param rootDir a <code>File</code> value
63 void addRecursively(File directory, File rootDir) {
64 String [] files = directory.list();
67 System.err.println("Cannot read contents of " + directory + ".");
72 String rootPath = rootDir.getPath();
73 String currentPath = directory.getPath();
74 String packageName = currentPath.substring(rootPath.length());
75 StringBuffer buf = new StringBuffer();
77 if (packageName.length() > 0) {
78 // Not the current directory
79 packageName = packageName.replace('\\', '.');
80 packageName = packageName.replace('/', '.');
81 packageName = packageName.substring(1);
84 for (int i = 0; i < files.length; i++) {
86 if (current.toLowerCase().endsWith(".class")) {
87 current = current.substring(0, current.length() - 6);
88 current = current.replace('$', '.'); // To handle inner-class .class files
89 if (currentPath.indexOf(rootPath) != 0) {
90 System.err.println("currentPath doesn't start with rootPath!\n"
91 + "rootPath: " + rootPath + "\n"
92 + "currentPath: " + currentPath + "\n");
93 } else if (packageName.length() > 0) {
94 // not the default package
95 buf.append(packageName);
98 addClass(buf.toString());
101 // The default package
105 // Check if it's a directory to recurse into
106 File currentFile = new File(directory, current);
107 if (currentFile.isDirectory()) {
108 addRecursively(currentFile,rootDir);
115 * return the directory as our string value.
117 * @return a <code>String</code> value
119 public String toString() {
120 return directory.toString();
125 * $Log: ClassPathDir.java,v $
126 * Revision 1.4 2003/10/20 03:55:49 paulk
127 * Fix to handle inner classes.
133 // End of ClassPathDir.java