69
|
1 |
"{ Package: 'stx:goodies/builder/reports' }"
|
|
2 |
|
|
3 |
"{ NameSpace: Builder }"
|
|
4 |
|
|
5 |
Object subclass:#Report
|
|
6 |
instanceVariableNames:'name format'
|
|
7 |
classVariableNames:'Verbose OutputDir'
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'Builder-Reports'
|
|
10 |
!
|
|
11 |
|
|
12 |
|
|
13 |
!Report class methodsFor:'initialization'!
|
|
14 |
|
|
15 |
initialize
|
|
16 |
|
|
17 |
Verbose := false.
|
|
18 |
OutputDir := Filename currentDirectory.
|
|
19 |
|
|
20 |
"Created: / 14-03-2011 / 19:42:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
21 |
! !
|
|
22 |
|
|
23 |
!Report class methodsFor:'instance creation'!
|
|
24 |
|
|
25 |
new
|
|
26 |
"return an initialized instance"
|
|
27 |
|
|
28 |
^ self basicNew initialize.
|
|
29 |
! !
|
|
30 |
|
|
31 |
!Report class methodsFor:'accessing'!
|
|
32 |
|
|
33 |
outputDir
|
|
34 |
|
|
35 |
^OutputDir ? '.'
|
|
36 |
|
|
37 |
"
|
|
38 |
Report outputDir: '/tmp/reports'
|
|
39 |
"
|
|
40 |
|
|
41 |
"Created: / 07-10-2011 / 09:12:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
42 |
!
|
|
43 |
|
|
44 |
outputDir: aStringOrFilename
|
|
45 |
|
|
46 |
OutputDir := aStringOrFilename asFilename.
|
|
47 |
|
|
48 |
"
|
|
49 |
Report outputDir: '/tmp/reports'
|
|
50 |
"
|
|
51 |
|
|
52 |
"Created: / 14-03-2011 / 19:40:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
53 |
! !
|
|
54 |
|
|
55 |
!Report class methodsFor:'private'!
|
|
56 |
|
|
57 |
convert: aString
|
|
58 |
^ (aString asString
|
|
59 |
copyReplaceAll: (String with: Character cr with: Character lf) with: (String with: Character lf))
|
|
60 |
copyReplaceAll: (String with: Character cr) with: (String with: Character lf)
|
|
61 |
!
|
|
62 |
|
|
63 |
encode: aString
|
|
64 |
|
|
65 |
| in out c |
|
|
66 |
|
|
67 |
(aString includesAny: #($< $> $& $")) ifFalse:[^aString].
|
|
68 |
in := aString readStream.
|
|
69 |
out := String new writeStream.
|
|
70 |
[in atEnd ] whileFalse:[
|
|
71 |
c := in next.
|
|
72 |
c == $< ifTrue:[out nextPutAll:'<'] ifFalse:[
|
|
73 |
c == $> ifTrue:[out nextPutAll:'>'] ifFalse:[
|
|
74 |
c == $& ifTrue:[out nextPutAll:'&'] ifFalse:[
|
|
75 |
c == $" ifTrue:[out nextPutAll:'"'] ifFalse:[
|
|
76 |
out nextPut: c]]]]].
|
|
77 |
^out contents.
|
|
78 |
|
|
79 |
"
|
|
80 |
HDReport basicNew encode: 'abx'
|
|
81 |
HDReport basicNew encode: ''
|
|
82 |
HDReport basicNew encode: 'sss <clint>()'
|
|
83 |
"
|
|
84 |
|
|
85 |
"Modified: / 11-03-2011 / 17:12:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
86 |
!
|
|
87 |
|
|
88 |
encodeFilename: aString
|
|
89 |
|
|
90 |
^(aString copyReplaceAll: $: with:$_) copyReplaceAll: $/ with:$_
|
|
91 |
|
|
92 |
"Created: / 14-03-2011 / 14:14:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
93 |
"Modified: / 14-03-2011 / 23:45:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
94 |
! !
|
|
95 |
|
|
96 |
!Report class methodsFor:'running'!
|
|
97 |
|
|
98 |
runClasses: aCollectionOfClasses
|
|
99 |
|
|
100 |
^self runClasses: aCollectionOfClasses named: 'Some classes'
|
|
101 |
|
|
102 |
"Created: / 04-08-2011 / 12:25:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
103 |
!
|
|
104 |
|
|
105 |
runClasses: aCollectionOfClasses named: aString
|
|
106 |
|
|
107 |
^self new runClasses: aCollectionOfClasses named: aString
|
|
108 |
|
|
109 |
"Modified: / 04-08-2011 / 12:23:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
110 |
!
|
|
111 |
|
|
112 |
runPackage: aString
|
|
113 |
|
|
114 |
"Run a report for given package (package id)"
|
|
115 |
|
|
116 |
^self runPackages: (Array with: aString)
|
|
117 |
|
|
118 |
"Modified (comment): / 04-08-2011 / 12:24:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
119 |
!
|
|
120 |
|
|
121 |
runPackages: packages
|
|
122 |
|
|
123 |
"Run a report for given list of packages
|
|
124 |
(package IDs)"
|
|
125 |
|
|
126 |
^self new runPackages: packages
|
|
127 |
|
|
128 |
"Modified (comment): / 04-08-2011 / 12:24:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
129 |
!
|
|
130 |
|
|
131 |
verbose
|
|
132 |
|
|
133 |
^ Verbose
|
|
134 |
|
|
135 |
"Created: / 21-07-2011 / 11:48:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
136 |
!
|
|
137 |
|
|
138 |
verbose: aBoolean
|
|
139 |
|
|
140 |
Verbose := aBoolean.
|
|
141 |
|
|
142 |
"Created: / 21-07-2011 / 11:48:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
143 |
! !
|
|
144 |
|
|
145 |
!Report methodsFor:'accessing'!
|
|
146 |
|
|
147 |
format
|
|
148 |
^ format
|
|
149 |
!
|
|
150 |
|
|
151 |
format: aFormatOrString
|
|
152 |
|
|
153 |
aFormatOrString isString ifTrue:[
|
|
154 |
format := ReportFormat named: aFormatOrString
|
|
155 |
] ifFalse:[
|
|
156 |
format := aFormatOrString
|
|
157 |
]
|
|
158 |
|
|
159 |
"Created: / 04-08-2011 / 11:55:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
160 |
!
|
|
161 |
|
|
162 |
name
|
|
163 |
|
|
164 |
^name isNil ifTrue:[
|
|
165 |
self defaultName
|
|
166 |
] ifFalse:[
|
|
167 |
name
|
|
168 |
]
|
|
169 |
|
|
170 |
"Modified: / 07-11-2011 / 09:47:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
171 |
!
|
|
172 |
|
|
173 |
name:aString
|
|
174 |
name := aString.
|
|
175 |
!
|
|
176 |
|
|
177 |
outputDirectory
|
|
178 |
|
|
179 |
^self class outputDir asFilename
|
|
180 |
|
|
181 |
"Created: / 07-10-2011 / 09:12:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
182 |
! !
|
|
183 |
|
|
184 |
!Report methodsFor:'accessing-command line options'!
|
|
185 |
|
|
186 |
cmdlineOptionFormat
|
|
187 |
|
|
188 |
^CmdLineOption new
|
|
189 |
short: $F;
|
|
190 |
long: '--format';
|
|
191 |
description: 'Report format to use';
|
|
192 |
action:[:option | self format: option ]
|
|
193 |
|
|
194 |
"Created: / 06-11-2011 / 21:49:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
195 |
!
|
|
196 |
|
|
197 |
cmdlineOptionPackage
|
|
198 |
|
|
199 |
^CmdLineOption new
|
|
200 |
short: $p;
|
|
201 |
long: '--package';
|
|
202 |
description: 'Package in which to run the report';
|
|
203 |
action:[:option | self setupForPackages: { option } ]
|
|
204 |
|
|
205 |
"Created: / 06-11-2011 / 21:49:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
206 |
! !
|
|
207 |
|
|
208 |
!Report methodsFor:'accessing-defaults'!
|
|
209 |
|
|
210 |
defaultFileSuffix
|
|
211 |
|
|
212 |
"Return a default filename suffix. Note that format suffix will be
|
|
213 |
appended too if not file is explicitely specified"
|
|
214 |
|
|
215 |
^self subclassResponsibility
|
|
216 |
|
|
217 |
"Created: / 04-08-2011 / 12:47:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
218 |
!
|
|
219 |
|
|
220 |
defaultFormat
|
|
221 |
"raise an error: must be redefined in concrete subclass(es)"
|
|
222 |
|
|
223 |
^ self subclassResponsibility
|
|
224 |
!
|
|
225 |
|
|
226 |
defaultName
|
|
227 |
|
|
228 |
^self class name
|
|
229 |
|
|
230 |
"Created: / 07-11-2011 / 09:47:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
231 |
! !
|
|
232 |
|
|
233 |
!Report methodsFor:'initialization'!
|
|
234 |
|
|
235 |
setupForClasses: classes
|
|
236 |
"raise an error: must be redefined in concrete subclass(es)"
|
|
237 |
|
|
238 |
^ self subclassResponsibility
|
|
239 |
|
|
240 |
"Created: / 04-08-2011 / 14:34:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
241 |
!
|
|
242 |
|
|
243 |
setupForPackages:arg
|
|
244 |
"raise an error: must be redefined in concrete subclass(es)"
|
|
245 |
|
|
246 |
^ self subclassResponsibility
|
|
247 |
! !
|
|
248 |
|
|
249 |
!Report methodsFor:'private'!
|
|
250 |
|
|
251 |
convert:arg
|
|
252 |
^ self class convert:arg
|
|
253 |
!
|
|
254 |
|
|
255 |
encode:arg
|
|
256 |
^ self class encode:arg
|
|
257 |
!
|
|
258 |
|
|
259 |
encodeFilename:arg
|
|
260 |
^ self class encodeFilename:arg
|
|
261 |
! !
|
|
262 |
|
|
263 |
!Report methodsFor:'running'!
|
|
264 |
|
|
265 |
run
|
|
266 |
|
|
267 |
self setUp.
|
|
268 |
format writeHeader.
|
|
269 |
[ self runReport ] ensure:[
|
|
270 |
format writeFooter.
|
|
271 |
self tearDown.
|
|
272 |
]
|
|
273 |
|
|
274 |
"Modified: / 04-08-2011 / 12:42:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
275 |
!
|
|
276 |
|
|
277 |
runClasses:classes named:aString
|
|
278 |
name := aString.
|
|
279 |
self setupForClasses:classes.
|
|
280 |
self run
|
|
281 |
|
|
282 |
"Modified: / 04-08-2011 / 14:34:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
283 |
!
|
|
284 |
|
|
285 |
runPackage: package
|
|
286 |
|
|
287 |
^self runPackages: (Array with: package)
|
|
288 |
|
|
289 |
"Created: / 04-08-2011 / 12:53:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
290 |
!
|
|
291 |
|
|
292 |
runPackages:packages
|
|
293 |
packages size == 1
|
|
294 |
ifTrue:[ name := packages anyOne. ]
|
|
295 |
ifFalse:[ name := ('%1 packages' bindWith:packages size). ].
|
|
296 |
self setupForPackages:packages.
|
|
297 |
^ self run
|
|
298 |
|
|
299 |
"
|
|
300 |
HDTestReport runPackage:'stx:goodies/monticello'
|
|
301 |
HDTestReport runPackage:'stx:libjava'"
|
|
302 |
"Created: / 04-08-2011 / 12:35:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
303 |
!
|
|
304 |
|
|
305 |
runReport
|
|
306 |
"Actually run the report. What to do (what classes/packages to check)
|
|
307 |
must be stored instance variables"
|
|
308 |
|
|
309 |
^ self subclassResponsibility
|
|
310 |
|
|
311 |
"Created: / 04-08-2011 / 12:39:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
312 |
!
|
|
313 |
|
|
314 |
setUp
|
|
315 |
|
|
316 |
| stream |
|
|
317 |
format isNil ifTrue:[format := self defaultFormat].
|
|
318 |
stream := (OutputDir / (self encodeFilename: ('%1-%2.%3' bindWith: self name with: self defaultFileSuffix with: format defaultFileSuffix))) writeStream.
|
|
319 |
format report: self stream: stream
|
|
320 |
|
|
321 |
"Created: / 04-08-2011 / 12:43:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
322 |
!
|
|
323 |
|
|
324 |
tearDown
|
|
325 |
|
|
326 |
format streamFlush; streamClose.
|
|
327 |
|
|
328 |
"Created: / 04-08-2011 / 12:43:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
329 |
! !
|
|
330 |
|
|
331 |
!Report class methodsFor:'documentation'!
|
|
332 |
|
|
333 |
version
|
|
334 |
^ '$Header$'
|
|
335 |
!
|
|
336 |
|
|
337 |
version_CVS
|
|
338 |
^ '$Header$'
|
|
339 |
!
|
|
340 |
|
|
341 |
version_SVN
|
|
342 |
^ '§Id: Builder__Report.st 294 2011-11-27 11:08:02Z vranyj1 §'
|
|
343 |
! !
|
|
344 |
|
|
345 |
Report initialize!
|