author | Claus Gittinger <cg@exept.de> |
Thu, 23 Nov 1995 02:58:09 +0100 | |
changeset 87 | e0f5b58481a6 |
parent 82 | e306d7662ae8 |
child 119 | 1a9c5a761edf |
permissions | -rw-r--r-- |
46 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by AEG Industry Automation |
|
3 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
4 |
All Rights Reserved |
|
5 |
||
6 |
This software is furnished under a license and may be used |
|
7 |
only in accordance with the terms of that license and with the |
|
8 |
inclusion of the above copyright notice. This software may not |
|
9 |
be provided or otherwise made available to, or used by, any |
|
10 |
other person. No title to or ownership of the software is |
|
11 |
hereby transferred. |
|
12 |
" |
|
13 |
||
41 | 14 |
Object subclass:#HistoryManager |
15 |
instanceVariableNames:'historyMode' |
|
16 |
classVariableNames:'TheOneAndOnlyInstance' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'System-Changes-History' |
|
19 |
! |
|
20 |
||
21 |
!HistoryManager class methodsFor:'documentation'! |
|
22 |
||
46 | 23 |
copyright |
24 |
" |
|
25 |
COPYRIGHT (c) 1995 by AEG Industry Automation |
|
26 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
27 |
All Rights Reserved |
|
28 |
||
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
41 | 38 |
documentation |
39 |
" |
|
40 |
This class is part of the |
|
41 |
----------------------- |
|
42 |
HistoryManagerProject. |
|
43 |
----------------------- |
|
44 |
It is used to create a multi user Smalltalk developers Environemt. |
|
45 |
||
46 |
All Methods and Classes in the system get a HistroyLine which contains a timestamp |
|
47 |
and the name of the Editor. This is acually the UniX loginname. |
|
48 |
The Manager registers all Classes in the System to get notifications on change. |
|
49 |
||
46 | 50 |
Author: Robert Sailer - AEG |
41 | 51 |
" |
52 |
! |
|
53 |
||
54 |
examples |
|
55 |
" |
|
56 |
HistoryManager new |
|
57 |
" |
|
58 |
"Modified: 11.08.1995 / 16:50:47 / robert" |
|
87 | 59 |
! |
60 |
||
61 |
version |
|
62 |
^ '$Header: /cvs/stx/stx/libbasic3/HistoryManager.st,v 1.12 1995-11-23 01:57:14 cg Exp $' |
|
41 | 63 |
! ! |
64 |
||
65 |
!HistoryManager class methodsFor:'initialization'! |
|
66 |
||
87 | 67 |
initMe |
68 |
"setup TheOneAndOnlyInstance (if not already present" |
|
69 |
^self new. |
|
70 |
||
71 |
"Modified: 14.08.1995 / 9:52:40 / robert" |
|
72 |
! |
|
73 |
||
41 | 74 |
initialize |
75 |
"" |
|
76 |
ObjectMemory addDependent: self. |
|
77 |
||
78 |
"Modified: 14.08.1995 / 9:49:56 / robert" |
|
79 |
! ! |
|
80 |
||
81 |
!HistoryManager class methodsFor:'instance creation'! |
|
82 |
||
83 |
new |
|
46 | 84 |
"because there can be only ONE HistoryManager, new must me redefiend" |
41 | 85 |
|
86 |
TheOneAndOnlyInstance isNil ifTrue:[ |
|
87 |
TheOneAndOnlyInstance := super new initialize. |
|
88 |
HistoryLine initialize. |
|
89 |
]. |
|
90 |
||
91 |
^ TheOneAndOnlyInstance |
|
92 |
||
93 |
" |
|
94 |
||
95 |
HistoryManager new. |
|
96 |
" |
|
97 |
||
98 |
"Modified: 11.08.1995 / 17:01:29 / robert" |
|
99 |
! ! |
|
100 |
||
101 |
!HistoryManager class methodsFor:'accessing'! |
|
102 |
||
103 |
instance |
|
104 |
"return the class variable" |
|
105 |
||
106 |
^TheOneAndOnlyInstance |
|
107 |
! |
|
108 |
||
109 |
isActive |
|
110 |
^TheOneAndOnlyInstance notNil |
|
111 |
||
112 |
"Modified: 27.8.1995 / 00:32:12 / claus" |
|
113 |
! ! |
|
114 |
||
115 |
!HistoryManager class methodsFor:'activation / deactivation'! |
|
116 |
||
117 |
activate |
|
118 |
self new "/ creating an instance activates me |
|
119 |
! |
|
120 |
||
121 |
deactivate |
|
122 |
Smalltalk allClassesDo:[:aClass | |
|
123 |
aClass removeDependent:TheOneAndOnlyInstance. |
|
124 |
aClass class removeDependent:TheOneAndOnlyInstance. |
|
125 |
]. |
|
126 |
TheOneAndOnlyInstance := nil. |
|
127 |
||
128 |
" |
|
129 |
HistoryManager release |
|
130 |
" |
|
131 |
! ! |
|
132 |
||
87 | 133 |
!HistoryManager class methodsFor:'change and update'! |
134 |
||
135 |
update: what |
|
136 |
(what == #restarted) ifTrue:[ |
|
137 |
TheOneAndOnlyInstance notNil ifTrue:[ |
|
138 |
" |
|
139 |
smalltalk is about to restart from an Image - |
|
140 |
" |
|
141 |
"/ 'HistoryManager initialize (via update)' infoPrintNL. |
|
142 |
self initMe. |
|
143 |
] |
|
144 |
]. |
|
145 |
||
146 |
"Modified: 27.8.1995 / 16:33:02 / claus" |
|
147 |
! ! |
|
148 |
||
47 | 149 |
!HistoryManager class methodsFor:'helpers'! |
150 |
||
151 |
getAllHistoriesFrom:someString |
|
152 |
"returns anArray of HistoryLines" |
|
153 |
||
154 |
|position aReadWriteStream firstFound nextFound aHistoryString rcOC h| |
|
155 |
||
156 |
"read begining from the end and look there for the first comment character. If there's none return" |
|
157 |
||
158 |
rcOC := OrderedCollection new. |
|
159 |
position := someString size. |
|
160 |
firstFound := false. |
|
161 |
nextFound := false. |
|
162 |
||
163 |
someString reverseDo:[ :aChar| |
|
164 |
position := position - 1. |
|
165 |
aChar = $" ifTrue:[ |
|
166 |
firstFound ifTrue:[ |
|
167 |
firstFound := false. |
|
168 |
nextFound := true. |
|
169 |
] ifFalse:[ |
|
170 |
aReadWriteStream := ReadWriteStream on: String new. |
|
171 |
firstFound := true. |
|
172 |
nextFound := false. |
|
173 |
]. |
|
174 |
]. |
|
175 |
(firstFound and: [nextFound not]) ifTrue:[ |
|
176 |
"now collect all up to the next comment character" |
|
177 |
aChar = $" ifFalse:[ |
|
178 |
aReadWriteStream nextPut: aChar. |
|
179 |
]. |
|
180 |
]. |
|
181 |
nextFound ifTrue:[ |
|
182 |
"End reached - now try to make a HistoryLine" |
|
183 |
aHistoryString := (aReadWriteStream contents) reverse. |
|
184 |
" |
|
185 |
Transcript showCr: aHistoryString. |
|
186 |
" |
|
187 |
h := HistoryLine fromString: aHistoryString at: position. |
|
188 |
h notNil ifTrue:[ |
|
189 |
rcOC add:h. |
|
190 |
]. |
|
191 |
"/ (aHistoryString startsWith: 'Modified:') ifTrue:[ |
|
192 |
"/ "a history line was found - now make a NewInstance of HistoryLine" |
|
193 |
"/ rcOC add: ( HistoryLine fromString: aHistoryString at: position). |
|
194 |
"/ ]. |
|
195 |
nextFound := false. |
|
196 |
]. |
|
197 |
]. |
|
198 |
||
199 |
^rcOC reverse "the OrderedCollection with HistoryLines in the right order" |
|
200 |
||
201 |
"Modified: 21.12.1993 / 18:32:30 / M.Noell" |
|
202 |
"Modified: 9.8.1995 / 22:45:30 / R.Sailer" |
|
203 |
"Modified: 8.9.1995 / 17:54:33 / claus" |
|
204 |
! ! |
|
205 |
||
41 | 206 |
!HistoryManager methodsFor:'accessing'! |
207 |
||
208 |
historyMode |
|
209 |
"return historyMode" |
|
210 |
||
211 |
^ historyMode |
|
212 |
||
213 |
"Modified: 11.08.1995 / 16:51:56 / robert" |
|
214 |
! |
|
215 |
||
216 |
historyMode:something |
|
217 |
"set historyMode" |
|
218 |
||
219 |
historyMode := something. |
|
220 |
||
221 |
"Modified: 11.08.1995 / 16:52:12 / robert" |
|
222 |
! ! |
|
223 |
||
224 |
!HistoryManager methodsFor:'initialization'! |
|
225 |
||
226 |
exclude |
|
46 | 227 |
"public - return an exclusionlist for some smalltalk classes which should not be notified or historisized" |
41 | 228 |
|
229 |
| oc | |
|
230 |
||
231 |
oc := OrderedCollection new. |
|
232 |
oc add: self. |
|
233 |
||
234 |
^oc |
|
235 |
||
236 |
"Modified: 11.08.1995 / 17:02:18 / robert" |
|
237 |
! |
|
238 |
||
239 |
initialize |
|
46 | 240 |
"public - make me depend on all smalltalk classes (except the exclusionList) |
241 |
to be notified later about changes. This intercepts source installation and allows |
|
242 |
be to patch the source-string with a historyLine." |
|
41 | 243 |
|
53 | 244 |
|exclusionlist| |
41 | 245 |
|
246 |
super initialize. |
|
247 |
historyMode := true. |
|
248 |
exclusionlist := self exclude. |
|
249 |
||
250 |
Smalltalk allClasses do:[:aClass| |
|
251 |
"all classes should send a notification if changed" |
|
252 |
"aClass = self " false ifFalse: [ |
|
253 |
(exclusionlist includes: aClass) ifFalse:[ |
|
254 |
aClass addDependent: self. |
|
255 |
aClass class addDependent: self. "for class methods" |
|
256 |
]. |
|
257 |
]. |
|
258 |
]. |
|
259 |
||
260 |
^self |
|
261 |
||
262 |
"Modified: 11.08.1995 / 17:12:51 / robert" |
|
263 |
! ! |
|
264 |
||
265 |
!HistoryManager methodsFor:'updateHistory'! |
|
266 |
||
267 |
addHistoryTo:someString |
|
268 |
"private - add a historyLine at end to the sourceCode; |
|
269 |
check for multiple lines of the same user and merge into one." |
|
270 |
||
53 | 271 |
| histLines pos wStream sourceCode previousHistories |
47 | 272 |
newLine | |
41 | 273 |
|
53 | 274 |
"Check whether we want a history to be added" |
275 |
historyMode ifFalse:[ |
|
276 |
^ someString |
|
277 |
]. |
|
47 | 278 |
previousHistories := self class getAllHistoriesFrom:someString. |
41 | 279 |
|
280 |
"extract source body." |
|
281 |
previousHistories isEmpty ifTrue: [ |
|
282 |
sourceCode := someString withoutSeparators. |
|
47 | 283 |
newLine := (HistoryLine newCreated). |
41 | 284 |
] ifFalse: [ |
285 |
pos := (previousHistories first) firstPositionInSourceCode. |
|
286 |
sourceCode := (someString copyFrom: 1 to: pos - 1) withoutSeparators. |
|
47 | 287 |
newLine := (HistoryLine new). |
41 | 288 |
]. |
289 |
||
290 |
"add the actual user's historyLine." |
|
47 | 291 |
previousHistories add:newLine. |
41 | 292 |
|
293 |
"Filtering historyLines each user with one entry)." |
|
294 |
histLines := HistoryLine filterHistoryLines: previousHistories. |
|
295 |
||
296 |
"create new body with added historyLine" |
|
297 |
wStream := WriteStream on: String new. |
|
298 |
wStream nextPutAll: sourceCode; cr. |
|
299 |
||
300 |
"append the historyLines to the source" |
|
301 |
wStream cr. |
|
302 |
histLines do: [:hl | |
|
303 |
wStream nextPutAll: hl printString; cr. |
|
304 |
]. |
|
305 |
||
306 |
^wStream contents. |
|
307 |
||
47 | 308 |
"Modified: 11.8.1995 / 16:51:50 / robert" |
309 |
"Modified: 8.9.1995 / 17:55:38 / claus" |
|
41 | 310 |
! |
311 |
||
53 | 312 |
addHistoryToHistoryMethodOf:aClass |
313 |
|cls historyMethod oldSource newSource| |
|
314 |
||
315 |
aClass isMeta ifFalse:[ |
|
316 |
cls := aClass class. |
|
317 |
] ifTrue:[ |
|
318 |
cls := aClass |
|
319 |
]. |
|
320 |
historyMethod := cls compiledMethodAt: #history. |
|
321 |
historyMethod notNil ifTrue:[ |
|
322 |
oldSource := historyMethod source. |
|
323 |
oldSource notNil ifTrue:[ |
|
68
5f7ac0b5c903
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
53
diff
changeset
|
324 |
newSource := self addHistoryTo:oldSource. |
5f7ac0b5c903
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
53
diff
changeset
|
325 |
historyMethod source:newSource. |
53 | 326 |
] |
327 |
] |
|
328 |
! |
|
329 |
||
41 | 330 |
update: something with: someArgument from: changedObject |
46 | 331 |
"public - sent whenever any class changed somehow. |
332 |
(something contains aSymbol or nil)" |
|
41 | 333 |
|
82
e306d7662ae8
oops - history line was only added to class methods
Claus Gittinger <cg@exept.de>
parents:
80
diff
changeset
|
334 |
| sourceCode aMethod fileInOrRecompiling ignore| |
41 | 335 |
|
336 |
"/ changedObject == self ifTrue:[ "for development only" |
|
337 |
"/ self halt. |
|
338 |
"/ ^self. |
|
339 |
"/ ]. |
|
46 | 340 |
|
341 |
fileInOrRecompiling := Class updateChangeFileQuerySignal raise. "Class updatingChanges." |
|
41 | 342 |
|
53 | 343 |
"/ changedObject isMeta ifTrue:[ |
43 | 344 |
"/ Transcript showCr: 'metaClass = ', changedObject printString. |
53 | 345 |
"/ ]. |
41 | 346 |
|
347 |
(changedObject == Smalltalk) & (something == #newClass) ifTrue:[ |
|
348 |
someArgument addDependent: self. |
|
349 |
someArgument class addDependent: self. "for class methods" |
|
350 |
]. |
|
351 |
||
352 |
fileInOrRecompiling ifFalse:[ |
|
42 | 353 |
"/ Transcript showCr: '* noChange in history'. |
53 | 354 |
^ self |
355 |
]. |
|
356 |
historyMode ifFalse:[ |
|
357 |
^ self |
|
41 | 358 |
]. |
359 |
||
360 |
" |
|
361 |
Class Variables |
|
362 |
" |
|
363 |
(something == #definition) ifTrue:[ |
|
53 | 364 |
"add handling for classes here ..." |
68
5f7ac0b5c903
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
53
diff
changeset
|
365 |
"/ self addHistoryToHistoryMethodOf:changedObject. |
41 | 366 |
]. |
367 |
||
368 |
"this is a sub item of #definition" |
|
369 |
(something == #classVariables) ifTrue:[ |
|
370 |
" |
|
371 |
Transcript showCr: 'classVariables changed'. |
|
372 |
" |
|
46 | 373 |
" das geht noch nicht, weil in someArgument nicht die Klasse steht die das betrifft" |
68
5f7ac0b5c903
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
53
diff
changeset
|
374 |
self addHistoryToHistoryMethodOf:changedObject. |
53 | 375 |
^ self |
41 | 376 |
]. |
377 |
||
378 |
" |
|
379 |
New Class creation |
|
380 |
" |
|
381 |
((changedObject == Smalltalk)and:[ (something == #newClass)]) ifTrue:[ |
|
382 |
" self in die Dependents eintragen damit die notification bei den Methoden kommt." |
|
383 |
someArgument addDependent: self. |
|
384 |
someArgument history: (self addHistoryTo:String new). "append historyString for new class" |
|
385 |
]. |
|
386 |
||
387 |
" |
|
388 |
Instance Handling |
|
389 |
" |
|
390 |
changedObject isBehavior ifTrue:[ |
|
391 |
something = #methodDictionary ifTrue:[ |
|
392 |
"SourceString der Methode holen" |
|
393 |
sourceCode := changedObject sourceCodeAt: someArgument. |
|
394 |
sourceCode isNil ifTrue:[ |
|
395 |
"method has been deleted" |
|
43 | 396 |
"/ Transcript showCr: 'method has been deleted'. |
41 | 397 |
] ifFalse:[ |
398 |
aMethod := changedObject compiledMethodAt: someArgument. |
|
82
e306d7662ae8
oops - history line was only added to class methods
Claus Gittinger <cg@exept.de>
parents:
80
diff
changeset
|
399 |
(changedObject isMeta not |
e306d7662ae8
oops - history line was only added to class methods
Claus Gittinger <cg@exept.de>
parents:
80
diff
changeset
|
400 |
or:[aMethod category ~= 'documentation']) ifTrue:[ |
e306d7662ae8
oops - history line was only added to class methods
Claus Gittinger <cg@exept.de>
parents:
80
diff
changeset
|
401 |
sourceCode := self addHistoryTo:sourceCode. |
e306d7662ae8
oops - history line was only added to class methods
Claus Gittinger <cg@exept.de>
parents:
80
diff
changeset
|
402 |
aMethod source: sourceCode. |
43 | 403 |
"/ Transcript showCr: 'history updated / added'. |
80 | 404 |
] |
41 | 405 |
]. |
406 |
^self |
|
407 |
]. |
|
408 |
||
409 |
something == #comment ifTrue:[ |
|
410 |
"in someArgument steht jetzt der alte kommentar" |
|
53 | 411 |
^ self. |
41 | 412 |
] ifFalse:[ |
413 |
"it is a class definition" |
|
43 | 414 |
"/ Transcript show: 'Class definition: ', changedObject printString;cr. |
68
5f7ac0b5c903
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
53
diff
changeset
|
415 |
self addHistoryToHistoryMethodOf:changedObject. |
41 | 416 |
]. |
417 |
]. |
|
418 |
||
419 |
^self |
|
420 |
||
43 | 421 |
"Modified: 27.8.1995 / 02:14:43 / claus" |
41 | 422 |
! ! |
423 |
||
424 |
HistoryManager initialize! |