1 package com.explosion.expfmodules.search;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.util.Vector;
6
7 import org.apache.log4j.LogManager;
8 import org.apache.log4j.Logger;
9
10 import com.explosion.utilities.FileIterator;
11 import com.explosion.utilities.process.StackableSimpleProcess;
12 import com.explosion.utilities.process.threads.Finishable;
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 /***
35 * @author Stephen
36 * Created on May 7, 2004
37 */
38 public class ClassSearchProcess extends StackableSimpleProcess
39 {
40 private static Logger log = LogManager.getLogger(ClassSearchProcess.class);
41 FileIterator iterator;
42 ClassSearcher searcher = null;
43 Vector results = new Vector();
44
45 /***
46 *
47 * @param finishable
48 * @param className
49 * @param caseSensitive
50 * @param directoryPath
51 * @param filenamePattern
52 * @param recursive
53 * @throws IOException
54 */
55 public ClassSearchProcess(Finishable finishable, String className, boolean caseSensitive, String directoryPath, String filenamePattern, boolean includeClassesOfSameType , boolean recursive) throws IOException
56 {
57 super(finishable, null);
58 searcher = new ClassSearcher(className, caseSensitive, includeClassesOfSameType);
59 iterator = new FileIterator(directoryPath, filenamePattern, false, recursive, true);
60 this.setIsUserProcess(true);
61 }
62
63 /***
64 * Processes a file
65 */
66 public void process() throws Exception
67 {
68 try
69 {
70 int count=1;
71 this.setStatusText("Starting search");
72 while ( iterator.hasNext())
73 {
74 if (isStopped()) return;
75 File file = iterator.next();
76 this.setStatusText("Searching file " + file.getAbsolutePath());
77 searcher.processFile(count, file.getAbsolutePath());
78 if (searcher.found())
79 {
80 results.add(searcher.getResults());
81 }
82 this.setPercentComplete(iterator.getPercentComplete());
83 count++;
84 }
85 this.setPercentComplete(100);
86 this.setStatusText("Finished, found " + count + " matches.");
87 }
88 finally
89 {
90 this.setPercentComplete(100);
91 }
92
93
94
95 }
96
97 /***
98 * @return
99 */
100 public Vector getFileSearchResults()
101 {
102 return results;
103 }
104
105 }