forked from SeasideSt/Grease
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGRPlatform.class.st
More file actions
408 lines (330 loc) · 11.7 KB
/
GRPlatform.class.st
File metadata and controls
408 lines (330 loc) · 11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
"
The abstract platform implementation. Each platform should provide a subclass implementing any abstract methods and overriding any other methods as necessary.
Default implementations should be provided here when possible/useful but default implementations MUST be valid on ALL PLATFORMS so it is rarely practical. VA Smalltalk flags sends of uknown messages so even these must be known to exist on all platforms.
Common cases where default implementations *are* appropriate are where there is a standard implementation that is valid on all platforms but one or more platforms have an additional, optimized implementation that should be used instead.
All classes and methods used by methods of this class should be either:
+ included in the Seaside-Platform package;
+ defined by the ANSI Smalltalk standard; or
+ (not ideal) referenced via 'Smalltalk at: #ClassName'.
"
Class {
#name : 'GRPlatform',
#superclass : 'GRObject',
#classVars : [
'Current'
],
#category : 'Grease-Core',
#package : 'Grease-Core'
}
{ #category : 'registration' }
GRPlatform class >> current [
^ Current
]
{ #category : 'registration' }
GRPlatform class >> current: aPlatform [
Current := aPlatform
]
{ #category : 'registration' }
GRPlatform class >> select [
GRPlatform current: self new
]
{ #category : 'registration' }
GRPlatform class >> unselect [
GRPlatform current class = self ifTrue: [ GRPlatform current: nil ]
]
{ #category : 'startup' }
GRPlatform >> addToShutDownList: anObject [
"Add anObject to the shutdown-list of the system. On shutdown the message #shutDown will be sent to anObject."
self subclassResponsibility
]
{ #category : 'startup' }
GRPlatform >> addToStartUpList: anObject [
"Add anObject to the startup-list of the system. On startup the message #startUp will be sent to anObject."
self subclassResponsibility
]
{ #category : 'file library' }
GRPlatform >> asMethodReturningByteArray: aByteArrayOrString named: aSymbol [
"Generates the source of a method named aSymbol that returns aByteArrayOrString as a ByteArray"
self subclassResponsibility
]
{ #category : 'file library' }
GRPlatform >> asMethodReturningString: aByteArrayOrString named: aSymbol [
"Generates the source of a method named aSymbol that returns aByteArrayOrString as a String.
This implementation answers a String formatted like so
aSymbol
^ aByteArrayOrString
Subclasses need to override this method if the dialect needs changes to support Unicode string literals"
^ String streamContents: [ :stream |
stream
nextPutAll: aSymbol;
nextPut: Character cr.
stream
tab;
nextPutAll: '^ '''.
aByteArrayOrString greaseString do: [ :each |
each = $' ifTrue: [ stream nextPut: $' ].
stream nextPut: each ].
stream nextPut: $' ]
]
{ #category : 'encoding' }
GRPlatform >> base64Decode: aString [
"Base64 decode the given String and answer the result as a String."
self subclassResponsibility
]
{ #category : 'encoding' }
GRPlatform >> base64Encode: aByteArray [
"Base64 encode the given byte array and answer the result as a String."
self subclassResponsibility
]
{ #category : 'bindings' }
GRPlatform >> bindingOf: aClass [
"Answer the binding of aClass.
The binding is the literal that get compiled into the method.
We need the binding to be updated when the class is changed.
The binding has to respond to #value.
This is mostly an issue on GemStone/S because when we hold on
to a class directly we will end up holding on to an old class version.
Dialects with namespaces will need to override this.
On VisualWorks this should like this
^ aClass fullyQualifiedReference"
^ Smalltalk associationAt: aClass name
]
{ #category : 'file library' }
GRPlatform >> compile: aString into: aClass classified: aSymbol [
"The trick here is to be as silently a possible so that the package is not marked dirty when running WAFileLibrary test.
This also makes running tests much faster."
self subclassResponsibility
]
{ #category : 'files' }
GRPlatform >> contentsOfFile: aString binary: aBoolean [
self subclassResponsibility
]
{ #category : 'file library' }
GRPlatform >> convertToSmalltalkNewlines: aString [
"Convert any line endings (CR, CRLF, LF) to the default platform newline."
aString isNil
ifTrue: [ ^ nil ].
^ String streamContents: [ :writeStream |
| readStream |
readStream := aString readStream.
[ readStream atEnd ] whileFalse: [
| next |
next := readStream next.
next = Character cr
ifTrue: [
readStream peek = Character lf
ifTrue: [ readStream skip: 1 ].
writeStream nextPutAll: self newline ]
ifFalse: [
next = Character lf
ifTrue: [ writeStream nextPutAll: self newline ]
ifFalse: [ writeStream nextPut: next ] ] ] ]
]
{ #category : 'files' }
GRPlatform >> deleteFile: aPathString [
self subclassResponsibility
]
{ #category : 'exceptions' }
GRPlatform >> deprecationExceptionSet [
"Answer the exception set that should considered besides WADeprecation."
^ ExceptionSet new
]
{ #category : 'files' }
GRPlatform >> directoriesIn: aPathString [
"Answer a collection of absolute paths for all the directories (no files) in the directory given by aPathString
must not include directory names that start with ."
self subclassResponsibility
]
{ #category : 'file library' }
GRPlatform >> doSilently: aBlock [
"Suspend all notifications value evaluating the given block."
^ aBlock value
]
{ #category : 'transactions' }
GRPlatform >> doTransaction: aBlock [
"for Gemstone/S compatibility
http://gemstonesoup.wordpress.com/2007/05/10/porting-application-specific-seaside-threads-to-gemstone/
use when modifying an object from an outside thread"
^ aBlock value
]
{ #category : 'files' }
GRPlatform >> ensureExistenceOfFolder: aString [
"Create a folder named aString in the image directory."
self subclassResponsibility
]
{ #category : 'files' }
GRPlatform >> fileExists: aString [
self subclassResponsibility
]
{ #category : 'files' }
GRPlatform >> fileStreamOn: aString do: aBlock binary: aBoolean [
self
greaseDeprecatedApi: 'GRPlatform>>#fileStreamOn:do:binary:'
details: 'Use readFileStreamOn:do:binary:'.
^ self readFileStreamOn: aString do: aBlock binary: aBoolean
]
{ #category : 'files' }
GRPlatform >> filesIn: aPathString [
"Answer a collection of absolute paths for all the files (no directories) in the directory given by aPathString
must not include file names that start with ."
self subclassResponsibility
]
{ #category : 'encoding' }
GRPlatform >> integerAsByteArray: anInteger [
^ anInteger asByteArray
]
{ #category : 'processes' }
GRPlatform >> isProcessTerminated: aProcess [
"Return a boolean indicating whether aProcess has been terminated."
self subclassResponsibility
]
{ #category : 'version info' }
GRPlatform >> label [
"Answer a descriptive label string for the platform implementation"
self subclassResponsibility
]
{ #category : 'files' }
GRPlatform >> localNameOf: aFilename [
"Answer the local name of a file identified by an absolute file path.
Eg.
If the platform is Windwos and aFilename is 'C:\Windows\win32.dll' then it would answer 'win32.dll'.
If the platform is Unix and aFilename is '/usr/bin/vim' then it would answer 'vim'."
self subclassResponsibility
]
{ #category : 'factory' }
GRPlatform >> newRandom [
"Answers the random number generator to be used to create session and continuation keys. Make sure it is seeded. They only methods that will be sent to it are:
#nextInt: - should answer a random integer in the interval [1, anInteger]
#randomFrom: - should answer a random element from the given collection
Make sure that both methods are safe under heavy concurrent load.
Used by Gemstone/S traditional Randoms which cannot be persisted.
Used by Squeak to use a secure random when avaiable."
self subclassResponsibility
]
{ #category : 'files' }
GRPlatform >> newTemporaryFile [
"Create a new temporary file in the systems temp directory and answer its pathString.
It is the users responsibility to delete or move the file, it will not be cleaned up automatically
(unless the host system has a policy for it)."
^ self subclassResponsibility
]
{ #category : 'files' }
GRPlatform >> newTemporaryFileNamed: aName [
"Create a new temporary file in the systems temp directory and answer its pathString.
It is the users responsibility to delete or move the file, it will not be cleaned up automatically
(unless the host system has a policy for it)."
self subclassResponsibility
]
{ #category : 'file library' }
GRPlatform >> newline [
"Answer a String with the default newline character of this platform."
self subclassResponsibility
]
{ #category : 'exceptions' }
GRPlatform >> openDebuggerOn: anError [
self subclassResponsibility
]
{ #category : 'files' }
GRPlatform >> pathSeparator [
"Answer the path separator as a String, eg. '/' on Unix and '\' on Windows."
self subclassResponsibility
]
{ #category : 'files' }
GRPlatform >> readFileStreamOn: aString do: aBlock binary: aBoolean [
self subclassResponsibility
]
{ #category : 'factory' }
GRPlatform >> readWriteByteStream [
"Return a ReadWriteStream on a ByteArray that stores integers 0..255
^ReadWriteStream on: ByteArray new
"
^ self subclassResponsibility
]
{ #category : 'factory' }
GRPlatform >> readWriteCharacterStream [
"Return a ReadWriteStream on a String that stores characters
^ReadWriteStream on: String new
"
^ self subclassResponsibility
]
{ #category : 'factory' }
GRPlatform >> reducedConflictDictionary [
"used by Gemstone/S reduced conflict classes that can be used to avoid transaction conflicts"
^ Dictionary
]
{ #category : 'startup' }
GRPlatform >> removeFromShutDownList: anObject [
"Remove anObject from the shutdown list in the system."
self subclassResponsibility
]
{ #category : 'startup' }
GRPlatform >> removeFromStartUpList: anObject [
"Remove anObject from the startup list in the system."
self subclassResponsibility
]
{ #category : 'file library' }
GRPlatform >> removeSelector: aSymbol from: aClass [
self subclassResponsibility
]
{ #category : 'cryptography' }
GRPlatform >> secureHashFor: aString [
self subclassResponsibility
]
{ #category : 'factory' }
GRPlatform >> semaphoreClass [
"used by Gemstone/S traditional Semaphores which cannot be persisted"
self subclassResponsibility
]
{ #category : 'files' }
GRPlatform >> sizeOfFile: aString [
self subclassResponsibility
]
{ #category : 'exceptions' }
GRPlatform >> stackDepth [
self subclassResponsibility
]
{ #category : 'processes' }
GRPlatform >> terminateProcess: aProcess [
"Permanently terminate the process, unwinding first to execute #ensure: and #ifCurtailed: blocks."
self subclassResponsibility
]
{ #category : 'processes' }
GRPlatform >> thisContext [
"Answer the current activation of a method execution or block activation.
For dialects with a thisContext variable and implementation can look like this.
^ thisContext sender"
self subclassResponsibility
]
{ #category : 'version info' }
GRPlatform >> version [
"Answer the Grease version"
^ (GRVersion major: 1 minor: 16 revision: 0)
yourself
]
{ #category : 'version info' }
GRPlatform >> versionString [
^ String streamContents: [ :stream |
stream
nextPutAll: (self version greaseString);
nextPutAll: ' (';
nextPutAll: (self label);
nextPut: $) ]
]
{ #category : 'factory' }
GRPlatform >> weakDictionaryOfSize: aNumber [
self subclassResponsibility
]
{ #category : 'files' }
GRPlatform >> write: aStringOrByteArray toFile: aFileNameString inFolder: aFolderString [
"Write aStringOrByteArray to a file named aFileNameString in the folder aFolderString."
self subclassResponsibility
]
{ #category : 'factory' }
GRPlatform >> writeCharacterStreamOn: aString [
"String based write stream"
^ WriteStream on: aString
]
{ #category : 'files' }
GRPlatform >> writeFileStreamOn: aString do: aBlock binary: aBoolean [
self subclassResponsibility
]