author | Claus Gittinger <cg@exept.de> |
Thu, 28 Mar 2019 13:54:38 +0100 | |
changeset 541 | aa25a71be62a |
parent 202 | 730a466fbe35 |
permissions | -rw-r--r-- |
73 | 1 |
"{ Package: 'stx:goodies/builder/reports' }" |
2 |
||
3 |
"{ NameSpace: Builder }" |
|
4 |
||
5 |
Object subclass:#ReportFormat |
|
6 |
instanceVariableNames:'report stream' |
|
7 |
classVariableNames:'' |
|
8 |
poolDictionaries:'' |
|
9 |
category:'Builder-Reports-Formats' |
|
10 |
! |
|
11 |
||
12 |
||
13 |
!ReportFormat class methodsFor:'instance creation'! |
|
14 |
||
15 |
named:aString |
|
16 |
"Return new format with given name. Name may be |
|
17 |
either class or symbolic name" |
|
18 |
||
19 |
self allSubclassesDo: |
|
20 |
[:cls | |
|
21 |
(cls isAbstract not and:[cls name = aString or:[ cls symbolicNames includes:aString ]]) |
|
22 |
ifTrue:[ ^ cls new ] ]. |
|
23 |
||
24 |
self error:'No format named ' , aString. |
|
25 |
||
26 |
" |
|
27 |
ReportFormat named: 'tap' |
|
28 |
ReportFormat named: 'JUnitFormat' |
|
29 |
ReportFormat named: 'NONEX' |
|
30 |
" |
|
31 |
||
32 |
"Created: / 04-08-2011 / 11:47:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
33 |
! |
|
34 |
||
35 |
new |
|
36 |
"return an initialized instance" |
|
37 |
||
38 |
^ self basicNew initialize. |
|
39 |
! ! |
|
40 |
||
41 |
!ReportFormat class methodsFor:'accessing'! |
|
42 |
||
43 |
symbolicNames |
|
44 |
"Returns a collection of symbolic names for this format" |
|
45 |
||
46 |
^ self subclassResponsibility |
|
47 |
||
48 |
"Modified (comment): / 04-08-2011 / 11:46:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
49 |
! ! |
|
50 |
||
51 |
!ReportFormat class methodsFor:'testing'! |
|
52 |
||
53 |
isAbstract |
|
54 |
||
55 |
^self == HDReportFormat |
|
56 |
||
57 |
"Created: / 04-08-2011 / 11:44:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
58 |
! ! |
|
59 |
||
60 |
!ReportFormat methodsFor:'accessing - defaults'! |
|
61 |
||
62 |
defaultFileSuffix |
|
63 |
||
64 |
^self subclassResponsibility |
|
65 |
||
66 |
"Created: / 04-08-2011 / 12:47:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
67 |
! ! |
|
68 |
||
69 |
!ReportFormat methodsFor:'initialization'! |
|
70 |
||
71 |
initialize |
|
72 |
"Invoked when a new instance is created." |
|
73 |
||
74 |
"/ please change as required (and remove this comment) |
|
75 |
"/ stream := nil. |
|
76 |
"/ suite := nil. |
|
77 |
||
78 |
"/ super initialize. -- commented since inherited method does nothing |
|
79 |
! |
|
80 |
||
81 |
report: aReport stream: aStream |
|
82 |
||
83 |
report := aReport. |
|
84 |
(aStream isKindOf: EncodedStream) ifTrue:[ |
|
85 |
stream := aStream. |
|
86 |
] ifFalse:[ |
|
89
b21b16d6c4f8
changed: #report:stream: - use XMLUTF8 encoder, if possible
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
73
diff
changeset
|
87 |
| encoder | |
b21b16d6c4f8
changed: #report:stream: - use XMLUTF8 encoder, if possible
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
73
diff
changeset
|
88 |
"Kludge since ISO10646_to_XMLUTF8 encoder may not be present" |
b21b16d6c4f8
changed: #report:stream: - use XMLUTF8 encoder, if possible
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
73
diff
changeset
|
89 |
|
b21b16d6c4f8
changed: #report:stream: - use XMLUTF8 encoder, if possible
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
73
diff
changeset
|
90 |
CharacterEncoderImplementations::ISO10646_to_XMLUTF8 notNil ifTrue:[ |
b21b16d6c4f8
changed: #report:stream: - use XMLUTF8 encoder, if possible
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
73
diff
changeset
|
91 |
CharacterEncoderImplementations::ISO10646_to_XMLUTF8 autoload. |
b21b16d6c4f8
changed: #report:stream: - use XMLUTF8 encoder, if possible
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
73
diff
changeset
|
92 |
encoder := CharacterEncoderImplementations::ISO10646_to_XMLUTF8 new. |
b21b16d6c4f8
changed: #report:stream: - use XMLUTF8 encoder, if possible
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
73
diff
changeset
|
93 |
] ifFalse:[ |
b21b16d6c4f8
changed: #report:stream: - use XMLUTF8 encoder, if possible
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
73
diff
changeset
|
94 |
encoder := CharacterEncoder encoderForUTF8. |
b21b16d6c4f8
changed: #report:stream: - use XMLUTF8 encoder, if possible
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
73
diff
changeset
|
95 |
]. |
b21b16d6c4f8
changed: #report:stream: - use XMLUTF8 encoder, if possible
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
73
diff
changeset
|
96 |
stream := EncodedStream stream: aStream encoder: encoder |
73 | 97 |
] |
98 |
||
99 |
"Created: / 03-08-2011 / 18:54:19 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
100 |
! ! |
|
101 |
||
102 |
!ReportFormat methodsFor:'stream - utilities'! |
|
103 |
||
104 |
stream |
|
105 |
||
106 |
^ stream |
|
107 |
||
108 |
! |
|
109 |
||
110 |
streamClose |
|
111 |
||
112 |
"Temporarily closes the stream" |
|
113 |
||
114 |
"stream is EncodedStream..." |
|
115 |
stream stream close. |
|
116 |
||
117 |
"Created: / 12-08-2011 / 09:30:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
118 |
! |
|
119 |
||
120 |
streamFlush |
|
121 |
||
122 |
"Temporarily closes the stream" |
|
123 |
||
124 |
"stream is EncodedStream..." |
|
125 |
stream stream flush. |
|
126 |
||
127 |
"Created: / 12-08-2011 / 09:35:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
128 |
! |
|
129 |
||
130 |
streamOpenForAppend |
|
131 |
||
132 |
"Open previously closes stream" |
|
133 |
||
134 |
| s | |
|
135 |
"stream is EncodedStream..." |
|
136 |
s := stream stream. |
|
137 |
s isExternalStream ifTrue:[ |
|
138 |
s isOpen ifTrue:[s close]. |
|
139 |
s openForWriting. |
|
140 |
s setToEnd. |
|
141 |
]. |
|
142 |
||
143 |
"Created: / 12-08-2011 / 09:31:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
144 |
! ! |
|
145 |
||
146 |
!ReportFormat methodsFor:'writing'! |
|
147 |
||
148 |
writeFooter |
|
149 |
"raise an error: must be redefined in concrete subclass(es)" |
|
150 |
||
151 |
^ self subclassResponsibility |
|
152 |
! |
|
153 |
||
154 |
writeHeader |
|
155 |
"raise an error: must be redefined in concrete subclass(es)" |
|
156 |
||
157 |
^ self subclassResponsibility |
|
158 |
! ! |
|
159 |
||
160 |
!ReportFormat methodsFor:'writing - utilities'! |
|
161 |
||
162 |
encode: aString |
|
163 |
||
164 |
^Report encode: aString |
|
165 |
||
166 |
"Created: / 03-08-2011 / 14:37:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
202
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
167 |
! |
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
168 |
|
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
169 |
writeCDATA: string |
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
170 |
| start stop | |
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
171 |
|
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
172 |
start := 1. |
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
173 |
stop := start. |
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
174 |
[ (stop := (string indexOf: $] startingAt: stop)) ~~ 0 ] whileTrue:[ |
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
175 |
((stop < (string size - 1)) |
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
176 |
and:[(string at: stop + 1) == $] |
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
177 |
and:[(string at: stop + 2) == $>]]) ifTrue:[ |
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
178 |
" Okay, found CDATA end token " |
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
179 |
stream nextPutAll: string startingAt: start to: stop + 1. |
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
180 |
stream nextPutAll: ']]><!![CDATA[>'. |
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
181 |
start := stop := stop + 3. |
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
182 |
] ifFalse:[ |
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
183 |
stop := stop + 1. |
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
184 |
]. |
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
185 |
]. |
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
186 |
start < string size ifTrue:[ |
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
187 |
stream nextPutAll: string startingAt: start to: string size. |
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
188 |
]. |
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
189 |
|
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
190 |
" |
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
191 |
String streamContents:[:s | Builder::TestReportFormat::JUnit new report: nil stream: s; writeCDATA:'ABCD'] |
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
192 |
String streamContents:[:s | Builder::TestReportFormat::JUnit new report: nil stream: s; writeCDATA:']]]]'] |
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
193 |
String streamContents:[:s | Builder::TestReportFormat::JUnit new report: nil stream: s; writeCDATA:'Some <[CDATA[ CDATA ]]> Some Text and stray terminator ]]> here'] |
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
194 |
" |
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
195 |
|
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
196 |
"Created: / 05-07-2013 / 16:54:24 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
73 | 197 |
! ! |
198 |
||
199 |
!ReportFormat class methodsFor:'documentation'! |
|
200 |
||
201 |
version |
|
202 |
^ '$Header$' |
|
203 |
! |
|
204 |
||
205 |
version_CVS |
|
206 |
^ '$Header$' |
|
207 |
! |
|
208 |
||
209 |
version_SVN |
|
202
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
210 |
^ '$Id$' |
73 | 211 |
! ! |
202
730a466fbe35
Temporary commit - improved line coverage reporting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
212 |