01: /*
02: * Copyright (c) 1998 - 2005 Versant Corporation
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Versant Corporation - initial API and implementation
10: */
11: package com.versant.core.jdo.tools.enhancer;
12:
13: import java.io.*;
14: import java.util.*;
15:
16: public class GrepFile {
17: private FileFilter fileFilter;
18:
19: private HashMap jdoFiles = new HashMap();
20:
21: public GrepFile(ArrayList dirs) throws IOException {
22: for (Iterator iterator = dirs.iterator(); iterator.hasNext();) {
23: File file = (File) iterator.next();
24: searchInDir(file.toString(), true);
25: }
26: }
27:
28: public Set getJdoFiles() {
29: return jdoFiles.keySet();
30: }
31:
32: private void searchInDir(String startDir, boolean recurse)
33: throws IOException {
34: fileFilter = new FileFilter() {
35: public boolean accept(File f) {
36: if (f.isDirectory()) {
37: return true;
38: } else if (f.getName().endsWith(".class")) {
39: return true;
40: } else {
41: return false;
42: }
43: }
44: };
45:
46: searchInDir_aux(new File(startDir), recurse);
47: }
48:
49: private void searchInDir_aux(File dir, boolean recurse)
50: throws IOException {
51: File[] contents = dir.listFiles(fileFilter);
52: for (int i = 0; i < contents.length; i++) {
53: File fileToCheck = contents[i];
54: if (fileToCheck.toString().endsWith(".class")) {
55: jdoFiles.put(fileToCheck.toString(), "");
56: } else if (recurse) {
57: searchInDir_aux(fileToCheck, recurse);
58: }
59: }
60: }
61: }
|