Re: [pmd-devel] Extracting violation details from Listener
A source code analyzer
Brought to you by:
adangel,
juansotuyo
|
From: Juan M. S. D. <jua...@gm...> - 2017-07-12 20:21:03
|
You should use directly the ruleViolationAdded method.
Keep in mind that method will be called once for each violation found on
any file. Your local variables l_rule, l_message, etc. will be rewritten,
and you will only keep the last one. I’d suggest you add the RuleViolations
to a list and process them after analysis.
Regards
On Wed, Jul 12, 2017 at 4:43 PM, Caleb Knox <cal...@en...>
wrote:
> 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
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Pmd-devel mailing list
> Pmd...@li...
> https://lists.sourceforge.net/lists/listinfo/pmd-devel
>
>
|