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