summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorChristian Meier <m.kristian@web.de>2015-02-02 18:47:02 +0100
committerChristian Meier <m.kristian@web.de>2015-02-26 17:33:11 +0100
commitb2dab9e80c62776138b4b63aa0b197e99033f239 (patch)
treeb7c466ece08cceb045b66815acbb8dfc5becbeea /ext
parent3ddffabc91bee3ba136a9367f24083b6bf9fd7ef (diff)
downloadpsych-b2dab9e80c62776138b4b63aa0b197e99033f239.zip
setup java platform gem
use maven to resolve jar dependencies for compilation. setup jar-dependencies to install the snakeyaml jar when installing the gem via rubygems or bundler. added java code to reflect the snakeyaml vesion which got finally loaded into the jruby-classloader.
Diffstat (limited to 'ext')
-rw-r--r--ext/java/PsychLibrary.java25
1 files changed, 18 insertions, 7 deletions
diff --git a/ext/java/PsychLibrary.java b/ext/java/PsychLibrary.java
index 2d2141b..3d6437e 100644
--- a/ext/java/PsychLibrary.java
+++ b/ext/java/PsychLibrary.java
@@ -27,6 +27,10 @@
***** END LICENSE BLOCK *****/
package org.jruby.ext.psych;
+import java.io.InputStream;
+import java.io.IOException;
+import java.util.Properties;
+
import org.jcodings.Encoding;
import org.jcodings.specific.UTF16BEEncoding;
import org.jcodings.specific.UTF16LEEncoding;
@@ -42,16 +46,23 @@ import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.load.Library;
public class PsychLibrary implements Library {
- // NOTE: we add the last .0 for format compat with libyaml version numbers
- // TODO: This should always reflect the SnakeYAML version
- private static final String SNAKEYAML_VERSION = "1.13.0";
public void load(final Ruby runtime, boolean wrap) {
RubyModule psych = runtime.defineModule("Psych");
-
- RubyString version = runtime.newString(SNAKEYAML_VERSION);
+
+ // load version from properties packed with the jar
+ Properties props = new Properties();
+ try( InputStream is = runtime.getJRubyClassLoader().getResourceAsStream("META-INF/maven/org.yaml/snakeyaml/pom.properties") ) {
+ props.load(is);
+ }
+ catch( IOException e ) {
+ // ignored
+ }
+ RubyString version = runtime.newString(props.getProperty("version", "0.0") + ".0");
version.setFrozen(true);
-
- final RubyArray versionElements = runtime.newArray(runtime.newFixnum(1), runtime.newFixnum(13), runtime.newFixnum(0));
+ psych.setConstant("SNAKEYAML_VERSION", version);
+
+ String[] versionParts = version.toString().split("\\.");
+ final RubyArray versionElements = runtime.newArray(runtime.newFixnum(Integer.parseInt(versionParts[0])), runtime.newFixnum(Integer.parseInt(versionParts[1])), runtime.newFixnum(Integer.parseInt(versionParts[2])));
versionElements.setFrozen(true);
psych.getSingletonClass().addMethod("libyaml_version", new JavaMethodZero(psych, Visibility.PUBLIC) {