GMetrics

The GMetrics project provides calculation and reporting of size and complexity metrics for Groovy source code. GMetrics scans Groovy source code, applying a set of metrics, and generates an HTML report of the results.

This project is maintained by dx42

GMetrics - Creating a MetricSet

Creating a Groovy MetricSet File

GMetrics provides a Groovy DSL (domain-specific language) for defining MetricSets.

A Sample Groovy MetricSet

The preferred syntax for defining a MetricSet is to specify the list of Metrics using the Metric names. Here is simple example:

metricset {

    description 'A simple MetricSet'

    ClassCount          // specify metric name only (note no "Metric" suffix on metric name)

    FieldCount {        // configure the Metric using a Closure
        functions = ['total']
    }

    MethodCount([functions:['total'])    // configure the Metric using a Map of properties
}

Things to note:

A More Comprehensive Groovy MetricSet

Here is an example of a more comprehensive Groovy MetricSet file, illustrating specifying Metrics by Metric class or Metric name, and also nested MetricSet files:

import org.gmetrics.metric.cyclomatic.CyclomaticComplexityMetric

metricset {

    description 'An example MetricSet'

    metricset("MyMetricSet.groovy")

    metric(org.gmetrics.metric.abc.AbcMetric) {
        functions = ['average', 'maximum']
    }

    metric(CyclomaticComplexityMetric)      // specify metric class (see import)

    ClassCount          // specify metric name only (note no "Metric" suffix on metric name)

    FieldCount {          // specify metric name only
        functions = ['total']
    }

    metricset("somepath/MyOtherMetricSet.groovy") {
        ClassLineCount {
            enabled = false
        }

        MethodLineCount name:'CustomMethodLineCount'
    }
}

Things to note:

About the “inner” metricset statements:

About the metric statements:

Turning off a Metric

You can turn off a Metric by setting its enabled boolean property to false. It defaults to true. This applies to all descendants of org.gmetrics.metric.AbstractMetric (i.e., all Metrics supplied with GMetrics).