How to define maxComplexity for methodContexts in maven clover plugin configuration

Dmitry Suslov October 9, 2012

Hi,

I want to customize clover coverage reports to exclude simple methods (setters/getters) with complexity less than 2. It's possible with Ant plug-in.

Сonfiguration example:

<clover-setup ...>
<!-- Don't instrument methods which have cyclomatic complexity <= 1 or <= 3 statements -->
<methodContext name="simple_method" regexp="(.* )?public .*(get|set|is)[A-Z0-9].*" " maxComplexity="1"/>
</clover-setup>
But It seems the same configuration can not be defined with maven clover plug-in. In maven plug-in only regexp can be defined.
Example:
<configuration>
<methodContexts>
<simple_method>((.* )?public .*(get|set|is)[A-Z0-9].*</simple_method>>
</methodContexts>
</configuration>
<configuration>
...
<contextFilters>simple_method</contextFilters>
</configuration>
Are there any ways/workarounds to define maxComplexity as one of criteria for filtered code?

2 answers

0 votes
Aryan September 14, 2015

Can we use a regex like below to eliminate Getter/Setters using methodContext in Maven ? 

<methodContexts>
<getterSetter>(?m)((?:public |private |protected )?[\w$]+) (get|set|is)([\w$]+)\(([\w$]+(?:\[\])? [\w$]+)?\) \{\s+(return [\w$]+;|this.[\w$]+ = [\w$]+;)\s+\}</getterSetter>
</methodContexts>

Marek Parfianowicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 14, 2015

No. The methodContext matches method's signature (i.e. annotations + modifiers + return type + name + arguments) and not method's body.

Marek Parfianowicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 14, 2015

Besides - your regexp part for method's signature is unnecessarily complex - Clover performs signature normalisation before comparison, see https://confluence.atlassian.com/display/CLOVER/Using+Coverage+Contexts

0 votes
Marek Parfianowicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 25, 2012

Unfortunately, maxComplexity/maxStatements are not available in Maven plugin right now (version 3.1.7). I've created CLOV-1173 improvement request for this. As a workaround you could try using the Maven Antrun Plugin and calling Clover from it.

See:

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events