cheri 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README +98 -0
  3. data/Rakefile +121 -0
  4. data/examples/hello_world_1.rb +28 -0
  5. data/examples/table_1.rb +44 -0
  6. data/lib/cheri/awt.rb +41 -0
  7. data/lib/cheri/builder.rb +31 -0
  8. data/lib/cheri/builder/awt/connecter.rb +63 -0
  9. data/lib/cheri/builder/awt/constants.rb +1003 -0
  10. data/lib/cheri/builder/awt/main.rb +191 -0
  11. data/lib/cheri/builder/awt/types.rb +220 -0
  12. data/lib/cheri/builder/base.rb +533 -0
  13. data/lib/cheri/builder/config.rb +187 -0
  14. data/lib/cheri/builder/connecter.rb +386 -0
  15. data/lib/cheri/builder/context.rb +655 -0
  16. data/lib/cheri/builder/generator.rb +425 -0
  17. data/lib/cheri/builder/html/charsets.rb +154 -0
  18. data/lib/cheri/builder/html/common.rb +32 -0
  19. data/lib/cheri/builder/html/connecter.rb +57 -0
  20. data/lib/cheri/builder/html/element.rb +156 -0
  21. data/lib/cheri/builder/html/main.rb +116 -0
  22. data/lib/cheri/builder/html/types.rb +123 -0
  23. data/lib/cheri/builder/main.rb +483 -0
  24. data/lib/cheri/builder/swing/connecter.rb +141 -0
  25. data/lib/cheri/builder/swing/constants.rb +420 -0
  26. data/lib/cheri/builder/swing/main.rb +446 -0
  27. data/lib/cheri/builder/swing/types.rb +270 -0
  28. data/lib/cheri/builder/xml/charsets.rb +154 -0
  29. data/lib/cheri/builder/xml/common.rb +32 -0
  30. data/lib/cheri/builder/xml/connecter.rb +42 -0
  31. data/lib/cheri/builder/xml/element.rb +189 -0
  32. data/lib/cheri/builder/xml/main.rb +130 -0
  33. data/lib/cheri/builder/xml/types.rb +36 -0
  34. data/lib/cheri/cheri.rb +70 -0
  35. data/lib/cheri/cjx.rb +3 -0
  36. data/lib/cheri/explorer.rb +32 -0
  37. data/lib/cheri/explorer/explorer.rb +560 -0
  38. data/lib/cheri/html.rb +31 -0
  39. data/lib/cheri/image/Delete24.gif +0 -0
  40. data/lib/cheri/image/Find24.gif +0 -0
  41. data/lib/cheri/image/FindAgain24.gif +0 -0
  42. data/lib/cheri/image/Refresh24.gif +0 -0
  43. data/lib/cheri/image/Search24.gif +0 -0
  44. data/lib/cheri/image/Thumbs.db +0 -0
  45. data/lib/cheri/image/cheri_icon_16x16.png +0 -0
  46. data/lib/cheri/image/cheri_icon_24x24.png +0 -0
  47. data/lib/cheri/image/cheri_logo_medium.png +0 -0
  48. data/lib/cheri/image/close_10x10.png +0 -0
  49. data/lib/cheri/image/close_10x10s.png +0 -0
  50. data/lib/cheri/image/close_12x12.png +0 -0
  51. data/lib/cheri/image/close_14x14.png +0 -0
  52. data/lib/cheri/image/close_24x24.png +0 -0
  53. data/lib/cheri/image/close_dim2_12x12.png +0 -0
  54. data/lib/cheri/image/close_dim_12x12.png +0 -0
  55. data/lib/cheri/image/cls_tree.png +0 -0
  56. data/lib/cheri/image/con_tree.png +0 -0
  57. data/lib/cheri/image/jruby_14x16.png +0 -0
  58. data/lib/cheri/image/jruby_logo.png +0 -0
  59. data/lib/cheri/image/mod_tree.png +0 -0
  60. data/lib/cheri/image/obj_tree.png +0 -0
  61. data/lib/cheri/image/ruby_16x16.png +0 -0
  62. data/lib/cheri/image/vars_tree.png +0 -0
  63. data/lib/cheri/java.rb +26 -0
  64. data/lib/cheri/java/builder.rb +28 -0
  65. data/lib/cheri/java/builder/main.rb +407 -0
  66. data/lib/cheri/java/builder/util.rb +480 -0
  67. data/lib/cheri/java/java.rb +56 -0
  68. data/lib/cheri/jruby.rb +32 -0
  69. data/lib/cheri/jruby/explorer.rb +43 -0
  70. data/lib/cheri/jruby/explorer/common.rb +38 -0
  71. data/lib/cheri/jruby/explorer/dialogs.rb +383 -0
  72. data/lib/cheri/jruby/explorer/explorer.rb +904 -0
  73. data/lib/cheri/jruby/explorer/splash.rb +80 -0
  74. data/lib/cheri/jruby/explorer/viewer.rb +619 -0
  75. data/lib/cheri/jruby/explorer/viewers.rb +1057 -0
  76. data/lib/cheri/jruby/jruby.rb +59 -0
  77. data/lib/cheri/swing.rb +41 -0
  78. data/lib/cheri/xml.rb +31 -0
  79. metadata +135 -0
