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 |
|
|
94 |
^ AbstractSourceCodeManager cacheDirectoryName asFilename
|
|
95 |
"/ repositoryId "/ TODO: Ignored for now, discuss with Claus
|
|
96 |
/ module
|
|
97 |
/ (package copyReplaceAll:$/ with: Filename separator)
|
|
98 |
/ (container, '_' , revision)
|
|
99 |
|
|
100 |
"
|
|
101 |
SourceCodeCache default
|
|
102 |
cachedFileNameForRepository: 'CVS01'
|
|
103 |
module: 'stx'
|
|
104 |
directory: 'goodies/sunit'
|
|
105 |
container: 'TestCase.st'
|
|
106 |
revision: '1234'
|
|
107 |
"
|
|
108 |
|
|
109 |
"Created: / 12-10-2011 / 09:51:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
110 |
! !
|
|
111 |
|
|
112 |
!SourceCodeCache class methodsFor:'documentation'!
|
|
113 |
|
|
114 |
version
|
|
115 |
^ '$Header: /cvs/stx/stx/libbasic3/SourceCodeCache.st,v 1.1 2011-10-12 10:28:43 vrany Exp $'
|
|
116 |
!
|
|
117 |
|
|
118 |
version_CVS
|
|
119 |
^ '$Header: /cvs/stx/stx/libbasic3/SourceCodeCache.st,v 1.1 2011-10-12 10:28:43 vrany Exp $'
|
|
120 |
! !
|