author | vrany |
Thu, 01 Dec 2011 11:52:43 +0100 | |
changeset 2632 | 323af4a2a7f3 |
parent 2573 | 3dae12b94fde |
child 3011 | 1997ff6e7e55 |
child 3377 | c25f2ef92268 |
permissions | -rw-r--r-- |
2573 | 1 |
"{ Package: 'stx:libbasic3' }" |
2 |
||
3 |
Object subclass:#SourceCodeCache |
|
4 |
instanceVariableNames:'' |
|
5 |
classVariableNames:'Default' |
|
6 |
poolDictionaries:'' |
|
7 |
category:'System-SourceCodeManagement' |
|
8 |
! |
|
9 |
||
10 |
!SourceCodeCache class methodsFor:'documentation'! |
|
11 |
||
12 |
documentation |
|
13 |
" |
|
14 |
This class represents global source code cache for caching |
|
15 |
class source in multiple revisions. |
|
16 |
||
17 |
It is intended to replace caching (copy-paste) code in |
|
18 |
CVS/Perforce source code managers in #streamForClass:... |
|
19 |
||
20 |
More features are planned in future like setting a limit |
|
21 |
for cache size or compressing cached files in a .zip file |
|
22 |
to save disk space. |
|
23 |
||
24 |
[author:] |
|
25 |
Jan Vrany <jan.vrany@fit.cvut.cz> |
|
26 |
||
27 |
[instance variables:] |
|
28 |
||
29 |
[class variables:] |
|
30 |
||
31 |
[see also:] |
|
32 |
CVSSourceCodeManager class>>streamForClass:fileName:revision:directory:module:cache: |
|
33 |
PerforceSourceCodeManager class>>streamForClass:fileName:revision:directory:module:cache: |
|
34 |
" |
|
35 |
! ! |
|
36 |
||
37 |
!SourceCodeCache class methodsFor:'accessing'! |
|
38 |
||
39 |
default |
|
40 |
||
41 |
Default isNil ifTrue:[Default := self new]. |
|
42 |
^Default |
|
43 |
||
44 |
"Created: / 11-10-2011 / 23:23:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
45 |
! ! |
|
46 |
||
47 |
!SourceCodeCache methodsFor:'accessing'! |
|
48 |
||
49 |
streamForClass:aClass fileName:classFileName revision:revisionString repository: repositoryId module:moduleDir directory:packageDir ifAbsent: block |
|
50 |
||
51 |
"Answers a stream for given class (stored in classFileName) at |
|
52 |
given revision. If the stream is not in the cache, then the |
|
53 |
block is called with the desired cached filename as an argument. |
|
54 |
The block should return a stream (not necesarily on the filename |
|
55 |
passed)." |
|
56 |
||
57 |
| file stream | |
|
58 |
file := self cachedFileNameForRepository: repositoryId module: moduleDir directory: packageDir container: classFileName revision: revisionString. |
|
59 |
file exists ifTrue:[ |
|
60 |
^file readStream. |
|
61 |
]. |
|
62 |
||
63 |
[ |
|
64 |
file directory recursiveMakeDirectory |
|
65 |
] on: Error do:[:ex| |
|
66 |
self error: 'Cannot make cache directory: ', ex description. |
|
67 |
]. |
|
68 |
stream := block valueWithOptionalArgument: file. |
|
69 |
stream isNil ifTrue:[^nil]. |
|
70 |
stream isPositionable ifFalse:[ |
|
71 |
self error: 'Source stream is not positionable!!'. |
|
72 |
]. |
|
73 |
stream isFileStream ifTrue:[ |
|
74 |
stream pathName ~= file pathName ifTrue:[ |
|
75 |
stream pathName asFilename copyTo: file. |
|
76 |
]. |
|
77 |
] ifFalse:[ |
|
78 |
file writingFileDo:[:cache| |
|
79 |
[ stream atEnd ] whileFalse:[ |
|
80 |
cache nextPutAll: (stream next: 4096) |
|
81 |
]. |
|
82 |
]. |
|
83 |
stream position0Based: 0. |
|
84 |
]. |
|
85 |
^stream |
|
86 |
||
87 |
"Created: / 12-10-2011 / 09:58:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
88 |
! ! |
|
89 |
||
90 |
!SourceCodeCache methodsFor:'private'! |
|
91 |
||
92 |
cachedFileNameForRepository: repositoryId module: module directory: package container: container revision: revision |
|
93 |
||
2632
323af4a2a7f3
changed: #cachedFileNameForRepository:module:directory:container:revision:
vrany
parents:
2573
diff
changeset
|
94 |
| cache | |
323af4a2a7f3
changed: #cachedFileNameForRepository:module:directory:container:revision:
vrany
parents:
2573
diff
changeset
|
95 |
cache := AbstractSourceCodeManager cacheDirectoryName. |
323af4a2a7f3
changed: #cachedFileNameForRepository:module:directory:container:revision:
vrany
parents:
2573
diff
changeset
|
96 |
cache isNil ifTrue:[AbstractSourceCodeManager initCacheDirPath]. |
323af4a2a7f3
changed: #cachedFileNameForRepository:module:directory:container:revision:
vrany
parents:
2573
diff
changeset
|
97 |
cache := AbstractSourceCodeManager cacheDirectoryName. |
323af4a2a7f3
changed: #cachedFileNameForRepository:module:directory:container:revision:
vrany
parents:
2573
diff
changeset
|
98 |
^ cache asFilename |
2573 | 99 |
"/ repositoryId "/ TODO: Ignored for now, discuss with Claus |
100 |
/ module |
|
101 |
/ (package copyReplaceAll:$/ with: Filename separator) |
|
102 |
/ (container, '_' , revision) |
|
103 |
||
104 |
" |
|
105 |
SourceCodeCache default |
|
106 |
cachedFileNameForRepository: 'CVS01' |
|
107 |
module: 'stx' |
|
108 |
directory: 'goodies/sunit' |
|
109 |
container: 'TestCase.st' |
|
110 |
revision: '1234' |
|
111 |
" |
|
112 |
||
113 |
"Created: / 12-10-2011 / 09:51:12 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
114 |
! ! |
|
115 |
||
116 |
!SourceCodeCache class methodsFor:'documentation'! |
|
117 |
||
118 |
version |
|
2632
323af4a2a7f3
changed: #cachedFileNameForRepository:module:directory:container:revision:
vrany
parents:
2573
diff
changeset
|
119 |
^ '$Header: /cvs/stx/stx/libbasic3/SourceCodeCache.st,v 1.2 2011-12-01 10:52:43 vrany Exp $' |
2573 | 120 |
! |
121 |
||
122 |
version_CVS |
|
2632
323af4a2a7f3
changed: #cachedFileNameForRepository:module:directory:container:revision:
vrany
parents:
2573
diff
changeset
|
123 |
^ '$Header: /cvs/stx/stx/libbasic3/SourceCodeCache.st,v 1.2 2011-12-01 10:52:43 vrany Exp $' |
2573 | 124 |
! ! |