[4.4.0] Add maxComplexity / maxStatements for Clover-for-Maven

Issue #19 resolved
Salvador Morera Soler created an issue

A common use case for method contexts is filtering out accessors. In fact, A pre-defined context for that already exists. However, this context matches more methods than just trivial accessors (accessors with lazy initialisation and many others), since it just checks the method signature. A project may want non-trivial accessors test-covered, while filtering out the trivial ones.

This use case can be implemented by using maxComplexity / maxStatements and their aggregated version in ant, but not by maven plugin configuration itself.

There is an improvement request in Altassian's Clover Jira related to this: https://jira.atlassian.com/browse/CLOV-1173

However, I'd like to suggest for your consideration a slightly different approach that might be easier to implement: by using attributes for the new properties, the current implementation that takes the tag itself as name of the context can remain as is, and the backwards compatibility is preserved. eg:

    <trivialAccessors maxAggregatedStatements="1">(.* )?public .*(get|set|is)[A-Z].*</trivialAccessors>

Comments (10)

  1. Marek Parfianowicz

    Hi Salvador, thank you very much for reporting this issue. This enhancement is also on our radar, so it will be implemented in one of the nearest releases.

    Regarding your proposal to use attributes - I'd be hesitant to use this approach, because using attributes in tags is not a common practice in Maven. Having new set of tags, as proposed in CLOV-1173, should be sufficient.

  2. Salvador Morera Soler reporter

    Hi Marek, thank you for answering and for your effort.

    Yes, I know attributes are not commonly used, and always wondered why maven renounces to them. I proposed that approach because it seemed easier to implement with your current approach ;) Of course sticking to conventions seems more reasonable.

    Anyway, thank you for putting this on your backlog and a big thank you for taking care of the project.

  3. Marek Parfianowicz


                   <name>simpleGetter</name> <!-- (mandatory) -->
                   <regexp>public .* get.*\(\)</regexp> <!-- (mandatory) -->
                   <maxComplexity>1</maxComplexity> <!-- at most 1 cycle (optional) -->
                   <maxStatements>1</maxStatements> <!-- at most 1 statement (optional) -->
                   <maxAggregatedComplexity>2</maxAggregatedComplexity> <!-- no more than 2 cycles including inline classes (optional) -->
                   <maxAggregatedStatements>10</maxAggregatedStatements> <!-- no more than 10 statements including inline classes (optional) -->
               <!-- can add more methodWithMetricsContext -->
  4. Log in to comment