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