[pmd-devel] Extracting violation details from Listener
A source code analyzer
Brought to you by:
adangel,
juansotuyo
|
From: Caleb K. <cal...@en...> - 2017-07-12 19:43:54
|
Hello again,
Here is some code I have for extracting the details of the PMD reports.
RuleContext l_ctx = new RuleContext();
final AtomicInteger violations = new AtomicInteger(0);
l_ctx.getReport().addListener(new ThreadSafeReportListener() {
@Override
public void ruleViolationAdded(RuleViolation ruleViolation)
{
violations.incrementAndGet();
}
// here is where you can extract violation info
// to update bean
public void ruleViolationDetailExtractor(RuleViolation
ruleViolation) {
l_rule = ruleViolation.getRule().getName();
l_message = ruleViolation.getDescription();
l_beginLine = ruleViolation.getBeginLine();
l_endLine = ruleViolation.getEndLine();
}
@Override
public void metricAdded(Metric metric) {
}
});
Does anyone know how I use the listener or my ruleViolationDetailExtractor
method outside of this context such that I can populate a bean with the
specified details (l_rule, l_message, etc.)?
Should I return the variables? Put my bean updating in the listener (that
seems very wrong)?
Thank you.
--
Caleb Knox
Endeveran
|