metricsReporter
authorClaus Gittinger <cg@exept.de>
Fri, 25 Mar 2016 16:29:17 +0100
changeset 639 ed6e926776b7
parent 638 51b8edf986fc
child 640 b319a80a14e2
metricsReporter
MetricsReporter.st
--- a/MetricsReporter.st	Fri Mar 25 16:28:56 2016 +0100
+++ b/MetricsReporter.st	Fri Mar 25 16:29:17 2016 +0100
@@ -16,7 +16,8 @@
 Object subclass:#MetricsReporter
 	instanceVariableNames:'packages stream classMetricNames methodMetricNames
 		packageMetricNames'
-	classVariableNames:''
+	classVariableNames:'DefaultClassMetricNames DefaultMethodMetricNames
+		DefaultPackageMetricNames'
 	poolDictionaries:''
 	category:'SUnit-Smalltalk/X-Report'
 !
@@ -52,6 +53,17 @@
     Currently supported formats are:
         #xml_metrics      - a java metrics compatible format
 
+    By default, the following metrics are generated:
+        per method: 
+                none
+                
+        per class: 
+                LOC (lines of code)
+
+        per package: 
+                LOC (lines of code)
+                NOC (number of classes)
+        
     [author:]
         Claus Gittinger
 
@@ -62,6 +74,13 @@
 examples
 "
                                                                                [exBegin]
