167
|
1 |
"{ Package: 'stx:goodies/builder/reports' }"
|
|
2 |
|
|
3 |
"{ NameSpace: Builder }"
|
|
4 |
|
|
5 |
ReportFormat subclass:#CoverageReportFormat
|
|
6 |
instanceVariableNames:''
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'Builder-Reports-Formats'
|
|
10 |
!
|
|
11 |
|
|
12 |
CoverageReportFormat subclass:#Cobertura
|
|
13 |
instanceVariableNames:'currentPackage currentClass currentMethod infos'
|
|
14 |
classVariableNames:''
|
|
15 |
poolDictionaries:''
|
|
16 |
privateIn:CoverageReportFormat
|
|
17 |
!
|
|
18 |
|
|
19 |
|
|
20 |
!CoverageReportFormat class methodsFor:'testing'!
|
|
21 |
|
|
22 |
isAbstract
|
|
23 |
|
|
24 |
^self == CoverageReportFormat
|
|
25 |
|
|
26 |
"Created: / 04-08-2011 / 11:44:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
27 |
"Modified: / 25-06-2013 / 01:26:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
28 |
! !
|
|
29 |
|
|
30 |
!CoverageReportFormat::Cobertura class methodsFor:'accessing'!
|
|
31 |
|
|
32 |
symbolicNames
|
|
33 |
"Returns a collection of symbolic names for this format"
|
|
34 |
|
|
35 |
^ self shouldImplement
|
|
36 |
! !
|
|
37 |
|
|
38 |
!CoverageReportFormat::Cobertura class methodsFor:'documentation'!
|
|
39 |
|
|
40 |
documentation
|
|
41 |
" }
|
|
42 |
|
|
43 |
Replace 'Object', 'NewClass1' and
|
|
44 |
the empty string arguments by true values.
|
|
45 |
|
|
46 |
Install (or change) the class by 'accepting',
|
|
47 |
either via the menu or the keyboard (usually CMD-A).
|
|
48 |
|
|
49 |
You can also change the category simply by editing
|
|
50 |
the categoryString and accepting.
|
|
51 |
|
|
52 |
To be nice to others (and yourself later), do not forget to
|
|
53 |
add some documentation; preferably under the classes documentation
|
|
54 |
protocol.
|
|
55 |
(see the `create documentation stubs' item in the methodList menu;
|
|
56 |
switch from instance to class to find this menu item.)
|
|
57 |
|
|
58 |
Notice, that ST/X uses the convention to document the class using
|
|
59 |
comment-only class methods (however, ST80 comments are supported and
|
|
60 |
can be changed via the class-documentation menu).
|
|
61 |
|
|
62 |
"
|
|
63 |
! !
|
|
64 |
|
|
65 |
!CoverageReportFormat::Cobertura methodsFor:'accessing - defaults'!
|
|
66 |
|
|
67 |
defaultFileSuffix
|
|
68 |
"superclass Builder::ReportFormat says that I am responsible to implement this method"
|
|
69 |
|
|
70 |
^ 'xml'
|
|
71 |
|
|
72 |
"Modified: / 25-06-2013 / 02:02:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
73 |
! !
|
|
74 |
|
|
75 |
!CoverageReportFormat::Cobertura methodsFor:'writing'!
|
|
76 |
|
|
77 |
write: instrumentedMethods
|
|
78 |
| packageMap |
|
|
79 |
|
|
80 |
packageMap := Dictionary new.
|
|
81 |
infos := Dictionary new.
|
|
82 |
instrumentedMethods do:[:method|
|
|
83 |
| classMap methodMap |
|
|
84 |
classMap := packageMap at: method package ifAbsentPut: [ Dictionary new ].
|
|
85 |
methodMap := classMap at: method mclass ifAbsentPut: [ Dictionary new ].
|
|
86 |
methodMap at: method selector put: method.
|
|
87 |
].
|
|
88 |
|
|
89 |
packageMap keys asSortedCollection do:[:package|
|
|
90 |
| classMap |
|
|
91 |
|
|
92 |
self writePackage: package with:[
|
|
93 |
((classMap := packageMap at: package) keys asSortedCollection:[:a :b| a name < b name ]) do:[:class|
|
|
94 |
| methodMap |
|
|
95 |
self writeClass: class with:[
|
|
96 |
(methodMap := classMap at: class) keys asSortedCollection do:[:selector|
|
|
97 |
| method |
|
|
98 |
|
|
99 |
method := methodMap at: selector.
|
|
100 |
self writeMethod: method.
|
|
101 |
]
|
|
102 |
]
|
|
103 |
]
|
|
104 |
]
|
|
105 |
]
|
|
106 |
|
|
107 |
"Created: / 25-06-2013 / 13:17:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
108 |
!
|
|
109 |
|
|
110 |
writeClass: class with: content
|
|
111 |
|
|
112 |
| className classFileName classPathName |
|
|
113 |
|
|
114 |
className := class name.
|
|
115 |
classFileName := class isPrivate
|
|
116 |
ifTrue:[Smalltalk fileNameForClass: class topOwningClass]
|
|
117 |
ifFalse:[classFileName := Smalltalk fileNameForClass: class].
|
|
118 |
class package ~~ currentPackage ifTrue:[
|
|
119 |
classFileName := 'extensions.st'
|
|
120 |
].
|
|
121 |
classPathName := ((currentPackage copyReplaceAll: $: with: Filename separator) replaceAll: $/ with: Filename separator)
|
|
122 |
, Filename separator , classFileName.
|
|
123 |
|
|
124 |
stream nextPutAll:' <class name="'; nextPutAll: className; nextPutAll: '" filename="'; nextPutAll: classPathName; nextPutLine:'" line-rate="1.0" branch-rate="1.0" complexity="1.0">'.
|
|
125 |
stream nextPutLine:' <methods>'.
|
|
126 |
currentClass := class.
|
|
127 |
content value.
|
|
128 |
currentClass := nil.
|
|
129 |
stream nextPutLine:' </methods>'.
|
|
130 |
stream nextPutLine:' </class>'
|
|
131 |
|
|
132 |
"Created: / 25-06-2013 / 12:29:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
133 |
!
|
|
134 |
|
|
135 |
writeFooter
|
|
136 |
stream nextPutAll:' </packages>
|
|
137 |
</coverage>'
|
|
138 |
|
|
139 |
"Modified: / 25-06-2013 / 11:57:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
140 |
!
|
|
141 |
|
|
142 |
writeHeader
|
|
143 |
stream nextPutAll:'<?xml version="1.0"?>
|
|
144 |
<!!--DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-03.dtd"-->
|
|
145 |
|
|
146 |
<coverage line-rate="1.0" branch-rate="1.0" version="1.9" timestamp="'; nextPutAll: Timestamp now utcSecondsSince1970 printString; nextPutAll:'">
|
|
147 |
<packages>'
|
|
148 |
|
|
149 |
"Modified: / 25-06-2013 / 11:56:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
150 |
!
|
|
151 |
|
|
152 |
writeLine: lineNr hits: nhits
|
|
153 |
|
|
154 |
stream nextPut:' <line number="'; nextPutAll: lineNr printString; nextPutAll:'" hits="'; nextPutAll: nhits printString; nextPutLine:'" branch="false" />'.
|
|
155 |
|
|
156 |
"Created: / 25-06-2013 / 13:04:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
157 |
"Modified: / 25-06-2013 / 14:23:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
158 |
!
|
|
159 |
|
|
160 |
writeMethod: method
|
|
161 |
|
|
162 |
| info firstCharOffset firstLineNr lastLineNr lines |
|
|
163 |
|
|
164 |
stream nextPutAll:' <method name="'; nextPutAll: method selector; nextPutLine: '" signature="()" line-rate="1.0" branch-rate="1.0" complexity="1.0">'.
|
|
165 |
stream nextPutLine:' <lines>'.
|
|
166 |
currentMethod := method.
|
|
167 |
|
|
168 |
info := infos at: method mclass ifAbsentPut:[ReportSourceInfo for: method mclass].
|
|
169 |
firstCharOffset := info offsetOfMethod: method.
|
|
170 |
firstLineNr := (info lineAndColumnOfOffset: firstCharOffset) x.
|
|
171 |
lastLineNr := (info lineAndColumnOfOffset: firstCharOffset + method source size) x.
|
|
172 |
|
|
173 |
lines := Array new: lastLineNr - firstLineNr + 1 withAll: method methodInvocationInfo count.
|
|
174 |
|
|
175 |
|
|
176 |
(method blockInvocationInfo copy sort:[:a :b | a startPosition < b startPosition]) do:[:eachBlockInfo |
|
|
177 |
| startLine endLine |
|
|
178 |
|
|
179 |
startLine := (info lineAndColumnOfOffset: firstCharOffset + eachBlockInfo startPosition - 1) x.
|
|
180 |
endLine := (info lineAndColumnOfOffset: firstCharOffset + eachBlockInfo endPosition - 1) x.
|
|
181 |
startLine to: endLine do:[:lineNr|
|
|
182 |
lines at: (lineNr - firstLineNr + 1) put: ((lines at: (lineNr - firstLineNr + 1)) min: eachBlockInfo count)
|
|
183 |
]
|
|
184 |
].
|
|
185 |
|
|
186 |
1 to: lines size do:[:i|
|
|
187 |
self writeLine: (i + firstLineNr - 1) hits: (lines at: i)
|
|
188 |
].
|
|
189 |
|
|
190 |
currentMethod := nil.
|
|
191 |
stream nextPutLine:' </lines>'.
|
|
192 |
stream nextPutLine:' </method>'
|
|
193 |
|
|
194 |
"Created: / 25-06-2013 / 13:17:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
195 |
"Modified: / 25-06-2013 / 14:51:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
196 |
!
|
|
197 |
|
|
198 |
writeMethod: method with: content
|
|
199 |
|
|
200 |
stream nextPutLine:' <method name="'; nextPutAll: method selector; nextPutAll: '" signature="()" line-rate="1.0" branch-rate="1.0" complexity="1.0">'.
|
|
201 |
stream nextPutLine:' <lines>'.
|
|
202 |
currentMethod := method.
|
|
203 |
content value.
|
|
204 |
currentMethod := nil.
|
|
205 |
stream nextPutLine:' </lines>'.
|
|
206 |
stream nextPutLine:' </method>'
|
|
207 |
|
|
208 |
"Created: / 25-06-2013 / 12:59:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
209 |
!
|
|
210 |
|
|
211 |
writePackage: packageName with: aBlock
|
|
212 |
|
|
213 |
stream nextPutAll:' <package name="'; nextPutAll: packageName; nextPutLine: '" line-rate="1.0" branch-rate="1.0" complexity="1.0">'.
|
|
214 |
stream nextPutLine:' <classes>'.
|
|
215 |
currentPackage := packageName.
|
|
216 |
aBlock value.
|
|
217 |
currentPackage := nil.
|
|
218 |
stream nextPutLine:' </classes>'.
|
|
219 |
stream nextPutLine:' </package>'
|
|
220 |
|
|
221 |
"Created: / 25-06-2013 / 11:55:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
222 |
"Modified: / 25-06-2013 / 13:24:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
223 |
! !
|
|
224 |
|
|
225 |
!CoverageReportFormat class methodsFor:'documentation'!
|
|
226 |
|
|
227 |
version
|
|
228 |
^ '$Header$'
|
|
229 |
!
|
|
230 |
|
|
231 |
version_CVS
|
|
232 |
^ '$Header$'
|
|
233 |
! !
|
|
234 |
|