author | Claus Gittinger <cg@exept.de> |
Thu, 07 Jun 2018 16:23:29 +0200 | |
changeset 23054 | 2f647561edc5 |
parent 22692 | 9f3eab852dbb |
child 23199 | 7aee2cc2ace7 |
permissions | -rw-r--r-- |
22692 | 1 |
"{ Encoding: utf8 }" |
2 |
||
9944 | 3 |
" |
4 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
5 |
All Rights Reserved |
|
6 |
||
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
14 |
"{ Package: 'stx:libbasic' }" |
|
15 |
||
17280 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
9944 | 18 |
Object subclass:#StandaloneStartup |
19 |
instanceVariableNames:'' |
|
10772 | 20 |
classVariableNames:'Verbose CommandLineArguments' |
9944 | 21 |
poolDictionaries:'' |
22 |
category:'System-Support' |
|
23 |
! |
|
24 |
||
11102 | 25 |
StandaloneStartup class instanceVariableNames:'MutexHandle' |
26 |
||
27 |
" |
|
28 |
No other class instance variables are inherited by this class. |
|
29 |
" |
|
30 |
! |
|
31 |
||
9944 | 32 |
!StandaloneStartup class methodsFor:'documentation'! |
33 |
||
34 |
copyright |
|
35 |
" |
|
36 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
37 |
All Rights Reserved |
|
38 |
||
39 |
This software is furnished under a license and may be used |
|
40 |
only in accordance with the terms of that license and with the |
|
41 |
inclusion of the above copyright notice. This software may not |
|
42 |
be provided or otherwise made available to, or used by, any |
|
43 |
other person. No title to or ownership of the software is |
|
44 |
hereby transferred. |
|
45 |
" |
|
46 |
! |
|
47 |
||
48 |
documentation |
|
49 |
" |
|
17280 | 50 |
When smalltalk is started as IDE (stx), the show starts in Smalltalk>>start. |
19517 | 51 |
In contrast, when a standAlone app is linked, |
52 |
the show starts in the startup class's start method. |
|
53 |
||
20672 | 54 |
This class is an abstrat, subclassable template for a standalone GUI-application's startup. |
19517 | 55 |
|
9944 | 56 |
For your own stand alone programs, define a subclass of this, |
12335 | 57 |
and redefine the #main: method there. |
9944 | 58 |
(of course, the other methods can also be redefined.) |
59 |
||
60 |
[author:] |
|
61 |
Claus Gittinger |
|
62 |
||
63 |
[start with:] |
|
64 |
<yourNamehere>Startup start |
|
10886 | 65 |
|
66 |
[see also:] |
|
67 |
Smalltalk |
|
68 |
GetOpt |
|
69 |
ReadEvalPrintLoop |
|
19517 | 70 |
StandaloneStartupHeadless |
9944 | 71 |
" |
11102 | 72 |
! |
73 |
||
74 |
howToDealWithMultipleApplicationInstances |
|
75 |
" |
|
76 |
please read the comment in the corresponding ApplicationModel class-documentation method. |
|
77 |
" |
|
11352 | 78 |
! |
79 |
||
80 |
whichMethodsToRedefine |
|
81 |
" |
|
82 |
main:argv |
|
20428 | 83 |
that's the actual program. |
11352 | 84 |
|
85 |
suppressRCFileReading |
|
86 |
false here; redefine to return true, to disable the rc-file reading. |
|
87 |
you loose the chance of configuration, but lock the user out from any access to any smalltalk |
|
88 |
(if you have a user-phobia) |
|
89 |
||
90 |
allowDebugOption |
|
11361
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
91 |
false here; redefine to return true, to enable the --debug startup option. |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
92 |
if disabled, you loose the chance of debugging, but lock the user out from any access to any smalltalk |
11352 | 93 |
|
94 |
allowScriptingOption |
|
11361
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
95 |
false here; redefine to return true, to enable the --scripting startup option. |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
96 |
if disabled, you loose the chance of remote control, but lock the user out from any access to any smalltalk |
11352 | 97 |
|
98 |
" |
|
9944 | 99 |
! ! |
100 |
||
101 |
!StandaloneStartup class methodsFor:'initialization'! |
|
102 |
||
103 |
initialize |
|
11360 | 104 |
"/ Verbose := true. |
9944 | 105 |
Verbose := false. |
106 |
! ! |
|
107 |
||
13375 | 108 |
!StandaloneStartup class methodsFor:'debugging support'! |
109 |
||
110 |
dumpCoverageInformation |
|
111 |
"if the --coverage argument was given, dump that information now. |
|
112 |
This is invoked via an exit block, when smalltalk terminates" |
|
113 |
||
13377 | 114 |
"/ count instrumented vs. non-instrumented classes |
115 |
|nClasses nMethods |
|
116 |
locOverall locExecuted locUnexecuted locInstrumented locUninstrumented |
|
117 |
locCovered locUncovered |
|
118 |
nInstrumentedClasses nUninstrumentedClasses nPartiallyInstrumentedClasses |
|
119 |
nInstrumentedMethods nUninstrumentedMethods |
|
120 |
nClassesCompletelyCovered nClassesPartiallyCovered nClassesUncovered |
|
121 |
nMethodsCompletelyCovered nMethodsPartiallyCovered nMethodsUncovered| |
|
122 |
||
123 |
nInstrumentedClasses := nUninstrumentedClasses := nPartiallyInstrumentedClasses := 0. |
|
124 |
nInstrumentedMethods := nUninstrumentedMethods := 0. |
|
125 |
nClasses := nMethods := 0. |
|
126 |
locOverall := locCovered := locUncovered := 0. |
|
127 |
locInstrumented := locUninstrumented := 0. |
|
128 |
locExecuted := locUnexecuted := 0. |
|
129 |
nClassesCompletelyCovered := nClassesPartiallyCovered := nClassesUncovered := 0. |
|
130 |
nMethodsCompletelyCovered := nMethodsPartiallyCovered := nMethodsUncovered := 0. |
|
131 |
||
132 |
Smalltalk allClassesDo:[:eachClass | |
|
133 |
|nInstrumentedMethodsInClass nUninstrumentedMethodsInClass |
|
134 |
nMethodsCompletelyCoveredInClass nMethodsPartiallyCoveredInClass nMethodsUncoveredInClass |
|
135 |
locInstrumentedMethodsInClass locUninstrumentedMethodsInClass |
|
136 |
locExecutedInClass locUnexecutedInClass locPartiallyExecutedInClass| |
|
137 |
||
138 |
nMethodsCompletelyCoveredInClass := nMethodsPartiallyCoveredInClass := nMethodsUncoveredInClass := 0. |
|
139 |
nInstrumentedMethodsInClass := nUninstrumentedMethodsInClass := 0. |
|
140 |
locInstrumentedMethodsInClass := locUninstrumentedMethodsInClass := 0. |
|
141 |
eachClass instAndClassMethodsDo:[:mthd | |
|
142 |
|locMethod| |
|
143 |
||
144 |
nMethods := nMethods + 1. |
|
145 |
locMethod := 0. "/ mthd source asCollectionOfLines size. |
|
146 |
||
147 |
mthd isInstrumented ifTrue:[ |
|
148 |
nInstrumentedMethodsInClass := nInstrumentedMethodsInClass + 1. |
|
149 |
locInstrumentedMethodsInClass := locInstrumentedMethodsInClass + locMethod. |
|
150 |
mthd hasBeenCalled ifTrue:[ |
|
151 |
mthd haveAllBlocksBeenExecuted ifTrue:[ |
|
152 |
"/ fully covered |
|
153 |
nMethodsCompletelyCoveredInClass := nMethodsCompletelyCoveredInClass + 1 |
|
154 |
] ifFalse:[ |
|
155 |
"/ partially covered |
|
156 |
nMethodsPartiallyCoveredInClass := nMethodsPartiallyCoveredInClass + 1 |
|
157 |
] |
|
158 |
] ifFalse:[ |
|
159 |
"/ completely uncovered |
|
160 |
nMethodsUncoveredInClass := nMethodsUncoveredInClass + 1 |
|
161 |
]. |
|
162 |
] ifFalse:[ |
|
163 |
nUninstrumentedMethodsInClass := nUninstrumentedMethodsInClass + 1. |
|
164 |
locUninstrumentedMethodsInClass := locUninstrumentedMethodsInClass + locMethod. |
|
165 |
]. |
|
166 |
]. |
|
167 |
||
168 |
nInstrumentedMethods := nInstrumentedMethods + nInstrumentedMethodsInClass. |
|
169 |
nUninstrumentedMethods := nUninstrumentedMethods + nUninstrumentedMethodsInClass. |
|
170 |
||
171 |
nMethodsCompletelyCovered := nMethodsCompletelyCovered + nMethodsCompletelyCoveredInClass. |
|
172 |
nMethodsUncovered := nMethodsUncovered + nMethodsUncoveredInClass. |
|
173 |
nMethodsPartiallyCovered := nMethodsPartiallyCovered + nMethodsPartiallyCoveredInClass. |
|
174 |
||
175 |
nClasses := nClasses + 1. |
|
176 |
nInstrumentedMethodsInClass == 0 ifTrue:[ |
|
177 |
nUninstrumentedMethodsInClass == 0 ifTrue:[ |
|
178 |
"/ empty class - do not count |
|
179 |
] ifFalse:[ |
|
180 |
"/ completely uninstrumented |
|
181 |
nUninstrumentedClasses := nUninstrumentedClasses + 1. |
|
182 |
]. |
|
183 |
] ifFalse:[ |
|
184 |
nUninstrumentedMethodsInClass == 0 ifTrue:[ |
|
185 |
"/ completely instrumented |
|
186 |
nInstrumentedClasses := nInstrumentedClasses + 1. |
|
187 |
] ifFalse:[ |
|
188 |
"/ part/part |
|
189 |
nPartiallyInstrumentedClasses := nPartiallyInstrumentedClasses + 1. |
|
190 |
]. |
|
191 |
]. |
|
192 |
||
193 |
nMethodsCompletelyCoveredInClass > 0 ifTrue:[ |
|
194 |
nClassesCompletelyCovered := nClassesCompletelyCovered + 1. |
|
195 |
] ifFalse:[ |
|
196 |
nMethodsPartiallyCoveredInClass > 0 ifTrue:[ |
|
197 |
nClassesPartiallyCovered := nClassesPartiallyCovered + 1. |
|
198 |
] ifFalse:[ |
|
199 |
nClassesUncovered := nClassesUncovered + 1. |
|
200 |
]. |
|
201 |
]. |
|
202 |
]. |
|
203 |
||
204 |
Stderr nextPutLine:'Coverage info:'. |
|
205 |
Stderr nextPutLine:(' Classes, overall: %1' bindWith:nClasses). |
|
206 |
Stderr nextPutLine:(' Classes, instrumented: %1 (%2%%)' bindWith:nInstrumentedClasses with:((nInstrumentedClasses / nClasses * 100) asFixedPoint:1)). |
|
207 |
Stderr nextPutLine:(' Classes, uninstrumented: %1 (%2%%)' bindWith:nUninstrumentedClasses with:((nUninstrumentedClasses / nClasses * 100) asFixedPoint:1)). |
|
208 |
Stderr nextPutLine:(' Classes, partially instrumented: %1 (%2%%)' bindWith:nPartiallyInstrumentedClasses with:((nPartiallyInstrumentedClasses / nClasses * 100) asFixedPoint:1)). |
|
209 |
Stderr nextPutLine:(' Classes, covered: %1 (%2%%)' bindWith:nClassesCompletelyCovered with:((nClassesCompletelyCovered / nClasses * 100) asFixedPoint:1)). |
|
210 |
Stderr nextPutLine:(' Classes, partially covered: %1 (%2%%)' bindWith:nClassesPartiallyCovered with:((nClassesPartiallyCovered / nClasses * 100) asFixedPoint:1)). |
|
211 |
Stderr nextPutLine:(' Classes, uncovered: %1 (%2%%)' bindWith:nClassesUncovered with:((nClassesUncovered / nClasses * 100) asFixedPoint:1)). |
|
212 |
Stderr nextPutLine:(' Methods, overall: %1' bindWith:nMethods). |
|
213 |
Stderr nextPutLine:(' Methods, instrumented: %1 (%2%%)' bindWith:nInstrumentedMethods with:((nInstrumentedMethods / nMethods * 100) asFixedPoint:1)). |
|
214 |
Stderr nextPutLine:(' Methods, uninstrumented: %1 (%2%%)' bindWith:nUninstrumentedMethods with:((nUninstrumentedMethods / nMethods * 100) asFixedPoint:1)). |
|
215 |
Stderr nextPutLine:(' Methods, covered: %1 (%2%%)' bindWith:nMethodsCompletelyCovered with:((nMethodsCompletelyCovered / nMethods * 100) asFixedPoint:1)). |
|
216 |
Stderr nextPutLine:(' Methods, partially covered: %1 (%2%%)' bindWith:nMethodsPartiallyCovered with:((nMethodsPartiallyCovered / nMethods * 100) asFixedPoint:1)). |
|
217 |
Stderr nextPutLine:(' Methods, uncovered: %1 (%2%%)' bindWith:nMethodsUncovered with:((nMethodsUncovered / nMethods * 100) asFixedPoint:1)). |
|
218 |
||
219 |
" |
|
220 |
self dumpCoverageInformation |
|
221 |
" |
|
13375 | 222 |
|
223 |
"Created: / 24-05-2011 / 17:08:46 / cg" |
|
13377 | 224 |
"Modified: / 25-05-2011 / 00:10:51 / cg" |
13375 | 225 |
! |
226 |
||
227 |
handleCoverageMeasurementOptionsFromArguments:argv |
|
228 |
"handle the coverage measurement command line argument: |
|
229 |
--coverage |
|
230 |
[+/-]package: <package-pattern> ... do / do not measure in package (regex match) |
|
231 |
[+/-]class: <class-pattern> ... do / do not measure in class (regex match, including nameSpace) |
|
232 |
[+/-]method: <className>#<methodName> ... do / do not measure in method |
|
233 |
||
234 |
adds instrumentation code to all selected methods. |
|
235 |
" |
|
236 |
||
237 |
|idx nextArg done doAdd addNames addMethodNames |
|
13377 | 238 |
anyItem nMethodsInstrumented checkClass checkMethod coverageAction |
13375 | 239 |
includedPackageNames excludedPackageNames |
240 |
includedClassNames excludedClassNames |
|
241 |
includedMethodNames excludedMethodNames| |
|
242 |
||
243 |
" |
|
13376 | 244 |
self handleCoverageMeasurementOptionsFromArguments:#('foo' '--coverage' '+package:' 'expeccoNET:*' '-class:' 'ExpeccoNET::ML' 'ExpeccoNET::LicenseString' ) |
13375 | 245 |
self handleCoverageMeasurementOptionsFromArguments:#('foo' '--coverage' '+package:' 'stx:*') |
246 |
self handleCoverageMeasurementOptionsFromArguments:#('foo' '--coverage' '+package:' 'stx:libtool*') |
|
247 |
self handleCoverageMeasurementOptionsFromArguments:#('foo' '--coverage' '+class:' 'Tools::*' '-class:' 'Tools::StringSearchTool' ) |
|
248 |
self handleCoverageMeasurementOptionsFromArguments:#('foo' '--coverage' '+class:' 'Tools::*Browser*' ) |
|
249 |
self handleCoverageMeasurementOptionsFromArguments:#('foo' '--coverage' '+method:' 'String#at:put:' 'String#at:') |
|
250 |
" |
|
251 |
includedPackageNames := Set new. |
|
252 |
excludedPackageNames := Set new. |
|
253 |
includedClassNames := Set new. |
|
254 |
excludedClassNames := Set new. |
|
255 |
includedMethodNames := Dictionary new. |
|
256 |
excludedMethodNames := Dictionary new. |
|
257 |
||
258 |
idx := argv indexOfAny:#('--coverage'). |
|
259 |
idx == 0 ifTrue:[^ self ]. |
|
260 |
||
261 |
addNames := [:collection | |
|
262 |
[ |
|
263 |
nextArg := argv at:idx ifAbsent:nil. |
|
264 |
nextArg notNil |
|
265 |
and:[ ((nextArg startsWith:'+') or:[(nextArg startsWith:'-')]) not |
|
266 |
and:[ (nextArg endsWith:':') not ]] |
|
267 |
] whileTrue:[ |
|
268 |
collection add:nextArg. |
|
269 |
anyItem := true. |
|
270 |
idx := idx + 1. |
|
271 |
]. |
|
272 |
]. |
|
273 |
||
274 |
addMethodNames := [:collection | |
|
275 |
|idx2 className selector| |
|
276 |
||
277 |
[ |
|
278 |
nextArg := argv at:idx ifAbsent:nil. |
|
279 |
nextArg notNil |
|
280 |
and:[ ((nextArg startsWith:'+') or:[(nextArg startsWith:'-')]) not] |
|
281 |
] whileTrue:[ |
|
282 |
idx2 := nextArg indexOf:$#. |
|
283 |
className := nextArg copyTo:idx2-1. |
|
284 |
selector := nextArg copyFrom:idx2+1. |
|
285 |
(collection at:className ifAbsentPut:[Set new]) add:selector. |
|
286 |
anyItem := true. |
|
287 |
idx := idx + 1. |
|
288 |
]. |
|
289 |
]. |
|
290 |
||
291 |
idx := idx + 1. |
|
292 |
done := false. |
|
293 |
||
294 |
[ |
|
295 |
nextArg := argv at:idx ifAbsent:nil. |
|
296 |
done not |
|
297 |
and:[ nextArg notNil |
|
298 |
and:[ ((nextArg startsWith:'+') or:[(nextArg startsWith:'-')]) ]] |
|
299 |
] whileTrue:[ |
|
300 |
idx := idx + 1. |
|
301 |
doAdd := nextArg first == $+. |
|
302 |
nextArg := nextArg copyFrom:2. |
|
303 |
nextArg = 'package:' ifTrue:[ |
|
304 |
addNames value:(doAdd ifTrue:includedPackageNames ifFalse:excludedPackageNames). |
|
305 |
] ifFalse:[ |
|
306 |
nextArg = 'class:' ifTrue:[ |
|
307 |
addNames value:(doAdd ifTrue:includedClassNames ifFalse:excludedClassNames). |
|
308 |
] ifFalse:[ |
|
309 |
nextArg = 'method:' ifTrue:[ |
|
310 |
addMethodNames value:(doAdd ifTrue:includedMethodNames ifFalse:excludedMethodNames). |
|
311 |
] ifFalse:[ |
|
312 |
done := true |
|
313 |
] |
|
314 |
]. |
|
315 |
]. |
|
316 |
]. |
|
317 |
||
318 |
anyItem ifFalse:[ ^ self ]. |
|
13377 | 319 |
nMethodsInstrumented := 0. |
13375 | 320 |
|
321 |
coverageAction := [:aMethod | |
|
22020 | 322 |
(aMethod isSubclassResponsibility not |
13375 | 323 |
and:[ aMethod hasPrimitiveCode not ]) ifTrue:[ |
324 |
Transcript show:'instrumenting '; showCR:aMethod. |
|
325 |
aMethod mclass recompile:aMethod selector usingCompilerClass:InstrumentingCompiler. |
|
13377 | 326 |
nMethodsInstrumented := nMethodsInstrumented + 1. |
13375 | 327 |
] ifFalse:[ |
328 |
Transcript show:'skipped '; showCR:aMethod. |
|
329 |
]. |
|
330 |
]. |
|
331 |
||
332 |
checkMethod := [:someMethod | |
|
333 |
((excludedMethodNames at:someMethod mclass name ifAbsent:#()) includes:someMethod selector) ifFalse:[ |
|
334 |
coverageAction value:someMethod |
|
335 |
]. |
|
336 |
]. |
|
337 |
||
338 |
checkClass := [:someClass | |
|
339 |
someClass instAndClassSelectorsAndMethodsDo:[:sel :mthd | |
|
340 |
checkMethod value:mthd |
|
341 |
] |
|
342 |
]. |
|
343 |
||
344 |
Smalltalk allClassesDo:[:eachClass | |
|
345 |
(includedPackageNames contains:[:somePackagePattern| somePackagePattern match:(eachClass package)]) ifTrue:[ |
|
346 |
(excludedPackageNames contains:[:somePackagePattern| somePackagePattern match:(eachClass package)]) ifFalse:[ |
|
347 |
(excludedClassNames contains:[:someClassPattern| someClassPattern match:(eachClass name)]) ifFalse:[ |
|
348 |
checkClass value:eachClass |
|
349 |
] |
|
350 |
] |
|
351 |
] ifFalse:[ |
|
352 |
(includedClassNames contains:[:someClassPattern| someClassPattern match:(eachClass name)]) ifTrue:[ |
|
353 |
(excludedClassNames contains:[:someClassPattern| someClassPattern match:(eachClass name)]) ifFalse:[ |
|
354 |
checkClass value:eachClass |
|
355 |
] |
|
356 |
] ifFalse:[ |
|
357 |
(Array with:eachClass theMetaclass with:eachClass) do:[:clsOrMeta | |
|
358 |
|selectors| |
|
359 |
||
360 |
selectors := includedMethodNames at:clsOrMeta name ifAbsent:nil. |
|
361 |
selectors notEmptyOrNil ifTrue:[ |
|
362 |
selectors do:[:eachSelector | |
|
363 |
coverageAction value:(clsOrMeta compiledMethodAt:eachSelector asSymbol). |
|
364 |
]. |
|
365 |
]. |
|
366 |
]. |
|
367 |
]. |
|
368 |
]. |
|
369 |
]. |
|
370 |
||
13377 | 371 |
nMethodsInstrumented ifTrue:[ |
372 |
Transcript show:('%1 methods instrumented' bindWith:nMethodsInstrumented). |
|
13375 | 373 |
Smalltalk addExitBlock:[ self dumpCoverageInformation ]. |
374 |
]. |
|
375 |
||
376 |
"Created: / 24-05-2011 / 16:30:54 / cg" |
|
22020 | 377 |
"Modified: / 16-07-2017 / 11:32:45 / cg" |
13375 | 378 |
! ! |
379 |
||
11361
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
380 |
!StandaloneStartup class methodsFor:'defaults'! |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
381 |
|
13375 | 382 |
allowCoverageMeasurementOption |
383 |
"enable/disable the --measureCoverage startup options. |
|
384 |
The default is false, so standAlone apps do not support coverage measurements by default. |
|
385 |
Can be redefined in subclasses to enable it |
|
386 |
(but will need the libcomp and possibly the programming/oom packages to be present)" |
|
387 |
||
13378
ed35cb03c4ed
changed: #allowCoverageMeasurementOption
Claus Gittinger <cg@exept.de>
parents:
13377
diff
changeset
|
388 |
^ Smalltalk isStandAloneApp not |
13375 | 389 |
|
390 |
"Created: / 24-05-2011 / 16:16:15 / cg" |
|
13378
ed35cb03c4ed
changed: #allowCoverageMeasurementOption
Claus Gittinger <cg@exept.de>
parents:
13377
diff
changeset
|
391 |
"Modified: / 25-05-2011 / 00:21:18 / cg" |
13375 | 392 |
! |
393 |
||
11361
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
394 |
allowDebugOption |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
395 |
"enable/disable the --debug startup option. |
11363 | 396 |
Can be redefined in subclasses to enable it" |
11361
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
397 |
|
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
398 |
^ false |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
399 |
! |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
400 |
|
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
401 |
allowScriptingOption |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
402 |
"enable/disable the --scripting startup option. |
11363 | 403 |
Can be redefined in subclasses to enable it" |
11361
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
404 |
|
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
405 |
^ false |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
406 |
! |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
407 |
|
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
408 |
suppressRCFileReading |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
409 |
"enable/disable the rc-file reading (and also the --rcFileName option). |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
410 |
If suppressed, there is no chance to interfere with the startup. |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
411 |
Can be redefined in subclasses to disable it" |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
412 |
|
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
413 |
^ false |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
414 |
! ! |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
415 |
|
9944 | 416 |
!StandaloneStartup class methodsFor:'helpers'! |
417 |
||
11423 | 418 |
printInfo:msg |
20669 | 419 |
"print an informal message using the logger" |
420 |
||
20668 | 421 |
('%1 [info]: ' bindWith:(self applicationName)) infoPrint. |
422 |
msg asString infoPrintCR. |
|
11423 | 423 |
! |
424 |
||
9944 | 425 |
redirectStandardStreams |
20669 | 426 |
"redirect all output for Transcript to stderr" |
427 |
||
9944 | 428 |
Transcript := Stderr. |
429 |
! |
|
430 |
||
13269 | 431 |
verbose |
20670 | 432 |
"true iff the program was started with --verbose flag" |
20669 | 433 |
|
13269 | 434 |
^ Verbose == true |
435 |
||
436 |
"Created: / 01-02-2011 / 15:52:47 / cg" |
|
437 |
! |
|
438 |
||
9944 | 439 |
verboseInfo:msg |
20670 | 440 |
"output some message, but only if the program was started with --verbose" |
20669 | 441 |
|
18180 | 442 |
Verbose == true ifTrue:[ |
443 |
self printInfo:msg |
|
444 |
] |
|
9944 | 445 |
|
446 |
"Modified: / 19-09-2006 / 16:30:27 / cg" |
|
447 |
! ! |
|
448 |
||
17707 | 449 |
|
11102 | 450 |
!StandaloneStartup class methodsFor:'multiple applications support'! |
451 |
||
452 |
applicationRegistryPath |
|
453 |
"the key under which this application stores its process ID in the registry |
|
454 |
as a collection of path-components. |
|
455 |
i.e. if #('foo' 'bar' 'baz') is returned here, the current applications ID will be stored |
|
456 |
in HKEY_CURRENT_USER\Software\foo\bar\baz\CurrentID. |
|
457 |
(would also be used as a relative path for a temporary lock file under unix). |
|
458 |
Used to detect if another instance of this application is already running." |
|
459 |
||
460 |
self subclassResponsibility |
|
461 |
! |
|
462 |
||
463 |
applicationUUID |
|
464 |
"answer an application-specific unique uuid. |
|
465 |
This is used as the name of some exclusive OS-resource, which is used to find out, |
|
466 |
if another instance of this application is already running. |
|
13595
c0db78969b83
comment/format in: #applicationUUID
Claus Gittinger <cg@exept.de>
parents:
13580
diff
changeset
|
467 |
Under win32, a mutex is used; under unix, an exclusive file in the tempDir could be used. |
c0db78969b83
comment/format in: #applicationUUID
Claus Gittinger <cg@exept.de>
parents:
13580
diff
changeset
|
468 |
If redefined, please return a real UUID (i.e. UUID fromString:'.....') and not a string or |
c0db78969b83
comment/format in: #applicationUUID
Claus Gittinger <cg@exept.de>
parents:
13580
diff
changeset
|
469 |
similar possibly conflicting identifier. |
c0db78969b83
comment/format in: #applicationUUID
Claus Gittinger <cg@exept.de>
parents:
13580
diff
changeset
|
470 |
You can paste a fresh worldwide unique id via the editor's more-misc-paste UUID menuFunction." |
11102 | 471 |
|
472 |
self subclassResponsibility |
|
13595
c0db78969b83
comment/format in: #applicationUUID
Claus Gittinger <cg@exept.de>
parents:
13580
diff
changeset
|
473 |
|
c0db78969b83
comment/format in: #applicationUUID
Claus Gittinger <cg@exept.de>
parents:
13580
diff
changeset
|
474 |
"Modified (comment): / 19-08-2011 / 01:54:39 / cg" |
11102 | 475 |
! |
476 |
||
12998
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
477 |
shouldReuseRunningApplication |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
478 |
"answer true, if an already running application instance should be re-used" |
11102 | 479 |
|
12998
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
480 |
^ false |
11102 | 481 |
! ! |
482 |
||
483 |
!StandaloneStartup class methodsFor:'multiple applications support-helpers'! |
|
484 |
||
485 |
applicationRegistryEntry |
|
486 |
"retrieve the registry entry in which (if present), any currently running application |
|
487 |
has left its process ID" |
|
488 |
||
489 |
|path relPathName applicationEntry softwareEntry| |
|
490 |
||
14321
783b5c28f912
changed: #applicationRegistryEntry
Stefan Vogel <sv@exept.de>
parents:
14048
diff
changeset
|
491 |
OperatingSystem isMSWINDOWSlike ifFalse:[^ nil]. |
783b5c28f912
changed: #applicationRegistryEntry
Stefan Vogel <sv@exept.de>
parents:
14048
diff
changeset
|
492 |
|
11102 | 493 |
path := self applicationRegistryPath. |
494 |
relPathName := path asStringWith:$\. |
|
495 |
applicationEntry := Win32OperatingSystem registryEntry key:'HKEY_CURRENT_USER\Software\',relPathName. |
|
496 |
applicationEntry isNil ifTrue:[ |
|
497 |
softwareEntry := Win32OperatingSystem registryEntry key:'HKEY_CURRENT_USER\Software'. |
|
498 |
softwareEntry isNil ifTrue:[ |
|
499 |
Transcript showCR: 'Failed to get Software entry in registry'. |
|
500 |
^ nil. |
|
501 |
]. |
|
11103 | 502 |
|
11102 | 503 |
path do:[:subKey | |
504 |
|subEntry| |
|
505 |
||
11103 | 506 |
subEntry := softwareEntry createSubKeyNamed:subKey. |
11102 | 507 |
subEntry isNil ifTrue:[ |
508 |
Transcript showCR: 'Failed to create ',subKey,' entry in registry'. |
|
509 |
^ nil. |
|
510 |
]. |
|
511 |
softwareEntry := subEntry. |
|
512 |
]. |
|
513 |
applicationEntry := softwareEntry. |
|
514 |
]. |
|
515 |
^ applicationEntry |
|
516 |
! |
|
517 |
||
12998
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
518 |
checkForAndExitIfAnotherApplicationInstanceIsRunning |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
519 |
"if another instance of this application is running, |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
520 |
send it an openFile command for my file-argument, and exit. |
20537 | 521 |
(i.e. the already running app gets a (processOpenPathCommand:argument) message |
522 |
to ask it to open up another window)." |
|
12998
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
523 |
|
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
524 |
|shouldExit| |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
525 |
|
13280 | 526 |
self verboseInfo:('check for another app'). |
12998
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
527 |
self isAnotherApplicationInstanceRunning ifTrue:[ |
13280 | 528 |
self verboseInfo:('other app is running'). |
12998
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
529 |
shouldExit := self processStartupOfASecondInstance. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
530 |
shouldExit ifTrue:[ |
13280 | 531 |
self verboseInfo:('yes; go away'). |
12998
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
532 |
self releaseApplicationMutex. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
533 |
Smalltalk isStandAloneApp ifTrue:[ |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
534 |
Smalltalk exit. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
535 |
] |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
536 |
]. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
537 |
]. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
538 |
|
13280 | 539 |
"Modified: / 04-02-2011 / 00:04:31 / cg" |
12998
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
540 |
! |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
541 |
|
11107 | 542 |
confirmOpenNewApplicationInstance |
543 |
||
544 |
^ Dialog confirm: ('Continue opening a new instance of %1 or exit?' bindWith:self applicationName) |
|
545 |
title: ('%1 is already open!!' bindWith:self applicationName) |
|
546 |
yesLabel: 'Continue' |
|
547 |
noLabel: 'Exit' |
|
548 |
! |
|
549 |
||
11102 | 550 |
currentIDKeyInRegistry |
551 |
^ 'CurrentID' |
|
552 |
! |
|
553 |
||
554 |
getCurrentIDFromRegistry |
|
555 |
||
556 |
|applicationEntry| |
|
557 |
||
558 |
applicationEntry := self applicationRegistryEntry. |
|
559 |
applicationEntry isNil ifTrue:[^ nil.]. |
|
560 |
^ applicationEntry valueNamed: self currentIDKeyInRegistry |
|
561 |
||
562 |
" |
|
563 |
|hWnd externalAddress| |
|
564 |
hWnd := DapasXStartup getCurrentIDFromRegistry. |
|
565 |
hWnd isEmptyOrNil ifTrue:[^ self halt.]. |
|
566 |
hWnd := hWnd asInteger. |
|
567 |
externalAddress := ExternalAddress newAddress: hWnd. |
|
568 |
Display raiseWindow:externalAddress. |
|
569 |
Display setForegroundWindow:externalAddress |
|
570 |
" |
|
571 |
! |
|
572 |
||
573 |
getIDOfRunningApplicationFromRegistryEntry |
|
574 |
|applicationEntry| |
|
575 |
||
576 |
applicationEntry := self applicationRegistryEntry. |
|
577 |
applicationEntry isNil ifTrue:[^ nil.]. |
|
578 |
^ applicationEntry valueNamed: self currentIDKeyInRegistry |
|
579 |
! |
|
580 |
||
581 |
isAnotherApplicationInstanceRunning |
|
13083
66a8fb472eb5
comment/format in: #isAnotherApplicationInstanceRunning
Claus Gittinger <cg@exept.de>
parents:
12999
diff
changeset
|
582 |
"answer true, if another instance of myself is currently running. |
11102 | 583 |
For now, it only works under win32, because it uses the underlying mutex mechanism." |
584 |
||
11106 | 585 |
| lastErrorCode alreadyExists handleAndLastErrorCode | |
11102 | 586 |
|
587 |
OperatingSystem isMSDOSlike ifTrue:[ |
|
13280 | 588 |
self verboseInfo:('create mutex...'). |
20592 | 589 |
handleAndLastErrorCode := OperatingSystem createMutexNamed:(self applicationUUID printString). |
11102 | 590 |
MutexHandle := handleAndLastErrorCode first. |
591 |
lastErrorCode := handleAndLastErrorCode second. |
|
592 |
"/ self assert: lastErrorCode == 0. |
|
593 |
alreadyExists := |
|
594 |
MutexHandle isNil |
|
595 |
or:[lastErrorCode == 183 "ERROR_ALREADY_EXISTS" |
|
596 |
or:[lastErrorCode == 5 "ERROR_ACCESS_DENIED"]]. |
|
597 |
||
13280 | 598 |
self verboseInfo:('alreadyExists = ',alreadyExists printString). |
20592 | 599 |
alreadyExists ifTrue:[ |
600 |
"we do not own the Mutex, so we cannot release it" |
|
601 |
MutexHandle notNil ifTrue:[ |
|
602 |
OperatingSystem primCloseHandle: MutexHandle. |
|
603 |
MutexHandle := nil. |
|
604 |
]. |
|
605 |
] ifFalse:[ |
|
606 |
"no need to wait, createMutex sets initialOwner = true" |
|
607 |
"/ OperatingSystem waitForSingleObject: MutexHandle. |
|
608 |
]. |
|
609 |
^ alreadyExists. |
|
11102 | 610 |
]. |
611 |
||
612 |
^ false. |
|
13083
66a8fb472eb5
comment/format in: #isAnotherApplicationInstanceRunning
Claus Gittinger <cg@exept.de>
parents:
12999
diff
changeset
|
613 |
|
13280 | 614 |
"Modified: / 04-02-2011 / 00:05:51 / cg" |
11102 | 615 |
! |
616 |
||
617 |
processStartupOfASecondInstance |
|
618 |
"This is executed when I have been started as a second instance of an already running application. |
|
619 |
If I can get the currentID (i.e. windowID) of the first one and there is a command line argument with a file, |
|
20537 | 620 |
send a message (processOpenPathCommand:argument) to the main window of the already running application, to ask it for another window. |
11102 | 621 |
If the currentID is unknown, ask if the user wants to open a new instance of the application anyway. |
622 |
Return true if the first instance has been notified, and this second instance should exit." |
|
623 |
||
11107 | 624 |
|currentIDStringFromRegistry currentIDFromRegistry fileArg commands aWindowId setForegroundWindowSucceeded| |
11102 | 625 |
|
12998
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
626 |
commands := CommandLineArguments. |
11102 | 627 |
|
628 |
currentIDStringFromRegistry := self getCurrentIDFromRegistry. |
|
629 |
||
630 |
"If the currentID is not found and there are arguments from the command line, |
|
631 |
we should wait in case of starting the first instance of the application |
|
632 |
with a multiple selection of files." |
|
633 |
(currentIDStringFromRegistry isEmptyOrNil and:[commands notEmptyOrNil]) ifTrue:[ |
|
634 |
Delay waitForSeconds: 2. |
|
635 |
]. |
|
636 |
||
637 |
currentIDStringFromRegistry := self getCurrentIDFromRegistry. |
|
638 |
currentIDStringFromRegistry isEmptyOrNil ifTrue:[ |
|
11107 | 639 |
^ self confirmOpenNewApplicationInstance not. |
11102 | 640 |
]. |
641 |
||
11107 | 642 |
currentIDFromRegistry := Integer readFrom:currentIDStringFromRegistry onError: 0. |
11102 | 643 |
|
644 |
"/ bring the other application to the foreground |
|
645 |
aWindowId := ExternalAddress newAddress: currentIDFromRegistry. |
|
11107 | 646 |
setForegroundWindowSucceeded := Display primSetForegroundWindow: aWindowId. |
11379 | 647 |
"/ setForegroundWindowSucceeded ifFalse:[^ self confirmOpenNewApplicationInstance not]. |
11102 | 648 |
|
649 |
"Autostart for associated extension" |
|
650 |
commands notEmpty ifTrue:[ |
|
651 |
fileArg := commands last asFilename. |
|
652 |
fileArg exists ifTrue:[ |
|
653 |
self sendOpenPathCommand:(fileArg pathName) toWindowId: aWindowId. |
|
654 |
]. |
|
655 |
]. |
|
656 |
^ true |
|
12935
49210cf2d978
comment/format in: #processStartupOfASecondInstance
Claus Gittinger <cg@exept.de>
parents:
12933
diff
changeset
|
657 |
|
49210cf2d978
comment/format in: #processStartupOfASecondInstance
Claus Gittinger <cg@exept.de>
parents:
12933
diff
changeset
|
658 |
"Modified: / 08-07-2010 / 00:47:44 / cg" |
11102 | 659 |
! |
660 |
||
661 |
releaseApplicationMutex |
|
12933
4e196c41604d
changed: #releaseApplicationMutex set MutexHandle to nil
ca
parents:
12626
diff
changeset
|
662 |
(MutexHandle notNil and:[OperatingSystem isMSDOSlike]) ifTrue:[ |
4e196c41604d
changed: #releaseApplicationMutex set MutexHandle to nil
ca
parents:
12626
diff
changeset
|
663 |
OperatingSystem releaseMutex: MutexHandle. |
4e196c41604d
changed: #releaseApplicationMutex set MutexHandle to nil
ca
parents:
12626
diff
changeset
|
664 |
OperatingSystem primCloseHandle: MutexHandle. |
4e196c41604d
changed: #releaseApplicationMutex set MutexHandle to nil
ca
parents:
12626
diff
changeset
|
665 |
|
4e196c41604d
changed: #releaseApplicationMutex set MutexHandle to nil
ca
parents:
12626
diff
changeset
|
666 |
MutexHandle := nil. |
11102 | 667 |
]. |
668 |
! |
|
669 |
||
670 |
sendCommand:message toWindowId:aWindowId |
|
671 |
"use the event send mechanism to forward a command to the already running application" |
|
672 |
||
673 |
Display |
|
20583 | 674 |
sendCopyData: message |
11102 | 675 |
toWindowId: aWindowId. |
676 |
! |
|
677 |
||
678 |
sendOpenPathCommand:pathName toWindowId:aWindowId |
|
679 |
"use the event send mechanism to forward an open-Path command to the already running application" |
|
680 |
||
681 |
self sendCommand:('openPath:', pathName) toWindowId:aWindowId. |
|
682 |
! |
|
683 |
||
684 |
writeCurrentIDIntoRegistry: currentID |
|
685 |
||
11104 | 686 |
|applicationEntry currentIDEntry| |
11102 | 687 |
|
11104 | 688 |
applicationEntry := self applicationRegistryEntry. |
689 |
applicationEntry isNil ifTrue:[^ false.]. |
|
11102 | 690 |
|
11104 | 691 |
currentIDEntry := applicationEntry createSubKeyNamed:(self currentIDKeyInRegistry). |
11102 | 692 |
currentIDEntry isNil ifTrue:[ |
693 |
Transcript showCR: 'Failed to create CurrentID entry in registry'. |
|
694 |
^ false. |
|
695 |
]. |
|
696 |
||
11104 | 697 |
^ applicationEntry valueNamed:(self currentIDKeyInRegistry) put:(currentID printString). |
11102 | 698 |
|
699 |
" |
|
700 |
| currentID returnedCurrentID | |
|
701 |
currentID := 999. |
|
702 |
DapasXStartup writeCurrentIDIntoRegistry: currentID. |
|
703 |
returnedCurrentID := DapasXStartup getCurrentIDFromRegistry. |
|
704 |
self assert: currentID = returnedCurrentID asNumber. |
|
705 |
" |
|
706 |
! ! |
|
707 |
||
9944 | 708 |
!StandaloneStartup class methodsFor:'queries'! |
709 |
||
710 |
applicationName |
|
11352 | 711 |
"used in verbose messages - can/should be redefined in subclasses" |
9944 | 712 |
|
713 |
|nm| |
|
714 |
||
715 |
nm := self nameWithoutPrefix. |
|
716 |
(nm endsWith:'Startup') ifTrue:[ |
|
15162
f17158d75a0e
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14977
diff
changeset
|
717 |
^ nm copyButLast:('Startup' size). |
9944 | 718 |
]. |
719 |
(nm endsWith:'Start') ifTrue:[ |
|
15162
f17158d75a0e
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14977
diff
changeset
|
720 |
^ nm copyButLast:('Start' size). |
9944 | 721 |
]. |
722 |
^ nm |
|
723 |
||
724 |
"Created: / 19-09-2006 / 16:26:44 / cg" |
|
725 |
! |
|
726 |
||
14544 | 727 |
commandLineArguments |
728 |
^ CommandLineArguments |
|
729 |
! |
|
730 |
||
19518 | 731 |
isAbstract |
732 |
^ self == StandaloneStartup |
|
733 |
! |
|
734 |
||
10040
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
735 |
isBrowserStartable |
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
736 |
"do not allow clicking on me in the browser" |
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
737 |
|
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
738 |
^ false |
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
739 |
|
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
740 |
"Created: / 06-10-2006 / 11:33:13 / cg" |
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
741 |
! |
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
742 |
|
12626
f85aaddaea1d
added: keepSplashWindowOpen
Claus Gittinger <cg@exept.de>
parents:
12523
diff
changeset
|
743 |
keepSplashWindowOpen |
f85aaddaea1d
added: keepSplashWindowOpen
Claus Gittinger <cg@exept.de>
parents:
12523
diff
changeset
|
744 |
"if true is returned here, the splashWindow is not closed and will be still open |
f85aaddaea1d
added: keepSplashWindowOpen
Claus Gittinger <cg@exept.de>
parents:
12523
diff
changeset
|
745 |
when the main: method is invoked. This allows for plugin-loads etc. to be shown in the |
f85aaddaea1d
added: keepSplashWindowOpen
Claus Gittinger <cg@exept.de>
parents:
12523
diff
changeset
|
746 |
splash screen. However, my subclass's main: has to make sure that the splashScreen is closed. |
f85aaddaea1d
added: keepSplashWindowOpen
Claus Gittinger <cg@exept.de>
parents:
12523
diff
changeset
|
747 |
(calling hideSplashWindow) |
f85aaddaea1d
added: keepSplashWindowOpen
Claus Gittinger <cg@exept.de>
parents:
12523
diff
changeset
|
748 |
The default is false here which means that the splashWindow will be already closed when the |
f85aaddaea1d
added: keepSplashWindowOpen
Claus Gittinger <cg@exept.de>
parents:
12523
diff
changeset
|
749 |
subclasses main: is invoked." |
f85aaddaea1d
added: keepSplashWindowOpen
Claus Gittinger <cg@exept.de>
parents:
12523
diff
changeset
|
750 |
|
f85aaddaea1d
added: keepSplashWindowOpen
Claus Gittinger <cg@exept.de>
parents:
12523
diff
changeset
|
751 |
^ false |
f85aaddaea1d
added: keepSplashWindowOpen
Claus Gittinger <cg@exept.de>
parents:
12523
diff
changeset
|
752 |
! |
f85aaddaea1d
added: keepSplashWindowOpen
Claus Gittinger <cg@exept.de>
parents:
12523
diff
changeset
|
753 |
|
15818 | 754 |
patchesDirectory |
755 |
"answer a directory containing patches. |
|
756 |
The directory needs not to be present." |
|
757 |
||
758 |
^ OperatingSystem pathOfSTXExecutable asFilename directory construct:'patches'. |
|
759 |
! |
|
760 |
||
9944 | 761 |
startupFilename |
11352 | 762 |
"used in verbose messages - can/should be redefined in subclasses" |
9944 | 763 |
|
764 |
^ self applicationName asLowercase,'Start.rc' |
|
765 |
||
766 |
" |
|
11352 | 767 |
ExpeccoStartup startupFilename -> 'expecco.rc' |
9944 | 768 |
" |
769 |
||
770 |
"Created: / 19-09-2006 / 16:38:28 / cg" |
|
771 |
! ! |
|
772 |
||
773 |
!StandaloneStartup class methodsFor:'startup'! |
|
774 |
||
13375 | 775 |
handleRCFileOptionsFromArguments:argv |
776 |
"handle rc-file command line arguments: |
|
777 |
--rcFileName ......... define a startup rc-file |
|
778 |
" |
|
779 |
||
780 |
|idx nextArg rcFilename| |
|
781 |
||
782 |
idx := argv indexOf:'--rcFileName'. |
|
783 |
idx ~~ 0 ifTrue:[ |
|
784 |
nextArg := argv at:(idx + 1) ifAbsent:nil. |
|
785 |
(nextArg notNil and:[ (nextArg startsWith:'-') not ]) ifTrue:[ |
|
786 |
rcFilename := nextArg. |
|
787 |
argv removeAtIndex:idx+1; removeAtIndex:idx. |
|
788 |
] |
|
789 |
]. |
|
790 |
||
791 |
rcFilename isNil ifTrue:[ |
|
792 |
rcFilename := self startupFilename. |
|
793 |
]. |
|
794 |
rcFilename asFilename exists ifTrue:[ |
|
795 |
self verboseInfo:('reading ',rcFilename,'...'). |
|
796 |
rcFilename isAbsolute ifFalse:[ |
|
797 |
rcFilename := OperatingSystem pathOfSTXExecutable asFilename directory constructString:rcFilename. |
|
798 |
]. |
|
799 |
Smalltalk secureFileIn:rcFilename |
|
800 |
]. |
|
801 |
||
802 |
"Created: / 24-05-2011 / 16:13:34 / cg" |
|
803 |
! |
|
804 |
||
805 |
handleScriptingOptionsFromArguments:argv |
|
806 |
"handle scripting command line argument: |
|
19879 | 807 |
--scripting portNr ... start a scripting server on port (or default, if missing) |
13375 | 808 |
--allowHost host ..... add host to the allowed scripting hosts |
809 |
" |
|
810 |
||
811 |
|scripting idx nextArg portNr allowedScriptingHosts| |
|
812 |
||
19881 | 813 |
self verboseInfo:('handle scripting: ',argv asArray printString). |
814 |
||
13375 | 815 |
scripting := false. |
816 |
||
13376 | 817 |
idx := argv indexOfAny:#('--scripting'). |
818 |
idx ~~ 0 ifTrue:[ |
|
819 |
nextArg := argv at:(idx + 1) ifAbsent:nil. |
|
820 |
(nextArg notNil and:[ (nextArg startsWith:'-') not ]) ifTrue:[ |
|
821 |
portNr := nextArg asInteger. |
|
822 |
argv removeAtIndex:idx+1. |
|
13375 | 823 |
]. |
13376 | 824 |
argv removeAtIndex:idx. |
13375 | 825 |
|
13376 | 826 |
scripting := true |
827 |
]. |
|
828 |
||
829 |
allowedScriptingHosts := OrderedCollection new. |
|
13375 | 830 |
|
13376 | 831 |
idx := argv indexOfAny:#('--allowHost'). |
832 |
[idx ~~ 0] whileTrue:[ |
|
833 |
nextArg := argv at:(idx + 1) ifAbsent:nil. |
|
834 |
nextArg isNil ifTrue:[ |
|
835 |
self usage. |
|
836 |
AbortOperationRequest raise. |
|
837 |
]. |
|
838 |
allowedScriptingHosts add:nextArg. |
|
13375 | 839 |
idx := argv indexOfAny:#('--allowHost'). |
840 |
]. |
|
841 |
||
842 |
scripting ifTrue:[ |
|
843 |
self verboseInfo:('scripting on'). |
|
16131 | 844 |
STXScriptingServer isNil ifTrue:[ |
16237 | 845 |
[ |
846 |
Smalltalk loadPackage:'stx:goodies/simpleServices'. |
|
847 |
] on:PackageLoadError do:[:ex| |
|
848 |
self verboseInfo:('missing STXScriptingServer package (stx:goodies/simpleServices)'). |
|
849 |
^ self. |
|
850 |
] |
|
16131 | 851 |
]. |
13375 | 852 |
STXScriptingServer notNil ifTrue:[ |
853 |
allowedScriptingHosts do:[:eachHost | STXScriptingServer allowHost:eachHost ]. |
|
854 |
||
855 |
"/ scripting on port/stdin_out/8008 |
|
856 |
self verboseInfo:('start scripting'). |
|
19881 | 857 |
STXScriptingServer server:(STXScriptingServer startAt:portNr) |
13375 | 858 |
] ifFalse:[ |
859 |
self verboseInfo:('missing STXScriptingServer class'). |
|
860 |
]. |
|
861 |
]. |
|
862 |
||
863 |
"Created: / 24-05-2011 / 16:12:02 / cg" |
|
13376 | 864 |
"Modified: / 24-05-2011 / 17:40:26 / cg" |
13375 | 865 |
! |
866 |
||
11055
e600e19e2e7f
loadPatch extracted to be redefinable.
Claus Gittinger <cg@exept.de>
parents:
10956
diff
changeset
|
867 |
loadPatch:fileName |
11056
e2c4a6e948b6
loadPatch extracted to be redefinable.
Claus Gittinger <cg@exept.de>
parents:
11055
diff
changeset
|
868 |
self verboseInfo:('loading patch: ',fileName baseName). |
22692 | 869 |
^ [ |
16307 | 870 |
Smalltalk silentFileIn:fileName. |
15899 | 871 |
] on:InvalidPatchError do:[:ex| |
872 |
self verboseInfo:('invalid patch: %1 error: %2' |
|
873 |
bindWith:fileName baseName with:ex messageText). |
|
22692 | 874 |
false. |
15899 | 875 |
]. |
22692 | 876 |
|
877 |
"Modified: / 23-04-2018 / 17:08:06 / stefan" |
|
11055
e600e19e2e7f
loadPatch extracted to be redefinable.
Claus Gittinger <cg@exept.de>
parents:
10956
diff
changeset
|
878 |
! |
e600e19e2e7f
loadPatch extracted to be redefinable.
Claus Gittinger <cg@exept.de>
parents:
10956
diff
changeset
|
879 |
|
9944 | 880 |
loadPatches |
13796 | 881 |
"load all patches in the application's patches dir" |
882 |
||
15504 | 883 |
self possiblyCheckForNewPatchesOnServer. |
13796 | 884 |
self loadPatchesMatching:nil. |
885 |
! |
|
886 |
||
887 |
loadPatchesMatching:aGlobString |
|
15502 | 888 |
"load the patches in the application's patches dir. |
21499 | 889 |
If aGlobString is not empty or nil, only patches matching the glob |
13796 | 890 |
pattern are loaded. E.g. '[0-9]*.chg'" |
891 |
||
15894 | 892 |
|patchesDir prevMode patchesToLoad| |
9944 | 893 |
|
18525
6b76f94a31ae
allow for patchesDirectory to return a string
Claus Gittinger <cg@exept.de>
parents:
18180
diff
changeset
|
894 |
patchesDir := self patchesDirectory asFilename. |
15818 | 895 |
patchesDir isDirectory ifTrue:[ |
11764
89c0c60feb24
Discard source code of patches that are loaded at startup
Stefan Vogel <sv@exept.de>
parents:
11753
diff
changeset
|
896 |
prevMode := ClassCategoryReader sourceMode. |
89c0c60feb24
Discard source code of patches that are loaded at startup
Stefan Vogel <sv@exept.de>
parents:
11753
diff
changeset
|
897 |
ClassCategoryReader sourceMode:#discard. |
89c0c60feb24
Discard source code of patches that are loaded at startup
Stefan Vogel <sv@exept.de>
parents:
11753
diff
changeset
|
898 |
[ |
15894 | 899 |
patchesToLoad := patchesDir directoryContentsAsFilenames. |
15818 | 900 |
patchesToLoad := patchesToLoad select:[:eachFilenameString| |
21499 | 901 |
eachFilenameString asFilename isRegularFile |
15818 | 902 |
]. |
13796 | 903 |
aGlobString notEmptyOrNil ifTrue:[ |
15894 | 904 |
patchesToLoad := patchesToLoad select:[:eachFilename| |
905 |
aGlobString match:eachFilename baseName caseSensitive:false |
|
13796 | 906 |
]. |
907 |
]. |
|
15894 | 908 |
(patchesToLoad sort:[:a :b | a baseName < b baseName]) do:[:patchFile | |
909 |
self loadPatch:patchFile. |
|
11764
89c0c60feb24
Discard source code of patches that are loaded at startup
Stefan Vogel <sv@exept.de>
parents:
11753
diff
changeset
|
910 |
]. |
89c0c60feb24
Discard source code of patches that are loaded at startup
Stefan Vogel <sv@exept.de>
parents:
11753
diff
changeset
|
911 |
] ensure:[ |
89c0c60feb24
Discard source code of patches that are loaded at startup
Stefan Vogel <sv@exept.de>
parents:
11753
diff
changeset
|
912 |
ClassCategoryReader sourceMode:prevMode. |
9944 | 913 |
]. |
914 |
]. |
|
915 |
||
916 |
"Modified: / 19-09-2006 / 16:30:58 / cg" |
|
15827 | 917 |
"Modified: / 25-11-2013 / 12:27:33 / sr" |
21499 | 918 |
"Modified (comment): / 21-02-2017 / 14:34:28 / mawalch" |
9944 | 919 |
! |
920 |
||
12998
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
921 |
loadRemainingClassLibraries |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
922 |
"To speedup startup, we did not load all dll's (only a subset of non-GUI dll's is present). |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
923 |
Now, load all skipped libs (the ones marked with '*') from modules.stx." |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
924 |
|
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
925 |
|modulesFile dllDirectory dlls| |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
926 |
|
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
927 |
OperatingSystem isMSWINDOWSlike ifFalse:[^ self ]. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
928 |
|
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
929 |
self verboseInfo:'loadRemainingClassLibraries'. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
930 |
modulesFile := self stxModulesFilename. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
931 |
dllDirectory := modulesFile directory. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
932 |
|
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
933 |
dlls := OrderedCollection new. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
934 |
|
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
935 |
modulesFile readingLinesDo:[:eachModulesLine| |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
936 |
|basename dllFile| |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
937 |
|
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
938 |
basename := eachModulesLine withoutSeparators. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
939 |
|
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
940 |
(basename notEmpty and:[basename first == $*]) ifTrue:[ |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
941 |
basename := (basename copyFrom:2) withoutSeparators, '.dll'. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
942 |
dllFile := dllDirectory construct:basename. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
943 |
|
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
944 |
dllFile exists ifTrue:[ |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
945 |
"/ self verboseInfo:('loading: ', basename). |
13580
e5383cbbf032
changed: #loadRemainingClassLibraries
Claus Gittinger <cg@exept.de>
parents:
13378
diff
changeset
|
946 |
"/ Smalltalk showSplashMessage:('loading ', basename). |
12998
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
947 |
dlls add:dllFile. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
948 |
] ifFalse:[ |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
949 |
self verboseInfo:( '**** cannot resolve: ', basename). |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
950 |
]. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
951 |
]. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
952 |
]. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
953 |
|
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
954 |
dlls notEmpty ifTrue:[ |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
955 |
ObjectFileLoader loadObjectFiles:dlls. |
13322
8a1d5d6205cc
changed: #loadRemainingClassLibraries
Stefan Vogel <sv@exept.de>
parents:
13280
diff
changeset
|
956 |
ProjectDefinition initializeAllProjectDefinitions. |
8a1d5d6205cc
changed: #loadRemainingClassLibraries
Stefan Vogel <sv@exept.de>
parents:
13280
diff
changeset
|
957 |
|
12998
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
958 |
Display notNil ifTrue:[ |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
959 |
"New view classes may have been loaded - have to update their styles" |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
960 |
self verboseInfo:'update style caches of loaded dlls'. |
12999
a5ab22c6470c
changed: #loadRemainingClassLibraries
Stefan Vogel <sv@exept.de>
parents:
12998
diff
changeset
|
961 |
SimpleView readStyleSheetAndUpdateAllStyleCaches. |
12998
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
962 |
]. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
963 |
]. |
13580
e5383cbbf032
changed: #loadRemainingClassLibraries
Claus Gittinger <cg@exept.de>
parents:
13378
diff
changeset
|
964 |
|
e5383cbbf032
changed: #loadRemainingClassLibraries
Claus Gittinger <cg@exept.de>
parents:
13378
diff
changeset
|
965 |
"Modified: / 11-08-2011 / 17:23:55 / cg" |
12998
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
966 |
! |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
967 |
|
15503 | 968 |
possiblyCheckForNewPatchesOnServer |
22332 | 969 |
"to be redefined in concrete applications: check for patches on a server" |
15503 | 970 |
|
971 |
"/ intentionally left blank |
|
22332 | 972 |
|
973 |
"Modified (comment): / 08-11-2017 / 17:59:40 / mawalch" |
|
15503 | 974 |
! |
975 |
||
15830 | 976 |
removeDebugger |
977 |
Smalltalk at:#Debugger put:nil. |
|
978 |
! |
|
979 |
||
980 |
removeInspector |
|
981 |
Smalltalk at:#Inspector put:nil. |
|
982 |
! |
|
983 |
||
984 |
removeLauncher |
|
985 |
NewLauncher notNil ifTrue:[ |
|
986 |
NewLauncher allPrivateClasses do:[:cls | |
|
987 |
Smalltalk at:(cls name) put:nil. |
|
988 |
]. |
|
989 |
Smalltalk at:#NewLauncher put:nil. |
|
990 |
]. |
|
991 |
! |
|
992 |
||
9944 | 993 |
setupSmalltalkFromArguments:argv |
11352 | 994 |
"handle common command line arguments: |
995 |
--help ............... print usage and exit |
|
996 |
--verbose (-V) ....... be verbose during startup |
|
997 |
--debug .............. enable debugger & inspector |
|
998 |
--rcFileName ......... define a startup rc-file |
|
11435 | 999 |
--scripting portNr ... start a scripting server |
1000 |
--allowHost host ..... add host to the allowed scripting hosts |
|
11352 | 1001 |
" |
1002 |
||
16235 | 1003 |
|idx debugging baseDir| |
9944 | 1004 |
|
1005 |
"/ Smalltalk beHeadless:true. |
|
1006 |
"/ OperatingSystem disableSignal:(OperatingSystem sigHUP). |
|
1007 |
"/ Smalltalk infoPrinting:true. |
|
1008 |
||
1009 |
(argv includes:'--help') ifTrue:[ |
|
1010 |
self usage. |
|
1011 |
AbortOperationRequest raise. |
|
1012 |
]. |
|
1013 |
||
1014 |
idx := argv indexOfAny:#('--verbose' '-V'). |
|
1015 |
idx ~~ 0 ifTrue:[ |
|
1016 |
argv removeAtIndex:idx. |
|
1017 |
Verbose := true. |
|
20486 | 1018 |
Logger notNil ifTrue:[ |
1019 |
Logger loggingThreshold: Logger severityALL. |
|
1020 |
]. |
|
9944 | 1021 |
]. |
10773 | 1022 |
self verboseInfo:('args: ',argv asArray printString). |
9944 | 1023 |
|
11352 | 1024 |
debugging := false. |
1025 |
(self allowDebugOption) ifTrue:[ |
|
13126
8cbc00290e5b
changed: #setupSmalltalkFromArguments:
Claus Gittinger <cg@exept.de>
parents:
13089
diff
changeset
|
1026 |
idx := argv indexOf:'--debug'. |
11352 | 1027 |
idx ~~ 0 ifTrue:[ |
11357 | 1028 |
self verboseInfo:('debug on'). |
11352 | 1029 |
argv removeAtIndex:idx. |
1030 |
debugging := true |
|
1031 |
]. |
|
1032 |
]. |
|
1033 |
debugging ifTrue:[ |
|
9944 | 1034 |
self setupToolsForDebug. |
1035 |
] ifFalse:[ |
|
1036 |
self setupToolsForNoDebug. |
|
1037 |
]. |
|
16236 | 1038 |
baseDir := OperatingSystem pathOfSTXExecutable asFilename directory. |
1039 |
baseDir baseName = 'application' ifTrue:[ |
|
1040 |
".../work/exept/expecco/application/expecco -> .../work/" |
|
1041 |
baseDir := baseDir directory directory directory. |
|
21676 | 1042 |
Smalltalk packagePath add:(baseDir pathName). |
16236 | 1043 |
] ifFalse:[ |
1044 |
"/opt/expecco/bin/expecco -> /opt/expecco/" |
|
1045 |
baseDir := baseDir directory. |
|
21676 | 1046 |
Smalltalk packagePath add:(baseDir constructString:'packages'). |
16236 | 1047 |
]. |
9944 | 1048 |
|
13375 | 1049 |
(self suppressRCFileReading) ifFalse:[ |
1050 |
self handleRCFileOptionsFromArguments:argv. |
|
9944 | 1051 |
]. |
11352 | 1052 |
(self allowScriptingOption) ifTrue:[ |
13375 | 1053 |
self handleScriptingOptionsFromArguments:argv. |
9944 | 1054 |
]. |
13375 | 1055 |
(self allowCoverageMeasurementOption) ifTrue:[ |
1056 |
self handleCoverageMeasurementOptionsFromArguments:argv. |
|
9944 | 1057 |
]. |
11352 | 1058 |
|
9944 | 1059 |
^ true |
1060 |
||
13375 | 1061 |
"Modified: / 24-05-2011 / 16:14:45 / cg" |
21676 | 1062 |
"Modified (format): / 31-03-2017 / 13:10:04 / cg" |
9944 | 1063 |
! |
1064 |
||
11355 | 1065 |
setupToolsForDebug |
1066 |
Debugger := DebugView ? MiniDebugger. |
|
1067 |
Inspector := InspectorView ? MiniInspector. |
|
11736 | 1068 |
Verbose ifTrue:[ 'debug enabled - CTRL-C brings you into a debugger.' errorPrintCR ]. |
1069 |
"/ self verboseInfo:('debug enabled - CTRL-C brings you into a debugger.'). |
|
9944 | 1070 |
|
1071 |
"Created: / 19-09-2006 / 16:40:32 / cg" |
|
1072 |
! |
|
1073 |
||
11355 | 1074 |
setupToolsForNoDebug |
1075 |
Smalltalk isStandAloneApp ifTrue:[ |
|
15830 | 1076 |
self removeDebugger. |
1077 |
self removeInspector. |
|
1078 |
||
11736 | 1079 |
Verbose ifTrue:[ 'debug disabled.' errorPrintCR ]. |
11355 | 1080 |
self redirectStandardStreams. |
10773 | 1081 |
]. |
9944 | 1082 |
|
1083 |
"Created: / 19-09-2006 / 16:40:47 / cg" |
|
10773 | 1084 |
"Modified: / 31-10-2007 / 16:18:40 / cg" |
9944 | 1085 |
! |
1086 |
||
11355 | 1087 |
start |
20575 | 1088 |
"this is the default initial entry into a standalone program. |
1089 |
It checks for any remaining shared libraries/packages which need to be |
|
1090 |
loaded, looks for any patch-files to be applied |
|
1091 |
and then enters into main. |
|
1092 |
On systems, which allow for the same app to be started for multiple documents |
|
1093 |
(i.e. windows), when clicking on a document), |
|
1094 |
first check if there is an already running application and tell it to open |
|
1095 |
a window for the new document." |
|
1096 |
||
12992 | 1097 |
GenericException handle:[:ex | |
19590 | 1098 |
self verboseInfo:'Error during startup:'. |
1099 |
self verboseInfo:ex description. |
|
12996 | 1100 |
Verbose == true ifTrue:[ex suspendedContext fullPrintAllLevels:10]. |
12992 | 1101 |
ex reject. |
1102 |
] do:[ |
|
12998
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1103 |
|idx| |
13127 | 1104 |
|
19590 | 1105 |
Smalltalk showSplashMessage:'start'. |
1106 |
self verboseInfo:'starting...'. |
|
12992 | 1107 |
CommandLineArguments := (self additionalArgumentsFromRegistry) |
1108 |
, Smalltalk commandLineArguments. |
|
9944 | 1109 |
|
12992 | 1110 |
self verboseInfo:('args: ', CommandLineArguments asStringCollection asString). |
1111 |
||
13089 | 1112 |
"--newAppInstance - do not reuse an existing application instance, |
12998
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1113 |
but run in a separate process" |
13089 | 1114 |
idx := CommandLineArguments indexOfAny:#('--newAppInstance'). |
12998
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1115 |
idx == 0 ifTrue:[ |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1116 |
self shouldReuseRunningApplication ifTrue:[ |
19590 | 1117 |
self verboseInfo:'should reuse app'. |
12998
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1118 |
"Multiple Application support: |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1119 |
if another expecco is running, ask it to open another window for me. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1120 |
If that is the case, the following function will not return, but instead exit." |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1121 |
self checkForAndExitIfAnotherApplicationInstanceIsRunning. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1122 |
]. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1123 |
] ifFalse:[ |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1124 |
CommandLineArguments removeAtIndex:idx. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1125 |
]. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1126 |
|
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1127 |
"/ Arrive here, if no other application is running. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1128 |
"/ to speedup startup, we did not load all dll's (only a subset of non-GUI dll's is present). |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1129 |
"/ now, load all skipped libs from modules.stx. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1130 |
self loadRemainingClassLibraries. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1131 |
|
12992 | 1132 |
Smalltalk isStandAloneApp ifTrue:[ |
20587 | 1133 |
self verboseInfo:'looking for patches'. |
12992 | 1134 |
self loadPatches. |
1135 |
]. |
|
20576 | 1136 |
self verboseInfo:'setup Smalltalk'. |
12992 | 1137 |
self setupSmalltalkFromArguments:CommandLineArguments. |
20575 | 1138 |
self main:CommandLineArguments |
9944 | 1139 |
]. |
1140 |
||
13280 | 1141 |
"Modified: / 04-02-2011 / 00:03:47 / cg" |
9944 | 1142 |
! |
1143 |
||
11807
f9e3c45c53c8
Moved #startStartBlockProcess from ExpeccoStandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
11806
diff
changeset
|
1144 |
startStartBlockProcess |
f9e3c45c53c8
Moved #startStartBlockProcess from ExpeccoStandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
11806
diff
changeset
|
1145 |
Smalltalk startStartBlockProcess |
f9e3c45c53c8
Moved #startStartBlockProcess from ExpeccoStandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
11806
diff
changeset
|
1146 |
! |
f9e3c45c53c8
Moved #startStartBlockProcess from ExpeccoStandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
11806
diff
changeset
|
1147 |
|
12998
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1148 |
stxModulesFilename |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1149 |
"answer the Filename of modules.stx" |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1150 |
|
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1151 |
|file| |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1152 |
|
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1153 |
file := 'modules.stx' asFilename. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1154 |
file exists ifTrue:[^ file]. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1155 |
|
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1156 |
file := OperatingSystem pathOfSTXExecutable asFilename directory construct:'modules.stx'. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1157 |
file exists ifTrue:[^ file]. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1158 |
|
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1159 |
self error:'cannot find: modules.stx'. |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1160 |
! |
c967aa65e09a
Move multiple app support and delayed DLL stuff to StandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
12996
diff
changeset
|
1161 |
|
11355 | 1162 |
usage |
13089 | 1163 |
Stderr nextPutLine:'usage: ',self applicationName,' [options...]'. |
1164 |
Stderr nextPutLine:' --help .................. output this message'. |
|
1165 |
Stderr nextPutLine:' --verbose ............... verbose startup'. |
|
17707 | 1166 |
self isHeadless ifFalse:[ |
1167 |
Stderr nextPutLine:' --noBanner .............. no splash screen'. |
|
1168 |
]. |
|
1169 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
|
1170 |
Stderr nextPutLine:' --newAppInstance ........ start as its own application process (do not reuse a running instance)'. |
|
1171 |
]. |
|
11352 | 1172 |
self allowScriptingOption ifTrue:[ |
19880 | 1173 |
Stderr nextPutLine:' --scripting <portNr> .... enable scripting via port (or stdin/stdOut, if 0. Default is 8008)'. |
11352 | 1174 |
]. |
1175 |
self allowDebugOption ifTrue:[ |
|
13089 | 1176 |
Stderr nextPutLine:' --debug ................. enable Debugger'. |
11352 | 1177 |
]. |
13375 | 1178 |
self allowCoverageMeasurementOption ifTrue:[ |
1179 |
Stderr nextPutLine:' --coverage .............. turn on coverage measurement'. |
|
1180 |
Stderr nextPutLine:' [+/-]package: pattern ... - include/exclude packages'. |
|
1181 |
Stderr nextPutLine:' [+/-]class: pattern ... - include/exclude classes'. |
|
1182 |
Stderr nextPutLine:' [+/-]method: cls#sel ... - include/exclude methods'. |
|
1183 |
]. |
|
11352 | 1184 |
self suppressRCFileReading ifFalse:[ |
13089 | 1185 |
Stderr nextPutLine:' --rcFileName file ....... execute code from file on startup (default: ',self startupFilename,')'. |
11352 | 1186 |
]. |
9944 | 1187 |
|
1188 |
"Created: / 19-09-2006 / 16:37:55 / cg" |
|
13375 | 1189 |
"Modified: / 24-05-2011 / 17:23:18 / cg" |
20563 | 1190 |
! |
1191 |
||
1192 |
usageAndExitWith:exitCode |
|
20566 | 1193 |
"show the usage message, then exit with given exitCode" |
1194 |
||
20563 | 1195 |
self usage. |
1196 |
Smalltalk exitIfStandalone:exitCode |
|
9944 | 1197 |
! ! |
1198 |
||
1199 |
!StandaloneStartup class methodsFor:'startup-to be redefined'! |
|
1200 |
||
12991
f9c0f556ea86
added: #additionalArgumentsFromRegistry
Claus Gittinger <cg@exept.de>
parents:
12988
diff
changeset
|
1201 |
additionalArgumentsFromRegistry |
f9c0f556ea86
added: #additionalArgumentsFromRegistry
Claus Gittinger <cg@exept.de>
parents:
12988
diff
changeset
|
1202 |
"can be redefined to fetch and return additional arguments from the registry |
f9c0f556ea86
added: #additionalArgumentsFromRegistry
Claus Gittinger <cg@exept.de>
parents:
12988
diff
changeset
|
1203 |
(or other .ini file). These are added to the beginning of the command line arguments." |
f9c0f556ea86
added: #additionalArgumentsFromRegistry
Claus Gittinger <cg@exept.de>
parents:
12988
diff
changeset
|
1204 |
|
f9c0f556ea86
added: #additionalArgumentsFromRegistry
Claus Gittinger <cg@exept.de>
parents:
12988
diff
changeset
|
1205 |
^ #() |
f9c0f556ea86
added: #additionalArgumentsFromRegistry
Claus Gittinger <cg@exept.de>
parents:
12988
diff
changeset
|
1206 |
|
f9c0f556ea86
added: #additionalArgumentsFromRegistry
Claus Gittinger <cg@exept.de>
parents:
12988
diff
changeset
|
1207 |
"Created: / 04-08-2010 / 12:20:27 / cg" |
f9c0f556ea86
added: #additionalArgumentsFromRegistry
Claus Gittinger <cg@exept.de>
parents:
12988
diff
changeset
|
1208 |
! |
f9c0f556ea86
added: #additionalArgumentsFromRegistry
Claus Gittinger <cg@exept.de>
parents:
12988
diff
changeset
|
1209 |
|
11806
6508528f9499
Define #isHeadless with default value (false)
Stefan Vogel <sv@exept.de>
parents:
11764
diff
changeset
|
1210 |
isHeadless |
6508528f9499
Define #isHeadless with default value (false)
Stefan Vogel <sv@exept.de>
parents:
11764
diff
changeset
|
1211 |
"this is invoked early by Smalltalk>>mainStartup, to ask if I like to |
6508528f9499
Define #isHeadless with default value (false)
Stefan Vogel <sv@exept.de>
parents:
11764
diff
changeset
|
1212 |
have a Display or if I am a non-GUI headless application. |
6508528f9499
Define #isHeadless with default value (false)
Stefan Vogel <sv@exept.de>
parents:
11764
diff
changeset
|
1213 |
|
6508528f9499
Define #isHeadless with default value (false)
Stefan Vogel <sv@exept.de>
parents:
11764
diff
changeset
|
1214 |
Redefine in subclass, if your application is a non-GUI application" |
6508528f9499
Define #isHeadless with default value (false)
Stefan Vogel <sv@exept.de>
parents:
11764
diff
changeset
|
1215 |
|
6508528f9499
Define #isHeadless with default value (false)
Stefan Vogel <sv@exept.de>
parents:
11764
diff
changeset
|
1216 |
^ false |
6508528f9499
Define #isHeadless with default value (false)
Stefan Vogel <sv@exept.de>
parents:
11764
diff
changeset
|
1217 |
! |
6508528f9499
Define #isHeadless with default value (false)
Stefan Vogel <sv@exept.de>
parents:
11764
diff
changeset
|
1218 |
|
11355 | 1219 |
main |
1220 |
self verboseInfo:('entering main'). |
|
1221 |
||
1222 |
self main:CommandLineArguments. |
|
1223 |
||
1224 |
" |
|
1225 |
self main |
|
1226 |
self main:#('--info') |
|
1227 |
" |
|
1228 |
||
1229 |
"Modified: / 31-10-2007 / 16:03:22 / cg" |
|
10636 | 1230 |
! |
1231 |
||
11355 | 1232 |
main:argv |
1233 |
self subclassResponsibility. |
|
1234 |
||
1235 |
"/ a typical main: looks like (in a subclass): |
|
1236 |
||
1237 |
"/ |app fileArg| |
|
1238 |
"/ |
|
1239 |
"/ self verboseInfo:('starting application'). |
|
14977 | 1240 |
"/ |
1241 |
"/ self startStartBlockProcess. |
|
1242 |
"/ Smalltalk openDisplay. |
|
9944 | 1243 |
"/ app := <someGUIApplicationModelClass> open. |
1244 |
"/ |
|
1245 |
"/ self verboseInfo:('looking for args in ',argv). |
|
1246 |
"/ argv notEmptyOrNil ifTrue:[ |
|
1247 |
"/ fileArg := argv last asFilename. |
|
1248 |
"/ self verboseInfo:('fileArg is ',fileArg name). |
|
1249 |
"/ fileArg exists ifTrue:[ |
|
1250 |
"/ self verboseInfo:('file exists'). |
|
1251 |
"/ |
|
1252 |
"/ ( #('foo' 'bar' 'baz' ) includes:fileArg suffix) ifTrue:[ |
|
1253 |
"/ self verboseInfo:('loading'). |
|
1254 |
"/ |
|
1255 |
"/ Error handle:[:ex | |
|
1256 |
"/ self verboseInfo:'error while loading'. |
|
1257 |
"/ ex suspendedContext fullPrintAll. |
|
1258 |
"/ ] do:[ |
|
1259 |
"/ app menuLoadFromFile:fileArg |
|
1260 |
"/ ]. |
|
1261 |
"/ ]. |
|
1262 |
"/ ]. |
|
1263 |
"/ ]. |
|
1264 |
||
1265 |
"Created: / 19-09-2006 / 16:48:29 / cg" |
|
1266 |
! ! |
|
1267 |
||
1268 |
!StandaloneStartup class methodsFor:'documentation'! |
|
1269 |
||
1270 |
version |
|
18525
6b76f94a31ae
allow for patchesDirectory to return a string
Claus Gittinger <cg@exept.de>
parents:
18180
diff
changeset
|
1271 |
^ '$Header$' |
12335 | 1272 |
! |
1273 |
||
1274 |
version_CVS |
|
18525
6b76f94a31ae
allow for patchesDirectory to return a string
Claus Gittinger <cg@exept.de>
parents:
18180
diff
changeset
|
1275 |
^ '$Header$' |
9944 | 1276 |
! ! |
1277 |
||
14977 | 1278 |
|
9944 | 1279 |
StandaloneStartup initialize! |