psych 2.1.0-java → 2.1.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +14 -0
  3. data/Gemfile +3 -0
  4. data/Mavenfile +7 -0
  5. data/bin/console +7 -0
  6. data/bin/setup +6 -0
  7. data/ext/java/PsychEmitter.java +345 -0
  8. data/ext/java/PsychLibrary.java +93 -0
  9. data/ext/java/PsychParser.java +399 -0
  10. data/ext/java/PsychToRuby.java +79 -0
  11. data/ext/java/PsychYamlTree.java +55 -0
  12. data/ext/psych/.gitignore +11 -0
  13. data/lib/psych.rb +2 -2
  14. data/lib/psych/visitors/to_ruby.rb +2 -2
  15. data/psych.gemspec +39 -0
  16. metadata +19 -53
  17. data/test/psych/handlers/test_recorder.rb +0 -26
  18. data/test/psych/helper.rb +0 -122
  19. data/test/psych/json/test_stream.rb +0 -110
  20. data/test/psych/nodes/test_enumerable.rb +0 -44
  21. data/test/psych/test_alias_and_anchor.rb +0 -97
  22. data/test/psych/test_array.rb +0 -58
  23. data/test/psych/test_boolean.rb +0 -37
  24. data/test/psych/test_class.rb +0 -37
  25. data/test/psych/test_coder.rb +0 -207
  26. data/test/psych/test_date_time.rb +0 -39
  27. data/test/psych/test_deprecated.rb +0 -215
  28. data/test/psych/test_document.rb +0 -47
  29. data/test/psych/test_emitter.rb +0 -112
  30. data/test/psych/test_encoding.rb +0 -269
  31. data/test/psych/test_exception.rb +0 -158
  32. data/test/psych/test_hash.rb +0 -95
  33. data/test/psych/test_json_tree.rb +0 -66
  34. data/test/psych/test_merge_keys.rb +0 -181
  35. data/test/psych/test_nil.rb +0 -19
  36. data/test/psych/test_null.rb +0 -20
  37. data/test/psych/test_numeric.rb +0 -46
  38. data/test/psych/test_object.rb +0 -45
  39. data/test/psych/test_object_references.rb +0 -72
  40. data/test/psych/test_omap.rb +0 -76
  41. data/test/psych/test_parser.rb +0 -340
  42. data/test/psych/test_psych.rb +0 -184
  43. data/test/psych/test_safe_load.rb +0 -98
  44. data/test/psych/test_scalar.rb +0 -12
  45. data/test/psych/test_scalar_scanner.rb +0 -111
  46. data/test/psych/test_serialize_subclasses.rb +0 -39
  47. data/test/psych/test_set.rb +0 -50
  48. data/test/psych/test_stream.rb +0 -94
  49. data/test/psych/test_string.rb +0 -231
  50. data/test/psych/test_struct.rb +0 -50
  51. data/test/psych/test_symbol.rb +0 -26
  52. data/test/psych/test_tainted.rb +0 -131
  53. data/test/psych/test_to_yaml_properties.rb +0 -64
  54. data/test/psych/test_tree_builder.rb +0 -80
  55. data/test/psych/test_yaml.rb +0 -1293
  56. data/test/psych/test_yamldbm.rb +0 -193
  57. data/test/psych/test_yamlstore.rb +0 -86
  58. data/test/psych/visitors/test_depth_first.rb +0 -50
  59. data/test/psych/visitors/test_emitter.rb +0 -145
  60. data/test/psych/visitors/test_to_ruby.rb +0 -332
  61. data/test/psych/visitors/test_yaml_tree.rb +0 -180
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e9dc0b94275e4a1293ff5f5d00f6a81d6f5a39c1
4
- data.tar.gz: 680468b64f8d7b1b9b703f0adbd5249c2f9cd48b
3
+ metadata.gz: 8645c7bd38a6dbc8c7b287fc65e9bfd18b2658fe
4
+ data.tar.gz: 13e09c0edcdea89dd682f1370dbd1642684d2a59
5
5
  SHA512:
