Methods Summary |
---|
public void | addSubdirToIgnore(java.lang.String subdir)
subdirsToIgnore.add(subdir);
|
private void | buildNameToNodeListTable(makedep.DirectoryTree$Node curNode)
String fullName = curNode.getName();
String parent = curNode.getParent();
String separator = System.getProperty("file.separator");
if (parent != null) {
if (!fullName.startsWith(parent)) {
throw new RuntimeException(
"Internal error: parent of file name \"" + fullName +
"\" does not match file name \"" + parent + "\""
);
}
int len = parent.length();
if (!parent.endsWith(separator)) {
len += separator.length();
}
String fileName = fullName.substring(len);
if (fileName == null) {
throw new RuntimeException(
"Internal error: file name was empty"
);
}
List nodeList = (List) nameToNodeListTable.get(fileName);
if (nodeList == null) {
nodeList = new Vector();
nameToNodeListTable.put(fileName, nodeList);
}
nodeList.add(curNode);
} else {
if (curNode != rootNode) {
throw new RuntimeException(
"Internal error: parent of file + \"" + fullName + "\"" +
" was null"
);
}
}
if (curNode.isDirectory()) {
Iterator iter = curNode.getChildren();
if (iter != null) {
while (iter.hasNext()) {
buildNameToNodeListTable((Node) iter.next());
}
}
}
|
public java.util.List | findFile(java.lang.String name)Queries the DirectoryTree for a file or directory name. Takes
only the name of the file or directory itself (i.e., no parent
directory information should be in the passed name). Returns a
List of DirectoryTreeNodes specifying the full paths of all of
the files or directories of this name in the DirectoryTree.
Returns null if the directory tree has not been read from disk
yet or if the file was not found in the tree.
if (rootNode == null) {
return null;
}
if (nameToNodeListTable == null) {
nameToNodeListTable = new Hashtable();
try {
buildNameToNodeListTable(rootNode);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
return (List) nameToNodeListTable.get(name);
|
public boolean | getVerbose()
return verbose;
|
public void | readDirectory(java.lang.String baseDirectory)Takes an absolute path to the root directory of this
DirectoryTree. Throws IllegalArgumentException if the given
string represents a plain file or nonexistent directory.
File root = new File(baseDirectory);
if (!root.isDirectory()) {
throw new IllegalArgumentException("baseDirectory \"" +
baseDirectory +
"\" does not exist or " +
"is not a directory");
}
try {
root = root.getCanonicalFile();
}
catch (IOException e) {
throw new RuntimeException(e.toString());
}
rootNode = new Node(root);
readDirectory(rootNode, root);
|
private void | readDirectory(makedep.DirectoryTree$Node parentNode, java.io.File parentDir)Reads all of the files in the given directory and adds them as
children of the directory tree node. Requires that the passed
node represents a directory.
File[] children = parentDir.listFiles();
if (children == null)
return;
if (verbose) {
System.out.print(".");
System.out.flush();
}
for (int i = 0; i < children.length; i++) {
File child = children[i];
children[i] = null;
boolean isDir = child.isDirectory();
boolean mustSkip = false;
if (isDir) {
for (Iterator iter = subdirsToIgnore.iterator();
iter.hasNext(); ) {
if (child.getName().equals((String) iter.next())) {
mustSkip = true;
break;
}
}
}
if (!mustSkip) {
Node childNode = new Node(child);
parentNode.addChild(childNode);
if (isDir) {
readDirectory(childNode, child);
}
}
}
|
public void | setVerbose(boolean newValue)Output "."'s to System.out as directories are read. Defaults
to false.
verbose = newValue;
|