1094
|
1 |
"{ Encoding: utf8 }"
|
|
2 |
|
1085
|
3 |
"{ Package: 'stx:goodies/monticello' }"
|
|
4 |
|
|
5 |
"{ NameSpace: Smalltalk }"
|
|
6 |
|
|
7 |
MCDirectoryRepository subclass:#MCFileTreeRepository
|
|
8 |
instanceVariableNames:'readonly repositoryProperties'
|
|
9 |
classVariableNames:''
|
|
10 |
poolDictionaries:''
|
|
11 |
category:'SCM-Monticello-FileTree-Core'
|
|
12 |
!
|
|
13 |
|
|
14 |
MCFileTreeRepository class instanceVariableNames:'defaultPackageExtension defaultPropertyFileExtension'
|
|
15 |
|
|
16 |
"
|
|
17 |
No other class instance variables are inherited by this class.
|
|
18 |
"
|
|
19 |
!
|
|
20 |
|
|
21 |
MCFileTreeRepository comment:'A file tree repository'
|
|
22 |
!
|
|
23 |
|
|
24 |
|
|
25 |
!MCFileTreeRepository class methodsFor:'instance creation'!
|
|
26 |
|
|
27 |
basicFromUrl: aZnUrl
|
|
28 |
^ self new directory: (self urlAsFileReference: aZnUrl)
|
|
29 |
!
|
|
30 |
|
|
31 |
description
|
|
32 |
^ 'filetree://'
|
|
33 |
! !
|
|
34 |
|
|
35 |
!MCFileTreeRepository class methodsFor:'accessing'!
|
|
36 |
|
|
37 |
defaultPackageExtension
|
|
38 |
".tree, .pkg, .package are the only formats supported at the moment:
|
|
39 |
.tree - original structure
|
|
40 |
.pkg - snapshot structure
|
|
41 |
.package - cypress structure"
|
|
42 |
|
|
43 |
defaultPackageExtension
|
|
44 |
ifNil: [
|
|
45 |
defaultPackageExtension := MCFileTreePackageStructureStWriter useCypressWriter
|
|
46 |
ifTrue: [ '.package' ]
|
|
47 |
ifFalse: [ '.pkg' ] ].
|
|
48 |
^ defaultPackageExtension
|
|
49 |
!
|
|
50 |
|
|
51 |
defaultPackageExtension: aString
|
|
52 |
".tree and .pkg are the only two formats supported at the moment"
|
|
53 |
|
|
54 |
"self defaultPackageExtension:'.package'"
|
|
55 |
|
|
56 |
(#('.tree' '.pkg' '.package') includes: aString)
|
|
57 |
ifFalse: [ self error: 'Unsupported package extension: ' , aString printString ].
|
|
58 |
defaultPackageExtension := aString
|
|
59 |
!
|
|
60 |
|
|
61 |
defaultPropertyFileExtension
|
|
62 |
defaultPropertyFileExtension
|
|
63 |
ifNil: [ defaultPropertyFileExtension := '.json' ].
|
|
64 |
^ defaultPropertyFileExtension
|
|
65 |
!
|
|
66 |
|
|
67 |
defaultPropertyFileExtension: aString
|
|
68 |
"self defaultPropertyFileExtension:'.ston'"
|
|
69 |
|
|
70 |
self validatePropertyFileExtension: aString.
|
|
71 |
defaultPropertyFileExtension := aString
|
|
72 |
!
|
|
73 |
|
|
74 |
urlSchemes
|
|
75 |
^ #(#filetree)
|
|
76 |
!
|
|
77 |
|
|
78 |
validatePropertyFileExtension: aString
|
|
79 |
"see Issue #90: https://github.com/dalehenrich/filetree/issues/90"
|
|
80 |
|
|
81 |
(#('.json' '.ston') includes: aString)
|
|
82 |
ifFalse: [ self error: 'Unsupported property file extension: ' , aString printString ]
|
|
83 |
! !
|
|
84 |
|
|
85 |
!MCFileTreeRepository class methodsFor:'utility'!
|
|
86 |
|
|
87 |
parseName: aString
|
|
88 |
^ self parseName: aString extension: self defaultPackageExtension
|
|
89 |
!
|
|
90 |
|
|
91 |
parseName: aString extension: extension
|
|
92 |
"picked up from GoferVersionReference>>parseName:"
|
|
93 |
|
1094
|
94 |
| "info" basicName package branch author versionNumber packageName |
|
1085
|
95 |
basicName := aString last isDigit
|
|
96 |
ifTrue: [ aString ]
|
|
97 |
ifFalse: [ (aString copyUpToLast: $.) copyUpTo: $( ].
|
|
98 |
package := basicName copyUpToLast: $-.
|
|
99 |
(package includes: $.)
|
|
100 |
ifFalse: [ branch := '' ]
|
|
101 |
ifTrue: [
|
|
102 |
branch := '.' , (package copyAfter: $.).
|
|
103 |
package := package copyUpTo: $. ].
|
|
104 |
author := (basicName copyAfterLast: $-) copyUpToLast: $..
|
|
105 |
versionNumber := (basicName copyAfterLast: $-) copyAfterLast: $..
|
|
106 |
(versionNumber notEmpty and: [ versionNumber allSatisfy: [ :each | each isDigit ] ])
|
|
107 |
ifTrue: [ versionNumber := versionNumber asNumber ]
|
|
108 |
ifFalse: [ versionNumber := 0 ].
|
|
109 |
packageName := package , branch.
|
|
110 |
^ {packageName.
|
|
111 |
author.
|
|
112 |
versionNumber.
|
|
113 |
(packageName , extension)}
|
1094
|
114 |
|
|
115 |
"Modified (comment): / 01-09-2018 / 17:33:38 / Claus Gittinger"
|
1085
|
116 |
!
|
|
117 |
|
|
118 |
urlAsFileReference: aZnUrl
|
|
119 |
"Extracted from ZnUrl since the scheme is restricted.
|
|
120 |
We need to keep host as a segment part."
|
|
121 |
|
|
122 |
| path |
|
|
123 |
path := aZnUrl host
|
|
124 |
ifNotNil: [
|
|
125 |
((aZnUrl host = #/) and: [ aZnUrl pathSegments isEmpty ])
|
|
126 |
ifTrue: [ ^ FileSystem root ].
|
|
127 |
aZnUrl pathSegments copyWithFirst: aZnUrl host ]
|
|
128 |
ifNil: [ aZnUrl pathSegments copyWithFirst: FileSystem disk delimiter asString ].
|
|
129 |
^ (String streamContents:
|
|
130 |
[ :stream |
|
|
131 |
path
|
|
132 |
asStringOn: stream
|
|
133 |
delimiter: FileSystem disk delimiter asString ])
|
|
134 |
asFileReference
|
|
135 |
! !
|
|
136 |
|
|
137 |
!MCFileTreeRepository methodsFor:'*Komitter-Models'!
|
|
138 |
|
|
139 |
isRemote
|
|
140 |
^ true
|
|
141 |
! !
|
|
142 |
|
|
143 |
!MCFileTreeRepository methodsFor:'*metacello-filetree'!
|
|
144 |
|
|
145 |
metacelloProjectClassFor: aScriptEngine
|
|
146 |
|
|
147 |
aScriptEngine versionString isEmptyOrNil
|
|
148 |
ifFalse: [
|
|
149 |
"If we have a version in the script, then a BaselineOf is not being referenced...use a MetacelloMCProject
|
|
150 |
see https://github.com/dalehenrich/metacello-work/issues/7"
|
|
151 |
^ super metacelloProjectClassFor: aScriptEngine ].
|
|
152 |
^ MetacelloMCBaselineProject
|
|
153 |
!
|
|
154 |
|
|
155 |
repositoryBranchName
|
|
156 |
"extract a branch name from the repository ... if possible"
|
|
157 |
|
1094
|
158 |
|sha|
|
|
159 |
|
|
160 |
(sha := MetacelloPlatform current gitBranchNameFor: self directory fullName)
|
|
161 |
notNil ifTrue:[ ^ sha ].
|
1085
|
162 |
^ super repositoryBranchName
|
1094
|
163 |
|
|
164 |
"Modified: / 01-09-2018 / 17:34:23 / Claus Gittinger"
|
1085
|
165 |
!
|
|
166 |
|
|
167 |
repositoryDescription
|
|
168 |
^ self description , ' [' , self repositoryVersionString , ':'
|
|
169 |
, self repositoryBranchName , ']'
|
|
170 |
!
|
|
171 |
|
|
172 |
repositoryVersionString
|
|
173 |
"extract a version string from the repository ... if possible"
|
|
174 |
|
1094
|
175 |
|sha|
|
|
176 |
|
|
177 |
(sha := MetacelloPlatform current gitCommitShaFor: self directory fullName)
|
|
178 |
notNil ifTrue: [^ sha ].
|
1085
|
179 |
^ super repositoryVersionString
|
1094
|
180 |
|
|
181 |
"Modified: / 01-09-2018 / 17:34:51 / Claus Gittinger"
|
1085
|
182 |
! !
|
|
183 |
|
|
184 |
!MCFileTreeRepository methodsFor:'*metacello-mc'!
|
|
185 |
|
|
186 |
versionInfoFromVersionNamed: aString
|
|
187 |
^ self versionInfoForPackageDirectory: (self fileDirectoryOn: (aString, self packageExtension))
|
|
188 |
! !
|
|
189 |
|
|
190 |
!MCFileTreeRepository methodsFor:'accessing'!
|
|
191 |
|
|
192 |
allFileNames
|
|
193 |
^ (self directory entries select: [ :entry | entry isDirectory and: [ self canReadFileNamed: entry name ] ])
|
|
194 |
collect: [ :entry | entry name ]
|
|
195 |
!
|
|
196 |
|
|
197 |
allFileNamesForVersionNamed: aString
|
|
198 |
^ self filterFileNames: self readableFileNames forVersionNamed: aString
|
|
199 |
!
|
|
200 |
|
|
201 |
asRepositorySpecFor: aMetacelloMCProject
|
|
202 |
^ aMetacelloMCProject repositorySpec
|
|
203 |
description: self description;
|
|
204 |
type: 'filetree';
|
|
205 |
yourself
|
|
206 |
!
|
|
207 |
|
|
208 |
defaultRepositoryProperties
|
|
209 |
^ Dictionary new
|
|
210 |
at: 'packageExtension' put: self class defaultPackageExtension;
|
|
211 |
at: 'propertyFileExtension' put: self propertyFileExtension;
|
|
212 |
yourself
|
|
213 |
!
|
|
214 |
|
|
215 |
directory: aDirectory
|
|
216 |
super directory: aDirectory.
|
|
217 |
repositoryProperties := nil. "force properties to be reloaded from new location"
|
|
218 |
self repositoryProperties "NOW"
|
|
219 |
!
|
|
220 |
|
|
221 |
fileUtils
|
|
222 |
^ MCFileTreeFileUtils current
|
|
223 |
!
|
|
224 |
|
|
225 |
filterFileNames: aCollection forVersionNamed: aString
|
|
226 |
^ aCollection select: [:ea | (self versionNameFromFileName: ea) = aString]
|
|
227 |
!
|
|
228 |
|
|
229 |
goferVersionFrom: aVersionReference
|
|
230 |
"until we no longer find .tree directories in the wild"
|
|
231 |
|
|
232 |
((self readableFileNames collect: [ :fileName | self fileDirectoryOn: fileName ])
|
|
233 |
select: [ :packageDirectory | self fileUtils directoryExists: packageDirectory ])
|
|
234 |
collect: [ :packageDirectory |
|
|
235 |
(self versionInfoForPackageDirectory: packageDirectory) name = aVersionReference name
|
|
236 |
ifTrue: [ ^ self loadVersionFromFileNamed: (self fileUtils directoryName: packageDirectory) ] ].
|
|
237 |
^ nil
|
|
238 |
!
|
|
239 |
|
|
240 |
readonly
|
|
241 |
readonly ifNil: [ readonly := false ].
|
|
242 |
^ readonly
|
|
243 |
!
|
|
244 |
|
|
245 |
readonly: anObject
|
|
246 |
readonly := anObject
|
|
247 |
!
|
|
248 |
|
|
249 |
repositoryProperties
|
1094
|
250 |
|configEntry|
|
|
251 |
|
1085
|
252 |
repositoryProperties
|
|
253 |
ifNil: [
|
|
254 |
repositoryProperties := Dictionary new.
|
|
255 |
(self fileUtils directoryExists: directory)
|
|
256 |
ifFalse: [
|
|
257 |
self
|
|
258 |
error:
|
|
259 |
'filetree:// repository '
|
|
260 |
,
|
|
261 |
(self fileUtils directoryPathString: self directory) printString
|
|
262 |
, ' does not exist.' ].
|
1094
|
263 |
(configEntry := self directory entries
|
1085
|
264 |
detect: [ :entry | entry name = '.filetree' ]
|
|
265 |
ifNone: [ ])
|
1094
|
266 |
isNil ifTrue: [
|
1085
|
267 |
repositoryProperties := self defaultRepositoryProperties.
|
|
268 |
self writeRepositoryProperties ]
|
1094
|
269 |
ifFalse: [
|
1085
|
270 |
configEntry
|
|
271 |
readStreamDo: [ :fileStream | repositoryProperties := MCFileTreeJsonParser parseStream: fileStream ] ] ].
|
|
272 |
^ repositoryProperties
|
1094
|
273 |
|
|
274 |
"Modified: / 01-09-2018 / 17:35:33 / Claus Gittinger"
|
1085
|
275 |
!
|
|
276 |
|
|
277 |
versionFrom: aVersionReferenceString
|
|
278 |
"until we no longer find .tree directories in the wild"
|
|
279 |
|
|
280 |
(self readableFileNames collect: [ :fileName | self fileDirectoryOn: fileName ])
|
|
281 |
select: [ :packageDirectory | self fileUtils directoryExists: packageDirectory ]
|
|
282 |
thenCollect: [ :packageDirectory |
|
|
283 |
(self versionInfoForPackageDirectory: packageDirectory) name = aVersionReferenceString
|
|
284 |
ifTrue: [ ^ self loadVersionFromFileNamed: (self fileUtils directoryName: packageDirectory) ] ].
|
|
285 |
^ nil
|
|
286 |
!
|
|
287 |
|
|
288 |
versionFromFileNamed: aString
|
|
289 |
^ self loadVersionFromFileNamed: aString
|
|
290 |
!
|
|
291 |
|
|
292 |
versionInfoFromFileNamed: aString
|
|
293 |
^ self loadVersionInfoFromFileNamed: aString
|
|
294 |
!
|
|
295 |
|
|
296 |
versionNameFromFileName: aString
|
|
297 |
| description |
|
|
298 |
description := self packageDescriptionFromPackageDirectory: (self fileDirectoryOn: aString).
|
|
299 |
^ description first , '-' , description second , '.' , description third printString
|
|
300 |
! !
|
|
301 |
|
|
302 |
!MCFileTreeRepository methodsFor:'actions'!
|
|
303 |
|
|
304 |
fileDirectoryOn: directoryPath
|
|
305 |
^ self fileUtils directoryFromPath: directoryPath relativeTo: self directory
|
|
306 |
!
|
|
307 |
|
|
308 |
packageDescriptionFromPackageDirectory: packageDirectory
|
|
309 |
| filename info extension |
|
|
310 |
filename := self fileUtils current directoryName: packageDirectory.
|
|
311 |
extension := filename copyFrom: (filename lastIndexOf: $.) to: filename size.
|
|
312 |
^ ((self packageExtension ~= '.package'
|
|
313 |
and: [
|
|
314 |
(self fileUtils filePathExists: 'version' relativeTo: packageDirectory)
|
|
315 |
and: [ self fileUtils filePathExists: 'package' relativeTo: packageDirectory ] ])
|
|
316 |
or: [
|
|
317 |
| dir |
|
|
318 |
dir := self fileUtils
|
|
319 |
directoryFromPath: MCFileTreeStCypressWriter monticelloMetaDirName
|
|
320 |
relativeTo: packageDirectory.
|
|
321 |
self fileUtils directoryExists: dir ])
|
|
322 |
ifTrue: [
|
|
323 |
info := self versionInfoForPackageDirectory: packageDirectory.
|
|
324 |
self parseName: info name extension: extension ]
|
|
325 |
ifFalse: [
|
|
326 |
{(filename copyFrom: 1 to: (filename lastIndexOf: $.) - 1).
|
|
327 |
'cypress'.
|
|
328 |
1.
|
|
329 |
filename} ]
|
|
330 |
!
|
|
331 |
|
|
332 |
packageDescriptionsFromReadableFileNames
|
|
333 |
^ ((self readableFileNames collect: [ :fileName | self fileDirectoryOn: fileName ])
|
|
334 |
select: [ :packageDirectory | self fileUtils directoryExists: packageDirectory ])
|
|
335 |
collect: [ :packageDirectory | self packageDescriptionFromPackageDirectory: packageDirectory ]
|
|
336 |
!
|
|
337 |
|
|
338 |
versionInfoForPackageDirectory: packageDirectory
|
|
339 |
^ ((MCReader readerClassForFileNamed: (self fileUtils directoryName: packageDirectory))
|
|
340 |
on: (self fileUtils parentDirectoryOf: packageDirectory)
|
|
341 |
fileName: (self fileUtils directoryName: packageDirectory))
|
|
342 |
loadVersionInfo;
|
|
343 |
info
|
|
344 |
! !
|
|
345 |
|
|
346 |
!MCFileTreeRepository methodsFor:'caching'!
|
|
347 |
|
|
348 |
cachedFileNames
|
|
349 |
^ #()
|
|
350 |
! !
|
|
351 |
|
|
352 |
!MCFileTreeRepository methodsFor:'descriptions'!
|
|
353 |
|
|
354 |
description
|
|
355 |
^ self class description , super description
|
|
356 |
! !
|
|
357 |
|
|
358 |
!MCFileTreeRepository methodsFor:'i/o'!
|
|
359 |
|
|
360 |
readStreamForFileNamed: aString do: aBlock
|
|
361 |
^ aBlock value: self directory
|
|
362 |
!
|
|
363 |
|
|
364 |
writeStreamForFileNamed: aString replace: aBoolean do: aBlock
|
|
365 |
self error: 'we do not open a single stream, but write multiple files'
|
|
366 |
! !
|
|
367 |
|
|
368 |
!MCFileTreeRepository methodsFor:'interface'!
|
|
369 |
|
|
370 |
versionWithInfo: aVersionInfo ifAbsent: errorBlock
|
|
371 |
(self allFileNamesForVersionNamed: aVersionInfo name)
|
|
372 |
ifNotEmpty: [ :aCollection | ^ self versionFromFileNamed: aCollection first ].
|
|
373 |
^ errorBlock value
|
|
374 |
! !
|
|
375 |
|
|
376 |
!MCFileTreeRepository methodsFor:'private'!
|
|
377 |
|
|
378 |
flushCache
|
|
379 |
"force properties to be reread ... if the directory exists, otherwise let nature
|
|
380 |
take it's course"
|
|
381 |
|
|
382 |
super flushCache.
|
|
383 |
directory
|
|
384 |
ifNotNil: [
|
|
385 |
(MCFileTreeFileUtils current directoryExists: directory)
|
|
386 |
ifTrue: [
|
|
387 |
repositoryProperties := nil.
|
|
388 |
self repositoryProperties ] ]
|
|
389 |
!
|
|
390 |
|
|
391 |
packageExtension
|
|
392 |
^ self repositoryProperties
|
|
393 |
at: 'packageExtension'
|
|
394 |
ifAbsent: [ self class defaultPackageExtension ]
|
|
395 |
!
|
|
396 |
|
|
397 |
parseName: aString extension: extension
|
|
398 |
^ self class parseName: aString extension: extension
|
|
399 |
!
|
|
400 |
|
|
401 |
propertyFileExtension
|
|
402 |
^ self repositoryProperties
|
|
403 |
at: 'propertyFileExtension'
|
|
404 |
ifAbsent: [ self class defaultPropertyFileExtension ]
|
|
405 |
!
|
|
406 |
|
|
407 |
propertyFileExtension: propertyFileExtension
|
|
408 |
self class validatePropertyFileExtension: propertyFileExtension.
|
|
409 |
self repositoryProperties
|
|
410 |
at: 'propertyFileExtension'
|
|
411 |
put: propertyFileExtension.
|
|
412 |
self writeRepositoryProperties
|
|
413 |
! !
|
|
414 |
|
|
415 |
!MCFileTreeRepository methodsFor:'storing'!
|
|
416 |
|
|
417 |
basicStoreVersion: aVersion
|
|
418 |
self readonly
|
|
419 |
ifTrue: [
|
|
420 |
^ self
|
|
421 |
error:
|
|
422 |
'The filetree repository: ' , self description printString
|
|
423 |
, ' was created read only.' ].
|
|
424 |
MCFileTreeWriter fileOut: aVersion on: self
|
|
425 |
! !
|
|
426 |
|
|
427 |
!MCFileTreeRepository methodsFor:'testing'!
|
|
428 |
|
|
429 |
canReadFileNamed: aString
|
|
430 |
^ (aString endsWith: self packageExtension)
|
|
431 |
or: [
|
|
432 |
(aString endsWith: '.tree')
|
|
433 |
or: [
|
|
434 |
"Cypress format"
|
|
435 |
aString endsWith: '.package' ] ]
|
|
436 |
!
|
|
437 |
|
|
438 |
writeRepositoryProperties
|
|
439 |
self fileUtils
|
|
440 |
writeStreamFor: '.filetree'
|
|
441 |
in: self directory
|
|
442 |
do: [ :fileStream |
|
|
443 |
| keyCount propertyCount |
|
|
444 |
repositoryProperties
|
|
445 |
ifNil: [ repositoryProperties := self defaultRepositoryProperties ].
|
|
446 |
keyCount := repositoryProperties size.
|
|
447 |
propertyCount := 0.
|
|
448 |
fileStream lineEndConvention: #'lf'.
|
|
449 |
fileStream nextPutAll: '{'.
|
|
450 |
repositoryProperties
|
|
451 |
keysAndValuesDo: [ :propertyName :propertyValue |
|
|
452 |
propertyCount := propertyCount + 1.
|
|
453 |
fileStream
|
|
454 |
nextPut: $";
|
|
455 |
nextPutAll: propertyName asString;
|
|
456 |
nextPutAll: '" : "';
|
|
457 |
nextPutAll: propertyValue asString;
|
|
458 |
nextPut: $";
|
|
459 |
yourself.
|
|
460 |
propertyCount < keyCount
|
|
461 |
ifTrue: [
|
|
462 |
fileStream
|
|
463 |
nextPutAll: ',';
|
|
464 |
cr ] ].
|
|
465 |
fileStream nextPutAll: ' }' ]
|
|
466 |
! !
|
|
467 |
|
|
468 |
!MCFileTreeRepository class methodsFor:'documentation'!
|
|
469 |
|
|
470 |
version_CVS
|
|
471 |
^ '$Header$'
|
|
472 |
! !
|
|
473 |
|