1
|
1 |
"{ Package: 'stx:goodies/metacello' }"
|
|
2 |
|
|
3 |
Object subclass:#MetacelloScriptExecutor
|
|
4 |
instanceVariableNames:'options roots singleRoot projectSpecGenerator actionArg
|
|
5 |
configurationArg baselineArg projectArg classNameArg versionArg
|
|
6 |
repositoryArg'
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'Metacello-Core-Scripts'
|
|
10 |
!
|
|
11 |
|
|
12 |
|
|
13 |
!MetacelloScriptExecutor methodsFor:'accessing'!
|
|
14 |
|
|
15 |
options
|
|
16 |
options ifNil: [ options := Dictionary new ].
|
|
17 |
^ options
|
|
18 |
!
|
|
19 |
|
|
20 |
roots
|
|
21 |
roots ifNil: [ roots := OrderedCollection new ].
|
|
22 |
^ roots
|
|
23 |
!
|
|
24 |
|
|
25 |
singleRoot
|
|
26 |
singleRoot ifNil: [ singleRoot := false ].
|
|
27 |
^ singleRoot
|
|
28 |
!
|
|
29 |
|
|
30 |
singleRoot: aBool
|
|
31 |
singleRoot := aBool
|
|
32 |
! !
|
|
33 |
|
|
34 |
!MetacelloScriptExecutor methodsFor:'actions api'!
|
|
35 |
|
|
36 |
fetch: required
|
|
37 |
actionArg := #'fetch:' -> {required}
|
|
38 |
!
|
|
39 |
|
|
40 |
get
|
|
41 |
actionArg := #'get' -> #()
|
|
42 |
!
|
|
43 |
|
|
44 |
list
|
|
45 |
actionArg := #'list' -> #()
|
|
46 |
!
|
|
47 |
|
|
48 |
load: required
|
|
49 |
actionArg := #'load:' -> {required}
|
|
50 |
!
|
|
51 |
|
|
52 |
lock
|
|
53 |
actionArg := #'lock' -> #()
|
|
54 |
!
|
|
55 |
|
|
56 |
record: required
|
|
57 |
actionArg := #'record:' -> {required}
|
|
58 |
!
|
|
59 |
|
|
60 |
unlock
|
|
61 |
actionArg := #'unlock' -> #()
|
|
62 |
! !
|
|
63 |
|
|
64 |
!MetacelloScriptExecutor methodsFor:'args'!
|
|
65 |
|
|
66 |
baselineArg
|
|
67 |
^ baselineArg
|
|
68 |
!
|
|
69 |
|
|
70 |
baselineArg: anObject
|
|
71 |
baselineArg := anObject
|
|
72 |
!
|
|
73 |
|
|
74 |
classNameArg
|
|
75 |
^ classNameArg
|
|
76 |
!
|
|
77 |
|
|
78 |
classNameArg: anObject
|
|
79 |
classNameArg := anObject
|
|
80 |
!
|
|
81 |
|
|
82 |
configurationArg
|
|
83 |
^ configurationArg
|
|
84 |
!
|
|
85 |
|
|
86 |
configurationArg: anObject
|
|
87 |
configurationArg := anObject
|
|
88 |
!
|
|
89 |
|
|
90 |
projectArg
|
|
91 |
^ projectArg
|
|
92 |
!
|
|
93 |
|
|
94 |
projectArg: anObject
|
|
95 |
projectArg := anObject
|
|
96 |
!
|
|
97 |
|
|
98 |
repositoryArg
|
|
99 |
^ repositoryArg
|
|
100 |
!
|
|
101 |
|
|
102 |
repositoryArg: anObject
|
|
103 |
repositoryArg := anObject
|
|
104 |
!
|
|
105 |
|
|
106 |
versionArg
|
|
107 |
^ versionArg
|
|
108 |
!
|
|
109 |
|
|
110 |
versionArg: anObject
|
|
111 |
versionArg := anObject
|
|
112 |
! !
|
|
113 |
|
|
114 |
!MetacelloScriptExecutor methodsFor:'execution'!
|
|
115 |
|
|
116 |
applyArgsToProjectSpec: aProjectSpec
|
|
117 |
classNameArg ifNotNil: [ aProjectSpec className: classNameArg ].
|
|
118 |
versionArg ifNotNil: [ aProjectSpec versionString: versionArg ].
|
|
119 |
repositoryArg ifNotNil: [ aProjectSpec repository: repositoryArg ].
|
|
120 |
^ aProjectSpec
|
|
121 |
!
|
|
122 |
|
|
123 |
execute: statements
|
|
124 |
statements
|
|
125 |
do: [ :assoc | assoc value ifNil: [ self perform: assoc key ] ifNotNil: [ self perform: assoc key withArguments: assoc value ] ].
|
|
126 |
projectSpecGenerator := self projectSpecGenerator.
|
|
127 |
projectSpecGenerator target
|
|
128 |
execute: [ :projectSpec |
|
|
129 |
| engine |
|
|
130 |
engine := MetacelloScriptEngine new
|
|
131 |
options: self options copy;
|
|
132 |
projectSpec: projectSpec;
|
|
133 |
yourself.
|
|
134 |
engine perform: actionArg key withArguments: actionArg value.
|
|
135 |
engine root ifNotNil: [ :root | self roots add: root ] ]
|
|
136 |
against: self.
|
|
137 |
^ (self singleRoot and: [ self roots size == 1 ])
|
|
138 |
ifTrue: [ self roots first ]
|
|
139 |
ifFalse: [ self roots ]
|
|
140 |
!
|
|
141 |
|
|
142 |
projectSpecGenerator
|
|
143 |
baselineArg
|
|
144 |
ifNotNil: [
|
|
145 |
configurationArg ifNotNil: [ self error: ' baseline: and configuration: are both be specified' ].
|
|
146 |
projectArg ifNotNil: [ self error: ' baseline: and project are both be specified' ].
|
|
147 |
^ MetacelloBaselineSpecGenerator new
|
|
148 |
target: baselineArg;
|
|
149 |
yourself ].
|
|
150 |
configurationArg
|
|
151 |
ifNotNil: [
|
|
152 |
baselineArg ifNotNil: [ self error: ' baseline: and configuration: are both be specified' ].
|
|
153 |
projectArg ifNotNil: [ self error: ' configuration and project are both be specified' ].
|
|
154 |
^ MetacelloConfigurationSpecGenerator new
|
|
155 |
target: configurationArg;
|
|
156 |
yourself ].
|
|
157 |
projectArg
|
|
158 |
ifNotNil: [
|
|
159 |
configurationArg ifNotNil: [ self error: ' project and configuration: are both be specified' ].
|
|
160 |
baselineArg ifNotNil: [ self error: ' baseline: and project are both be specified' ].
|
|
161 |
^ MetacelloProjectSpecGenerator new
|
|
162 |
target: projectArg;
|
|
163 |
yourself ].
|
|
164 |
self error: 'project, baseline, or configuration not specified'
|
|
165 |
! !
|
|
166 |
|
|
167 |
!MetacelloScriptExecutor methodsFor:'execution callback'!
|
|
168 |
|
|
169 |
executeBlock: selectBlock do: projectSpecBlock
|
|
170 |
((projectSpecGenerator projectSpecListBlock value select: selectBlock) select: self projectSpecSelectBlock)
|
|
171 |
do: [ :projectSpec | projectSpecBlock value: (self applyArgsToProjectSpec: projectSpec copy) ]
|
|
172 |
!
|
|
173 |
|
|
174 |
executeCollection: aCollection do: projectSpecBlock
|
|
175 |
aCollection
|
|
176 |
do: [ :projectName |
|
|
177 |
((projectSpecGenerator projectSpecLookupBlock value: projectName) select: self projectSpecSelectBlock)
|
|
178 |
do: [ :projectSpec | projectSpecBlock value: (self applyArgsToProjectSpec: projectSpec copy) ] ]
|
|
179 |
!
|
|
180 |
|
|
181 |
executeString: aString do: projectSpecBlock
|
|
182 |
self singleRoot: true.
|
|
183 |
((projectSpecGenerator projectSpecLookupBlock value: aString) select: self projectSpecSelectBlock)
|
|
184 |
do: [ :projectSpec | projectSpecBlock value: (self applyArgsToProjectSpec: projectSpec copy) ]
|
|
185 |
!
|
|
186 |
|
|
187 |
projectSpecSelectBlock
|
|
188 |
^ [ :projectSpec | true ]
|
|
189 |
! !
|
|
190 |
|
|
191 |
!MetacelloScriptExecutor methodsFor:'options api'!
|
|
192 |
|
|
193 |
cacheRepository: aRepositoryDescription
|
|
194 |
self options at: #'cacheRepository' put: aRepositoryDescription
|
|
195 |
!
|
|
196 |
|
|
197 |
ignoreImage: aBool
|
|
198 |
self options at: #'ignoreImage' put: aBool
|
|
199 |
!
|
|
200 |
|
|
201 |
onConflict: aBlock
|
|
202 |
self options at: #'onConflict' put: aBlock
|
|
203 |
!
|
|
204 |
|
|
205 |
onDowngrade: aBlock
|
|
206 |
self options at: #'onDowngrade' put: aBlock
|
|
207 |
!
|
|
208 |
|
|
209 |
onUpgrade: aBlock
|
|
210 |
self options at: #'onUpgrade' put: aBlock
|
|
211 |
!
|
|
212 |
|
|
213 |
repositoryOverrides: aRepositoryDescriptionList
|
|
214 |
self options at: #'repositoryOverrides' put: aRepositoryDescriptionList
|
|
215 |
!
|
|
216 |
|
|
217 |
silently: aBool
|
|
218 |
self options at: #'silently' put: aBool
|
|
219 |
!
|
|
220 |
|
|
221 |
useCurrentVersion: aBool
|
|
222 |
"private option used to implement the classic mode"
|
|
223 |
|
|
224 |
self options at: #'useCurrentVersion' put: aBool
|
|
225 |
! !
|
|
226 |
|
|
227 |
!MetacelloScriptExecutor class methodsFor:'documentation'!
|
|
228 |
|
|
229 |
version_SVN
|
|
230 |
^ '$Id:: $'
|
|
231 |
! !
|