+    MetricsReporter 
+        reportPackages:{ 'stx:libjavascript' } 
+        format:#xml_metrics 
+        on:Transcript.
+                                                                               [exEnd]
+                                                                               
+                                                                               [exBegin]
     String streamContents:[:stream |
         MetricsReporter 
             reportPackages:{ 'stx:libjavascript' } 
@@ -72,14 +91,6 @@
                                                                                [exBegin]
     String streamContents:[:stream |
         MetricsReporter 
-            reportPackages:{ 'stx:libbasic' } 
-            format:#xml_metrics 
-            on:stream.
-    ].
-                                                                               [exEnd]
-                                                                               [exBegin]
-    String streamContents:[:stream |
-        MetricsReporter 
             reportPackages:{ 'stx:libbasic*' } 
             format:#xml_metrics 
             on:stream.
@@ -134,7 +145,7 @@
             classMetricNames: #();    
             methodMetricNames: #();    
             packageMetricNames: #( 'LOC' 'NOM' 'NOC');    
-            reportXml_metrics.
+            report.
                                                                                [exEnd]
                                                                                [exBegin]
     MetricsReporter new
@@ -146,7 +157,7 @@
             classMetricNames: #();    
             methodMetricNames: #();    
             packageMetricNames: #( 'LOC' 'NOM' 'NOC');    
-            reportXml_metrics.
+            report.
                                                                                [exEnd]
                                                                                [exBegin]
     MetricsReporter new
@@ -158,7 +169,21 @@
             classMetricNames: #();    
             methodMetricNames: #();    
             packageMetricNames: #( 'LOC' 'NOM' 'NOC');    
-            reportXml_metrics.
+            report.
+                                                                               [exEnd]
+                                                                               
+    Number of methods without comment (NMWNC):
+                                                                               [exBegin]
+    MetricsReporter new
+            stream: Transcript;
+            packages:
+                    { 
+                        'stx:libbasic' . 
+                    };
+            classMetricNames: #();    
+            methodMetricNames: #();    
+            packageMetricNames: #( 'NOM' 'NMWNC');    
+            report.
                                                                                [exEnd]
 "
 !
@@ -189,6 +214,20 @@
 "
 ! !
 
+!MetricsReporter class methodsFor:'defaults'!
+
+defaultClassMetricNames
+    ^ DefaultClassMetricNames ? #( 'NOM' 'LOC' )
+!
+
+defaultMethodMetricNames
+    ^ DefaultMethodMetricNames ? #( "'LOC'" )
+!
+
+defaultPackageMetricNames
+    ^ DefaultPackageMetricNames ? #( 'LOC' 'NOC' 'NOM')
+! !
+
 !MetricsReporter class methodsFor:'queries'!
 
 supportedFormats
@@ -203,43 +242,74 @@
 
 !MetricsReporter class methodsFor:'reporting'!
 
-reportPackages: aCollectionOfPackages format: format on: stream
+reportPackages: aCollectionOfPackages format: formatSymbol on: aStream
     self new 
-        reportPackages: aCollectionOfPackages format: format on: stream
+        reportPackages: aCollectionOfPackages format: formatSymbol on: aStream
+
+    "    
+     MetricsReporter 
+         reportPackages:{ 'stx:libbasic' . 'stx:libbasic2' } 
+         format:#xml_metrics 
+         on:Transcript.
+    "
+!
+
+reportSummaryForPackages: aCollectionOfPackages format: aSymbol on: aStream
+    self new
+        classMetricNames:#();
+        methodMetricNames:#();   
+        reportPackages: aCollectionOfPackages format: aSymbol on: aStream
+
+    "    
+     MetricsReporter 
+         reportSummaryForPackages:{ 'stx:libbasic' . 'stx:libbasic2' } 
+         format:#xml_metrics 
+         on:Transcript.
+    "
 ! !
 
 !MetricsReporter methodsFor:'accessing'!
 
 classMetricNames
-    ^ classMetricNames ? #( 'NOM' 'LOC' )
+    ^ classMetricNames ? (self class defaultClassMetricNames)
 !
 
-classMetricNames:something
-    classMetricNames := something.
+classMetricNames:aCollectionOfNames
+    "to overwrite the set of class metrics, which are to be measured and reported"
+
+    classMetricNames := aCollectionOfNames.
 !
 
 methodMetricNames
-    ^ methodMetricNames ? #( "'LOC'" )
+    ^ methodMetricNames ? (self class defaultMethodMetricNames )
 !
 
-methodMetricNames:something
-    methodMetricNames := something.
+methodMetricNames:aCollectionOfNames
+    "to overwrite the set of method metrics, which are to be measured and reported"
+
+    methodMetricNames := aCollectionOfNames.
 !
 
 packageMetricNames
-    ^ packageMetricNames ? #( 'LOC' )
+    ^ packageMetricNames ? self class defaultPackageMetricNames
 !
 
-packageMetricNames:something
-    packageMetricNames := something.
+packageMetricNames:aCollectionOfNames
+    "to overwrite the set of package metrics, which are to be measured and reported"
+
+    packageMetricNames := aCollectionOfNames.
 !
 
-packages:something
-    packages := something.
+packages:aCollectionOfPackages
+    "defines the packages, for which a report is generated"
+
+    packages := aCollectionOfPackages.
 !
 
-stream:something
-    stream := something.
+stream:aWriteStream
+    "sets the stream onto which the report is written"
+    
+    stream := aWriteStream.
 ! !
 
 !MetricsReporter methodsFor:'metric generation'!
@@ -299,11 +369,40 @@
 
 !MetricsReporter methodsFor:'reporting'!
 
+report
+    "report in the default format, which is the currently only supported format,
+            xml_metrics"
+
+    self report:#xml_metrics
+!
+
+report:formatSymbol
+    "formatSymbol controls, in what format the report is written.
+     currently supported formatSymbols:
+            xml_metrics"
+
+    |reportFormatSelector|
+
+    reportFormatSelector := self reportFormatSelector:formatSymbol.
+    (self respondsTo: reportFormatSelector)
+        ifTrue:[self perform: reportFormatSelector]
+        ifFalse:[self error:'Unsupported format: ', formatSymbol].
+
+    "Modified (comment): / 03-08-2011 / 12:57:54 / cg"
+!
+
 reportPackages: aCollectionOfPackages format: aSymbol on: aStream
 
     packages := aCollectionOfPackages.
     stream := aStream.
     self report: aSymbol
+
+    "    
+     MetricsReporter 
+         reportPackages:{ 'stx:libbasic' . 'stx:libbasic2' } 
+         format:#xml_metrics 
+         on:Transcript.
+    "
 ! !
 
 !MetricsReporter methodsFor:'reporting - xml-metrics'!
@@ -443,20 +542,6 @@
 
 !MetricsReporter methodsFor:'reporting-private'!
 
-report:formatSymbol
-    "currently supported formatSymbols:
-            xml_metrics"
-
-    |reportFormatSelector|
-
-    reportFormatSelector := self reportFormatSelector:formatSymbol.
-    (self respondsTo: reportFormatSelector)
-        ifTrue:[self perform: reportFormatSelector]
-        ifFalse:[self error:'Unsupported format: ', formatSymbol].
-
-    "Modified (comment): / 03-08-2011 / 12:57:54 / cg"
-!
-
 reportFormatSelector:format
     ^ ('report' , format asString asUppercaseFirst) asSymbol
 ! !