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]
|
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
|
|
333 |
(Smalltalk loadPackage:'exept:programming/oom') ifFalse:[
|
|
334 |
self error:'cannot load oom package'.
|
|
335 |
].
|
509
|
336 |
|
|
337 |
stream nextPutLine: '<?xml version="1.0"?>';
|
|
338 |
nextPutLine: '<metrics>'.
|
|
339 |
|
|
340 |
packages do:[:eachPackageID |
|
568
|
341 |
"/ if the package is a matchPattern, generate metrics for all loaded packages
|
|
342 |
"/ which match that pattern.
|
|
343 |
"/ Otherwise, make sure that this package is loaded and generate metrics for that
|
|
344 |
"/ one only.
|
|
345 |
eachPackageID includesMatchCharacters ifFalse:[
|
|
346 |
Smalltalk loadPackage:eachPackageID.
|
|
347 |
].
|
509
|
348 |
self reportXml_metricsForPackage:eachPackageID
|
|
349 |
].
|
|
350 |
stream nextPutLine: '</metrics>'.
|
|
351 |
!
|
|
352 |
|
|
353 |
reportXml_metricsForClass:aClass
|
|
354 |
stream nextPutLine: ' <class>'.
|
|
355 |
stream nextPutLine: (' <name>%1</name>' bindWith:aClass name).
|
|
356 |
|
|
357 |
self methodMetricNames notEmptyOrNil ifTrue:[
|
|
358 |
aClass instAndClassMethodsDo:[:eachMethod |
|
|
359 |
self reportXml_metricsForMethod:eachMethod
|
|
360 |
].
|
|
361 |
].
|
|
362 |
|
519
|
363 |
self classMetricNames notEmptyOrNil ifTrue:[
|
|
364 |
self reportXml_metricValues:(self generateClassMetricsFor:aClass).
|
|
365 |
].
|
|
366 |
|
509
|
367 |
stream nextPutLine: ' </class>'.
|
|
368 |
!
|
|
369 |
|
|
370 |
reportXml_metricsForMethod:aMethod
|
|
371 |
stream nextPutLine: ' <method>'.
|
|
372 |
stream nextPutLine:(' <name>%1</name>' bindWith:aMethod selector).
|
|
373 |
|
|
374 |
self reportXml_metricValues:(self generateMethodMetricsFor:aMethod).
|
|
375 |
|
|
376 |
stream nextPutLine: ' </method>'.
|
|
377 |
!
|
|
378 |
|
568
|
379 |
reportXml_metricsForPackage:aPackageIDOrPattern
|
|
380 |
|genMetricsForClass|
|
|
381 |
|
|
382 |
genMetricsForClass :=
|
|
383 |
[:aClass |
|
|
384 |
Autoload autoloadFailedSignal handle:[:ex |
|
|
385 |
] do:[
|
|
386 |
aClass autoload.
|
|
387 |
self reportXml_metricsForClass:aClass
|
|
388 |
]
|
|
389 |
].
|
|
390 |
|
509
|
391 |
stream nextPutLine: ' <project>'.
|
568
|
392 |
stream nextPutLine: (' <name>%1</name>' bindWith:aPackageIDOrPattern).
|
509
|
393 |
|
|
394 |
(self classMetricNames notEmptyOrNil
|
|
395 |
or:[self methodMetricNames notEmptyOrNil]) ifTrue:[
|
568
|
396 |
aPackageIDOrPattern includesMatchCharacters ifTrue:[
|
|
397 |
Smalltalk allClasses do:[:eachClass |
|
|
398 |
(eachClass package matches:aPackageIDOrPattern) iftrue:[
|
|
399 |
genMetricsForClass value:eachClass
|
|
400 |
].
|
509
|
401 |
].
|
568
|
402 |
] ifFalse:[
|
|
403 |
Smalltalk allClassesInPackage:aPackageIDOrPattern do:genMetricsForClass.
|
509
|
404 |
].
|
|
405 |
].
|
|
406 |
|
568
|
407 |
self reportXml_metricValues:(self generatePackageMetricsFor:aPackageIDOrPattern).
|
519
|
408 |
|
509
|
409 |
stream nextPutLine: ' </project>'.
|
|
410 |
! !
|
|
411 |
|
|
412 |
!MetricsReporter methodsFor:'reporting-private'!
|
|
413 |
|
|
414 |
report:formatSymbol
|
|
415 |
"currently supported formatSymbols:
|
568
|
416 |
xml_metrics"
|
509
|
417 |
|
|
418 |
|reportFormatSelector|
|
|
419 |
|
|
420 |
reportFormatSelector := self reportFormatSelector:formatSymbol.
|
|
421 |
(self respondsTo: reportFormatSelector)
|
|
422 |
ifTrue:[self perform: reportFormatSelector]
|
|
423 |
ifFalse:[self error:'Unsupported format: ', formatSymbol].
|
|
424 |
|
|
425 |
"Modified (comment): / 03-08-2011 / 12:57:54 / cg"
|
|
426 |
!
|
|
427 |
|
|
428 |
reportFormatSelector:format
|
|
429 |
^ ('report' , format asString capitalized) asSymbol
|
|
430 |
! !
|
|
431 |
|
|
432 |
!MetricsReporter class methodsFor:'documentation'!
|
|
433 |
|
|
434 |
version
|
568
|
435 |
^ '$Header: /cvs/stx/stx/goodies/sunit/MetricsReporter.st,v 1.6 2013-04-16 18:09:01 cg Exp $'
|
509
|
436 |
!
|
|
437 |
|
|
438 |
version_CVS
|
568
|
439 |
^ '$Header: /cvs/stx/stx/goodies/sunit/MetricsReporter.st,v 1.6 2013-04-16 18:09:01 cg Exp $'
|
509
|
440 |
! !
|
568
|
441 |
|