@@ -0,0 +1,36 @@
1
+ #--
2
+ # Copyright (C) 2007 William N Dortch <bill.dortch@gmail.com>
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+ #
24
+
25
+ module Cheri
26
+ module Xml
27
+ Types = Hash[
28
+ :xml => XmlRoot,
29
+ :text! => TextElem,
30
+ :t! => TextElem,
31
+ :esc! => EscElem,
32
+ :proc! => ProcElem,
33
+ ]
34
+
35
+ end #Xml
36
+ end #Cheri
@@ -0,0 +1,70 @@
1
+ #--
2
+ # Copyright (C) 2007 William N Dortch <bill.dortch@gmail.com>
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+ #
24
+
25
+ require 'thread'
26
+
27
+ # TODO: module comments
28
+ module Cheri
29
+ module VERSION #:nodoc:
30
+ MAJOR = 0
31
+ MINOR = 0
32
+ TINY = 2
33
+ STRING = [MAJOR, MINOR, TINY].join('.').freeze
34
+ end
35
+ PathExp = Regexp.new "cheri-#{VERSION::STRING}\\/lib$" #:nodoc:
36
+ class CheriException < StandardError; end
37
+ # global threadsafe; set if all Cheri module instances in a system
38
+ # must be threadsafe
39
+ # TODO: not yet widely implemented by Cheri modules
40
+ @threadsafe = false
41
+ class << self
42
+ def threadsafe?
43
+ @threadsafe
44
+ end
45
+ # once threadsafe is set, it cannot be unset (by normal means)
46
+ def threadsafe!
47
+ @threadsafe ||= true
48
+ end
49
+ def type_error(object, *expected_type)
50
+ TypeError.new("wrong argument type #{object.class} (expected #{expected_type.join(' or ')})")
51
+ end
52
+ def argument_error(argc, expected_argc)
53
+ ArgumentError.new("wrong number of arguments (#{argc} for #{expected_argc})")
54
+ end
55
+ def load_path
56
+ unless @load_path
57
+ $LOAD_PATH.each do |path|
58
+ if path =~ PathExp
59
+ @load_path = "#{path}/"
60
+ break
61
+ end
62
+ end
63
+ end
64
+ @load_path ||= ''
65
+ end
66
+ def img_path
67
+ @img_path ||= "#{load_path}cheri/image/"
68
+ end
69
+ end #self
70
+ end #Cheri
data/lib/cheri/cjx.rb ADDED
@@ -0,0 +1,3 @@
1
+ # Loads and runs Cheri::JRuby::Explorer
2
+ require 'cheri/jruby/explorer'
3
+ Cheri::JRuby::Explorer.run
@@ -0,0 +1,32 @@
1
+ #--
2
+ # Copyright (C) 2007 William N Dortch <bill.dortch@gmail.com>
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+ #
24
+
25
+ require 'cheri/cheri'
26
+
27
+ if (defined?JRUBY_VERSION) && 0 == (JRUBY_VERSION =~ /(\d+\.\d+\.\d+)([-\.A-Z0-9]*)/) &&
28
+ (($1 == '1.0.0' && ($2.empty? || $2 >= 'RC3')) || $1 > '1.0.0')
29
+ require 'cheri/jruby'
30
+ end
31
+
32
+ require 'cheri/explorer/explorer'
@@ -0,0 +1,560 @@
1
+ #--
2
+ # Copyright (C) 2007 William N Dortch <bill.dortch@gmail.com>
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+ #
24
+
25
+ require 'drb'
26
+ require 'rbconfig'
27
+ require 'cheri/cheri'
28
+
29
+ module Cheri
30
+ #
31
+ # I just want to reiterate this section from the license. Be *VERY* sure you
32
+ # have adequate safeguards in place (firewalls, secure network, etc.) before
33
+ # you install this component on a remote machine, particularly anything running
34
+ # live applications with real (therefore potentially private/sensitive) data.
35
+ #
36
+ # "Careful, it's hot!"
37
+ #
38
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
39
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
40
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
41
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
42
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
43
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
44
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
45
+ #
46
+ module Explorer
47
+
48
+ def self.start(port)
49
+ if (server = @server)
50
+ raise "server active -- call stop first" if server.alive?
51
+ server.stop_service rescue nil
52
+ server.thread.kill rescue nil
53
+ end
54
+ @explorer = RubyExplorer.new
55
+ @server = DRb::DRbServer.new("druby://localhost:#{port}",@explorer)
56
+ puts "Cheri::Explorer started on port #{port}\n"
57
+ STDERR.puts %{
58
+ WARNING! This server can expose sensitive information about the Ruby instance
59
+ in which it runs, including file/directory paths, configuration information,
60
+ and, if ObjectSpace is enabled, any object that has not been garbage-collected.
61
+ If you have not taken adequate precautions to secure this installation, such as,
62
+ but not limited to, firewalls, secure network access, and access control lists,
63
+ you should terminate this application now by entering the following command:
64
+
65
+ Cheri::Explorer.thread.kill
66
+
67
+ }
68
+ end
69
+ def self.stop
70
+ if (server = @server)
71
+ server.stop_service rescue nil
72
+ server.thread.kill rescue nil
73
+ @explorer = nil
74
+ @server = nil
75
+ end
76
+ end
77
+ def self.thread
78
+ @server.thread if @server
79
+ end
80
+
81
+ class ObjectRec
82
+ def initialize(obj)
83
+ @z = obj.class.to_s rescue nil
84
+ @i = obj.__id__ rescue nil
85
+ if obj.respond_to?(:instance_variables) && (vars = (obj.instance_variables rescue nil)) && !vars.empty?
86
+ @v = []
87
+ vars.each do |v|
88
+ value = obj.instance_variable_get(v.to_sym) rescue nil
89
+ type = value.class rescue nil
90
+ @v << NameTypeValue.new(v,type,value)
91
+ end
92
+ end
93
+ if obj.respond_to?(:ancestors) && (a = obj.ancestors rescue nil)
94
+ @a = Array.new(a.length) {|i| ValueType.new(a[i]) }
95
+ end
96
+ @u = (obj.superclass.to_s rescue nil) if obj.respond_to?(:superclass)
97
+ @s = obj.inspect rescue nil
98
+ end
99
+ def clazz
100
+ @z
101
+ end
102
+ def superclazz
103
+ @u
104
+ end
105
+ def id
106
+ @i
107
+ end
108
+ def value
109
+ @s
110
+ end
111
+ def vars
112
+ @v
113
+ end
114
+ def ancestors
115
+ @a
116
+ end
117
+ def <=>(other)
118
+ if ObjectRec === other
119
+ value <=> other.value
120
+ else
121
+ value <=> (other.to_s rescue '')
122
+ end
123
+ end
124
+ def to_s
125
+ @s || ''
126
+ end
127
+
128
+ end #ObjectRec
129
+
130
+ class ConstRec < ObjectRec
131
+ def initialize(parent,name,obj)
132
+ raise Cheri.type_error(name,String) unless String === name
133
+ raise Cheri.type_error(parent,String) if parent && !(String === parent)
134
+ super(obj)
135
+ @p = parent if parent
136
+ @n = name
137
+ end
138
+ def parent
139
+ @p
140
+ end
141
+ def name
142
+ @n
143
+ end
144
+ def qname
145
+ @p ? "#{@p}::#{@n}" : @n
146
+ end
147
+ def <=>(other)
148
+ if ConstRec === other
149
+ name <=> other.name
150
+ else
151
+ name <=> (other.to_s rescue '')
152
+ end
153
+ end
154
+ end #ConstRec
155
+
156
+ class ValueType
157
+ def initialize(value)
158
+ @z = value.class.to_s rescue '?'
159
+ @i = value.__id__ rescue '?'
160
+ @v = value.to_s rescue '?'
161
+ end
162
+ def clazz
163
+ @z
164
+ end
165
+ def id
166
+ @i
167
+ end
168
+ def value
169
+ @v
170
+ end
171
+ def <=>(other)
172
+ if ValueRec === other
173
+ value <=> other.value
174
+ else
175
+ value <=> (other.to_s rescue '')
176
+ end
177
+ end
178
+ def to_a
179
+ [@v,@z,@i]
180
+ end
181
+ alias_method :to_ary, :to_a
182
+ end #ValueType
183
+
184
+ class NameValue
185
+ def initialize(name,value)
186
+ raise Cheri.type_error(name,String) unless String === name
187
+ @n = name
188
+ @i = value.__id__ rescue '?'
189
+ @v = String === value ? value[0,100] : (value.to_s[0,100] rescue '?')
190
+ end
191
+ def name
192
+ @n
193
+ end
194
+ def value
195
+ @v
196
+ end
197
+ def id
198
+ @i
199
+ end
200
+ def <=>(other)
201
+ if NameValue === other
202
+ value <=> other.value
203
+ else
204
+ value <=> (other.to_s rescue '')
205
+ end
206
+ end
207
+ def to_a
208
+ [@n,@v,@i]
209
+ end
210
+ alias_method :to_ary, :to_a
211
+ end #NameValue
212
+
213
+ class NameTypeValue < NameValue
214
+ def initialize(name,type,value)
215
+ super(name,value)
216
+ @t = String === type ? type : (type.to_s rescue '?')
217
+ @d = type.__id__ rescue nil
218
+ end
219
+ def type
220
+ @t
221
+ end
222
+ def type_id
223
+ @d
224
+ end
225
+ def to_a
226
+ [@n,@t,@v,@i]
227
+ end
228
+ alias_method :to_ary, :to_a
229
+ end #NameTypeValue
230
+
231
+ class SearchArgs
232
+ def initialize(clazz,vars=nil,any=nil)
233
+ raise Cheri.type_error(clazz,String) unless String === clazz
234
+ raise ArgumentError,"Invalid class "+ clazz unless /^([A-Z])((\w|::[A-Z])*)$/.match clazz
235
+ @z = clazz
236
+ if vars
237
+ raise Cheri.type_error(vars,Array) unless Array === vars
238
+ vars.each do |v|
239
+ raise Cheri.type_error(v,SearchNameValue) unless SearchNameValue === v
240
+ raise Cheri.type_error(v.name,Symbol) unless Symbol === v.name
241
+ end
242
+ @v = vars
243
+ @a = !(any == nil || any == false)
244
+ end
245
+ end
246
+
247
+ def clazz
248
+ @z
249
+ end
250
+
251
+ def vars
252
+ @v
253
+ end
254
+
255
+ def any
256
+ @a
257
+ end
258
+
259
+ end #SearchArgs
260
+
261
+ class SearchNameValue
262
+ def initialize(name,value)
263
+ @n = name
264
+ @v = value
265
+ @r = Regexp === value
266
+ end
267
+ def name
268
+ @n
269
+ end
270
+ def value
271
+ @v
272
+ end
273
+ def rx?
274
+ @r
275
+ end
276
+ end
277
+
278
+ class SearchResults
279
+ def initialize(sargs,results)
280
+ raise Cheri.type_error(sargs,SearchArgs) unless SearchArgs === sargs
281
+ raise Cheri.type_error(results,Array) unless Array === results
282
+ @a = sargs
283
+ @r = results
284
+ end
285
+ def args
286
+ @a
287
+ end
288
+ def results
289
+ @r
290
+ end
291
+ def length
292
+ @r.length
293
+ end
294
+ end
295
+ class MethodRec
296
+ def initialize(mod)
297
+ @pu = mod.public_methods(false) if mod.respond_to?(:public_methods)
298
+ # rescue works around JRuby bug prior to 1.0.0RC3
299
+ @pt = mod.protected_methods(false) rescue mod.protected_methods if mod.respond_to?(:protected_methods)
300
+ @pv = mod.private_methods(false) rescue mod.private_methods if mod.respond_to?(:private_methods)
301
+ @pui = mod.public_instance_methods(false) if mod.respond_to?(:public_instance_methods)
302
+ @pti = mod.protected_instance_methods(false) if mod.respond_to?(:protected_instance_methods)
303
+ @pvi = mod.private_instance_methods(false) if mod.respond_to?(:private_instance_methods)
304
+ end
305
+
306
+ def pub
307
+ @pu
308
+ end
309
+ def pro
310
+ @pt
311
+ end
312
+ def pri
313
+ @pv
314
+ end
315
+ def pub_inst
316
+ @pui
317
+ end
318
+ def pro_inst
319
+ @pti
320
+ end
321
+ def pri_inst
322
+ @pvi
323
+ end
324
+ end #MethodRec
325
+
326
+
327
+ class RubyExplorer
328
+ # TODO: aggregate values that will be displayed together
329
+ def ruby_platform
330
+ RUBY_PLATFORM
331
+ end
332
+ def ruby_version
333
+ RUBY_VERSION
334
+ end
335
+ def ruby_release_date
336
+ RUBY_RELEASE_DATE
337
+ end
338
+ def env
339
+ ENV.to_a
340
+ end
341
+ # TODO: this doesn't make much sense, needs to be per thread
342
+ def global_vars
343
+ result = []
344
+ global_variables.each do |v|
345
+ ev = eval(v) rescue '???'
346
+ if Array === ev
347
+ eva = []
348
+ ev.each do |e|
349
+ eva << e.to_s
350
+ end
351
+ ev = eva
352
+ elsif Hash === ev
353
+ eva = []
354
+ ev.each_pair do |k,e|
355
+ eva << [k.to_s,e.to_s]
356
+ end
357
+ ev = eva
358
+ else
359
+ ev = ev.to_s
360
+ end
361
+ result << [v,ev]
362
+ end
363
+ result
364
+ end
365
+ def constants
366
+ result = []
367
+ begin
368
+ Module.constants.each do |c|
369
+ result << ([c,eval("::#{c}.class").to_s,eval("::#{c}.to_s")] rescue [c.to_s,'???', '???'])
370
+ end
371
+ rescue
372
+ end
373
+ result
374
+ end
375
+ def const_recs(parent_str=nil)
376
+ parent_str = nil if 'Module' == parent_str
377
+ result = []
378
+ if parent_str
379
+ raise Cheri.type_error(parent_str,String) unless String === parent_str
380
+ # make sure we don't have anything executable before we eval it
381
+ raise ArgumentError,"Invalid constant "+parent_str unless /^([A-Z])((\w|::[A-Z])*)$/.match parent_str
382
+ parent_str = parent_str[2,parent_str.length-2] if parent_str.rindex('::',0)
383
+ if (parent = eval("::#{parent_str}") rescue nil) &&
384
+ ((parent.respond_to?(:constants) && (consts = parent.constants rescue nil)) ||
385
+ (parent.respond_to?(:__constants__) && (consts = parent.__constants__ rescue nil)))
386
+ consts.each do |c|
387
+ if (ec = (eval("::#{parent_str}::#{c}") rescue nil))
388
+ result << ConstRec.new(parent_str,c,ec)
389
+ end
390
+ end
391
+ end
392
+ else
393
+ Module.constants.each do |c|
394
+ if (ec = (eval("::#{c}") rescue nil))
395
+ result << ConstRec.new(nil,c,ec)
396
+ end
397
+ end
398
+ end
399
+ result
400
+ end
401
+
402
+ def module_methods(name,id=nil)
403
+ if id && defined?ObjectSpace
404
+ raise Cheri.type_error(id,Fixnum) unless Fixnum === id
405
+ if Module === (mod = ObjectSpace._id2ref(id) rescue nil)
406
+ return MethodRec.new(mod)
407
+ end
408
+ elsif name
409
+ raise Cheri.type_error(name,String) unless String === name
410
+ return if /#/.match name
411
+ # make sure we don't have anything executable before we eval it
412
+ raise ArgumentError,"Invalid module "+name unless /^([A-Z])((\w|::[A-Z])*)$/.match name
413
+ if Module === (mod = eval("::#{name}") rescue nil)
414
+ return MethodRec.new(mod)
415
+ end
416
+ end
417
+ nil
418
+ end
419
+
420
+ def object(id)
421
+ return unless id && defined?ObjectSpace
422
+ raise Cheri.type_error(id,Fixnum) unless Fixnum === id
423
+ if (obj = ObjectSpace._id2ref(id) rescue nil) && !(Fixnum === obj)
424
+ if Module === obj && (name = obj.name rescue nil)
425
+ if (ix = name.rindex('::'))
426
+ parent = name[0,ix]
427
+ name = name[ix+2,name.length - ix - 2]
428
+ else
429
+ parent = nil
430
+ end
431
+ ConstRec.new(parent,name,obj)
432
+ else
433
+ ObjectRec.new(obj)
434
+ end
435
+ else
436
+ nil
437
+ end
438
+ end
439
+
440
+ def object_methods(id)
441
+ return unless id && defined?ObjectSpace
442
+ raise Cheri.type_error(id,Fixnum) unless Fixnum === id
443
+ if (obj = ObjectSpace._id2ref(id) rescue nil) && !(Fixnum === obj)
444
+ return MethodRec.new(obj)
445
+ end
446
+ end
447
+
448
+ def simple_value(id)
449
+ return unless id && defined?ObjectSpace
450
+ raise Cheri.type_error(id,Fixnum) unless Fixnum === id
451
+ if (obj = ObjectSpace._id2ref(id)) && !(Fixnum === obj)
452
+ obj.to_s[0,40] rescue 'Unreadable'
453
+ else
454
+ 'Unavailable'
455
+ end
456
+ end
457
+
458
+ def find(sargs)
459
+ return unless sargs && defined?ObjectSpace
460
+ raise Cheri.type_error(sargs,SearchArgs) unless SearchArgs === sargs
461
+ sclazz = sargs.clazz
462
+ raise Cheri.type_error(sclazz,String) unless String === sclazz
463
+ # make sure we don't have anything executable before we eval it
464
+ raise ArgumentError,"Invalid class "+ sclazz unless /^([A-Z])((\w|::[A-Z])*)$/.match sclazz
465
+ if Module === (clazz = (eval("::#{sclazz}") rescue nil))
466
+ #GC.start
467
+ result = []
468
+ vars = sargs.vars
469
+ len = vars.length if vars
470
+ any = sargs.any
471
+ ObjectSpace.each_object(clazz) do |o|
472
+ if (id = o.__id__ rescue nil)
473
+ if vars
474
+ match = 0
475
+ vars.each do |v|
476
+ if (iv = o.instance_variable_get(v.name) rescue nil) &&
477
+ (v.rx? ? (iv.to_s =~ v.value rescue nil) : (iv.to_s.index(v.value) rescue nil))
478
+ if any
479
+ match = 1
480
+ break
481
+ else
482
+ match += 1
483
+ end
484
+ end
485
+ end
486
+ result << id if (any && match == 1) || match == len
487
+ else
488
+ result << id
489
+ end
490
+ end
491
+ end
492
+ result
493
+ else
494
+ []
495
+ end
496
+ end
497
+
498
+ def config
499
+ Config::CONFIG
500
+ end
501
+
502
+ if (defined?JRUBY_VERSION) && 0 == (JRUBY_VERSION =~ /(\d+\.\d+\.\d+)([-\.A-Z0-9]*)/) &&
503
+ (($1 == '1.0.0' && ($2.empty? || $2 >= 'RC2')) || $1 > '1.0.0')
504
+
505
+ System = ::Java::JavaLang::System
506
+ Runtime = ::Java::JavaLang::Runtime
507
+ JDate = ::Java::JavaUtil::Date
508
+ JVersion = 'java.version'.freeze
509
+ JVendor = 'java.vendor'.freeze
510
+ RtName = 'java.runtime.name'.freeze
511
+ RtVersion = 'java.runtime.version'.freeze
512
+ VmName = 'java.vm.name'.freeze
513
+ VmVersion = 'java.vm.version'.freeze
514
+ VmVendor = 'java.vm.vendor'.freeze
515
+
516
+ def jruby_version
517
+ JRUBY_VERSION
518
+ end
519
+ def env_java
520
+ ENV_JAVA.to_hash
521
+ end
522
+ def env_java_brief
523
+ {
524
+ JVersion => ENV_JAVA[JVersion],
525
+ JVendor => ENV_JAVA[JVendor],
526
+ RtName => ENV_JAVA[RtName],
527
+ RtVersion => ENV_JAVA[RtVersion],
528
+ VmName => ENV_JAVA[VmName],
529
+ VmVersion => ENV_JAVA[VmVersion],
530
+ VmVendor => ENV_JAVA[VmVendor],
531
+ }
532
+ end
533
+ def security_manager
534
+ System.security_manager ? System.security_manager.to_string : nil
535
+ end
536
+ def available_processors
537
+ Runtime.runtime.available_processors
538
+ end
539
+ def free_memory
540
+ Runtime.runtime.free_memory
541
+ end
542
+ def total_memory
543
+ Runtime.runtime.total_memory
544
+ end
545
+ def max_memory
546
+ Runtime.runtime.max_memory
547
+ end
548
+ def jruby_start_time
549
+ @start_time ||= JDate.new(Cheri::JRuby.start_time).to_string
550
+ end
551
+ def object_space?
552
+ Cheri::JRuby.object_space?
553
+ end
554
+
555
+ end # if defined...
556
+
557
+ end #RubyExplorer
558
+
559
+ end #Explorer
560
+ end #Cheri