6
- metadata.gz: 7cd7a891073f8c4469729780b92f90a7fe08277ae74b859b8d0c8a76180a016f223c4ed63908925cdd9accbdb29d277d2152ead31d2486008cfef338f88cb9a8
7
- data.tar.gz: 3ac6acb3cdcc50b90870e2e0f5870470c8353725f06b75a9baa800beefd5dfc084ca9c43359f6c47c513dc320e1d38be2598ed778d45f15b748adfecbfb5888d
6
+ metadata.gz: b37a81b39236778d2fc23d53aef025f90449638f486c9bb72eae2dd7d05f5366bcac94c8596d8638e2394de2ae217ed15ffe0b84b98e858a7415e09a0ead6969
7
+ data.tar.gz: 75826880b51eeac52e0cb5eee62f931e4931bffc548aad3b12ed5798d5ab18c6e5e7a62d6ca8849db687efaf2058f9d7cd296f80f030850329bd50e95b52a3ec
@@ -0,0 +1,14 @@
1
+ *.swp
2
+ *.bundle
3
+ *.jar
4
+ *.class
5
+ .mvn
6
+ /.bundle/
7
+ /.yardoc
8
+ /Gemfile.lock
9
+ /_yardoc/
10
+ /coverage/
11
+ /doc/
12
+ /pkg/
13
+ /spec/reports/
14
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,7 @@
1
+ #-*- mode: ruby -*-
2
+
3
+ jar 'org.yaml:snakeyaml:${snakeyaml.version}'
4
+
5
+ plugin :dependency, '2.8', :outputFile => 'pkg/classpath'
6
+
7
+ # vim: syntax=Ruby
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "psych"
5
+
6
+ require "irb"
7
+ IRB.start
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,345 @@
1
+ /***** BEGIN LICENSE BLOCK *****
2
+ * Version: EPL 1.0/GPL 2.0/LGPL 2.1
3
+ *
4
+ * The contents of this file are subject to the Eclipse Public
5
+ * License Version 1.0 (the "License"); you may not use this file
6
+ * except in compliance with the License. You may obtain a copy of
7
+ * the License at http://www.eclipse.org/legal/epl-v10.html
8
+ *
9
+ * Software distributed under the License is distributed on an "AS
10
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11
+ * implied. See the License for the specific language governing
12
+ * rights and limitations under the License.
13
+ *
14
+ * Copyright (C) 2010 Charles O Nutter <headius@headius.com>
15
+ *
16
+ * Alternatively, the contents of this file may be used under the terms of
17
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
18
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
19
+ * in which case the provisions of the GPL or the LGPL are applicable instead
20
+ * of those above. If you wish to allow use of your version of this file only
21
+ * under the terms of either the GPL or the LGPL, and not to allow others to
22
+ * use your version of this file under the terms of the EPL, indicate your
23
+ * decision by deleting the provisions above and replace them with the notice
24
+ * and other provisions required by the GPL or the LGPL. If you do not delete
25
+ * the provisions above, a recipient may use your version of this file under
26
+ * the terms of any one of the EPL, the GPL or the LGPL.
27
+ ***** END LICENSE BLOCK *****/
28
+ package org.jruby.ext.psych;
29
+
30
+ import java.io.IOException;
31
+ import java.io.OutputStreamWriter;
32
+ import java.nio.charset.Charset;
33
+ import java.util.HashMap;
34
+ import java.util.Map;
35
+
36
+ import org.jcodings.Encoding;
37
+ import org.jruby.Ruby;
38
+ import org.jruby.RubyArray;
39
+ import org.jruby.RubyClass;
40
+ import org.jruby.RubyFixnum;
41
+ import org.jruby.RubyModule;
42
+ import org.jruby.RubyObject;
43
+ import org.jruby.RubyString;
44
+ import org.jruby.anno.JRubyMethod;
45
+ import org.jruby.runtime.ObjectAllocator;
46
+ import org.jruby.runtime.ThreadContext;
47
+ import org.jruby.runtime.builtin.IRubyObject;
48
+ import org.jruby.util.IOOutputStream;
49
+ import org.yaml.snakeyaml.DumperOptions;
50
+ import org.yaml.snakeyaml.emitter.Emitter;
51
+ import org.yaml.snakeyaml.emitter.EmitterException;
52
+ import org.yaml.snakeyaml.error.Mark;
53
+ import org.yaml.snakeyaml.events.AliasEvent;
54
+ import org.yaml.snakeyaml.events.DocumentEndEvent;
55
+ import org.yaml.snakeyaml.events.DocumentStartEvent;
56
+ import org.yaml.snakeyaml.events.Event;
57
+ import org.yaml.snakeyaml.events.ImplicitTuple;
58
+ import org.yaml.snakeyaml.events.MappingEndEvent;
59
+ import org.yaml.snakeyaml.events.MappingStartEvent;
60
+ import org.yaml.snakeyaml.events.ScalarEvent;
61
+ import org.yaml.snakeyaml.events.SequenceEndEvent;
62
+ import org.yaml.snakeyaml.events.SequenceStartEvent;
63
+ import org.yaml.snakeyaml.events.StreamEndEvent;
64
+ import org.yaml.snakeyaml.events.StreamStartEvent;
65
+
66
+ import static org.jruby.runtime.Visibility.*;
67
+
68
+ public class PsychEmitter extends RubyObject {
69
+ public static void initPsychEmitter(Ruby runtime, RubyModule psych) {
70
+ RubyClass psychHandler = runtime.defineClassUnder("Handler", runtime.getObject(), runtime.getObject().getAllocator(), psych);
71
+ RubyClass psychEmitter = runtime.defineClassUnder("Emitter", psychHandler, new ObjectAllocator() {
72
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
73
+ return new PsychEmitter(runtime, klazz);
74
+ }
75
+ }, psych);
76
+
77
+ psychEmitter.defineAnnotatedMethods(PsychEmitter.class);
78
+ }
79
+
80
+ public PsychEmitter(Ruby runtime, RubyClass klass) {
81
+ super(runtime, klass);
82
+ }
83
+
84
+ @JRubyMethod(visibility = PRIVATE)
85
+ public IRubyObject initialize(ThreadContext context, IRubyObject io) {
86
+ options = new DumperOptions();
87
+ options.setIndent(2);
88
+
89
+ this.io = io;
90
+
91
+ return context.nil;
92
+ }
93
+
94
+ @JRubyMethod(visibility = PRIVATE)
95
+ public IRubyObject initialize(ThreadContext context, IRubyObject io, IRubyObject rbOptions) {
96
+ IRubyObject width = rbOptions.callMethod(context, "line_width");
97
+ IRubyObject canonical = rbOptions.callMethod(context, "canonical");
98
+ IRubyObject level = rbOptions.callMethod(context, "indentation");
99
+
100
+ options = new DumperOptions();
101
+
102
+ options.setCanonical(canonical.isTrue());
103
+ options.setIndent((int)level.convertToInteger().getLongValue());
104
+ options.setWidth((int)width.convertToInteger().getLongValue());
105
+
106
+ this.io = io;
107
+
108
+ return context.nil;
109
+ }
110
+
111
+ @JRubyMethod
112
+ public IRubyObject start_stream(ThreadContext context, IRubyObject encoding) {
113
+ if (!(encoding instanceof RubyFixnum)) {
114
+ throw context.runtime.newTypeError(encoding, context.runtime.getFixnum());
115
+ }
116
+
117
+ initEmitter(context, encoding);
118
+
119
+ StreamStartEvent event = new StreamStartEvent(NULL_MARK, NULL_MARK);
120
+
121
+ emit(context, event);
122
+
123
+ return this;
124
+ }
125
+
126
+ @JRubyMethod
127
+ public IRubyObject end_stream(ThreadContext context) {
128
+ StreamEndEvent event = new StreamEndEvent(NULL_MARK, NULL_MARK);
129
+ emit(context, event);
130
+ return this;
131
+ }
132
+
133
+ @JRubyMethod
134
+ public IRubyObject start_document(ThreadContext context, IRubyObject _version, IRubyObject tags, IRubyObject implicit) {
135
+ DumperOptions.Version version = null;
136
+ boolean implicitBool = implicit.isTrue();
137
+ Map<String, String> tagsMap = null;
138
+
139
+ RubyArray versionAry = _version.convertToArray();
140
+ if (versionAry.size() == 2) {
141
+ int versionInt0 = (int)versionAry.eltInternal(0).convertToInteger().getLongValue();
142
+ int versionInt1 = (int)versionAry.eltInternal(1).convertToInteger().getLongValue();
143
+
144
+ if (versionInt0 == 1) {
145
+ if (versionInt1 == 0) {
146
+ version = DumperOptions.Version.V1_0;
147
+ } else if (versionInt1 == 1) {
148
+ version = DumperOptions.Version.V1_1;
149
+ }
150
+ }
151
+ if (version == null) {
152
+ throw context.runtime.newArgumentError("invalid YAML version: " + versionAry);
153
+ }
154
+ }
155
+
156
+ RubyArray tagsAry = tags.convertToArray();
157
+ if (tagsAry.size() > 0) {
158
+ tagsMap = new HashMap<String, String>(tagsAry.size());
159
+ for (int i = 0; i < tagsAry.size(); i++) {
160
+ RubyArray tagsTuple = tagsAry.eltInternal(i).convertToArray();
161
+ if (tagsTuple.size() != 2) {
162
+ throw context.runtime.newRuntimeError("tags tuple must be of length 2");
163
+ }
164
+ IRubyObject key = tagsTuple.eltInternal(0);
165
+ IRubyObject value = tagsTuple.eltInternal(1);
166
+ tagsMap.put(
167
+ key.asJavaString(),
168
+ value.asJavaString());
169
+ }
170
+ }
171
+
172
+ DocumentStartEvent event = new DocumentStartEvent(NULL_MARK, NULL_MARK, !implicitBool, version, tagsMap);
173
+ emit(context, event);
174
+ return this;
175
+ }
176
+
177
+ @JRubyMethod
178
+ public IRubyObject end_document(ThreadContext context, IRubyObject implicit) {
179
+ DocumentEndEvent event = new DocumentEndEvent(NULL_MARK, NULL_MARK, !implicit.isTrue());
180
+ emit(context, event);
181
+ return this;
182
+ }
183
+
184
+ @JRubyMethod(required = 6)
185
+ public IRubyObject scalar(ThreadContext context, IRubyObject[] args) {
186
+ IRubyObject value = args[0];
187
+ IRubyObject anchor = args[1];
188
+ IRubyObject tag = args[2];
189
+ IRubyObject plain = args[3];
190
+ IRubyObject quoted = args[4];
191
+ IRubyObject style = args[5];
192
+
193
+ if (!(value instanceof RubyString)) {
194
+ throw context.runtime.newTypeError(value, context.runtime.getString());
195
+ }
196
+
197
+ ScalarEvent event = new ScalarEvent(
198
+ anchor.isNil() ? null : anchor.asJavaString(),
199
+ tag.isNil() ? null : tag.asJavaString(),
200
+ new ImplicitTuple(plain.isTrue(),
201
+ quoted.isTrue()),
202
+ value.asJavaString(),
203
+ NULL_MARK,
204
+ NULL_MARK,
205
+ SCALAR_STYLES[(int)style.convertToInteger().getLongValue()]);
206
+ emit(context, event);
207
+ return this;
208
+ }
209
+
210
+ @JRubyMethod(required = 4)
211
+ public IRubyObject start_sequence(ThreadContext context, IRubyObject[] args) {
212
+ IRubyObject anchor = args[0];
213
+ IRubyObject tag = args[1];
214
+ IRubyObject implicit = args[2];
215
+ IRubyObject style = args[3];
216
+
217
+ final int SEQUENCE_BLOCK = 1; // see psych/nodes/sequence.rb
218
+
219
+ SequenceStartEvent event = new SequenceStartEvent(
220
+ anchor.isNil() ? null : anchor.asJavaString(),
221
+ tag.isNil() ? null : tag.asJavaString(),
222
+ implicit.isTrue(),
223
+ NULL_MARK,
224
+ NULL_MARK,
225
+ SEQUENCE_BLOCK != style.convertToInteger().getLongValue());
226
+ emit(context, event);
227
+ return this;
228
+ }
229
+
230
+ @JRubyMethod
231
+ public IRubyObject end_sequence(ThreadContext context) {
232
+ SequenceEndEvent event = new SequenceEndEvent(NULL_MARK, NULL_MARK);
233
+ emit(context, event);
234
+ return this;
235
+ }
236
+
237
+ @JRubyMethod(required = 4)
238
+ public IRubyObject start_mapping(ThreadContext context, IRubyObject[] args) {
239
+ IRubyObject anchor = args[0];
240
+ IRubyObject tag = args[1];
241
+ IRubyObject implicit = args[2];
242
+ IRubyObject style = args[3];
243
+
244
+ final int MAPPING_BLOCK = 1; // see psych/nodes/mapping.rb
245
+
246
+ MappingStartEvent event = new MappingStartEvent(
247
+ anchor.isNil() ? null : anchor.asJavaString(),
248
+ tag.isNil() ? null : tag.asJavaString(),
249
+ implicit.isTrue(),
250
+ NULL_MARK,
251
+ NULL_MARK,
252
+ MAPPING_BLOCK != style.convertToInteger().getLongValue());
253
+ emit(context, event);
254
+ return this;
255
+ }
256
+
257
+ @JRubyMethod
258
+ public IRubyObject end_mapping(ThreadContext context) {
259
+ MappingEndEvent event = new MappingEndEvent(NULL_MARK, NULL_MARK);
260
+ emit(context, event);
261
+ return this;
262
+ }
263
+
264
+ @JRubyMethod
265
+ public IRubyObject alias(ThreadContext context, IRubyObject anchor) {
266
+ AliasEvent event = new AliasEvent(anchor.asJavaString(), NULL_MARK, NULL_MARK);
267
+ emit(context, event);
268
+ return this;
269
+ }
270
+
271
+ @JRubyMethod(name = "canonical=")
272
+ public IRubyObject canonical_set(ThreadContext context, IRubyObject canonical) {
273
+ // TODO: unclear if this affects a running emitter
274
+ options.setCanonical(canonical.isTrue());
275
+ return canonical;
276
+ }
277
+
278
+ @JRubyMethod
279
+ public IRubyObject canonical(ThreadContext context) {
280
+ // TODO: unclear if this affects a running emitter
281
+ return context.runtime.newBoolean(options.isCanonical());
282
+ }
283
+
284
+ @JRubyMethod(name = "indentation=")
285
+ public IRubyObject indentation_set(ThreadContext context, IRubyObject level) {
286
+ // TODO: unclear if this affects a running emitter
287
+ options.setIndent((int)level.convertToInteger().getLongValue());
288
+ return level;
289
+ }
290
+
291
+ @JRubyMethod
292
+ public IRubyObject indentation(ThreadContext context) {
293
+ // TODO: unclear if this affects a running emitter
294
+ return context.runtime.newFixnum(options.getIndent());
295
+ }
296
+
297
+ @JRubyMethod(name = "line_width=")
298
+ public IRubyObject line_width_set(ThreadContext context, IRubyObject width) {
299
+ options.setWidth((int)width.convertToInteger().getLongValue());
300
+ return width;
301
+ }
302
+
303
+ @JRubyMethod
304
+ public IRubyObject line_width(ThreadContext context) {
305
+ return context.runtime.newFixnum(options.getWidth());
306
+ }
307
+
308
+ private void emit(ThreadContext context, Event event) {
309
+ try {
310
+ if (emitter == null) throw context.runtime.newRuntimeError("uninitialized emitter");
311
+
312
+ emitter.emit(event);
313
+ } catch (IOException ioe) {
314
+ throw context.runtime.newIOErrorFromException(ioe);
315
+ } catch (EmitterException ee) {
316
+ throw context.runtime.newRuntimeError(ee.toString());
317
+ }
318
+ }
319
+
320
+ private void initEmitter(ThreadContext context, IRubyObject _encoding) {
321
+ if (emitter != null) throw context.runtime.newRuntimeError("already initialized emitter");
322
+
323
+ Encoding encoding = PsychLibrary.YAMLEncoding.values()[(int)_encoding.convertToInteger().getLongValue()].encoding;
324
+ Charset charset = context.runtime.getEncodingService().charsetForEncoding(encoding);
325
+
326
+ emitter = new Emitter(new OutputStreamWriter(new IOOutputStream(io, encoding), charset), options);
327
+ }
328
+
329
+ Emitter emitter;
330
+ DumperOptions options = new DumperOptions();
331
+ IRubyObject io;
332
+
333
+ private static final Mark NULL_MARK = new Mark(null, 0, 0, 0, null, 0);
334
+
335
+ // Map style constants from Psych values (ANY = 0 ... FOLDED = 5)
336
+ // to SnakeYaml values; see psych/nodes/scalar.rb.
337
+ private static final Character[] SCALAR_STYLES = new Character[] {
338
+ null, // ANY; we'll choose plain
339
+ null, // PLAIN
340
+ '\'', // SINGLE_QUOTED
341
+ '"', // DOUBLE_QUOTED
342
+ '|', // LITERAL
343
+ '>', // FOLDED
344
+ };
345
+ }
@@ -0,0 +1,93 @@
1
+ /***** BEGIN LICENSE BLOCK *****
2
+ * Version: EPL 1.0/GPL 2.0/LGPL 2.1
3
+ *
4
+ * The contents of this file are subject to the Eclipse Public
5
+ * License Version 1.0 (the "License"); you may not use this file
6
+ * except in compliance with the License. You may obtain a copy of
7
+ * the License at http://www.eclipse.org/legal/epl-v10.html
8
+ *
9
+ * Software distributed under the License is distributed on an "AS
10
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11
+ * implied. See the License for the specific language governing
12
+ * rights and limitations under the License.
13
+ *
14
+ * Copyright (C) 2010 Charles O Nutter <headius@headius.com>
15
+ *
16
+ * Alternatively, the contents of this file may be used under the terms of
17
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
18
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
19
+ * in which case the provisions of the GPL or the LGPL are applicable instead
20
+ * of those above. If you wish to allow use of your version of this file only
21
+ * under the terms of either the GPL or the LGPL, and not to allow others to
22
+ * use your version of this file under the terms of the EPL, indicate your
23
+ * decision by deleting the provisions above and replace them with the notice
24
+ * and other provisions required by the GPL or the LGPL. If you do not delete
25
+ * the provisions above, a recipient may use your version of this file under
26
+ * the terms of any one of the EPL, the GPL or the LGPL.
27
+ ***** END LICENSE BLOCK *****/
28
+ package org.jruby.ext.psych;
29
+
30
+ import java.io.InputStream;
31
+ import java.io.IOException;
32
+ import java.util.Properties;
33
+
34
+ import org.jcodings.Encoding;
35
+ import org.jcodings.specific.UTF16BEEncoding;
36
+ import org.jcodings.specific.UTF16LEEncoding;
37
+ import org.jcodings.specific.UTF8Encoding;
38
+ import org.jruby.Ruby;
39
+ import org.jruby.RubyArray;
40
+ import org.jruby.RubyModule;
41
+ import org.jruby.RubyString;
42
+ import org.jruby.internal.runtime.methods.JavaMethod.JavaMethodZero;
43
+ import org.jruby.runtime.ThreadContext;
44
+ import org.jruby.runtime.Visibility;
45
+ import org.jruby.runtime.builtin.IRubyObject;
46
+ import org.jruby.runtime.load.Library;
47
+
48
+ public class PsychLibrary implements Library {
49
+ public void load(final Ruby runtime, boolean wrap) {
50
+ RubyModule psych = runtime.defineModule("Psych");
51
+
52
+ // load version from properties packed with the jar
53
+ Properties props = new Properties();
54
+ try( InputStream is = runtime.getJRubyClassLoader().getResourceAsStream("META-INF/maven/org.yaml/snakeyaml/pom.properties") ) {
55
+ props.load(is);
56
+ }
57
+ catch( IOException e ) {
58
+ // ignored
59
+ }
60
+ RubyString version = runtime.newString(props.getProperty("version", "0.0") + ".0");
61
+ version.setFrozen(true);
62
+ psych.setConstant("SNAKEYAML_VERSION", version);
63
+
64
+ String[] versionParts = version.toString().split("\\.");
65
+ final RubyArray versionElements = runtime.newArray(runtime.newFixnum(Integer.parseInt(versionParts[0])), runtime.newFixnum(Integer.parseInt(versionParts[1])), runtime.newFixnum(Integer.parseInt(versionParts[2])));
66
+ versionElements.setFrozen(true);
67
+
68
+ psych.getSingletonClass().addMethod("libyaml_version", new JavaMethodZero(psych, Visibility.PUBLIC) {
69
+ @Override
70
+ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name) {
71
+ return versionElements;
72
+ }
73
+ });
74
+
75
+ PsychParser.initPsychParser(runtime, psych);
76
+ PsychEmitter.initPsychEmitter(runtime, psych);
77
+ PsychToRuby.initPsychToRuby(runtime, psych);
78
+ PsychYamlTree.initPsychYamlTree(runtime, psych);
79
+ }
80
+
81
+ public enum YAMLEncoding {
82
+ YAML_ANY_ENCODING(UTF8Encoding.INSTANCE),
83
+ YAML_UTF8_ENCODING(UTF8Encoding.INSTANCE),
84
+ YAML_UTF16LE_ENCODING(UTF16LEEncoding.INSTANCE),
85
+ YAML_UTF16BE_ENCODING(UTF16BEEncoding.INSTANCE);
86
+
87
+ YAMLEncoding(Encoding encoding) {
88
+ this.encoding = encoding;
89
+ }
90
+
91
+ public final Encoding encoding;
92
+ }
93
+ }