author | Merge Script |
Tue, 09 Aug 2016 06:39:39 +0200 | |
branch | jv |
changeset 1179 | a3c51fbc33cf |
parent 1062 | 1cf3156ef57f |
permissions | -rw-r--r-- |
657 | 1 |
" |
2 |
Copyright (c) 2007-2010 Jan Vrany |
|
3 |
Copyright (c) 2009-2010 eXept Software AG |
|
4 |
||
5 |
Permission is hereby granted, free of charge, to any person |
|
6 |
obtaining a copy of this software and associated documentation |
|
7 |
files (the 'Software'), to deal in the Software without |
|
8 |
restriction, including without limitation the rights to use, |
|
9 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
10 |
copies of the Software, and to permit persons to whom the |
|
11 |
Software is furnished to do so, subject to the following |
|
12 |
conditions: |
|
13 |
||
14 |
The above copyright notice and this permission notice shall be |
|
15 |
included in all copies or substantial portions of the Software. |
|
16 |
||
17 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
18 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
19 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
20 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
21 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
22 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
23 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
24 |
OTHER DEALINGS IN THE SOFTWARE. |
|
25 |
" |
|
26 |
"{ Package: 'stx:libsvn' }" |
|
27 |
||
28 |
"{ NameSpace: SVN }" |
|
29 |
||
30 |
Object subclass:#OSProcess |
|
31 |
instanceVariableNames:'executable arguments environment workdir stdin stdout stderr |
|
32 |
exitValue runningLock' |
|
33 |
classVariableNames:'' |
|
34 |
poolDictionaries:'' |
|
35 |
category:'OS-Support' |
|
36 |
! |
|
37 |
||
38 |
!OSProcess class methodsFor:'documentation'! |
|
39 |
||
40 |
copyright |
|
41 |
" |
|
42 |
Copyright (c) 2007-2010 Jan Vrany |
|
43 |
Copyright (c) 2009-2010 eXept Software AG |
|
44 |
||
45 |
Permission is hereby granted, free of charge, to any person |
|
46 |
obtaining a copy of this software and associated documentation |
|
47 |
files (the 'Software'), to deal in the Software without |
|
48 |
restriction, including without limitation the rights to use, |
|
49 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
50 |
copies of the Software, and to permit persons to whom the |
|
51 |
Software is furnished to do so, subject to the following |
|
52 |
conditions: |
|
53 |
||
54 |
The above copyright notice and this permission notice shall be |
|
55 |
included in all copies or substantial portions of the Software. |
|
56 |
||
57 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
58 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
59 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
60 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
61 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
62 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
63 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
64 |
OTHER DEALINGS IN THE SOFTWARE. |
|
65 |
||
66 |
" |
|
67 |
! ! |
|
68 |
||
672 | 69 |
!OSProcess class methodsFor:'others'! |
70 |
||
71 |
version_CVS |
|
836
efb273cb104f
checkin to get version methods correct
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
672
diff
changeset
|
72 |
^ '$Header$' |
672 | 73 |
! ! |
74 |
||
657 | 75 |
!OSProcess class methodsFor:'private'! |
76 |
||
77 |
asShellQuotedArgument: anObject |
|
78 |
||
79 |
| aString unquotedStream quotedStream | |
|
80 |
aString := anObject asString. |
|
81 |
||
82 |
(aString first = $' and: [aString last = $']) |
|
83 |
ifTrue:[^aString]. |
|
84 |
||
85 |
(aString first = $" and: [aString last = $"]) |
|
86 |
ifTrue:[^aString]. |
|
87 |
||
88 |
(aString allSatisfy: |
|
89 |
[:char|char isSeparator not and: [(#($" $< $> $& $# $; $\) includes: char) not]]) |
|
90 |
ifTrue:[^aString]. |
|
91 |
||
92 |
unquotedStream := aString readStream. |
|
93 |
quotedStream := (String new: aString size + 10) writeStream. |
|
94 |
quotedStream nextPut: $". |
|
95 |
[ unquotedStream atEnd ] whileFalse: |
|
96 |
[|char| |
|
97 |
char := unquotedStream next. |
|
98 |
(#($" $\) includes: char) ifTrue:[quotedStream nextPut: $\]. |
|
99 |
quotedStream nextPut: char]. |
|
100 |
quotedStream nextPut: $". |
|
101 |
^quotedStream contents. |
|
102 |
||
103 |
" |
|
104 |
OSProcess asShellQuotedArgument: 'Hello' . |
|
105 |
OSProcess asShellQuotedArgument: 'Hello world' |
|
106 |
OSProcess asShellQuotedArgument: 'Hello'' world' |
|
107 |
OSProcess asShellQuotedArgument: 'Hello |
|
108 |
World' |
|
109 |
" |
|
110 |
||
111 |
"Created: / 10-10-2008 / 12:32:18 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
112 |
"Modified: / 02-06-2009 / 19:41:05 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
113 |
! ! |
|
114 |
||
115 |
!OSProcess methodsFor:'accessing'! |
|
116 |
||
117 |
arguments |
|
118 |
^ arguments ? #() |
|
119 |
||
120 |
"Created: / 15-03-2008 / 18:09:37 / janfrog" |
|
121 |
! |
|
122 |
||
123 |
arguments:something |
|
124 |
arguments := something. |
|
125 |
||
126 |
"Created: / 15-03-2008 / 18:09:37 / janfrog" |
|
127 |
! |
|
128 |
||
129 |
environment |
|
130 |
^ environment |
|
131 |
||
132 |
"Created: / 15-03-2008 / 18:09:37 / janfrog" |
|
133 |
! |
|
134 |
||
135 |
environment:something |
|
136 |
environment := something. |
|
137 |
||
138 |
"Created: / 15-03-2008 / 18:09:37 / janfrog" |
|
139 |
! |
|
140 |
||
141 |
executable |
|
142 |
^ executable |
|
143 |
||
144 |
"Created: / 15-03-2008 / 18:09:37 / janfrog" |
|
145 |
! |
|
146 |
||
147 |
executable:something |
|
148 |
executable := something. |
|
149 |
||
150 |
"Created: / 15-03-2008 / 18:09:37 / janfrog" |
|
151 |
! |
|
152 |
||
153 |
exitValue |
|
154 |
||
155 |
self waitFor. |
|
156 |
^exitValue |
|
157 |
||
158 |
"Created: / 15-03-2008 / 18:08:00 / janfrog" |
|
159 |
"Modified: / 19-04-2008 / 12:25:56 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
160 |
! |
|
161 |
||
162 |
stderr |
|
163 |
^ stderr ? Stderr |
|
164 |
||
165 |
"Created: / 15-03-2008 / 18:21:05 / janfrog" |
|
166 |
! |
|
167 |
||
168 |
stderr:something |
|
169 |
stderr := something. |
|
170 |
||
171 |
"Created: / 15-03-2008 / 18:21:05 / janfrog" |
|
172 |
! |
|
173 |
||
174 |
stdin |
|
175 |
^ stdin ? Stdin |
|
176 |
||
177 |
"Created: / 15-03-2008 / 18:21:05 / janfrog" |
|
178 |
! |
|
179 |
||
180 |
stdin:something |
|
181 |
stdin := something. |
|
182 |
||
183 |
"Created: / 15-03-2008 / 18:21:05 / janfrog" |
|
184 |
! |
|
185 |
||
186 |
stdout |
|
187 |
^ stdout ? Transcript |
|
188 |
||
189 |
"Created: / 15-03-2008 / 18:21:05 / janfrog" |
|
190 |
! |
|
191 |
||
192 |
stdout:something |
|
193 |
stdout := something. |
|
194 |
||
195 |
"Created: / 15-03-2008 / 18:21:05 / janfrog" |
|
196 |
! |
|
197 |
||
198 |
workdir |
|
199 |
^ workdir ? Filename defaultDirectory |
|
200 |
||
201 |
"Created: / 15-03-2008 / 18:09:37 / janfrog" |
|
202 |
! |
|
203 |
||
204 |
workdir:aStringOrFilename |
|
205 |
workdir := aStringOrFilename asString. |
|
206 |
||
207 |
"Created: / 15-03-2008 / 18:09:37 / janfrog" |
|
208 |
"Modified: / 09-04-2009 / 17:32:25 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
209 |
! ! |
|
210 |
||
211 |
!OSProcess methodsFor:'conversion'! |
|
212 |
||
213 |
asShellCommandString |
|
214 |
||
215 |
| cmdStream | |
|
216 |
cmdStream := String new writeStream. |
|
217 |
cmdStream nextPutAll:self executable. |
|
218 |
self arguments do: |
|
219 |
[:arg| |
|
220 |
cmdStream space. |
|
221 |
cmdStream nextPutAll:(self asShellQuotedArgument: arg)]. |
|
222 |
||
223 |
^cmdStream contents utf8Encoded |
|
224 |
||
225 |
"Created: / 19-03-2008 / 12:34:59 / janfrog" |
|
226 |
"Modified: / 31-03-2008 / 14:09:05 / janfrog" |
|
227 |
"Modified: / 23-03-2009 / 10:09:55 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
228 |
! ! |
|
229 |
||
230 |
!OSProcess methodsFor:'operations'! |
|
231 |
||
232 |
execute |
|
233 |
" |
|
234 |
self synchronized: |
|
235 |
[runningLock |
|
236 |
ifNotNil:[self error:'Process already running'] |
|
237 |
ifNil:[runningLock := Semaphore new:0]]. |
|
238 |
[[" |
|
239 |
OperatingSystem isMSWINDOWSlike"false" |
|
240 |
ifTrue: [self executeOnStupidPlatform] |
|
241 |
ifFalse:[self executeOnReasonablePlatform] |
|
242 |
" |
|
243 |
] ensure:[runningLock signalForAll. runningLock := nil]] fork |
|
244 |
" |
|
245 |
||
246 |
"Created: / 15-03-2008 / 18:11:20 / janfrog" |
|
247 |
"Modified: / 19-03-2008 / 12:35:05 / janfrog" |
|
248 |
"Modified: / 08-06-2008 / 19:15:45 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
249 |
"Modified: / 11-04-2010 / 13:04:54 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
250 |
! |
|
251 |
||
252 |
waitFor |
|
253 |
||
254 |
"| lock | |
|
255 |
self synchronized: |
|
256 |
[runningLock |
|
257 |
ifNil:[^self] |
|
258 |
ifNotNil:[lock := runningLock]]. |
|
259 |
lock wait" |
|
260 |
||
261 |
"Created: / 15-03-2008 / 18:32:41 / janfrog" |
|
262 |
"Modified: / 08-06-2008 / 19:15:22 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
263 |
! ! |
|
264 |
||
265 |
!OSProcess methodsFor:'private'! |
|
266 |
||
267 |
asShellQuotedArgument:arg |
|
268 |
^ self class asShellQuotedArgument:arg |
|
269 |
||
270 |
"Created: / 10-10-2008 / 12:32:18 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
271 |
! |
|
272 |
||
273 |
executeOnReasonablePlatform |
|
274 |
" |
|
275 |
self synchronized: |
|
276 |
[runningLock |
|
277 |
ifNotNil:[self error:'Process already running'] |
|
278 |
ifNil:[runningLock := Semaphore new:0]]. |
|
279 |
[[" |
|
280 |
(OperatingSystem |
|
281 |
executeCommand: self asShellCommandString |
|
282 |
inputFrom: self stdin |
|
283 |
outputTo: self stdout |
|
284 |
errorTo: self stderr |
|
285 |
auxFrom: nil |
|
286 |
environment: nil |
|
287 |
inDirectory: self workdir asString |
|
288 |
lineWise: (self stdout = self stderr) |
|
289 |
onError:[:value|exitValue := value code.false]) |
|
290 |
ifTrue:[exitValue := 0] |
|
291 |
" |
|
292 |
] ensure:[runningLock signalForAll. runningLock := nil]] fork |
|
293 |
" |
|
294 |
||
295 |
"Modified: / 19-03-2008 / 12:35:05 / janfrog" |
|
296 |
"Modified: / 08-06-2008 / 19:15:45 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
297 |
"Created: / 11-04-2010 / 12:49:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
298 |
! |
|
299 |
||
300 |
executeOnStupidPlatform |
|
301 |
||
302 |
"i.e., on MS Windows. For some reasons sometimes part |
|
303 |
of stdout bytes are lost. Arghh. |
|
304 |
To workaround it, redirect output to file and then |
|
305 |
read that file. Stupid & complicated kludge, sigh." |
|
306 |
||
307 |
| extStdoutF extStdout extStderrF extStderr | |
|
308 |
[extStdout := (extStdoutF := Filename newTemporary) writeStream. |
|
309 |
extStderr := (extStderrF := Filename newTemporary) writeStream. |
|
310 |
(OperatingSystem |
|
311 |
executeCommand: self asShellCommandString |
|
312 |
inputFrom: self stdin |
|
313 |
outputTo: extStdout |
|
314 |
errorTo: extStderr |
|
315 |
auxFrom: nil |
|
316 |
environment: nil |
|
317 |
inDirectory: self workdir asString |
|
318 |
lineWise: (self stdout = self stderr) |
|
319 |
onError:[:value|exitValue := value code.false]) |
|
320 |
ifTrue:[exitValue := 0] |
|
321 |
] ensure: [ |
|
322 |
extStdout close. extStderr close. |
|
323 |
stdout nextPutAll: extStdoutF contentsAsString. |
|
324 |
stderr nextPutAll: extStderrF contentsAsString. |
|
325 |
"Windows are really stupid!! Sometimes they lock files |
|
326 |
longer than needed. Even same process is not allowed |
|
327 |
to work with them. Sigh sigh sigh..." |
|
328 |
[ extStdoutF remove ] on: Error do: |
|
329 |
[Delay waitForMilliseconds: 10. |
|
330 |
[ extStdoutF remove ] on: Error do: |
|
1062
1cf3156ef57f
changed: #executeOnStupidPlatform
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
836
diff
changeset
|
331 |
[Delay waitForMilliseconds: 50. |
1cf3156ef57f
changed: #executeOnStupidPlatform
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
836
diff
changeset
|
332 |
[extStdoutF remove] on:Error do:["Givin up, Windows are shit"]]]. |
657 | 333 |
"Same for stderr" |
334 |
[ extStderrF remove ] on: Error do: |
|
335 |
[Delay waitForMilliseconds: 10. |
|
336 |
[ extStderrF remove ] on: Error do: |
|
337 |
[Delay waitForMilliseconds: 20. |
|
1062
1cf3156ef57f
changed: #executeOnStupidPlatform
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
836
diff
changeset
|
338 |
[extStderrF remove] on:Error do:["Givin up, Windows are shit"]]]] |
657 | 339 |
|
340 |
"Created: / 11-04-2010 / 12:50:57 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
341 |
"Modified: / 04-09-2010 / 23:41:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1062
1cf3156ef57f
changed: #executeOnStupidPlatform
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
836
diff
changeset
|
342 |
"Modified: / 13-03-2012 / 23:30:32 / jv" |
657 | 343 |
! ! |
344 |
||
345 |
!OSProcess class methodsFor:'documentation'! |
|
346 |
||
347 |
version |
|
836
efb273cb104f
checkin to get version methods correct
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
672
diff
changeset
|
348 |
^ '$Header$' |
657 | 349 |
! |
350 |
||
351 |
version_SVN |
|
836
efb273cb104f
checkin to get version methods correct
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
672
diff
changeset
|
352 |
^ '§Id: SVN__OSProcess.st 362 2011-08-08 13:07:42Z vranyj1 §' |
657 | 353 |
! ! |