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; }
public static String markerTypeFor(RuleViolation violation) { int priorityId = violation.getRule().getPriority().getPriority(); switch (priorityId) { case 1: return PMDRuntimeConstants.PMD_MARKER_1; case 2: return PMDRuntimeConstants.PMD_MARKER_2; case 3: return PMDRuntimeConstants.PMD_MARKER_3; case 4: return PMDRuntimeConstants.PMD_MARKER_4; case 5: return PMDRuntimeConstants.PMD_MARKER_5; default: return PMDRuntimeConstants.PMD_MARKER; } }
/** Generates a html table with violation information. */ private String displayRuleViolation(RuleViolation vio) { StringBuilder sb = new StringBuilder(200); sb.append("<table border=\"0\">"); renderViolationRow(sb, "Rule:", vio.getRule().getName()); renderViolationRow(sb, "Description:", vio.getDescription()); if (StringUtil.isNotEmpty(vio.getVariableName())) { renderViolationRow(sb, "Variable:", vio.getVariableName()); } if (vio.getEndLine() > 0) { renderViolationRow(sb, "Line:", vio.getEndLine() + " and " + vio.getBeginLine()); } else { renderViolationRow(sb, "Line:", Integer.toString(vio.getBeginLine())); } sb.append("</table>"); return sb.toString(); }
private void updateMarkers(IFile file, RuleContext context, boolean fTask) throws CoreException, PropertiesException { Map<IFile, Set<MarkerInfo2>> accumulator = getAccumulator(); Set<MarkerInfo2> markerSet = new HashSet<MarkerInfo2>(); List<Review> reviewsList = findReviewedViolations(file); Review review = new Review(); Iterator<RuleViolation> iter = context.getReport().iterator(); // final IPreferences preferences = PMDPlugin.getDefault().loadPreferences(); // final int maxViolationsPerFilePerRule = preferences.getMaxViolationsPerFilePerRule(); Map<Rule, Integer> violationsByRule = new HashMap<Rule, Integer>(); Rule rule = null; while (iter.hasNext()) { RuleViolation violation = iter.next(); rule = violation.getRule(); review.ruleName = rule.getName(); review.lineNumber = violation.getBeginLine(); if (reviewsList.contains(review)) { log.debug( "Ignoring violation of rule " + rule.getName() + " at line " + violation.getBeginLine() + " because of a review."); continue; } Integer count = violationsByRule.get(rule); if (count == null) { count = NumericConstants.ZERO; violationsByRule.put(rule, count); } int maxViolations = maxAllowableViolationsFor(rule); if (count.intValue() < maxViolations) { // Ryan Gustafson 02/16/2008 - Always use PMD_MARKER, as people get confused as to why PMD // problems don't always show up on Problems view like they do when you do build. // markerSet.add(getMarkerInfo(violation, fTask ? PMDRuntimeConstants.PMD_TASKMARKER : // PMDRuntimeConstants.PMD_MARKER)); markerSet.add(getMarkerInfo(violation, markerTypeFor(violation))); /* if (isDfaEnabled && violation.getRule().usesDFA()) { markerSet.add(getMarkerInfo(violation, PMDRuntimeConstants.PMD_DFA_MARKER)); } else { markerSet.add(getMarkerInfo(violation, fTask ? PMDRuntimeConstants.PMD_TASKMARKER : PMDRuntimeConstants.PMD_MARKER)); } */ violationsByRule.put(rule, Integer.valueOf(count.intValue() + 1)); log.debug( "Adding a violation for rule " + rule.getName() + " at line " + violation.getBeginLine()); } else { log.debug( "Ignoring violation of rule " + rule.getName() + " at line " + violation.getBeginLine() + " because maximum violations has been reached for file " + file.getName()); } } if (accumulator != null) { log.debug("Adding markerSet to accumulator for file " + file.getName()); accumulator.put(file, markerSet); } }