author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Mon, 17 Sep 2012 21:34:55 +0000 | |
changeset 15 | 31a33727c629 |
parent 14 | d5b81c30785e |
child 17 | d387df3d4e46 |
permissions | -rw-r--r-- |
14 | 1 |
"{ Package: 'stx:goodies/cypress' }" |
2 |
||
15
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
3 |
CypressAbstractReaderWriter subclass:#CypressAbstractWriter |
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
4 |
instanceVariableNames:'' |
14 | 5 |
classVariableNames:'' |
6 |
poolDictionaries:'' |
|
7 |
category:'Cypress-New-Reader & Writer' |
|
8 |
! |
|
9 |
||
10 |
!CypressAbstractWriter class methodsFor:'documentation'! |
|
11 |
||
12 |
documentation |
|
13 |
" |
|
14 |
Base abstract class for writing code in Cypress format. Subclasses may |
|
15 |
implement various versions of the 'standard'. |
|
16 |
||
17 |
[author:] |
|
18 |
Jan Vrany <jan.vrany@fit.cvut.cz> |
|
19 |
||
20 |
[instance variables:] |
|
21 |
||
22 |
[class variables:] |
|
23 |
||
24 |
[see also:] |
|
25 |
CypressWriter |
|
26 |
||
27 |
" |
|
28 |
! ! |
|
29 |
||
30 |
!CypressAbstractWriter methodsFor:'accessing'! |
|
31 |
||
32 |
notice |
|
33 |
"Return the copyright notice to be written" |
|
34 |
||
35 |
^notice |
|
36 |
||
37 |
"Created: / 17-09-2012 / 17:18:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
38 |
! |
|
39 |
||
40 |
notice: aString |
|
41 |
"Sets the copyright notice to be written in each file" |
|
42 |
||
43 |
notice := aString. |
|
44 |
||
45 |
"Modified (comment): / 17-09-2012 / 17:19:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
46 |
! ! |
|
47 |
||
48 |
!CypressAbstractWriter methodsFor:'accessing-filenames'! |
|
49 |
||
50 |
directoryNameForClass: cclass |
|
51 |
^((cclass name copyReplaceAll: $: with: $_) , '.', self suffixForClass). |
|
52 |
||
53 |
"Created: / 17-09-2012 / 18:11:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
54 |
! |
|
55 |
||
56 |
directoryNameForExtensions: classname |
|
57 |
^((classname copyReplaceAll: $: with: $_) , '.', self suffixForExtensions). |
|
58 |
||
59 |
"Created: / 17-09-2012 / 18:27:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
60 |
! |
|
61 |
||
62 |
directoryNameForPackage: aCypressPackage |
|
63 |
||
64 |
^(aCypressPackage name copy |
|
65 |
replaceAll:$: with: $_; |
|
66 |
replaceAll:$/ with: $_; |
|
67 |
yourself) , '.' , self suffixForPackage |
|
68 |
||
69 |
"Created: / 17-09-2012 / 17:32:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
70 |
! |
|
71 |
||
72 |
fileNameForComment |
|
73 |
^repository properties at:'commentFile' ifAbsent:['README.md'] |
|
74 |
||
75 |
"Created: / 17-09-2012 / 18:07:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
76 |
! |
|
77 |
||
78 |
fileNameForMethod: cmethod |
|
79 |
^Dictionary new |
|
80 |
at: $/ put: '__quo__'; |
|
81 |
"/Add more..." |
|
82 |
||
83 |
at: cmethod selector ifAbsent:[ |
|
84 |
((cmethod selector copyReplaceAll:$: with: $.) , '.st') |
|
85 |
] |
|
86 |
||
87 |
"Created: / 17-09-2012 / 18:22:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
88 |
! |
|
89 |
||
90 |
filenameNameForProperties |
|
91 |
^'properties.ston' |
|
92 |
||
93 |
"Created: / 17-09-2012 / 17:38:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
94 |
! |
|
95 |
||
96 |
suffixForClass |
|
97 |
^'class' |
|
98 |
||
99 |
"Created: / 17-09-2012 / 18:09:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
100 |
! |
|
101 |
||
102 |
suffixForExtensions |
|
103 |
^'extension' |
|
104 |
||
105 |
"Created: / 17-09-2012 / 18:09:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
106 |
! |
|
107 |
||
108 |
suffixForPackage |
|
109 |
^'package' |
|
110 |
||
111 |
"Created: / 17-09-2012 / 18:09:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
112 |
! ! |
|
113 |
||
114 |
!CypressAbstractWriter methodsFor:'writing-model'! |
|
115 |
||
15
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
116 |
writeClass: cclass as: name to: directory |
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
117 |
"Writes a given 'cclass' into directory named 'name' under |
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
118 |
'directory'" |
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
119 |
|
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
120 |
self subclassResponsibility |
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
121 |
|
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
122 |
"Created: / 17-09-2012 / 22:19:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
123 |
! |
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
124 |
|
14 | 125 |
writeClass: cclass to: directory |
15
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
126 |
|
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
127 |
self writeClass: cclass |
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
128 |
as: (self directoryNameForClass: cclass) |
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
129 |
to: directory |
14 | 130 |
|
131 |
"Created: / 17-09-2012 / 18:40:53 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
132 |
! |
|
133 |
||
15
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
134 |
writeMethod: cmethod as: name to: directory |
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
135 |
"Writes a given 'cmethod' into directory named 'name' under |
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
136 |
'directory'" |
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
137 |
|
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
138 |
self subclassResponsibility |
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
139 |
|
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
140 |
"Created: / 17-09-2012 / 22:20:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
141 |
! |
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
142 |
|
14 | 143 |
writeMethod: cmethod to: directory |
15
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
144 |
|
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
145 |
self writeMethod: cmethod |
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
146 |
as: (self fileNameForMethod: cmethod) |
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
147 |
to: directory |
14 | 148 |
|
149 |
"Created: / 17-09-2012 / 18:40:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
150 |
! |
|
151 |
||
15
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
152 |
writePackage: cpackage as: name to: directory |
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
153 |
"Writes a given 'cpackage' into directory named 'name' under |
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
154 |
'directory'" |
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
155 |
|
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
156 |
self subclassResponsibility |
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
157 |
|
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
158 |
"Created: / 17-09-2012 / 22:15:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
159 |
! |
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
160 |
|
14 | 161 |
writePackage: cpackage to: directory |
15
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
162 |
|
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
163 |
self writePackage: cpackage |
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
164 |
as: (self directoryNameForPackage: cpackage) |
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
165 |
to: directory |
14 | 166 |
|
167 |
"Created: / 17-09-2012 / 17:34:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
168 |
! ! |
|
169 |
||
170 |
!CypressAbstractWriter methodsFor:'writing-utils'! |
|
171 |
||
172 |
writeClasses: classes to: directory |
|
173 |
"Writes my classes into 'directory' with given copyrightNotice" |
|
174 |
||
175 |
| obsolete | |
|
176 |
||
177 |
" collect possibly obsolete .class directories " |
|
178 |
obsolete := Set new. |
|
179 |
directory directoryContentsAsFilenamesDo:[:each| |
|
180 |
| suffix | |
|
181 |
||
182 |
each suffix = self suffixForClass ifTrue:[ |
|
183 |
obsolete add: each. |
|
184 |
] |
|
185 |
]. |
|
186 |
||
187 |
" write classes... " |
|
188 |
classes do:[:cclass| |
|
15
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
189 |
| cpsClsDir name | |
14 | 190 |
|
15
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
191 |
cpsClsDir := directory / (name := self directoryNameForClass: cclass). |
14 | 192 |
obsolete remove:cpsClsDir ifAbsent:[]. |
15
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
193 |
self writeClass: cclass as: name to: directory |
14 | 194 |
]. |
195 |
||
196 |
" wipe out obsolete .class directories " |
|
197 |
obsolete do:[:each| |
|
198 |
each recursiveRemove. |
|
199 |
]. |
|
200 |
||
201 |
"Created: / 17-09-2012 / 18:12:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
202 |
! |
|
203 |
||
204 |
writeComment: comment to: directory |
|
205 |
comment isNil ifTrue:[ ^ self ]. |
|
206 |
||
207 |
(directory / (self fileNameForComment)) writingFileDo:[:f| |
|
208 |
f nextPutAll: comment |
|
209 |
] |
|
210 |
||
211 |
"Created: / 17-09-2012 / 17:47:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
212 |
! |
|
213 |
||
214 |
writeExtensions: extensions to: directory |
|
215 |
"Writes extensions into 'directory'/file with given copyrightNotice" |
|
216 |
||
217 |
| obsolete extensionsPerClass | |
|
218 |
||
219 |
" group extensions by class... " |
|
220 |
extensionsPerClass := Dictionary new. |
|
221 |
extensions do:[:cpsMthd | |
|
222 |
(extensionsPerClass at: cpsMthd klass ifAbsentPut: [ Set new ]) |
|
223 |
add: cpsMthd. |
|
224 |
]. |
|
225 |
||
226 |
" collect possibly obsolete .extension directories " |
|
227 |
obsolete := Set new. |
|
228 |
directory directoryContentsAsFilenamesDo:[:each| |
|
229 |
| suffix | |
|
230 |
||
231 |
each suffix = 'extension' ifTrue:[ |
|
232 |
obsolete add: each. |
|
233 |
] |
|
234 |
]. |
|
235 |
||
236 |
" write individual extensions... " |
|
237 |
extensionsPerClass keysAndValuesDo:[:name :cpsMthds | |
|
238 |
| cpsClsDir cpsCls | |
|
239 |
||
240 |
cpsClsDir := directory / (self directoryNameForExtensions: name). |
|
241 |
obsolete remove: cpsClsDir ifAbsent:[]. |
|
242 |
cpsClsDir exists ifFalse: [ cpsClsDir makeDirectory ]. |
|
243 |
||
244 |
self writeMethods: cpsMthds to: cpsClsDir. |
|
245 |
]. |
|
246 |
||
247 |
" wipe out obsolete .class directories " |
|
248 |
obsolete do:[:each| |
|
249 |
each recursiveRemove. |
|
250 |
]. |
|
251 |
||
252 |
"Created: / 17-09-2012 / 18:29:29 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
253 |
! |
|
254 |
||
255 |
writeMethods: methods to:directory |
|
256 |
"Writes methods into given 'directory' with copyrightNotice in each file" |
|
257 |
||
258 |
| obsolete instDir classDir | |
|
259 |
||
260 |
instDir := directory / 'instance'. |
|
261 |
classDir := directory / 'class'. |
|
262 |
||
263 |
" collect possibly obsolete directories/files " |
|
264 |
obsolete := Set new. |
|
265 |
instDir exists ifTrue:[ |
|
266 |
obsolete add: instDir. |
|
267 |
obsolete addAll: instDir directoryContentsAsFilenames |
|
268 |
]. |
|
269 |
classDir exists ifTrue:[ |
|
270 |
obsolete add: classDir. |
|
271 |
obsolete addAll: classDir directoryContentsAsFilenames |
|
272 |
]. |
|
273 |
||
274 |
methods do:[:cpsMthd| |
|
15
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
275 |
| dir dottedSel file baseNameWithoutSuffix name| |
14 | 276 |
|
277 |
dir := cpsMthd meta ifTrue:[classDir] ifFalse:[instDir]. |
|
278 |
dir exists ifFalse:[ dir makeDirectory ]. |
|
15
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
279 |
file := dir / (name := self fileNameForMethod: cpsMthd). |
14 | 280 |
baseNameWithoutSuffix := file withoutSuffix baseName. |
15
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
281 |
self writeMethod: cpsMthd as: name to: dir. |
14 | 282 |
obsolete := obsolete reject:[:each| |
283 |
each withoutSuffix baseName = baseNameWithoutSuffix |
|
284 |
]. |
|
285 |
]. |
|
286 |
||
287 |
" wipe out obsolete directories / files " |
|
288 |
obsolete do:[:each| |
|
289 |
each exists ifTrue:[ each recursiveRemove ] |
|
290 |
]. |
|
291 |
||
292 |
"Created: / 17-09-2012 / 18:29:57 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
293 |
! |
|
294 |
||
295 |
writeProperties: properties to: directory |
|
296 |
| props propertyFile | |
|
297 |
||
298 |
props := properties copy. |
|
299 |
props isEmptyOrNil ifTrue:[ ^ self ]. |
|
300 |
propertyFile := directory / self filenameNameForProperties. |
|
301 |
||
302 |
" add notice " |
|
303 |
props at: '_cypress_copyright' put: notice. |
|
304 |
||
305 |
" be nice and do not discard properties of others. Merge them" |
|
306 |
propertyFile exists ifTrue:[ |
|
307 |
| existing | |
|
15
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
308 |
existing := CypressJSONReader parse: propertyFile. |
14 | 309 |
existing keysAndValuesDo:[:key :value| |
310 |
(props includesKey: key) ifFalse:[ |
|
311 |
props at: key put: value |
|
312 |
] |
|
313 |
] |
|
314 |
]. |
|
315 |
props isEmpty ifTrue:[ |
|
316 |
propertyFile exist ifTrue:[ |
|
317 |
propertyFile remove |
|
318 |
] |
|
319 |
] ifFalse:[ |
|
320 |
propertyFile writingFileDo:[:s| |
|
321 |
props writeCypressJsonOn: s forHtml: false indent: 0. |
|
322 |
] |
|
323 |
]. |
|
324 |
||
325 |
"Created: / 17-09-2012 / 17:38:47 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
326 |
! ! |
|
327 |
||
328 |
!CypressAbstractWriter class methodsFor:'documentation'! |
|
329 |
||
330 |
version_SVN |
|
331 |
^ '$Id:: $' |
|
332 |
! ! |