Extracting violation details from Listener

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Extracting violation details from Listener

Caleb Knox
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/pmd-devel
Reply | Threaded
Open this post in threaded view
|

Re: Extracting violation details from Listener

Juan Martín Sotuyo Dodero

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 <[hidden email]> 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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/pmd-devel



------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/pmd-devel
Reply | Threaded
Open this post in threaded view
|

Re: Extracting violation details from Listener

Caleb Knox
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 <[hidden email]> 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 <[hidden email]> 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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/pmd-devel





--
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/pmd-devel
Reply | Threaded
Open this post in threaded view
|

Re: Extracting violation details from Listener

Juan Martín Sotuyo Dodero
Yeap, you got it.

On Wed, Jul 12, 2017 at 5:27 PM, Caleb Knox <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/pmd-devel





--
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/pmd-devel
Reply | Threaded
Open this post in threaded view
|

Re: Extracting violation details from Listener

Caleb Knox
Awesome, thanks! 

On Jul 12, 2017 3:47 PM, "Juan Martín Sotuyo Dodero" <[hidden email]> wrote:
Yeap, you got it.

On Wed, Jul 12, 2017 at 5:27 PM, Caleb Knox <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/pmd-devel





--
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/pmd-devel