author | Claus Gittinger <cg@exept.de> |
Mon, 02 Jul 2018 14:58:32 +0200 | |
changeset 4336 | d5a9051236fb |
parent 4293 | 6ad063b90b0f |
permissions | -rw-r--r-- |
3438 | 1 |
" |
2 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
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 |
" |
|
2573 | 12 |
"{ Package: 'stx:libbasic3' }" |
13 |
||
4293 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
2573 | 16 |
Object subclass:#SourceCodeCache |
17 |
instanceVariableNames:'' |
|
18 |
classVariableNames:'Default' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'System-SourceCodeManagement' |
|
21 |
! |
|
22 |
||
23 |
!SourceCodeCache class methodsFor:'documentation'! |
|
24 |
||
3438 | 25 |
copyright |
26 |
" |
|
27 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
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 |
||
2573 | 39 |
documentation |
40 |
" |
|
41 |
This class represents global source code cache for caching |
|
42 |
class source in multiple revisions. |
|
43 |
||
44 |
It is intended to replace caching (copy-paste) code in |
|
45 |
CVS/Perforce source code managers in #streamForClass:... |
|
46 |
||
47 |
More features are planned in future like setting a limit |
|
48 |
for cache size or compressing cached files in a .zip file |
|
49 |
to save disk space. |
|
50 |
||
51 |
[author:] |
|
52 |
Jan Vrany <jan.vrany@fit.cvut.cz> |
|
53 |
||
54 |
[instance variables:] |
|
55 |
||
56 |
[class variables:] |
|
57 |
||
58 |
[see also:] |
|
59 |
CVSSourceCodeManager class>>streamForClass:fileName:revision:directory:module:cache: |
|
60 |
PerforceSourceCodeManager class>>streamForClass:fileName:revision:directory:module:cache: |
|
61 |
" |
|
62 |
! ! |
|
63 |
||
64 |
!SourceCodeCache class methodsFor:'accessing'! |
|
65 |
||
66 |
default |
|
67 |
||
68 |
Default isNil ifTrue:[Default := self new]. |
|
69 |
^Default |
|
70 |
||
71 |
"Created: / 11-10-2011 / 23:23:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
72 |
! ! |
|
73 |
||
74 |
!SourceCodeCache methodsFor:'accessing'! |
|
75 |
||
76 |
streamForClass:aClass fileName:classFileName revision:revisionString repository: repositoryId module:moduleDir directory:packageDir ifAbsent: block |
|
77 |
||
78 |
"Answers a stream for given class (stored in classFileName) at |
|
79 |
given revision. If the stream is not in the cache, then the |
|
80 |
block is called with the desired cached filename as an argument. |
|
4293 | 81 |
The block should return a stream (not necessarily on the filename |
2573 | 82 |
passed)." |
83 |
||
84 |
| file stream | |
|
85 |
file := self cachedFileNameForRepository: repositoryId module: moduleDir directory: packageDir container: classFileName revision: revisionString. |
|
86 |
file exists ifTrue:[ |
|
87 |
^file readStream. |
|
88 |
]. |
|
89 |
||
4293 | 90 |
[ |
91 |
file directory recursiveMakeDirectory |
|
2573 | 92 |
] on: Error do:[:ex| |
4293 | 93 |
self error: 'Cannot make cache directory: ', ex description. |
2573 | 94 |
]. |
95 |
stream := block valueWithOptionalArgument: file. |
|
96 |
stream isNil ifTrue:[^nil]. |
|
97 |
stream isPositionable ifFalse:[ |
|
98 |
self error: 'Source stream is not positionable!!'. |
|
99 |
]. |
|
100 |
stream isFileStream ifTrue:[ |
|
101 |
stream pathName ~= file pathName ifTrue:[ |
|
102 |
stream pathName asFilename copyTo: file. |
|
103 |
]. |
|
104 |
] ifFalse:[ |
|
105 |
file writingFileDo:[:cache| |
|
106 |
[ stream atEnd ] whileFalse:[ |
|
107 |
cache nextPutAll: (stream next: 4096) |
|
108 |
]. |
|
109 |
]. |
|
3377 | 110 |
stream position: 0. |
2573 | 111 |
]. |
112 |
^stream |
|
113 |
||
114 |
"Created: / 12-10-2011 / 09:58:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
4293 | 115 |
"Modified (comment): / 18-12-2017 / 10:12:24 / mawalch" |
2573 | 116 |
! ! |
117 |
||
118 |
!SourceCodeCache methodsFor:'private'! |
|
119 |
||
120 |
cachedFileNameForRepository: repositoryId module: module directory: package container: container revision: revision |
|
121 |
||
2632
323af4a2a7f3
changed: #cachedFileNameForRepository:module:directory:container:revision:
vrany
parents:
2573
diff
changeset
|
122 |
| cache | |
323af4a2a7f3
changed: #cachedFileNameForRepository:module:directory:container:revision:
vrany
parents:
2573
diff
changeset
|
123 |
cache := AbstractSourceCodeManager cacheDirectoryName. |
323af4a2a7f3
changed: #cachedFileNameForRepository:module:directory:container:revision:
vrany
parents:
2573
diff
changeset
|
124 |
cache isNil ifTrue:[AbstractSourceCodeManager initCacheDirPath]. |
323af4a2a7f3
changed: #cachedFileNameForRepository:module:directory:container:revision:
vrany
parents:
2573
diff
changeset
|
125 |
cache := AbstractSourceCodeManager cacheDirectoryName. |
323af4a2a7f3
changed: #cachedFileNameForRepository:module:directory:container:revision:
vrany
parents:
2573
diff
changeset
|
126 |
^ cache asFilename |
2573 | 127 |
"/ repositoryId "/ TODO: Ignored for now, discuss with Claus |
128 |
/ module |
|
129 |
/ (package copyReplaceAll:$/ with: Filename separator) |
|
130 |
/ (container, '_' , revision) |
|
131 |
||
132 |
" |
|
133 |
SourceCodeCache default |
|
134 |
cachedFileNameForRepository: 'CVS01' |
|
135 |
module: 'stx' |
|
136 |
directory: 'goodies/sunit' |
|
137 |
container: 'TestCase.st' |
|
138 |
revision: '1234' |
|
139 |
" |
|
140 |
||
141 |
"Created: / 12-10-2011 / 09:51:12 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
142 |
! ! |
|
143 |
||
144 |
!SourceCodeCache class methodsFor:'documentation'! |
|
145 |
||
146 |
version |
|
4293 | 147 |
^ '$Header$' |
2573 | 148 |
! |
149 |
||
150 |
version_CVS |
|
4293 | 151 |
^ '$Header$' |
2573 | 152 |
! ! |
3377 | 153 |