How to define maxComplexity for methodContexts in maven clover plugin configuration

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

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:

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>

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

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Featured Groups

Tuesday tips & tricks: What is the Atlassian Community?

It's officially Tuesday, which means it's officially time for another tip to help you better navigate this space we call the Atlassian Community. 😄 I got a great question from community member, Sa...

55 views 2 5
View post

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you