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