Ejemplo n.º 1
0
 public static List<DataSource> getApplicableFiles(
     PMDConfiguration configuration, Set<Language> languages) {
   long startFiles = System.nanoTime();
   LanguageFilenameFilter fileSelector = new LanguageFilenameFilter(languages);
   List<DataSource> files = FileUtil.collectFiles(configuration.getInputPaths(), fileSelector);
   long endFiles = System.nanoTime();
   Benchmarker.mark(Benchmark.CollectFiles, endFiles - startFiles, 0);
   return files;
 }
  /**
   * @param args String[]
   * @throws RuleSetNotFoundException
   * @throws IOException
   * @throws PMDException
   */
  public static void main(String[] args)
      throws RuleSetNotFoundException, IOException, PMDException {

    String targetjdk = findOptionalStringValue(args, "--targetjdk", "1.4");
    Language language = Language.JAVA;
    LanguageVersion languageVersion = language.getVersion(targetjdk);
    if (languageVersion == null) {
      languageVersion = language.getDefaultVersion();
    }

    String srcDir =
        findOptionalStringValue(args, "--source-directory", "/usr/local/java/src/java/lang/");
    List<DataSource> dataSources =
        FileUtil.collectFiles(srcDir, new LanguageFilenameFilter(language));

    boolean debug = findBooleanSwitch(args, "--debug");
    boolean parseOnly = findBooleanSwitch(args, "--parse-only");

    if (debug) {
      System.out.println("Using " + language.getName() + " " + languageVersion.getVersion());
    }
    if (parseOnly) {
      Parser parser = PMD.parserFor(languageVersion, null);
      parseStress(parser, dataSources, debug);
    } else {
      String ruleset = findOptionalStringValue(args, "--ruleset", "");
      if (debug) {
        System.out.println("Checking directory " + srcDir);
      }
      Set<RuleDuration> results = new TreeSet<RuleDuration>();
      RuleSetFactory factory = new RuleSetFactory();
      if (StringUtil.isNotEmpty(ruleset)) {
        stress(languageVersion, factory.createRuleSet(ruleset), dataSources, results, debug);
      } else {
        Iterator<RuleSet> i = factory.getRegisteredRuleSets();
        while (i.hasNext()) {
          stress(languageVersion, i.next(), dataSources, results, debug);
        }
      }

      TextReport report = new TextReport();
      report.generate(results, System.err);
    }
  }