KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > workflow > RecursiveSearchForJavaFiles


1 /*
2  * FindBugs - Find Bugs in Java programs
3  * Copyright (C) 2006, University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package edu.umd.cs.findbugs.workflow;
21
22 import java.io.File JavaDoc;
23 import java.util.*;
24
25 public class RecursiveSearchForJavaFiles {
26
27     public static void main(String JavaDoc args[]) {
28         for(File JavaDoc f : search(new File JavaDoc(args[0])))
29             System.out.println(f.getPath());
30     }
31     public static Set<File JavaDoc> search(File JavaDoc root) {
32         Set<File JavaDoc> result = new HashSet<File JavaDoc>();
33         Set<File JavaDoc> directories = new HashSet<File JavaDoc>();
34         LinkedList<File JavaDoc> worklist = new LinkedList<File JavaDoc>();
35         directories.add(root);
36         worklist.add(root);
37         while (!worklist.isEmpty()) {
38             File JavaDoc next = worklist.removeFirst();
39             File JavaDoc[] files = next.listFiles();
40             if (files != null) for (File JavaDoc f : files) {
41                 if (f.getName().endsWith(".java"))
42                     result.add(f);
43                 else if (f.isDirectory() && directories.add(f)) {
44                     worklist.add(f);
45                 }
46
47             }
48
49         }
50         return result;
51
52     }
53
54 }
55
Popular Tags