11
11
<<GMetrics>> provides a Groovy DSL (domain-specific language) for defining <MetricSets>.
14
13
** A Sample Groovy MetricSet
15
14
~~~~~~~~~~~~~~~~~~~~~~~~~~~
17
Here is an example of a Groovy <MetricSet> file:
16
The preferred syntax for defining a <MetricSet> is to specify the list of <Metric>s using the <Metric>
17
names. Here is simple example:
19
+----------------------------------------------------------------------------------------
22
description 'A simple MetricSet'
24
ClassCount // specify metric name only (note no "Metric" suffix on metric name)
26
FieldCount { // configure the Metric using a Closure
30
MethodCount([functions:['total']) // configure the Metric using a Map of properties
32
+----------------------------------------------------------------------------------------
36
* The Groovy <MetricSet> file itself must be accessible on the classpath.
38
* This <MetricSet> includes the <<ClassCount>>, <<FieldCount>> and <<MethodCount>> <Metric>s.
40
* Note that the <Metric> names do not include the "Metric" suffix (of the <Metric> implementation class name).
42
* <Metric> properties can be configured either within a Closure (as assignments) or through a
43
<Map> passed in within the parentheses (after the <Metric> name).
45
* You can specify the <Metric> names for all <Metric>s provided with <<GMetrics>>. If you provide
46
your own custom <Metric>s, then you must use the <<<metric(Class)>>> syntax instead -- see below.
49
** A More Comprehensive Groovy MetricSet
50
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
52
Here is an example of a more comprehensive Groovy <MetricSet> file, illustrating specifying <Metric>s
53
by <Metric> class or <Metric> name, and also nested <MetricSet> files:
19
55
+----------------------------------------------------------------------------------------
20
56
import org.gmetrics.metric.cyclomatic.CyclomaticComplexityMetric
24
description 'A sample MetricSet'
60
description 'An example MetricSet'
26
62
metricset("MyMetricSet.groovy")
29
65
functions = ['average', 'maximum']
32
metric(CyclomaticComplexityMetric)
68
metric(CyclomaticComplexityMetric) // specify metric class (see import)
70
ClassCount // specify metric name only (note no "Metric" suffix on metric name)
72
FieldCount { // specify metric name only
34
76
metricset("somepath/MyOtherMetricSet.groovy") {
81
123
As within <<MetricSet>> statements, properties set this way can be of type <<<String>>>, <<<int>>>,
82
124
<<<long>>> or <<<boolean>>>.
126
* The <<ClassCount>> and <<FieldCount>> <Metric>s are included by specifying only the <Metric> name (not the class)
84
128
* Setting the <<<enabled>>> property of a <Metric> turns it off so that it will not show up in the