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