Ejemplo n.º 1
0
 /**
  * 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);
   }
 }
 public void testPluginname() throws Throwable {
   Rule rule = new XPathRule();
   rule.addProperty("xpath", "//VariableDeclaratorId[string-length(@Image) < 3]");
   rule.setMessage("{0}");
   rule.addProperty("pluginname", "true");
   PMD p = new PMD();
   RuleContext ctx = new RuleContext();
   Report report = new Report();
   ctx.setReport(report);
   ctx.setSourceCodeFilename("n/a");
   RuleSet rules = new RuleSet();
   rules.addRule(rule);
   p.processFile(new StringReader(TEST1), rules, ctx);
   RuleViolation rv = (RuleViolation) report.iterator().next();
   assertEquals("a", rv.getDescription());
 }
Ejemplo n.º 3
0
  public Map<Object, Collection<IRuleViolation>> getInstanceByPackage() {
    if (null == instanceByPackage) {
      instanceByPackage = new TreeMap<Object, Collection<IRuleViolation>>();

      Iterator<IRuleViolation> ruleViolationIterator = report.iterator();

      while (ruleViolationIterator.hasNext()) {
        IRuleViolation ruleViolation = ruleViolationIterator.next();
        PackageKey packageKey = new PackageKey(ruleViolation);
        Collection<IRuleViolation> ruleViolations = instanceByPackage.get(packageKey);

        if (null == ruleViolations) {
          ruleViolations = new ArrayList<IRuleViolation>();
          instanceByPackage.put(packageKey, ruleViolations);
        }

        ruleViolations.add(ruleViolation);
      }
    }

    return instanceByPackage;
  }
Ejemplo n.º 4
0
  public Map<Object, Collection<IRuleViolation>> getInstanceByClass() {
    if (null == instanceByClass) {
      instanceByClass = new TreeMap<Object, Collection<IRuleViolation>>();

      Iterator<IRuleViolation> ruleViolationIterator = report.iterator();

      while (ruleViolationIterator.hasNext()) {
        IRuleViolation ruleViolation = ruleViolationIterator.next();
        ClassKey classKey = new ClassKey(ruleViolation);
        Collection<IRuleViolation> ruleViolations = instanceByClass.get(classKey);

        if (null == ruleViolations) {
          ruleViolations = new ArrayList<IRuleViolation>();
          instanceByClass.put(classKey, ruleViolations);
        }

        ruleViolations.add(ruleViolation);
      }
    }

    return instanceByClass;
  }
Ejemplo n.º 5
0
  public Map<Object, Collection<IRuleViolation>> getInstanceByType() {
    if (null == instanceByType) {
      Map<Object, Collection<IRuleViolation>> tempInstanceByType =
          new TreeMap<Object, Collection<IRuleViolation>>();

      Iterator<IRuleViolation> ruleViolationIterator = report.iterator();

      while (ruleViolationIterator.hasNext()) {
        IRuleViolation ruleViolation = ruleViolationIterator.next();
        CategoryKey categoryKey = new CategoryKey(ruleViolation);
        Collection<IRuleViolation> ruleViolations = tempInstanceByType.get(categoryKey);

        if (null == ruleViolations) {
          ruleViolations = new ArrayList<IRuleViolation>();
          tempInstanceByType.put(categoryKey, ruleViolations);
        }

        ruleViolations.add(ruleViolation);
      }
      instanceByType = tempInstanceByType;
    }

    return instanceByType;
  }
Ejemplo n.º 6
0
 public long getBugCount() {
   return report.size();
 }