author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Tue, 18 Sep 2012 13:49:14 +0000 | |
changeset 20 | cdf3ee8ceeaa |
parent 17 | d387df3d4e46 |
child 22 | 9086d6f7096a |
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 |
||
20 | 48 |
!CypressAbstractWriter methodsFor:'writing'! |
49 |
||
50 |
writePackage: cpackage as: name to: directory |
|
51 |
"Writes a given 'cpackage' into directory named 'name' under |
|
52 |
'directory'" |
|
53 |
||
54 |
self subclassResponsibility |
|
55 |
||
56 |
"Created: / 17-09-2012 / 22:15:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
57 |
! |
|
58 |
||
59 |
writePackage: cpackage to: directory |
|
60 |
||
61 |
self writePackage: cpackage |
|
62 |
as: (self defaultFileNameForClassPackageNamed:cpackage) |
|
63 |
to: directory |
|
64 |
||
65 |
"Created: / 17-09-2012 / 17:34:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
66 |
! ! |
|
67 |
||
68 |
!CypressAbstractWriter methodsFor:'writing-private'! |
|
14 | 69 |
|
15
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
70 |
writeClass: cclass as: name to: directory |
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
71 |
"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
|
72 |
'directory'" |
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
73 |
|
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
74 |
self subclassResponsibility |
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
75 |
|
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
76 |
"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
|
77 |
! |
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
78 |
|
17
d387df3d4e46
- CypressAbstractReaderWriter
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15
diff
changeset
|
79 |
writeClass: cclass to: directory |
d387df3d4e46
- CypressAbstractReaderWriter
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15
diff
changeset
|
80 |
|
d387df3d4e46
- CypressAbstractReaderWriter
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15
diff
changeset
|
81 |
self writeClass: cclass |
d387df3d4e46
- CypressAbstractReaderWriter
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15
diff
changeset
|
82 |
as: (self defaultFileNameForClassNamed:cclass name) |
d387df3d4e46
- CypressAbstractReaderWriter
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15
diff
changeset
|
83 |
to: directory |
d387df3d4e46
- CypressAbstractReaderWriter
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15
diff
changeset
|
84 |
|
d387df3d4e46
- CypressAbstractReaderWriter
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15
diff
changeset
|
85 |
"Created: / 17-09-2012 / 18:40:53 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
d387df3d4e46
- CypressAbstractReaderWriter
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15
diff
changeset
|
86 |
! |
d387df3d4e46
- CypressAbstractReaderWriter
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15
diff
changeset
|
87 |
|
14 | 88 |
writeClasses: classes to: directory |
89 |
"Writes my classes into 'directory' with given copyrightNotice" |
|
90 |
||
91 |
| obsolete | |
|
92 |
||
93 |
" collect possibly obsolete .class directories " |
|
94 |
obsolete := Set new. |
|
95 |
directory directoryContentsAsFilenamesDo:[:each| |
|
96 |
| suffix | |
|
97 |
||
17
d387df3d4e46
- CypressAbstractReaderWriter
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15
diff
changeset
|
98 |
each suffix = self defaultFileSuffixForClass ifTrue:[ |
14 | 99 |
obsolete add: each. |
100 |
] |
|
101 |
]. |
|
102 |
||
103 |
" write classes... " |
|
104 |
classes do:[:cclass| |
|
15
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
105 |
| cpsClsDir name | |
14 | 106 |
|
17
d387df3d4e46
- CypressAbstractReaderWriter
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15
diff
changeset
|
107 |
cpsClsDir := directory / (name := self defaultFileNameForClassNamed:cclass name). |
14 | 108 |
obsolete remove:cpsClsDir ifAbsent:[]. |
15
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
109 |
self writeClass: cclass as: name to: directory |
14 | 110 |
]. |
111 |
||
112 |
" wipe out obsolete .class directories " |
|
113 |
obsolete do:[:each| |
|
114 |
each recursiveRemove. |
|
115 |
]. |
|
116 |
||
117 |
"Created: / 17-09-2012 / 18:12:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
118 |
! |
|
119 |
||
120 |
writeComment: comment to: directory |
|
121 |
comment isNil ifTrue:[ ^ self ]. |
|
122 |
||
17
d387df3d4e46
- CypressAbstractReaderWriter
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15
diff
changeset
|
123 |
(directory / self defaultFileNameForComment) writingFileDo:[:f| |
14 | 124 |
f nextPutAll: comment |
125 |
] |
|
126 |
||
127 |
"Created: / 17-09-2012 / 17:47:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
128 |
! |
|
129 |
||
130 |
writeExtensions: extensions to: directory |
|
131 |
"Writes extensions into 'directory'/file with given copyrightNotice" |
|
132 |
||
133 |
| obsolete extensionsPerClass | |
|
134 |
||
135 |
" group extensions by class... " |
|
136 |
extensionsPerClass := Dictionary new. |
|
137 |
extensions do:[:cpsMthd | |
|
138 |
(extensionsPerClass at: cpsMthd klass ifAbsentPut: [ Set new ]) |
|
139 |
add: cpsMthd. |
|
140 |
]. |
|
141 |
||
142 |
" collect possibly obsolete .extension directories " |
|
143 |
obsolete := Set new. |
|
144 |
directory directoryContentsAsFilenamesDo:[:each| |
|
145 |
| suffix | |
|
146 |
||
147 |
each suffix = 'extension' ifTrue:[ |
|
148 |
obsolete add: each. |
|
149 |
] |
|
150 |
]. |
|
151 |
||
152 |
" write individual extensions... " |
|
153 |
extensionsPerClass keysAndValuesDo:[:name :cpsMthds | |
|
154 |
| cpsClsDir cpsCls | |
|
155 |
||
17
d387df3d4e46
- CypressAbstractReaderWriter
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15
diff
changeset
|
156 |
cpsClsDir := directory / (self defaultFileNameForClassExtensionsNamed:name). |
14 | 157 |
obsolete remove: cpsClsDir ifAbsent:[]. |
158 |
cpsClsDir exists ifFalse: [ cpsClsDir makeDirectory ]. |
|
159 |
||
160 |
self writeMethods: cpsMthds to: cpsClsDir. |
|
161 |
]. |
|
162 |
||
163 |
" wipe out obsolete .class directories " |
|
164 |
obsolete do:[:each| |
|
165 |
each recursiveRemove. |
|
166 |
]. |
|
167 |
||
168 |
"Created: / 17-09-2012 / 18:29:29 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
169 |
! |
|
170 |
||
20 | 171 |
writeMethod: cmethod as: name to: directory |
172 |
"Writes a given 'cmethod' into directory named 'name' under |
|
173 |
'directory'" |
|
174 |
||
175 |
self subclassResponsibility |
|
176 |
||
177 |
"Created: / 17-09-2012 / 22:20:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
178 |
! |
|
179 |
||
17
d387df3d4e46
- CypressAbstractReaderWriter
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15
diff
changeset
|
180 |
writeMethod: cmethod to: directory |
d387df3d4e46
- CypressAbstractReaderWriter
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15
diff
changeset
|
181 |
|
d387df3d4e46
- CypressAbstractReaderWriter
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15
diff
changeset
|
182 |
self writeMethod: cmethod |
d387df3d4e46
- CypressAbstractReaderWriter
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15
diff
changeset
|
183 |
as: (self defaultFileNameForMethodNamed:cmethod selector) |
d387df3d4e46
- CypressAbstractReaderWriter
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15
diff
changeset
|
184 |
to: directory |
d387df3d4e46
- CypressAbstractReaderWriter
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15
diff
changeset
|
185 |
|
d387df3d4e46
- CypressAbstractReaderWriter
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15
diff
changeset
|
186 |
"Created: / 17-09-2012 / 18:40:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
d387df3d4e46
- CypressAbstractReaderWriter
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15
diff
changeset
|
187 |
! |
d387df3d4e46
- CypressAbstractReaderWriter
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15
diff
changeset
|
188 |
|
14 | 189 |
writeMethods: methods to:directory |
190 |
"Writes methods into given 'directory' with copyrightNotice in each file" |
|
191 |
||
192 |
| obsolete instDir classDir | |
|
193 |
||
194 |
instDir := directory / 'instance'. |
|
195 |
classDir := directory / 'class'. |
|
196 |
||
197 |
" collect possibly obsolete directories/files " |
|
198 |
obsolete := Set new. |
|
199 |
instDir exists ifTrue:[ |
|
200 |
obsolete add: instDir. |
|
201 |
obsolete addAll: instDir directoryContentsAsFilenames |
|
202 |
]. |
|
203 |
classDir exists ifTrue:[ |
|
204 |
obsolete add: classDir. |
|
205 |
obsolete addAll: classDir directoryContentsAsFilenames |
|
206 |
]. |
|
207 |
||
208 |
methods do:[:cpsMthd| |
|
15
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
209 |
| dir dottedSel file baseNameWithoutSuffix name| |
14 | 210 |
|
211 |
dir := cpsMthd meta ifTrue:[classDir] ifFalse:[instDir]. |
|
212 |
dir exists ifFalse:[ dir makeDirectory ]. |
|
20 | 213 |
obsolete remove: dir ifAbsent:[]. |
17
d387df3d4e46
- CypressAbstractReaderWriter
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15
diff
changeset
|
214 |
file := dir / (name := self defaultFileNameForMethodNamed:cpsMthd selector). |
14 | 215 |
baseNameWithoutSuffix := file withoutSuffix baseName. |
15
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
216 |
self writeMethod: cpsMthd as: name to: dir. |
14 | 217 |
obsolete := obsolete reject:[:each| |
218 |
each withoutSuffix baseName = baseNameWithoutSuffix |
|
219 |
]. |
|
220 |
]. |
|
221 |
||
222 |
" wipe out obsolete directories / files " |
|
223 |
obsolete do:[:each| |
|
224 |
each exists ifTrue:[ each recursiveRemove ] |
|
225 |
]. |
|
226 |
||
227 |
"Created: / 17-09-2012 / 18:29:57 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
228 |
! |
|
229 |
||
230 |
writeProperties: properties to: directory |
|
231 |
| props propertyFile | |
|
232 |
||
233 |
props := properties copy. |
|
234 |
props isEmptyOrNil ifTrue:[ ^ self ]. |
|
17
d387df3d4e46
- CypressAbstractReaderWriter
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15
diff
changeset
|
235 |
propertyFile := directory / self defaultFileNameForProperties. |
14 | 236 |
|
237 |
" add notice " |
|
238 |
props at: '_cypress_copyright' put: notice. |
|
239 |
||
240 |
" be nice and do not discard properties of others. Merge them" |
|
241 |
propertyFile exists ifTrue:[ |
|
242 |
| existing | |
|
15
31a33727c629
- Getting rid of old Cypress implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14
diff
changeset
|
243 |
existing := CypressJSONReader parse: propertyFile. |
14 | 244 |
existing keysAndValuesDo:[:key :value| |
245 |
(props includesKey: key) ifFalse:[ |
|
246 |
props at: key put: value |
|
247 |
] |
|
248 |
] |
|
249 |
]. |
|
250 |
props isEmpty ifTrue:[ |
|
251 |
propertyFile exist ifTrue:[ |
|
252 |
propertyFile remove |
|
253 |
] |
|
254 |
] ifFalse:[ |
|
255 |
propertyFile writingFileDo:[:s| |
|
256 |
props writeCypressJsonOn: s forHtml: false indent: 0. |
|
257 |
] |
|
258 |
]. |
|
259 |
||
260 |
"Created: / 17-09-2012 / 17:38:47 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
261 |
! ! |
|
262 |
||
263 |
!CypressAbstractWriter class methodsFor:'documentation'! |
|
264 |
||
265 |
version_SVN |
|
266 |
^ '$Id:: $' |
|
267 |
! ! |