Groovy Documentation

groovy.org.codenarc.rule.size
[Groovy] Class CrapMetricRule

java.lang.Object
  org.codenarc.rule.AbstractAstVisitorRule
      groovy.org.codenarc.rule.size.CrapMetricRule

class CrapMetricRule
extends AbstractAstVisitorRule

Rule that calculates the CRAP Metric for methods/classes and checks against configured threshold values.

Note that this rule requires the GMetrics 0.5 (or later) jar on the classpath, as well as a Cobertura XML coverage file. If either of these prerequisites is not available, this rule logs a warning messages and exits (i.e., does nothing).

The coberturaXmlFile property must be set to the path to the Cobertura XML coverage file for the Groovy code being analyzed. By default, the path is relative to the classpath. But the path may be optionally prefixed by any of the valid java.net.URL prefixes, such as "file:" (to load from a relative or absolute path on the filesystem), or "http:". This property is REQUIRED.

The maxMethodCrapScore property holds the threshold value for the CRAP crapMetric value for each method. If this value is non-zero, a method with a CRAP score value greater than this value is considered a violation. The maxMethodCrapScore property defaults to 30.

The maxClassAverageCrapScore property holds the threshold value for the average CRAP crapMetric value for each class. If this value is non-zero, a class with an average CRAP score value greater than this value is considered a violation. The maxMethodAverageCrapScore property defaults to 30.

The ignoreMethodNames property optionally specifies one or more (comma-separated) method names that should be ignored (i.e., that should not cause a rule violation). The name(s) may optionally include wildcard characters ('*' or '?'). Note that the ignored methods still contribute to the class complexity value.

This rule does NOT treat "closure fields" as methods (unlike some of the other size/complexity rules).

Authors:
Chris Mair
See Also:


Field Summary
protected String crapMetricClassName

 
Property Summary
String coberturaXmlFile

String ignoreMethodNames

BigDecimal maxClassAverageMethodCrapScore

BigDecimal maxMethodCrapScore

String name

int priority

 
Method Summary
AstVisitor getAstVisitor()

boolean isReady()

 

Field Detail

crapMetricClassName

protected String crapMetricClassName


 
Property Detail

coberturaXmlFile

String coberturaXmlFile


ignoreMethodNames

String ignoreMethodNames


maxClassAverageMethodCrapScore

BigDecimal maxClassAverageMethodCrapScore


maxMethodCrapScore

BigDecimal maxMethodCrapScore


name

String name


priority

int priority


 
Method Detail

getAstVisitor

@Override
AstVisitor getAstVisitor()


isReady

@Override
boolean isReady()


 

Groovy Documentation