View Javadoc

1   package org.kit.furia.fragment;
2   
3   import java.io.File;
4   import java.util.List;
5   
6   
7   public abstract class AbstractFragmentExtractor implements FragmentExtractor {
8   
9       public AbstractFragmentExtractor() {
10          super();
11      }
12      
13      /**
14       * Receives a directory and returns all the class files found
15       * in it.
16       * @param directory
17       * @param result Returns all the files in the given folder
18       */
19      protected void getClassFiles(File directory, List<File> result) {
20          File[] files = directory.listFiles();
21          int i = 0;
22          while (i < files.length) {
23              if (files[i].isDirectory()) {
24                  getClassFiles(files[i], result);
25              } else if (files[i].getName().matches(".*[.]class$")) {
26                 result.add(files[i]);
27              }
28              i++;
29          }
30      }
31  
32      /**
33       * Iterates the given directory, and returns all the .class files found in
34       * it, if there are other directories. iterates through all of them
35       * @param x
36       *                the directory where we will take the classes from
37       * @param output
38       *                A list where all the file names will be stored.
39       * @param dir The parent class file.
40       *  
41       */
42      protected void getClassFiles(File x, List < String > output, String dir) {
43          File[] files = x.listFiles();
44          int i = 0;
45          while (i < files.length) {
46              if (files[i].isDirectory()) {
47                  getClassFiles(files[i], output, dir);
48              } else if (files[i].getName().matches(".*[.]class$")) {
49                  String p = files[i].getParent().replace(dir + File.separator,
50                          "").replaceAll(File.separator, ".");
51                  String c = p + "."
52                          + files[i].getName().replaceFirst("[.]class$", "");
53                  // logger.info("processing class:" + c);
54                  output.add(c);
55              }
56              i++;
57          }
58      }
59  
60  }