"{ Package: 'stx:goodies/cypress' }"
CypressModel subclass:#CypressRepository
instanceVariableNames:'directory'
classVariableNames:''
poolDictionaries:''
category:'Cypress-New-Model'
!
!CypressRepository class methodsFor:'documentation'!
documentation
"
An abstraction of Cypress repository. Use it to read & write packages
in Cypress format.
Usage:
creating repository:
crepo := CypressRepository on:'~/Projects/SmalltalkX/repositories/git/cypress/implementations/smalltalkx/packages'.
writing package:
crepo write: #'stx:goodies/cypress'
[author:]
Jan Vrany <jan.vrany@fit.cvut.cz>
[instance variables:]
[class variables:]
[see also:]
"
! !
!CypressRepository class methodsFor:'instance creation'!
on: directory
^self new directory: directory
"Created: / 13-09-2012 / 14:49:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!CypressRepository methodsFor:'accessing'!
directory
"Returns the root directory of the repository"
^ directory
"Modified (comment): / 13-09-2012 / 11:55:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
directory:aStringOrFilename
"Sets the root directory of a Cypress Repository"
directory := aStringOrFilename asFilename.
self readPropertiesFrom: directory.
"Modified: / 13-09-2012 / 14:49:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!CypressRepository methodsFor:'reading'!
read: packageName
"Reads the package from repository. Returns package contents as changeset.
To load that package into an image, send it #apply"
^self read: packageName as: nil
"Created: / 13-09-2012 / 15:21:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
read: packageName as: packageId
"Reads the package from repository. Returns package contents as changeset.
If packageId is not nil, then force package to be a 'packageId',
otherwise, use package name specified in package properties.
To load that package into an image, send it #apply"
| cpkgdir cpkg |
cpkgdir := directory / packageName.
cpkgdir exists ifFalse:[
"Try add '.package'..."
cpkgdir := directory / (packageName , '.package').
cpkgdir exists ifFalse:[
"Hmm...maybe a Smalltalk/X package Id, not a directory name,
let's try"
cpkgdir := directory / ((packageName asString copy replaceAll:$: with:$_; replaceAll:$/ with:$_) , '.package').
cpkgdir exists ifFalse:[
self error:'Cannot find package , ' , packageName, ' in repository'.
^nil.
]
]
].
cpkg := CypressPackage fromDirectory: cpkgdir.
^cpkg
"Created: / 13-09-2012 / 15:37:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!CypressRepository methodsFor:'writing'!
write: packageId
^self write: packageId as: nil
"Created: / 13-09-2012 / 14:23:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
write: packageId as: packageNameOrNil
"Writes a package into repository under given name. If
'packageNameOrNil' is nil, then default filename is used"
| cpkg cpkgdir |
cpkg := packageId asCypressPackage.
cpkgdir := packageNameOrNil isNil ifTrue:[
directory / ((cpkg name copy replaceAll:$: with:$_; replaceAll:$/ with:$_) , '.package').
] ifFalse:[
directory / (packageNameOrNil endsWith:'.package') ifTrue:[packageNameOrNil] ifFalse:[packageNameOrNil , '.package'].
].
directory exists ifFalse:[ directory recursiveMakeDirectory ].
cpkg writeTo: cpkgdir notice: (properties at: 'copyrightLine' ifAbsent:[nil])
"Created: / 13-09-2012 / 14:22:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!CypressRepository class methodsFor:'documentation'!
version_SVN
^ '$Id:: $'
! !