509
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2012 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
"{ Package: 'stx:goodies/sunit' }"
|
|
13 |
|
|
14 |
Object subclass:#MetricsReporter
|
|
15 |
instanceVariableNames:'packages stream classMetricNames methodMetricNames
|
|
16 |
packageMetricNames'
|
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'SUnit-Report'
|
|
20 |
!
|
|
21 |
|
|
22 |
!MetricsReporter class methodsFor:'documentation'!
|
|
23 |
|
|
24 |
copyright
|
|
25 |
"
|
|
26 |
COPYRIGHT (c) 2012 by eXept Software AG
|
|
27 |
All Rights Reserved
|
|
28 |
|
|
29 |
This software is furnished under a license and may be used
|
|
30 |
only in accordance with the terms of that license and with the
|
|
31 |
inclusion of the above copyright notice. This software may not
|
|
32 |
be provided or otherwise made available to, or used by, any
|
|
33 |
other person. No title to or ownership of the software is
|
|
34 |
hereby transferred.
|
|
35 |
|
|
36 |
"
|
|
37 |
!
|
|
38 |
|
|
39 |
documentation
|
|
40 |
"
|
|
41 |
this is used as a last step in jenkins automated builds.
|
|
42 |
|
|
43 |
Currently supported formats are:
|
|
44 |
#xml_metrics - a java metrics compatible format
|
|
45 |
|
|
46 |
[author:]
|
|
47 |
Claus Gittinger
|
|
48 |
|
|
49 |
[see also:]
|
|
50 |
"
|
|
51 |
!
|
|
52 |
|
|
53 |
examples
|
|
54 |
"
|
|
55 |
[exBegin]
|
|
56 |
'metrics.xml' asFilename writingFileDo:[:stream |
|
|
57 |
MetricsReporter reportPackages:{ 'stx:libjavascript' } format:#xml_metrics on:stream.
|
|
58 |
].
|
|
59 |
[exEnd]
|
|
60 |
|
|
61 |
[exBegin]
|
|
62 |
'metrics.xml' asFilename writingFileDo:[:stream |
|
|
63 |
MetricsReporter
|
|
64 |
reportPackages:
|
|
65 |
{
|
|
66 |
'exept:workflow'
|
|
67 |
'exept:expecco'
|
|
68 |
'exept:expecco/plugins/*'
|
|
69 |
}
|
|
70 |
format:#xml_metrics
|
|
71 |
on:stream.
|
|
72 |
].
|
|
73 |
[exEnd]
|
522
|
74 |
|
|
75 |
[exBegin]
|
|
76 |
MetricsReporter new
|
|
77 |
stream: Transcript;
|
|
78 |
packages:
|
|
79 |
{
|
|
80 |
'exept:workflow' .
|
|
81 |
'exept:expecco' .
|
|
82 |
};
|
|
83 |
classMetricNames: #();
|
|
84 |
methodMetricNames: #();
|
|
85 |
packageMetricNames: #( 'LOC' 'NOM' 'NOC');
|
|
86 |
reportXml_metrics.
|
|
87 |
[exEnd]
|
509
|
88 |
"
|
|
89 |
!
|
|
90 |
|
|
91 |
format_metrics
|
|
92 |
"
|
|
93 |
<?xml version=""1.0"" encoding=""UTF-8"" ?>
|
|
94 |
|
|
95 |
<!!ELEMENT metrics (project)* >
|
|
96 |
<!!ELEMENT project (name, measurement*, group*) >
|
|
97 |
<!!ELEMENT group (name, measurement*, class*) >
|
|
98 |
<!!ELEMENT class (name, measurement*, method*) >
|
|
99 |
<!!ELEMENT method (name, measurement*) >
|
|
100 |
<!!ELEMENT name (#PCDATA) >
|
|
101 |
<!!ELEMENT measurement (short-name, long-name, value, (members? | (minimum, median, average, standard-deviation, maximum, sum, nb-data-points))) >
|
|
102 |
<!!ELEMENT short-name (#PCDATA) >
|
|
103 |
<!!ELEMENT long-name (#PCDATA) >
|
|
104 |
<!!ELEMENT value (#PCDATA) >
|
|
105 |
<!!ELEMENT members (member*) >
|
|
106 |
<!!ELEMENT minimum (#PCDATA) >
|
|
107 |
<!!ELEMENT median (#PCDATA) >
|
|
108 |
<!!ELEMENT average (#PCDATA) >
|
|
109 |
<!!ELEMENT standard-deviation (#PCDATA) >
|
|
110 |
<!!ELEMENT maximum (#PCDATA) >
|
|
111 |
<!!ELEMENT sum (#PCDATA) >
|
|
112 |
<!!ELEMENT nb-data-points (#PCDATA) >
|
|
113 |
<!!ELEMENT member (#PCDATA) >
|
|
114 |
"
|
|
115 |
! !
|
|
116 |
|
|
117 |
!MetricsReporter class methodsFor:'queries'!
|
|
118 |
|
|
119 |
supportedFormats
|
|
120 |
"return a list of formats and short-info-string, as per supported format symbol"
|
|
121 |
|
|
122 |
^ #(
|
|
123 |
(#'xml_metrics' 'xml format')
|
|
124 |
)
|
|
125 |
|
|
126 |
"Created: / 30-07-2011 / 10:18:18 / cg"
|
|
127 |
! !
|
|
128 |
|
|
129 |
!MetricsReporter class methodsFor:'reporting'!
|
|
130 |
|
|
131 |
reportPackages: aCollectionOfPackages format: format on: stream
|
|
132 |
self new
|
|
133 |
reportPackages: aCollectionOfPackages format: format on: stream
|
|
134 |
! !
|
|
135 |
|
|
136 |
!MetricsReporter methodsFor:'accessing'!
|
|
137 |
|
|
138 |
classMetricNames
|
520
|
139 |
^ classMetricNames ? #( 'NOM' 'LOC' )
|
509
|
140 |
!
|
|
141 |
|
521
|
142 |
classMetricNames:something
|
|
143 |
classMetricNames := something.
|
|
144 |
!
|
|
145 |
|
509
|
146 |
methodMetricNames
|
|
147 |
^ methodMetricNames ? #( "'LOC'" )
|
|
148 |
!
|
|
149 |
|
521
|
150 |
methodMetricNames:something
|
|
151 |
methodMetricNames := something.
|
|
152 |
!
|
|
153 |
|
509
|
154 |
packageMetricNames
|
|
155 |
^ packageMetricNames ? #( 'LOC' )
|
|
156 |
!
|
|
157 |
|
521
|
158 |
packageMetricNames:something
|
|
159 |
packageMetricNames := something.
|
|
160 |
!
|
|
161 |
|
509
|
162 |
packages:something
|
|
163 |
packages := something.
|
|
164 |
!
|
|
165 |
|
|
166 |
stream:something
|
|
167 |
stream := something.
|
|
168 |
! !
|
|
169 |
|
|
170 |
!MetricsReporter methodsFor:'metric generation'!
|
|
171 |
|
|
172 |
classMetricValue:metricName for:aClass
|
|
173 |
|metric|
|
|
174 |
|
|
175 |
metric := OOM::ClassMetrics type:metricName for:aClass.
|
|
176 |
^ self metricInfoFor:metric
|
|
177 |
!
|
|
178 |
|
|
179 |
methodMetricValue:metricName for:aMethod
|
|
180 |
|metric|
|
|
181 |
|
|
182 |
metric := OOM::MethodMetrics type:metricName for:aMethod.
|
|
183 |
^ self metricInfoFor:metric
|
|
184 |
!
|
|
185 |
|
|
186 |
metricInfoFor:metric
|
|
187 |
^ { metric class shortName . metric class descriptiveName . metric metricValue }
|
|
188 |
!
|
|
189 |
|
|
190 |
packageMetricValue:metricName for:aPackageID
|
|
191 |
|metric|
|
|
192 |
|
|
193 |
metric := OOM::PackageMetrics type:metricName for:aPackageID.
|
|
194 |
^ self metricInfoFor:metric
|
|
195 |
! !
|
|
196 |
|
|
197 |
!MetricsReporter methodsFor:'reporting'!
|
|
198 |
|
|
199 |
reportPackages: aCollectionOfPackages format: aSymbol on: aStream
|
|
200 |
|
|
201 |
packages := aCollectionOfPackages.
|
|
202 |
stream := aStream.
|
|
203 |
self report: aSymbol
|
|
204 |
! !
|
|
205 |
|
|
206 |
!MetricsReporter methodsFor:'reporting - xml-metrics'!
|
|
207 |
|
|
208 |
generateClassMetricsFor:aClass
|
|
209 |
^ self classMetricNames collect:[:metricName |
|
|
210 |
self classMetricValue:metricName for:aClass.
|
|
211 |
].
|
|
212 |
!
|
|
213 |
|
|
214 |
generateMethodMetricsFor:aMethod
|
|
215 |
^ self methodMetricNames collect:[:metricName |
|
|
216 |
self methodMetricValue:metricName for:aMethod.
|
|
217 |
].
|
|
218 |
!
|
|
219 |
|
|
220 |
generatePackageMetricsFor:aPackage
|
|
221 |
^ self packageMetricNames collect:[:metricName |
|
|
222 |
self packageMetricValue:metricName for:aPackage.
|
|
223 |
].
|
|
224 |
!
|
|
225 |
|
|
226 |
reportXml_metricValues:metricValues
|
|
227 |
|metricShortName metricLongName metricValue|
|
|
228 |
|
|
229 |
metricValues do:[:eachTuple |
|
|
230 |
metricShortName := eachTuple first.
|
|
231 |
metricLongName := eachTuple second.
|
|
232 |
metricValue := eachTuple third.
|
|
233 |
|
|
234 |
stream nextPutLine: ' <measurement>'.
|
|
235 |
stream nextPutLine: (' <short-name>%1</short-name>' bindWith:metricShortName).
|
|
236 |
stream nextPutLine: (' <long-name>%1</long-name>' bindWith:metricLongName).
|
|
237 |
stream nextPutLine: (' <value>%1</value>' bindWith:metricValue).
|
|
238 |
stream nextPutLine: ' </measurement>'.
|
|
239 |
]
|
|
240 |
!
|
|
241 |
|
|
242 |
reportXml_metrics
|
|
243 |
"
|
|
244 |
self new
|
|
245 |
stream:Transcript;
|
|
246 |
packages:#( 'exept:workflow' );
|
|
247 |
reportXml_metrics
|
|
248 |
"
|
|
249 |
|
|
250 |
Smalltalk loadPackage:'exept:programming/oom'.
|
|
251 |
|
|
252 |
stream nextPutLine: '<?xml version="1.0"?>';
|
|
253 |
nextPutLine: '<metrics>'.
|
|
254 |
|
|
255 |
packages do:[:eachPackageID |
|
|
256 |
Smalltalk loadPackage:eachPackageID.
|
|
257 |
self reportXml_metricsForPackage:eachPackageID
|
|
258 |
].
|
|
259 |
|
|
260 |
stream nextPutLine: '</metrics>'.
|
|
261 |
!
|
|
262 |
|
|
263 |
reportXml_metricsForClass:aClass
|
|
264 |
stream nextPutLine: ' <class>'.
|
|
265 |
stream nextPutLine: (' <name>%1</name>' bindWith:aClass name).
|
|
266 |
|
|
267 |
self methodMetricNames notEmptyOrNil ifTrue:[
|
|
268 |
aClass instAndClassMethodsDo:[:eachMethod |
|
|
269 |
self reportXml_metricsForMethod:eachMethod
|
|
270 |
].
|
|
271 |
].
|
|
272 |
|
519
|
273 |
self classMetricNames notEmptyOrNil ifTrue:[
|
|
274 |
self reportXml_metricValues:(self generateClassMetricsFor:aClass).
|
|
275 |
].
|
|
276 |
|
509
|
277 |
stream nextPutLine: ' </class>'.
|
|
278 |
!
|
|
279 |
|
|
280 |
reportXml_metricsForMethod:aMethod
|
|
281 |
stream nextPutLine: ' <method>'.
|
|
282 |
stream nextPutLine:(' <name>%1</name>' bindWith:aMethod selector).
|
|
283 |
|
|
284 |
self reportXml_metricValues:(self generateMethodMetricsFor:aMethod).
|
|
285 |
|
|
286 |
stream nextPutLine: ' </method>'.
|
|
287 |
!
|
|
288 |
|
|
289 |
reportXml_metricsForPackage:aPackageID
|
|
290 |
stream nextPutLine: ' <project>'.
|
|
291 |
stream nextPutLine: (' <name>%1</name>' bindWith:aPackageID).
|
|
292 |
|
|
293 |
(self classMetricNames notEmptyOrNil
|
|
294 |
or:[self methodMetricNames notEmptyOrNil]) ifTrue:[
|
|
295 |
Smalltalk allClassesInPackage:aPackageID do:[:eachClass |
|
|
296 |
Autoload autoloadFailedSignal handle:[:ex |
|
|
297 |
] do:[
|
|
298 |
eachClass autoload.
|
|
299 |
self reportXml_metricsForClass:eachClass
|
|
300 |
].
|
|
301 |
].
|
|
302 |
].
|
|
303 |
|
519
|
304 |
self reportXml_metricValues:(self generatePackageMetricsFor:aPackageID).
|
|
305 |
|
509
|
306 |
stream nextPutLine: ' </project>'.
|
|
307 |
! !
|
|
308 |
|
|
309 |
!MetricsReporter methodsFor:'reporting-private'!
|
|
310 |
|
|
311 |
report:formatSymbol
|
|
312 |
"currently supported formatSymbols:
|
|
313 |
xml_cobertura"
|
|
314 |
|
|
315 |
|reportFormatSelector|
|
|
316 |
|
|
317 |
reportFormatSelector := self reportFormatSelector:formatSymbol.
|
|
318 |
(self respondsTo: reportFormatSelector)
|
|
319 |
ifTrue:[self perform: reportFormatSelector]
|
|
320 |
ifFalse:[self error:'Unsupported format: ', formatSymbol].
|
|
321 |
|
|
322 |
"Modified (comment): / 03-08-2011 / 12:57:54 / cg"
|
|
323 |
!
|
|
324 |
|
|
325 |
reportFormatSelector:format
|
|
326 |
^ ('report' , format asString capitalized) asSymbol
|
|
327 |
! !
|
|
328 |
|
|
329 |
!MetricsReporter class methodsFor:'documentation'!
|
|
330 |
|
|
331 |
version
|
522
|
332 |
^ '$Header: /cvs/stx/stx/goodies/sunit/MetricsReporter.st,v 1.5 2012-11-07 21:21:56 cg Exp $'
|
509
|
333 |
!
|
|
334 |
|
|
335 |
version_CVS
|
522
|
336 |
^ '$Header: /cvs/stx/stx/goodies/sunit/MetricsReporter.st,v 1.5 2012-11-07 21:21:56 cg Exp $'
|
509
|
337 |
! !
|