author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 09 Jul 2014 23:00:04 +0100 | |
branch | working_v5_0 |
changeset 613 | 5a546630cfcf |
parent 586 | 9d8e935e6a25 |
child 604 | d9117215a675 |
permissions | -rw-r--r-- |
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:'' |
|
584
aab981776647
Moved to category "SUnit-Smalltalk/X-Report" as it is St/X-specific (and mostly obsolete)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
568
diff
changeset
|
19 |
category:'SUnit-Smalltalk/X-Report' |
509 | 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] |
|
568 | 56 |
String streamContents:[:stream | |
57 |
MetricsReporter |
|
58 |
reportPackages:{ 'stx:libjavascript' } |
|
59 |
format:#xml_metrics |
|
60 |
on:stream. |
|
61 |
]. |
|
62 |
[exEnd] |
|
63 |
[exBegin] |
|
64 |
String streamContents:[:stream | |
|
65 |
MetricsReporter |
|
66 |
reportPackages:{ 'stx:libbasic' } |
|
67 |
format:#xml_metrics |
|
68 |
on:stream. |
|
69 |
]. |
|
70 |
[exEnd] |
|
71 |
[exBegin] |
|
72 |
String streamContents:[:stream | |
|
73 |
MetricsReporter |
|
74 |
reportPackages:{ 'stx:libbasic*' } |
|
75 |
format:#xml_metrics |
|
76 |
on:stream. |
|
77 |
]. |
|
78 |
[exEnd] |
|
79 |
[exBegin] |
|
509 | 80 |
'metrics.xml' asFilename writingFileDo:[:stream | |
568 | 81 |
MetricsReporter |
82 |
reportPackages:{ 'stx:libjavascript' } |
|
83 |
format:#xml_metrics |
|
84 |
on:stream. |
|
509 | 85 |
]. |
86 |
[exEnd] |
|
87 |
||
88 |
[exBegin] |
|
89 |
'metrics.xml' asFilename writingFileDo:[:stream | |
|
90 |
MetricsReporter |
|
91 |
reportPackages: |
|
92 |
{ |
|
93 |
'exept:workflow' |
|
94 |
'exept:expecco' |
|
95 |
'exept:expecco/plugins/*' |
|
96 |
} |
|
97 |
format:#xml_metrics |
|
98 |
on:stream. |
|
99 |
]. |
|
100 |
[exEnd] |
|
522 | 101 |
|
568 | 102 |
package metrics only: |
522 | 103 |
[exBegin] |
104 |
MetricsReporter new |
|
105 |
stream: Transcript; |
|
106 |
packages: |
|
107 |
{ |
|
108 |
'exept:workflow' . |
|
109 |
'exept:expecco' . |
|
110 |
}; |
|
111 |
classMetricNames: #(); |
|
112 |
methodMetricNames: #(); |
|
113 |
packageMetricNames: #( 'LOC' 'NOM' 'NOC'); |
|
114 |
reportXml_metrics. |
|
115 |
[exEnd] |
|
568 | 116 |
[exBegin] |
117 |
MetricsReporter new |
|
118 |
stream: Transcript; |
|
119 |
packages: |
|
120 |
{ |
|
121 |
'stx:libbasic' . |
|
122 |
'stx:libbasic2' . |
|
123 |
'stx:libbasic3' . |
|
124 |
}; |
|
125 |
classMetricNames: #(); |
|
126 |
methodMetricNames: #(); |
|
127 |
packageMetricNames: #( 'LOC' 'NOM' 'NOC'); |
|
128 |
reportXml_metrics. |
|
129 |
[exEnd] |
|
130 |
[exBegin] |
|
131 |
MetricsReporter new |
|
132 |
stream: Transcript; |
|
133 |
packages: |
|
134 |
{ |
|
135 |
'stx:libbasic*' . |
|
136 |
}; |
|
137 |
classMetricNames: #(); |
|
138 |
methodMetricNames: #(); |
|
139 |
packageMetricNames: #( 'LOC' 'NOM' 'NOC'); |
|
140 |
reportXml_metrics. |
|
141 |
[exEnd] |
|
142 |
[exBegin] |
|
143 |
MetricsReporter new |
|
144 |
stream: Transcript; |
|
145 |
packages: |
|
146 |
{ |
|
147 |
'stx:*' . |
|
148 |
}; |
|
149 |
classMetricNames: #(); |
|
150 |
methodMetricNames: #(); |
|
151 |
packageMetricNames: #( 'LOC' 'NOM' 'NOC'); |
|
152 |
reportXml_metrics. |
|
153 |
[exEnd] |
|
509 | 154 |
" |
155 |
! |
|
156 |
||
157 |
format_metrics |
|
158 |
" |
|
159 |
<?xml version=""1.0"" encoding=""UTF-8"" ?> |
|
160 |
||
161 |
<!!ELEMENT metrics (project)* > |
|
162 |
<!!ELEMENT project (name, measurement*, group*) > |
|
163 |
<!!ELEMENT group (name, measurement*, class*) > |
|
164 |
<!!ELEMENT class (name, measurement*, method*) > |
|
165 |
<!!ELEMENT method (name, measurement*) > |
|
166 |
<!!ELEMENT name (#PCDATA) > |
|
167 |
<!!ELEMENT measurement (short-name, long-name, value, (members? | (minimum, median, average, standard-deviation, maximum, sum, nb-data-points))) > |
|
168 |
<!!ELEMENT short-name (#PCDATA) > |
|
169 |
<!!ELEMENT long-name (#PCDATA) > |
|
170 |
<!!ELEMENT value (#PCDATA) > |
|
171 |
<!!ELEMENT members (member*) > |
|
172 |
<!!ELEMENT minimum (#PCDATA) > |
|
173 |
<!!ELEMENT median (#PCDATA) > |
|
174 |
<!!ELEMENT average (#PCDATA) > |
|
175 |
<!!ELEMENT standard-deviation (#PCDATA) > |
|
176 |
<!!ELEMENT maximum (#PCDATA) > |
|
177 |
<!!ELEMENT sum (#PCDATA) > |
|
178 |
<!!ELEMENT nb-data-points (#PCDATA) > |
|
179 |
<!!ELEMENT member (#PCDATA) > |
|
180 |
" |
|
181 |
! ! |
|
182 |
||
183 |
!MetricsReporter class methodsFor:'queries'! |
|
184 |
||
185 |
supportedFormats |
|
186 |
"return a list of formats and short-info-string, as per supported format symbol" |
|
187 |
||
188 |
^ #( |
|
189 |
(#'xml_metrics' 'xml format') |
|
190 |
) |
|
191 |
||
192 |
"Created: / 30-07-2011 / 10:18:18 / cg" |
|
193 |
! ! |
|
194 |
||
195 |
!MetricsReporter class methodsFor:'reporting'! |
|
196 |
||
197 |
reportPackages: aCollectionOfPackages format: format on: stream |
|
198 |
self new |
|
199 |
reportPackages: aCollectionOfPackages format: format on: stream |
|
200 |
! ! |
|
201 |
||
202 |
!MetricsReporter methodsFor:'accessing'! |
|
203 |
||
204 |
classMetricNames |
|
520 | 205 |
^ classMetricNames ? #( 'NOM' 'LOC' ) |
509 | 206 |
! |
207 |
||
521 | 208 |
classMetricNames:something |
209 |
classMetricNames := something. |
|
210 |
! |
|
211 |
||
509 | 212 |
methodMetricNames |
213 |
^ methodMetricNames ? #( "'LOC'" ) |
|
214 |
! |
|
215 |
||
521 | 216 |
methodMetricNames:something |
217 |
methodMetricNames := something. |
|
218 |
! |
|
219 |
||
509 | 220 |
packageMetricNames |
221 |
^ packageMetricNames ? #( 'LOC' ) |
|
222 |
! |
|
223 |
||
521 | 224 |
packageMetricNames:something |
225 |
packageMetricNames := something. |
|
226 |
! |
|
227 |
||
509 | 228 |
packages:something |
229 |
packages := something. |
|
230 |
! |
|
231 |
||
232 |
stream:something |
|
233 |
stream := something. |
|
234 |
! ! |
|
235 |
||
236 |
!MetricsReporter methodsFor:'metric generation'! |
|
237 |
||
238 |
classMetricValue:metricName for:aClass |
|
239 |
|metric| |
|
240 |
||
241 |
metric := OOM::ClassMetrics type:metricName for:aClass. |
|
242 |
^ self metricInfoFor:metric |
|
243 |
! |
|
244 |
||
245 |
methodMetricValue:metricName for:aMethod |
|
246 |
|metric| |
|
247 |
||
248 |
metric := OOM::MethodMetrics type:metricName for:aMethod. |
|
249 |
^ self metricInfoFor:metric |
|
250 |
! |
|
251 |
||
252 |
metricInfoFor:metric |
|
253 |
^ { metric class shortName . metric class descriptiveName . metric metricValue } |
|
254 |
! |
|
255 |
||
568 | 256 |
packageMetricValue:metricName for:aPackageIDOrPattern |
257 |
|overAllInfo| |
|
258 |
||
259 |
aPackageIDOrPattern includesMatchCharacters ifTrue:[ |
|
260 |
Smalltalk allProjectIDs do:[:eachPackageID | |
|
261 |
|thisInfo| |
|
509 | 262 |
|
568 | 263 |
(eachPackageID matches:aPackageIDOrPattern) ifTrue:[ |
264 |
thisInfo := self metricInfoFor:(OOM::PackageMetrics type:metricName for:eachPackageID). |
|
265 |
overAllInfo isNil ifTrue:[ |
|
266 |
overAllInfo := thisInfo |
|
267 |
] ifFalse:[ |
|
268 |
"/ kludge: only works with accumulative metrics (i.e. not with averages etc.) |
|
269 |
overAllInfo at:(overAllInfo size) put:(overAllInfo last + thisInfo last). |
|
270 |
]. |
|
271 |
]. |
|
272 |
]. |
|
273 |
^ overAllInfo |
|
274 |
] ifFalse:[ |
|
275 |
^ self metricInfoFor:(OOM::PackageMetrics type:metricName for:aPackageIDOrPattern). |
|
276 |
]. |
|
509 | 277 |
! ! |
278 |
||
279 |
!MetricsReporter methodsFor:'reporting'! |
|
280 |
||
281 |
reportPackages: aCollectionOfPackages format: aSymbol on: aStream |
|
282 |
||
283 |
packages := aCollectionOfPackages. |
|
284 |
stream := aStream. |
|
285 |
self report: aSymbol |
|
286 |
! ! |
|
287 |
||
288 |
!MetricsReporter methodsFor:'reporting - xml-metrics'! |
|
289 |
||
290 |
generateClassMetricsFor:aClass |
|
291 |
^ self classMetricNames collect:[:metricName | |
|
292 |
self classMetricValue:metricName for:aClass. |
|
293 |
]. |
|
294 |
! |
|
295 |
||
296 |
generateMethodMetricsFor:aMethod |
|
297 |
^ self methodMetricNames collect:[:metricName | |
|
298 |
self methodMetricValue:metricName for:aMethod. |
|
299 |
]. |
|
300 |
! |
|
301 |
||
568 | 302 |
generatePackageMetricsFor:aPackageIDOrPattern |
509 | 303 |
^ self packageMetricNames collect:[:metricName | |
568 | 304 |
self packageMetricValue:metricName for:aPackageIDOrPattern. |
509 | 305 |
]. |
306 |
! |
|
307 |
||
308 |
reportXml_metricValues:metricValues |
|
309 |
|metricShortName metricLongName metricValue| |
|
310 |
||
311 |
metricValues do:[:eachTuple | |
|
312 |
metricShortName := eachTuple first. |
|
313 |
metricLongName := eachTuple second. |
|
314 |
metricValue := eachTuple third. |
|
315 |
||
316 |
stream nextPutLine: ' <measurement>'. |
|
317 |
stream nextPutLine: (' <short-name>%1</short-name>' bindWith:metricShortName). |
|
318 |
stream nextPutLine: (' <long-name>%1</long-name>' bindWith:metricLongName). |
|
319 |
stream nextPutLine: (' <value>%1</value>' bindWith:metricValue). |
|
320 |
stream nextPutLine: ' </measurement>'. |
|
321 |
] |
|
322 |
! |
|
323 |
||
324 |
reportXml_metrics |
|
325 |
" |
|
326 |
self new |
|
327 |
stream:Transcript; |
|
328 |
packages:#( 'exept:workflow' ); |
|
329 |
reportXml_metrics |
|
330 |
" |
|
331 |
||
568 | 332 |
"/ need the exept-metrics package |
586 | 333 |
Smalltalk loadPackage:'exept:programming/oom'. |
509 | 334 |
|
335 |
stream nextPutLine: '<?xml version="1.0"?>'; |
|
336 |
nextPutLine: '<metrics>'. |
|
337 |
||
338 |
packages do:[:eachPackageID | |
|
568 | 339 |
"/ if the package is a matchPattern, generate metrics for all loaded packages |
340 |
"/ which match that pattern. |
|
341 |
"/ Otherwise, make sure that this package is loaded and generate metrics for that |
|
342 |
"/ one only. |
|
343 |
eachPackageID includesMatchCharacters ifFalse:[ |
|
344 |
Smalltalk loadPackage:eachPackageID. |
|
345 |
]. |
|
509 | 346 |
self reportXml_metricsForPackage:eachPackageID |
347 |
]. |
|
348 |
stream nextPutLine: '</metrics>'. |
|
349 |
! |
|
350 |
||
351 |
reportXml_metricsForClass:aClass |
|
352 |
stream nextPutLine: ' <class>'. |
|
353 |
stream nextPutLine: (' <name>%1</name>' bindWith:aClass name). |
|
354 |
||
355 |
self methodMetricNames notEmptyOrNil ifTrue:[ |
|
356 |
aClass instAndClassMethodsDo:[:eachMethod | |
|
357 |
self reportXml_metricsForMethod:eachMethod |
|
358 |
]. |
|
359 |
]. |
|
360 |
||
519 | 361 |
self classMetricNames notEmptyOrNil ifTrue:[ |
362 |
self reportXml_metricValues:(self generateClassMetricsFor:aClass). |
|
363 |
]. |
|
364 |
||
509 | 365 |
stream nextPutLine: ' </class>'. |
366 |
! |
|
367 |
||
368 |
reportXml_metricsForMethod:aMethod |
|
369 |
stream nextPutLine: ' <method>'. |
|
370 |
stream nextPutLine:(' <name>%1</name>' bindWith:aMethod selector). |
|
371 |
||
372 |
self reportXml_metricValues:(self generateMethodMetricsFor:aMethod). |
|
373 |
||
374 |
stream nextPutLine: ' </method>'. |
|
375 |
! |
|
376 |
||
568 | 377 |
reportXml_metricsForPackage:aPackageIDOrPattern |
378 |
|genMetricsForClass| |
|
379 |
||
380 |
genMetricsForClass := |
|
381 |
[:aClass | |
|
382 |
Autoload autoloadFailedSignal handle:[:ex | |
|
383 |
] do:[ |
|
384 |
aClass autoload. |
|
385 |
self reportXml_metricsForClass:aClass |
|
386 |
] |
|
387 |
]. |
|
388 |
||
509 | 389 |
stream nextPutLine: ' <project>'. |
568 | 390 |
stream nextPutLine: (' <name>%1</name>' bindWith:aPackageIDOrPattern). |
509 | 391 |
|
392 |
(self classMetricNames notEmptyOrNil |
|
393 |
or:[self methodMetricNames notEmptyOrNil]) ifTrue:[ |
|
568 | 394 |
aPackageIDOrPattern includesMatchCharacters ifTrue:[ |
395 |
Smalltalk allClasses do:[:eachClass | |
|
396 |
(eachClass package matches:aPackageIDOrPattern) iftrue:[ |
|
397 |
genMetricsForClass value:eachClass |
|
398 |
]. |
|
509 | 399 |
]. |
568 | 400 |
] ifFalse:[ |
401 |
Smalltalk allClassesInPackage:aPackageIDOrPattern do:genMetricsForClass. |
|
509 | 402 |
]. |
403 |
]. |
|
404 |
||
568 | 405 |
self reportXml_metricValues:(self generatePackageMetricsFor:aPackageIDOrPattern). |
519 | 406 |
|
509 | 407 |
stream nextPutLine: ' </project>'. |
408 |
! ! |
|
409 |
||
410 |
!MetricsReporter methodsFor:'reporting-private'! |
|
411 |
||
412 |
report:formatSymbol |
|
413 |
"currently supported formatSymbols: |
|
568 | 414 |
xml_metrics" |
509 | 415 |
|
416 |
|reportFormatSelector| |
|
417 |
||
418 |
reportFormatSelector := self reportFormatSelector:formatSymbol. |
|
419 |
(self respondsTo: reportFormatSelector) |
|
420 |
ifTrue:[self perform: reportFormatSelector] |
|
421 |
ifFalse:[self error:'Unsupported format: ', formatSymbol]. |
|
422 |
||
423 |
"Modified (comment): / 03-08-2011 / 12:57:54 / cg" |
|
424 |
! |
|
425 |
||
426 |
reportFormatSelector:format |
|
427 |
^ ('report' , format asString capitalized) asSymbol |
|
428 |
! ! |
|
429 |
||
430 |
!MetricsReporter class methodsFor:'documentation'! |
|
431 |
||
432 |
version |
|
586 | 433 |
^ '$Header: /cvs/stx/stx/goodies/sunit/MetricsReporter.st,v 1.8 2014-02-25 13:32:36 stefan Exp $' |
509 | 434 |
! |
435 |
||
436 |
version_CVS |
|
586 | 437 |
^ '$Header: /cvs/stx/stx/goodies/sunit/MetricsReporter.st,v 1.8 2014-02-25 13:32:36 stefan Exp $' |
509 | 438 |
! ! |
568 | 439 |