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