コード例 #1
0
ファイル: SourceValidator.java プロジェクト: kitsook/qulice
 /**
  * Performs validation of the input source files.
  *
  * @param sources Input source files.
  * @param path Base path.
  */
 @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
 public void validate(final Collection<DataSource> sources, final String path) {
   this.config.setRuleSets("com/qulice/pmd/ruleset.xml");
   final Report report = new Report();
   report.addListener(this.listener);
   this.context.setReport(report);
   for (final DataSource source : sources) {
     final String name = source.getNiceFileName(false, path);
     this.context.setSourceCodeFilename(name);
     this.context.setSourceCodeFile(new File(name));
     this.validateOne(source);
   }
 }
コード例 #2
0
  /**
   * @param parser Parser
   * @param dataSources List<DataSource>
   * @param debug boolean
   * @throws IOException
   */
  private static void parseStress(Parser parser, List<DataSource> dataSources, boolean debug)
      throws IOException {

    long start = System.currentTimeMillis();

    for (DataSource dataSource : dataSources) {
      parser.parse(
          dataSource.getNiceFileName(false, null),
          new InputStreamReader(dataSource.getInputStream()));
    }

    if (debug) {
      long end = System.currentTimeMillis();
      long elapsed = end - start;
      System.out.println("That took " + elapsed + " ms");
    }
  }
コード例 #3
0
  /**
   * @param languageVersion LanguageVersion
   * @param ruleSet RuleSet
   * @param dataSources List<DataSource>
   * @param results Set<RuleDuration>
   * @param debug boolean
   * @throws PMDException
   * @throws IOException
   */
  private static void stress(
      LanguageVersion languageVersion,
      RuleSet ruleSet,
      List<DataSource> dataSources,
      Set<RuleDuration> results,
      boolean debug)
      throws PMDException, IOException {

    for (Rule rule : ruleSet.getRules()) {
      if (debug) {
        System.out.println("Starting " + rule.getName());
      }

      RuleSet working = new RuleSet();
      working.addRule(rule);
      RuleSets ruleSets = new RuleSets(working);

      PMDConfiguration config = new PMDConfiguration();
      config.setDefaultLanguageVersion(languageVersion);

      RuleContext ctx = new RuleContext();
      long start = System.currentTimeMillis();
      Reader reader = null;
      for (DataSource dataSource : dataSources) {
        reader = new InputStreamReader(dataSource.getInputStream());
        ctx.setSourceCodeFilename(dataSource.getNiceFileName(false, null));
        new SourceCodeProcessor(config).processSourceCode(reader, ruleSets, ctx);
        IOUtil.closeQuietly(reader);
      }
      long end = System.currentTimeMillis();
      long elapsed = end - start;
      results.add(new RuleDuration(elapsed, rule));
      if (debug) {
        System.out.println("Done timing " + rule.getName() + "; elapsed time was " + elapsed);
      }
    }
  }