45 ^self new directory: directory |
45 ^self new directory: directory |
46 |
46 |
47 "Created: / 13-09-2012 / 14:49:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
47 "Created: / 13-09-2012 / 14:49:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
48 ! ! |
48 ! ! |
49 |
49 |
|
50 !CypressRepository class methodsFor:'private'! |
|
51 |
|
52 packageDirectoryForPackageName: pkgName in: repoDir |
|
53 | pkgDir | |
|
54 |
|
55 pkgDir := repoDir / pkgName. |
|
56 pkgDir exists ifTrue:[ ^ pkgDir ]. |
|
57 |
|
58 "/Try add .package" |
|
59 pkgDir := pkgDir withSuffix: self defaultFileSuffixForPackage. |
|
60 pkgDir exists ifTrue:[ ^ pkgDir ]. |
|
61 |
|
62 "/Hmm...maybe stx package name |
|
63 pkgDir := repoDir / ((pkgName asString copy replaceAll:$: with:$_; replaceAll:$/ with:$_) , '.' , self defaultFileSuffixForPackage). |
|
64 pkgDir exists ifTrue:[ ^ pkgDir ]. |
|
65 |
|
66 "/ No luck, return nil |
|
67 ^nil |
|
68 |
|
69 "Created: / 18-09-2012 / 13:33:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
70 ! ! |
|
71 |
50 !CypressRepository methodsFor:'accessing'! |
72 !CypressRepository methodsFor:'accessing'! |
51 |
73 |
52 directory |
74 directory |
53 "Returns the root directory of the repository" |
75 "Returns the root directory of the repository" |
54 |
76 |
108 |
118 |
109 initialize |
119 initialize |
110 | props | |
120 | props | |
111 |
121 |
112 writerClass := CypressWriter. |
122 writerClass := CypressWriter. |
113 readerClass := CypressReader. |
123 readerClass := nil. |
114 directory isNil ifTrue:[ ^ self ]. |
124 directory isNil ifTrue:[ ^ self ]. |
115 directory exists ifFalse:[ ^ self ]. |
125 directory exists ifFalse:[ ^ self ]. |
116 |
126 |
117 ( props := directory / 'properties.json' ) exists ifTrue:[ |
127 ( props := directory / 'properties.json' ) exists ifTrue:[ |
118 readerClass := CypressFileTreeReader. |
128 readerClass := CypressFileTreeReader. |
133 "superclass CypressModel says that I am responsible to implement this method" |
143 "superclass CypressModel says that I am responsible to implement this method" |
134 |
144 |
135 ^ self shouldNotImplement |
145 ^ self shouldNotImplement |
136 |
146 |
137 "Modified: / 18-09-2012 / 10:58:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
147 "Modified: / 18-09-2012 / 10:58:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
148 ! |
|
149 |
|
150 writer |
|
151 ^writerClass onRepository: self |
|
152 |
|
153 "Created: / 17-09-2012 / 22:22:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
154 ! ! |
|
155 |
|
156 !CypressRepository methodsFor:'reading'! |
|
157 |
|
158 read: packageName |
|
159 |
|
160 ^self read: packageName as: nil |
|
161 |
|
162 "Created: / 18-09-2012 / 09:34:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
163 ! |
|
164 |
|
165 read: packageName as: packageId |
|
166 | readerCls | |
|
167 |
|
168 readerCls := readerClass. |
|
169 readerCls isNil ifTrue:[ |
|
170 | pdir | |
|
171 |
|
172 pdir := self class packageDirectoryForPackageName: packageName in: directory. |
|
173 pdir notNil ifTrue:[ |
|
174 readerCls := (pdir / 'properties.json') exists |
|
175 ifTrue:[CypressFileTreeReader] |
|
176 ifFalse:[CypressReader]. |
|
177 ] ifFalse:[ |
|
178 self error:'No such package found'. |
|
179 ]. |
|
180 ]. |
|
181 |
|
182 ^(readerCls onRepository: self) readPackage: packageName as: packageId from: directory |
|
183 |
|
184 "Created: / 18-09-2012 / 13:15:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
138 ! ! |
185 ! ! |
139 |
186 |
140 !CypressRepository methodsFor:'writing'! |
187 !CypressRepository methodsFor:'writing'! |
141 |
|
142 read: packageName |
|
143 |
|
144 ^self reader readPackage: packageName from: directory |
|
145 |
|
146 "Created: / 18-09-2012 / 09:34:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
147 ! |
|
148 |
188 |
149 write: packageIdOrProjectDefinition |
189 write: packageIdOrProjectDefinition |
150 |
190 |
151 self writer writePackage: packageIdOrProjectDefinition asCypressPackage to: directory |
191 self writer writePackage: packageIdOrProjectDefinition asCypressPackage to: directory |
152 |
192 |