author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 26 Jun 2013 23:47:46 +0200 | |
changeset 182 | 556ad4c2c381 |
parent 167 | 394b26be9d47 |
child 183 | 4e6fc1b6c282 |
permissions | -rw-r--r-- |
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 |
|
182
556ad4c2c381
class: Builder::CoverageReportFormat
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
167
diff
changeset
|
116 |
ifTrue:[(Smalltalk fileNameForClass: class topOwningClass) , '.st'] |
556ad4c2c381
class: Builder::CoverageReportFormat
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
167
diff
changeset
|
117 |
ifFalse:[(Smalltalk fileNameForClass: class) , '.st']. |
167 | 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>" |
|
182
556ad4c2c381
class: Builder::CoverageReportFormat
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
167
diff
changeset
|
133 |
"Modified: / 26-06-2013 / 17:46:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
167 | 134 |
! |
135 |
||
136 |
writeFooter |
|
137 |
stream nextPutAll:' </packages> |
|
138 |
</coverage>' |
|
139 |
||
140 |
"Modified: / 25-06-2013 / 11:57:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
141 |
! |
|
142 |
||
143 |
writeHeader |
|
144 |
stream nextPutAll:'<?xml version="1.0"?> |
|
145 |
<!!--DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-03.dtd"--> |
|
146 |
||
182
556ad4c2c381
class: Builder::CoverageReportFormat
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
167
diff
changeset
|
147 |
<coverage line-rate="1.0" branch-rate="1.0" version="1.9" timestamp="'; nextPutAll: Timestamp now utcSecondsSince1970 printString; nextPutLine:'">'. |
556ad4c2c381
class: Builder::CoverageReportFormat
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
167
diff
changeset
|
148 |
stream nextPutLine:' <sources>'. |
556ad4c2c381
class: Builder::CoverageReportFormat
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
167
diff
changeset
|
149 |
Smalltalk packagePath do:[:each| |
556ad4c2c381
class: Builder::CoverageReportFormat
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
167
diff
changeset
|
150 |
stream |
556ad4c2c381
class: Builder::CoverageReportFormat
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
167
diff
changeset
|
151 |
nextPutAll: '<source>'; |
556ad4c2c381
class: Builder::CoverageReportFormat
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
167
diff
changeset
|
152 |
nextPutAll: each asFilename asAbsoluteFilename pathName; |
556ad4c2c381
class: Builder::CoverageReportFormat
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
167
diff
changeset
|
153 |
nextPutAll: '</source>'; |
556ad4c2c381
class: Builder::CoverageReportFormat
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
167
diff
changeset
|
154 |
cr. |
556ad4c2c381
class: Builder::CoverageReportFormat
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
167
diff
changeset
|
155 |
]. |
556ad4c2c381
class: Builder::CoverageReportFormat
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
167
diff
changeset
|
156 |
stream nextPutLine:' </sources>'. |
556ad4c2c381
class: Builder::CoverageReportFormat
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
167
diff
changeset
|
157 |
stream nextPutLine:' <packages>'. |
167 | 158 |
|
182
556ad4c2c381
class: Builder::CoverageReportFormat
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
167
diff
changeset
|
159 |
"Modified: / 26-06-2013 / 17:50:24 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
167 | 160 |
! |
161 |
||
162 |
writeLine: lineNr hits: nhits |
|
163 |
||
164 |
stream nextPut:' <line number="'; nextPutAll: lineNr printString; nextPutAll:'" hits="'; nextPutAll: nhits printString; nextPutLine:'" branch="false" />'. |
|
165 |
||
166 |
"Created: / 25-06-2013 / 13:04:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
167 |
"Modified: / 25-06-2013 / 14:23:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
168 |
! |
|
169 |
||
170 |
writeMethod: method |
|
171 |
||
172 |
| info firstCharOffset firstLineNr lastLineNr lines | |
|
173 |
||
174 |
stream nextPutAll:' <method name="'; nextPutAll: method selector; nextPutLine: '" signature="()" line-rate="1.0" branch-rate="1.0" complexity="1.0">'. |
|
175 |
stream nextPutLine:' <lines>'. |
|
176 |
currentMethod := method. |
|
177 |
||
178 |
info := infos at: method mclass ifAbsentPut:[ReportSourceInfo for: method mclass]. |
|
179 |
firstCharOffset := info offsetOfMethod: method. |
|
180 |
firstLineNr := (info lineAndColumnOfOffset: firstCharOffset) x. |
|
181 |
lastLineNr := (info lineAndColumnOfOffset: firstCharOffset + method source size) x. |
|
182 |
||
183 |
lines := Array new: lastLineNr - firstLineNr + 1 withAll: method methodInvocationInfo count. |
|
184 |
||
185 |
||
186 |
(method blockInvocationInfo copy sort:[:a :b | a startPosition < b startPosition]) do:[:eachBlockInfo | |
|
187 |
| startLine endLine | |
|
188 |
||
189 |
startLine := (info lineAndColumnOfOffset: firstCharOffset + eachBlockInfo startPosition - 1) x. |
|
190 |
endLine := (info lineAndColumnOfOffset: firstCharOffset + eachBlockInfo endPosition - 1) x. |
|
191 |
startLine to: endLine do:[:lineNr| |
|
192 |
lines at: (lineNr - firstLineNr + 1) put: ((lines at: (lineNr - firstLineNr + 1)) min: eachBlockInfo count) |
|
193 |
] |
|
194 |
]. |
|
195 |
||
196 |
1 to: lines size do:[:i| |
|
197 |
self writeLine: (i + firstLineNr - 1) hits: (lines at: i) |
|
198 |
]. |
|
199 |
||
200 |
currentMethod := nil. |
|
201 |
stream nextPutLine:' </lines>'. |
|
202 |
stream nextPutLine:' </method>' |
|
203 |
||
204 |
"Created: / 25-06-2013 / 13:17:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
205 |
"Modified: / 25-06-2013 / 14:51:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
206 |
! |
|
207 |
||
208 |
writeMethod: method with: content |
|
209 |
||
182
556ad4c2c381
class: Builder::CoverageReportFormat
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
167
diff
changeset
|
210 |
stream nextPutLine:' <method name="'; nextPutAll: method selector; nextPutAll: '" signature="" line-rate="1.0" branch-rate="1.0" complexity="1.0">'. |
167 | 211 |
stream nextPutLine:' <lines>'. |
212 |
currentMethod := method. |
|
213 |
content value. |
|
214 |
currentMethod := nil. |
|
215 |
stream nextPutLine:' </lines>'. |
|
216 |
stream nextPutLine:' </method>' |
|
217 |
||
218 |
"Created: / 25-06-2013 / 12:59:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
182
556ad4c2c381
class: Builder::CoverageReportFormat
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
167
diff
changeset
|
219 |
"Modified: / 26-06-2013 / 18:22:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
167 | 220 |
! |
221 |
||
222 |
writePackage: packageName with: aBlock |
|
223 |
||
224 |
stream nextPutAll:' <package name="'; nextPutAll: packageName; nextPutLine: '" line-rate="1.0" branch-rate="1.0" complexity="1.0">'. |
|
225 |
stream nextPutLine:' <classes>'. |
|
226 |
currentPackage := packageName. |
|
227 |
aBlock value. |
|
228 |
currentPackage := nil. |
|
229 |
stream nextPutLine:' </classes>'. |
|
230 |
stream nextPutLine:' </package>' |
|
231 |
||
232 |
"Created: / 25-06-2013 / 11:55:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
233 |
"Modified: / 25-06-2013 / 13:24:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
234 |
! ! |
|
235 |
||
236 |
!CoverageReportFormat class methodsFor:'documentation'! |
|
237 |
||
238 |
version |
|
239 |
^ '$Header$' |
|
240 |
! |
|
241 |
||
242 |
version_CVS |
|
243 |
^ '$Header$' |
|
244 |
! ! |
|
245 |