View Javadoc

1   package net.sourceforge.pmd;
2   
3   import java.io.File;
4   
5   /**
6    * Filtering of wanted source files.
7    *
8    * @author Pieter_Van_Raemdonck - Application Engineers NV/SA - www.ae.be
9    */
10  public class SourceFileSelector {
11  
12      private boolean selectJavaFiles = true;
13  
14      // TODO: is false the wanted default option?
15      private boolean selectJspFiles = false;
16  
17      /**
18       * Check if a file with given fileName should be checked by PMD.
19       *
20       * @param fileName String
21       * @return True if the file must be checked; false otherwise
22       */
23      public boolean isWantedFile(String fileName) {
24          int lastDotIndex = fileName.lastIndexOf('.');
25          if (lastDotIndex < 0) {
26              return false;
27          }
28  
29          String extensionUppercase = fileName.substring(1 + lastDotIndex)
30                  .toUpperCase();
31  
32          if (selectJavaFiles
33                  && extensionUppercase
34                  .equals(SourceFileConstants.JAVA_EXTENSION_UPPERCASE)) {
35              return true;
36          }
37  
38          if (selectJspFiles
39                  && (extensionUppercase
40                  .equals(SourceFileConstants.JSP_EXTENSION_UPPERCASE) || extensionUppercase
41                  .equals(SourceFileConstants.JSPX_EXTENSION_UPPERCASE))) {
42              return true;
43          }
44  
45          return false;
46      }
47  
48      /**
49       * Check if a given file should be checked by PMD.
50       *
51       * @param file The File
52       * @return True if the file must be checked; false otherwise
53       */
54      public boolean isWantedFile(File file) {
55          return isWantedFile(file.getAbsolutePath());
56      }
57  
58      /**
59       * @return Returns the selectJavaFiles.
60       */
61      public boolean isSelectJavaFiles() {
62          return selectJavaFiles;
63      }
64  
65      /**
66       * @param selectJavaFiles The selectJavaFiles to set.
67       */
68      public void setSelectJavaFiles(boolean selectJavaFiles) {
69          this.selectJavaFiles = selectJavaFiles;
70      }
71  
72      /**
73       * @return Returns the selectJspFiles.
74       */
75      public boolean isSelectJspFiles() {
76          return selectJspFiles;
77      }
78  
79      /**
80       * @param selectJspFiles The selectJspFiles to set.
81       */
82      public void setSelectJspFiles(boolean selectJspFiles) {
83          this.selectJspFiles = selectJspFiles;
84      }
85  }