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