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:47:53
|
Yeap, you got it.
On Wed, Jul 12, 2017 at 5:27 PM, Caleb Knox <cal...@en...>
wrote:
> So, I should add my variables into the ruleViolationAdded method, and/or
> add the RuleViolation instances to a list? Right now, my variables are
> lists to which I add a value every time the method is called.
>
> public void ruleViolationAdded(RuleViolation ruleViolation) {
> violations.incrementAndGet();
> l_rule.add(ruleViolation.getRule().getName());
> l_message.add(ruleViolation.getDescription());
> l_beginLine.add(ruleViolation.getBeginLine());
> l_endLine.add(ruleViolation.getEndLine());
>
> //l_ruleset.add("Custom");
> //l_priority.add(3);
>
> //j++;
> }
>
> On Wed, Jul 12, 2017 at 3:20 PM, Juan Martín Sotuyo Dodero <
> jua...@gm...> wrote:
>
>> 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
>>>
>>>
>>
>
>
> --
> Caleb Knox
>
> Endeveran
>
|