/**
   * Search a rule in a set of rules
   *
   * @param rule
   * @param set
   * @return
   */
  private static boolean searchRule(
      final Rule rule, final Collection<Rule> set, final PrintStream out) {
    boolean found = false;

    for (final Iterator<Rule> i = set.iterator(); i.hasNext() && !found; ) {
      final Rule r = i.next();
      if (r.getClass().getName().equals(rule.getClass().getName())) {
        found =
            r.getName().equals(rule.getName())
                && propertiesMatchFor(r, rule)
                && r.getPriority() == rule.getPriority();
        if (!found && r.getName().equals(rule.getName())) {
          out.println("Rules " + r.getName() + " are different because:");
          out.println("Priorities are different: " + (r.getPriority() != rule.getPriority()));
          out.println("Properties are different: " + !propertiesMatchFor(r, rule));
          out.println();
          out.println("Rule to search");
          dumpRule(rule, out);
          out.println();
          out.println("Rule from set");
          dumpRule(r, out);
          out.println();
        }
      }
    }

    return found;
  }
Exemple #2
0
  private MarkerInfo2 getMarkerInfo(RuleViolation violation, String type)
      throws PropertiesException {

    Rule rule = violation.getRule();

    MarkerInfo2 info = new MarkerInfo2(type, 7);

    info.add(IMarker.MESSAGE, violation.getDescription());
    info.add(IMarker.LINE_NUMBER, violation.getBeginLine());
    info.add(PMDRuntimeConstants.KEY_MARKERATT_LINE2, violation.getEndLine());
    info.add(PMDRuntimeConstants.KEY_MARKERATT_RULENAME, rule.getName());
    info.add(PMDRuntimeConstants.KEY_MARKERATT_PRIORITY, rule.getPriority().getPriority());

    switch (rule.getPriority().getPriority()) {
      case 1:
        info.add(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
        info.add(
            IMarker.SEVERITY,
            projectProperties.violationsAsErrors()
                ? IMarker.SEVERITY_ERROR
                : IMarker.SEVERITY_WARNING);
        break;
      case 2:
        if (projectProperties.violationsAsErrors()) {
          info.add(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
        } else {
          info.add(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
          info.add(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
        }
        break;

      case 5:
        info.add(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
        break;

      case 3:
        info.add(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
      case 4:
      default:
        info.add(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
        break;
    }

    return info;
  }
 /**
  * Print rule details
  *
  * @param rule
  */
 private static void dumpRule(final Rule rule, final PrintStream out) {
   out.println("Rule: " + rule.getName());
   out.println("Priority: " + rule.getPriority());
   final Map<PropertyDescriptor<?>, Object> properties = rule.getPropertiesByPropertyDescriptor();
   final Set<Entry<PropertyDescriptor<?>, Object>> keys = properties.entrySet();
   for (final Entry<PropertyDescriptor<?>, Object> entry : keys) {
     out.println("   " + entry.getKey().name() + " = " + entry.getValue());
   }
 }