#FEATURE
class: MetricsReporter
added:5 methods
removed:
#reportXml_metricValues:
#reportXml_metricsForClass:
#reportXml_metricsForMethod:
#reportXml_metricsForPackage:
comment/format in:
#documentation
#examples
#format_metrics
#reportPackages:format:on:
changed:
#reportXml_metrics
#supportedFormats
category of:
#generateClassMetricsFor:
#generateMethodMetricsFor:
#generatePackageMetricsFor:
#reportXml_metrics
--- a/MetricsReporter.st Fri Apr 01 00:05:58 2016 +0200
+++ b/MetricsReporter.st Fri Apr 01 14:23:52 2016 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
"
COPYRIGHT (c) 2012 by eXept Software AG
All Rights Reserved
@@ -49,9 +51,16 @@
documentation
"
this is used as a last step in jenkins automated builds.
+ see examples on how to generate an xml file containing code metrics information.
+ Call this after a build (see goodies/builder/quichSelfTest.st) and import from jenkins.
Currently supported formats are:
- #xml_metrics - a java metrics compatible format
+ #xml_xradar - an xradar metrics compatible format
+ see http://xradar.sourceforge.net/
+ (see http://grepcode.com/file/repo1.maven.org/maven2/net.sf.xradar/xradar/1.1.2/dtds/metrics.dtd)
+
+ #xml_metrics defaults to xradar
+
By default, the following metrics are generated:
per method:
@@ -76,7 +85,7 @@
[exBegin]
MetricsReporter
reportPackages:{ 'stx:libjavascript' }
- format:#xml_metrics
+ format:#xml_xradar
on:Transcript.
[exEnd]
@@ -84,7 +93,7 @@
String streamContents:[:stream |
MetricsReporter
reportPackages:{ 'stx:libjavascript' }
- format:#xml_metrics
+ format:#xml_xradar
on:stream.
].
[exEnd]
@@ -92,21 +101,21 @@
String streamContents:[:stream |
MetricsReporter
reportPackages:{ 'stx:libbasic*' }
- format:#xml_metrics
+ format:#xml_xradar
on:stream.
].
[exEnd]
[exBegin]
- 'metrics.xml' asFilename writingFileDo:[:stream |
+ 'xradar.xml' asFilename writingFileDo:[:stream |
MetricsReporter
reportPackages:{ 'stx:libjavascript' }
- format:#xml_metrics
+ format:#xml_xradar
on:stream.
].
[exEnd]
[exBegin]
- 'metrics.xml' asFilename writingFileDo:[:stream |
+ 'xradar.xml' asFilename writingFileDo:[:stream |
MetricsReporter
reportPackages:
{
@@ -114,12 +123,12 @@
'exept:expecco'
'exept:expecco/plugins/*'
}
- format:#xml_metrics
+ format:#xml_xradar
on:stream.
].
[exEnd]
- package metrics only:
+ package xradar only:
[exBegin]
MetricsReporter new
stream: Transcript;
@@ -131,7 +140,7 @@
classMetricNames: #();
methodMetricNames: #();
packageMetricNames: #( 'LOC' 'NOM' 'NOC');
- reportXml_metrics.
+ reportXml_xradar.
[exEnd]
[exBegin]
MetricsReporter new
@@ -190,6 +199,7 @@
format_metrics
"
+<-- from http://grepcode.com/file/repo1.maven.org/maven2/net.sf.xradar/xradar/1.1.2/dtds/metrics.dtd -->
<?xml version=""1.0"" encoding=""UTF-8"" ?>
<!!ELEMENT metrics (project)* >
@@ -234,7 +244,8 @@
"return a list of formats and short-info-string, as per supported format symbol"
^ #(
- (#'xml_metrics' 'xml format')
+ (#'xml_xradar' 'xradar xml format')
+ (#'xml_metrics' 'xml format (defaults to xradar)')
)
"Created: / 30-07-2011 / 10:18:18 / cg"
@@ -400,12 +411,28 @@
"
MetricsReporter
reportPackages:{ 'stx:libbasic' . 'stx:libbasic2' }
- format:#xml_metrics
+ format:#xml_xradar
on:Transcript.
"
! !
-!MetricsReporter methodsFor:'reporting - xml-metrics'!
+!MetricsReporter methodsFor:'reporting - xml-default'!
+
+reportXml_metrics
+ "invoked via perform, if the formatSymbol is #xml_metrics"
+
+ "
+ self new
+ stream:Transcript;
+ packages:#( 'exept:workflow' );
+ reportXml_metrics
+ "
+
+ ^ self reportXml_xradar
+! !
+
+
+!MetricsReporter methodsFor:'reporting-private'!
generateClassMetricsFor:aClass
^ self classMetricNames collect:[:metricName |
@@ -425,123 +452,6 @@
].
!
-reportXml_metricValues:metricValues
- |metricShortName metricLongName metricValue possibleErrorMessage|
-
- metricValues do:[:eachMetricInfo |
- metricShortName := eachMetricInfo shortName.
- metricLongName := eachMetricInfo longName.
- metricValue := eachMetricInfo metricValue.
- possibleErrorMessage := eachMetricInfo errorMessage.
- possibleErrorMessage notNil ifTrue:[
- metricLongName := metricLongName , '(Error: ',possibleErrorMessage,')'.
- ].
-
- stream nextPutLine: ' <measurement>'.
- stream nextPutLine: (' <short-name>%1</short-name>' bindWith:metricShortName).
- stream nextPutLine: (' <long-name>%1</long-name>' bindWith:metricLongName).
- stream nextPutLine: (' <value>%1</value>' bindWith:metricValue).
- stream nextPutLine: ' </measurement>'.
- ]
-!
-
-reportXml_metrics
- "invoked via perform, if the formatSymbol is #xml_metrics"
-
- "
- self new
- stream:Transcript;
- packages:#( 'exept:workflow' );
- reportXml_metrics
- "
-
- "/ need the exept-metrics package
- Smalltalk loadPackage:'exept:programming/oom'.
-
- packages do:[:eachPackageID |
- "/ if the package is a matchPattern, generate metrics for all loaded packages
- "/ which match that pattern.
- "/ Otherwise, make sure that this package is loaded and generate metrics for that
- "/ one only.
- eachPackageID includesMatchCharacters ifFalse:[
- Smalltalk loadPackage:eachPackageID.
- ].
- ].
-
- stream nextPutLine: '<?xml version="1.0"?>';
- nextPutLine: '<metrics>'.
-
- packages do:[:eachPackageID |
- "/ if the package is a matchPattern, generate metrics for all loaded packages
- "/ which match that pattern.
- "/ Otherwise, make sure that this package is loaded and generate metrics for that
- "/ one only.
- self reportXml_metricsForPackage:eachPackageID
- ].
- stream nextPutLine: '</metrics>'.
-!
-
-reportXml_metricsForClass:aClass
- stream nextPutLine: ' <class>'.
- stream nextPutLine: (' <name>%1</name>' bindWith:aClass name).
-
- self methodMetricNames notEmptyOrNil ifTrue:[
- aClass instAndClassMethodsDo:[:eachMethod |
- self reportXml_metricsForMethod:eachMethod
- ].
- ].
-
- self classMetricNames notEmptyOrNil ifTrue:[
- self reportXml_metricValues:(self generateClassMetricsFor:aClass).
- ].
-
- stream nextPutLine: ' </class>'.
-!
-
-reportXml_metricsForMethod:aMethod
- stream nextPutLine: ' <method>'.
- stream nextPutLine:(' <name>%1</name>' bindWith:aMethod selector).
-
- self reportXml_metricValues:(self generateMethodMetricsFor:aMethod).
-
- stream nextPutLine: ' </method>'.
-!
-
-reportXml_metricsForPackage:aPackageIDOrPattern
- |genMetricsForClass|
-
- genMetricsForClass :=
- [:aClass |
- Autoload autoloadFailedSignal handle:[:ex |
- ] do:[
- aClass autoload.
- self reportXml_metricsForClass:aClass
- ]
- ].
-
- stream nextPutLine: ' <project>'.
- stream nextPutLine: (' <name>%1</name>' bindWith:aPackageIDOrPattern).
-
- (self classMetricNames notEmptyOrNil
- or:[self methodMetricNames notEmptyOrNil]) ifTrue:[
- aPackageIDOrPattern includesMatchCharacters ifTrue:[
- Smalltalk allClasses do:[:eachClass |
- (eachClass package matches:aPackageIDOrPattern) ifTrue:[
- genMetricsForClass value:eachClass
- ].
- ].
- ] ifFalse:[
- Smalltalk allClassesInPackage:aPackageIDOrPattern do:genMetricsForClass.
- ].
- ].
-
- self reportXml_metricValues:(self generatePackageMetricsFor:aPackageIDOrPattern).
-
- stream nextPutLine: ' </project>'.
-! !
-
-!MetricsReporter methodsFor:'reporting-private'!
-
reportFormatSelector:format
^ ('report' , format asString asUppercaseFirst) asSymbol
! !