author | Claus Gittinger <cg@exept.de> |
Sun, 12 May 2019 13:22:00 +0200 | |
changeset 4421 | d992c2e999b4 |
parent 4346 | 6604af2f1554 |
child 4541 | b08f22706921 |
permissions | -rw-r--r-- |
2653 | 1 |
" |
2 |
COPYRIGHT (c) 2011 by Claus Gittinger |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
"{ Package: 'stx:libbasic3' }" |
|
13 |
||
4082 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
2653 | 16 |
AbstractSourceCodeManager subclass:#FileBasedSourceCodeManager |
17 |
instanceVariableNames:'' |
|
4224 | 18 |
classVariableNames:'ModulePathes RepositoryPath Verbose' |
2653 | 19 |
poolDictionaries:'' |
20 |
category:'System-SourceCodeManagement' |
|
21 |
! |
|
22 |
||
23 |
!FileBasedSourceCodeManager class methodsFor:'documentation'! |
|
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 2011 by Claus Gittinger |
|
28 |
All Rights Reserved |
|
29 |
||
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
39 |
documentation |
|
40 |
" |
|
41 |
A simple file based sourceCodeManager, which saves versions in a local directory. |
|
42 |
Versions will be stored as filename.st.vNr (i.e. Foo.st.1, Foo.st.2, etc.) |
|
2672 | 43 |
|
44 |
This is more an example of the protocol which needs to be implemented, |
|
45 |
than a real manager (although it may be useful for tiny private projects or classroom examples) |
|
46 |
||
2653 | 47 |
[author:] |
48 |
Claus Gittinger |
|
49 |
" |
|
50 |
! ! |
|
51 |
||
52 |
!FileBasedSourceCodeManager class methodsFor:'accessing'! |
|
53 |
||
2672 | 54 |
getRepositoryPathForModule:aModuleName |
55 |
"internal: used when accessing a source repository. |
|
56 |
Return the path to the top directory for a particular module. |
|
57 |
If no specific path was defined for that module, return the value of |
|
58 |
the global (fallBack) repositoryPath. |
|
4082 | 59 |
Nil is returned if no repository is available." |
2672 | 60 |
|
61 |
ModulePathes isNil ifTrue:[^ RepositoryPath]. |
|
62 |
aModuleName isNil ifTrue:[^ RepositoryPath]. |
|
63 |
^ ModulePathes at:aModuleName ifAbsent:RepositoryPath. |
|
64 |
||
65 |
"Modified: / 20-05-1998 / 16:30:12 / cg" |
|
66 |
"Created: / 21-12-2011 / 23:05:51 / cg" |
|
67 |
! |
|
68 |
||
2653 | 69 |
knownModules |
70 |
"return the modules, we currently know" |
|
71 |
||
2685 | 72 |
ModulePathes isEmptyOrNil ifTrue:[^ #() ]. |
2653 | 73 |
^ ModulePathes keys |
74 |
||
2685 | 75 |
"Modified: / 26-12-2011 / 00:49:10 / cg" |
2653 | 76 |
! |
77 |
||
2672 | 78 |
repositoryInfoPerModule |
4082 | 79 |
"return the dictionary, which associates repository paths to module names. |
2672 | 80 |
If no entry is contained in this dictionary for some module, |
81 |
the default path will be used." |
|
82 |
||
83 |
^ ModulePathes ? #() |
|
84 |
||
85 |
"Created: / 22-12-2011 / 00:35:32 / cg" |
|
86 |
! |
|
87 |
||
88 |
repositoryInfoPerModule:aDictionary |
|
4082 | 89 |
"set the dictionary, which associates repository paths to module names. |
2672 | 90 |
If no entry is contained in this dictionary for some module, |
91 |
the default path will be used." |
|
92 |
||
93 |
ModulePathes := aDictionary |
|
94 |
||
95 |
"Created: / 22-12-2011 / 00:34:52 / cg" |
|
96 |
! |
|
97 |
||
2653 | 98 |
repositoryPath |
99 |
"return the path of the default repository" |
|
100 |
||
101 |
^ RepositoryPath |
|
102 |
||
103 |
"Created: / 21-12-2011 / 14:55:12 / cg" |
|
2672 | 104 |
! |
105 |
||
106 |
repositoryPath:aPath |
|
107 |
"set the path of the default repository" |
|
108 |
||
109 |
RepositoryPath := aPath |
|
110 |
||
111 |
"Created: / 22-12-2011 / 00:30:19 / cg" |
|
2653 | 112 |
! ! |
113 |
||
114 |
!FileBasedSourceCodeManager class methodsFor:'queries'! |
|
115 |
||
2672 | 116 |
defaultRepositoryPath |
117 |
^ './repository' |
|
118 |
||
119 |
"Created: / 21-12-2011 / 23:59:52 / cg" |
|
120 |
! |
|
121 |
||
2653 | 122 |
enabled |
123 |
^ true "/ false. |
|
124 |
||
125 |
"Created: / 21-12-2011 / 17:53:34 / cg" |
|
126 |
! |
|
127 |
||
128 |
isContainerBased |
|
129 |
"true, if the SCM uses some kind of source container (,v files). |
|
130 |
False, if it is like a database or filesystem." |
|
131 |
||
132 |
^ false |
|
133 |
||
134 |
"Created: / 21-12-2011 / 18:53:55 / cg" |
|
135 |
! |
|
136 |
||
137 |
isResponsibleForPackage:aString |
|
2672 | 138 |
^ true. |
2653 | 139 |
|
140 |
"Created: / 09-07-2011 / 14:32:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2672 | 141 |
"Modified (comment): / 22-12-2011 / 00:05:54 / cg" |
2653 | 142 |
! |
143 |
||
144 |
managerTypeName |
|
145 |
^ 'FileRepository' |
|
146 |
||
147 |
"Created: / 16-08-2006 / 11:05:56 / cg" |
|
148 |
! |
|
149 |
||
150 |
nameOfVersionMethodForExtensions |
|
151 |
^ #'extensionsVersion_FileRepository' |
|
152 |
||
153 |
"Modified: / 21-12-2011 / 13:02:45 / cg" |
|
154 |
! |
|
155 |
||
156 |
nameOfVersionMethodInClasses |
|
157 |
^ #'version_FileRepository' |
|
158 |
||
159 |
"Modified: / 21-12-2011 / 13:02:52 / cg" |
|
160 |
! |
|
161 |
||
2672 | 162 |
repositoryNameForPackage:packageId |
163 |
"superclass AbstractSourceCodeManager class says that I am responsible to implement this method" |
|
2653 | 164 |
|
2672 | 165 |
^ self getRepositoryPathForModule:(packageId upTo:$: ) |
2653 | 166 |
|
2672 | 167 |
"Created: / 21-12-2011 / 23:07:02 / cg" |
2653 | 168 |
! |
169 |
||
170 |
settingsApplicationClass |
|
171 |
"link to my settings application (needed for the settings dialog" |
|
172 |
||
173 |
^ FileBasedSourceCodeManagementSettingsAppl |
|
174 |
||
175 |
"Created: / 19-04-2011 / 12:43:29 / cg" |
|
176 |
"Modified: / 21-12-2011 / 13:02:58 / cg" |
|
177 |
! |
|
178 |
||
179 |
supportsCheckinLogMessages |
|
180 |
"no, log-messages are not supported (I am too stupid)" |
|
181 |
||
182 |
^ false |
|
183 |
||
184 |
"Created: / 21-12-2011 / 18:02:42 / cg" |
|
185 |
! ! |
|
186 |
||
187 |
!FileBasedSourceCodeManager class methodsFor:'saving'! |
|
188 |
||
189 |
savePreferencesOn:aStream |
|
2672 | 190 |
aStream nextPutLine:'FileBasedSourceCodeManager notNil ifTrue:['. |
191 |
self repositoryInfoPerModule notEmptyOrNil ifTrue:[ |
|
192 |
aStream nextPutLine:' FileBasedSourceCodeManager repositoryInfoPerModule:' , self repositoryInfoPerModule storeString , '.'. |
|
193 |
]. |
|
194 |
(Smalltalk at:#SourceCodeManager) == self ifTrue:[ |
|
195 |
aStream nextPutLine:' Smalltalk at:#SourceCodeManager put:FileBasedSourceCodeManager.'. |
|
196 |
]. |
|
197 |
aStream nextPutLine:' FileBasedSourceCodeManager repositoryPath:' , self repositoryPath storeString , '.'. |
|
198 |
aStream nextPutLine:'].'. |
|
2653 | 199 |
|
200 |
"Created: / 09-11-2006 / 15:09:25 / cg" |
|
2672 | 201 |
"Modified: / 22-12-2011 / 00:46:29 / cg" |
2653 | 202 |
! ! |
203 |
||
204 |
!FileBasedSourceCodeManager class methodsFor:'source code administration'! |
|
205 |
||
4224 | 206 |
checkForExistingContainer:fileName inModule:moduleName directory:packageDirName |
207 |
"check for a container to exist. Return a boolean result." |
|
208 |
||
209 |
^ self checkForExistingModule:moduleName directory:packageDirName |
|
2653 | 210 |
|
211 |
"Created: / 21-12-2011 / 17:56:23 / cg" |
|
4224 | 212 |
"Modified (format): / 24-02-2017 / 11:32:26 / cg" |
2653 | 213 |
! |
214 |
||
215 |
checkForExistingModule:moduleDir |
|
216 |
"check for a package directory to be present" |
|
217 |
||
218 |
|dir| |
|
219 |
||
220 |
dir := self moduleDirectoryFor:moduleDir. |
|
221 |
^ dir exists |
|
222 |
||
223 |
"Created: / 21-12-2011 / 18:37:28 / cg" |
|
224 |
! |
|
225 |
||
226 |
checkForExistingModule:moduleDir directory:packageDir |
|
227 |
"check for a package directory to be present" |
|
228 |
||
229 |
|dir| |
|
230 |
||
231 |
dir := self packageDirectoryForModule:moduleDir package:packageDir. |
|
232 |
^ dir exists |
|
233 |
||
234 |
"Created: / 21-12-2011 / 18:03:33 / cg" |
|
235 |
! |
|
236 |
||
237 |
checkinClass:aClass fileName:classFileName directory:packageDir module:moduleDir source:sourceFile logMessage:logMessage force:force |
|
238 |
"Return true if ok, false if not." |
|
239 |
||
4313 | 240 |
|targetDir newestRevision newRevision newFile packageMode filter outStream logFile| |
2653 | 241 |
|
242 |
targetDir := self packageDirectoryForModule:moduleDir package:packageDir. |
|
4138 | 243 |
targetDir exists ifFalse:[ |
244 |
targetDir recursiveMakeDirectory |
|
245 |
]. |
|
2653 | 246 |
(targetDir filesMatching:(classFileName,'_*')) do:[:eachVersionFile | |
247 |
|versionString| |
|
248 |
||
249 |
versionString := eachVersionFile copyFrom:(classFileName size + 2). |
|
250 |
(newestRevision isNil |
|
251 |
or:[ self isRevision:versionString after:newestRevision ]) ifTrue:[ |
|
252 |
newestRevision := versionString |
|
253 |
]. |
|
254 |
]. |
|
255 |
||
256 |
newestRevision isNil ifTrue:[ |
|
257 |
newRevision := '1' |
|
258 |
] ifFalse:[ |
|
259 |
newRevision := self revisionAfter:newestRevision |
|
260 |
]. |
|
4313 | 261 |
newFile := targetDir construct:(classFileName,'_',newRevision printString). |
262 |
logFile := targetDir construct:(classFileName,'_',newRevision printString,'.log'). |
|
2653 | 263 |
|
264 |
self updateVersionMethodOf:aClass for:(self revisionStringFor:aClass inModule:moduleDir directory:packageDir container:classFileName revision:newRevision). |
|
265 |
||
266 |
packageMode := self checkMethodPackagesOf:aClass. |
|
267 |
packageMode == #base ifTrue:[ |
|
2978
75c908c1d2a1
class: FileBasedSourceCodeManager
Claus Gittinger <cg@exept.de>
parents:
2840
diff
changeset
|
268 |
filter := [:mthd | mthd package == aClass package]. |
2653 | 269 |
]. |
270 |
||
271 |
[ |
|
272 |
outStream := newFile writeStream. |
|
273 |
] on:FileStream openErrorSignal do:[:ex| |
|
274 |
self reportError:('fileout failed'). |
|
275 |
^ false |
|
276 |
]. |
|
277 |
||
278 |
Method flushSourceStreamCache. |
|
279 |
Class fileOutErrorSignal handle:[:ex | |
|
280 |
outStream close. |
|
4308 | 281 |
newFile remove. |
2653 | 282 |
self reportError:('fileout failed (',ex description,')'). |
283 |
^ false |
|
284 |
] do:[ |
|
285 |
self |
|
286 |
fileOutSourceCodeOf:aClass |
|
287 |
on:outStream |
|
288 |
withTimeStamp:false |
|
289 |
withInitialize:true |
|
290 |
withDefinition:true |
|
291 |
methodFilter:filter. |
|
292 |
]. |
|
293 |
outStream close. |
|
294 |
||
295 |
newFile exists ifFalse:[ |
|
296 |
self reportError:'fileout failed'. |
|
297 |
^ false. |
|
298 |
]. |
|
299 |
||
4313 | 300 |
logMessage isEmptyOrNil ifTrue:[ |
301 |
logFile contents:'no log message'. |
|
302 |
] ifFalse:[ |
|
303 |
logFile contents:logMessage. |
|
304 |
]. |
|
2653 | 305 |
^ true |
306 |
||
307 |
"Created: / 21-12-2011 / 19:01:07 / cg" |
|
308 |
! |
|
309 |
||
310 |
createModule:moduleDir |
|
311 |
"create a module directory" |
|
312 |
||
313 |
|dir| |
|
314 |
||
315 |
dir := self moduleDirectoryFor:moduleDir. |
|
316 |
dir recursiveMakeDirectory. |
|
317 |
^ dir exists. |
|
318 |
||
319 |
"Created: / 21-12-2011 / 18:38:22 / cg" |
|
320 |
! |
|
321 |
||
322 |
createModule:moduleDir directory:packageDir |
|
323 |
"create a package directory" |
|
324 |
||
325 |
|dir| |
|
326 |
||
327 |
dir := self packageDirectoryForModule:moduleDir package:packageDir. |
|
328 |
dir recursiveMakeDirectory. |
|
329 |
^ dir exists. |
|
330 |
||
331 |
"Created: / 21-12-2011 / 18:44:20 / cg" |
|
332 |
! |
|
333 |
||
334 |
initialRevisionStringFor:aClass inModule:moduleDir directory:packageDir container:fileName |
|
335 |
"return a string usable as initial revision string" |
|
336 |
||
337 |
^ self |
|
338 |
revisionStringFor:aClass |
|
339 |
inModule:moduleDir |
|
340 |
directory:packageDir |
|
341 |
container:fileName |
|
342 |
revision:'1' |
|
343 |
||
344 |
"Created: / 21-12-2011 / 18:14:03 / cg" |
|
345 |
! |
|
346 |
||
347 |
moduleDirectoryFor:moduleDir |
|
348 |
"a modules directory as filename" |
|
349 |
||
350 |
|root| |
|
351 |
||
2672 | 352 |
root := self getRepositoryPathForModule:moduleDir. |
2653 | 353 |
root isNil ifTrue:[ |
354 |
RepositoryPath := root := './versions'. |
|
355 |
]. |
|
356 |
||
357 |
^ (root asFilename construct:moduleDir) |
|
358 |
||
359 |
"Created: / 21-12-2011 / 18:38:38 / cg" |
|
360 |
! |
|
361 |
||
362 |
packageDirectoryForModule:moduleDir package:package |
|
363 |
"a packages directory as filename" |
|
364 |
||
365 |
|dir| |
|
366 |
||
367 |
dir := self moduleDirectoryFor:moduleDir. |
|
368 |
^ dir construct:package |
|
369 |
||
370 |
"Created: / 21-12-2011 / 18:43:27 / cg" |
|
371 |
! |
|
372 |
||
2672 | 373 |
revisionInfoFromString:aString |
374 |
"{ Pragma: +optSpace }" |
|
375 |
||
376 |
"return a VersionInfo object filled with revision info. |
|
377 |
This extracts the relevant info from aString." |
|
378 |
||
2840
4aaf2ddbe966
added: #revisionStringFor:inModule:directory:container:revision:
Claus Gittinger <cg@exept.de>
parents:
2736
diff
changeset
|
379 |
^ self revisionInfoFromStandardVersionString:aString |
2672 | 380 |
|
381 |
" |
|
382 |
self revisionInfoFromString:'Path: stx/libbasic/Array.st, Version: 123, User: cg, Time: 2011-12-21T21:03:08.826' |
|
383 |
" |
|
384 |
||
385 |
"Created: / 21-12-2011 / 14:50:12 / cg" |
|
386 |
! |
|
387 |
||
3599
c051587e01f9
class: FileBasedSourceCodeManager
Claus Gittinger <cg@exept.de>
parents:
2978
diff
changeset
|
388 |
revisionLogOf:clsOrNil |
c051587e01f9
class: FileBasedSourceCodeManager
Claus Gittinger <cg@exept.de>
parents:
2978
diff
changeset
|
389 |
fromRevision:rev1OrNil toRevision:rev2OrNil numberOfRevisions:limitOrNil |
c051587e01f9
class: FileBasedSourceCodeManager
Claus Gittinger <cg@exept.de>
parents:
2978
diff
changeset
|
390 |
fileName:classFileName directory:packageDir module:moduleDir |
2672 | 391 |
|
392 |
|info log targetDir count newestRevision| |
|
393 |
||
394 |
targetDir := self packageDirectoryForModule:moduleDir package:packageDir. |
|
395 |
targetDir exists ifFalse:[^ nil ]. |
|
396 |
||
397 |
info := IdentityDictionary new. |
|
398 |
log := OrderedCollection new. |
|
399 |
count := 0. |
|
400 |
||
401 |
(targetDir filesMatching:(classFileName,'_*')) do:[:eachVersionFile | |
|
402 |
|versionString cs versionChange info| |
|
403 |
||
404 |
versionString := eachVersionFile copyFrom:(classFileName size + 2). |
|
405 |
count := count + 1. |
|
406 |
(newestRevision isNil |
|
407 |
or:[ self isRevision:versionString after:newestRevision ]) ifTrue:[ |
|
408 |
newestRevision := versionString |
|
409 |
]. |
|
410 |
||
411 |
(rev1OrNil isNil |
|
412 |
or:[ rev1OrNil = 0 |
|
413 |
or:[ versionString = rev1OrNil |
|
414 |
or:[ self isRevision:versionString after:rev1OrNil ]]]) |
|
415 |
ifTrue:[ |
|
416 |
(rev2OrNil isNil |
|
417 |
or:[ rev2OrNil = 0 |
|
418 |
or:[ versionString = rev2OrNil |
|
419 |
or:[ self isRevision:rev2OrNil after:versionString ]]]) |
|
420 |
ifTrue:[ |
|
421 |
(limitOrNil isNil |
|
422 |
or:[ log size < limitOrNil ]) |
|
423 |
ifTrue:[ |
|
424 |
cs := ChangeSet fromFile:(targetDir construct:eachVersionFile). |
|
425 |
versionChange := cs detect:[:chg | chg isMethodChange |
|
426 |
and:[chg selector = self nameOfVersionMethodInClasses]] |
|
427 |
ifNone:nil. |
|
428 |
versionChange notNil ifTrue:[ |
|
429 |
info := self revisionInfoFromString:versionChange source. |
|
430 |
] ifFalse:[ |
|
3660
523f83d184f2
class: FileBasedSourceCodeManager
Claus Gittinger <cg@exept.de>
parents:
3599
diff
changeset
|
431 |
info := self versionInfoClass new. |
2672 | 432 |
]. |
433 |
||
434 |
info revision:versionString. |
|
435 |
log add:info. |
|
436 |
] |
|
437 |
]. |
|
438 |
]. |
|
439 |
]. |
|
440 |
log sort:[:a :b | self isRevision:b revision after:a revision]. |
|
441 |
||
442 |
info at:#revisions put:log. |
|
443 |
info at:#numberOfRevisions put:count. |
|
444 |
info at:#newestRevision put:newestRevision. |
|
445 |
||
446 |
^ info |
|
447 |
||
448 |
"Created: / 21-12-2011 / 20:39:31 / cg" |
|
449 |
! |
|
450 |
||
451 |
streamForClass:aClass fileName:classFileName revision:revision directory:packageDir module:moduleDir cache:doCache |
|
452 |
|targetDir oldFile| |
|
453 |
||
454 |
targetDir := self packageDirectoryForModule:moduleDir package:packageDir. |
|
455 |
oldFile := (targetDir construct:classFileName,'_',revision). |
|
456 |
^ oldFile readStream |
|
457 |
||
458 |
"Created: / 21-12-2011 / 20:49:01 / cg" |
|
2653 | 459 |
! ! |
460 |
||
461 |
!FileBasedSourceCodeManager class methodsFor:'documentation'! |
|
462 |
||
463 |
version |
|
4082 | 464 |
^ '$Header$' |
2653 | 465 |
! |
466 |
||
467 |
version_CVS |
|
4082 | 468 |
^ '$Header$' |
2653 | 469 |
! ! |
3599
c051587e01f9
class: FileBasedSourceCodeManager
Claus Gittinger <cg@exept.de>
parents:
2978
diff
changeset
|
470 |