summaryrefslogtreecommitdiff
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
parent3ddffabc91bee3ba136a9367f24083b6bf9fd7ef (diff)
downloadpsych-b2dab9e80c62776138b4b63aa0b197e99033f239.tar.gz
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.
-rw-r--r--Manifest.txt3
-rw-r--r--Mavenfile9
-rw-r--r--Rakefile20
-rw-r--r--ext/java/PsychLibrary.java25
-rw-r--r--lib/psych.rb2
-rw-r--r--lib/psych/versions.rb3
-rw-r--r--lib/psych_jars.rb5
-rw-r--r--lib/snakeyaml-1.10.jarbin266956 -> 0 bytes
8 files changed, 55 insertions, 12 deletions
diff --git a/Manifest.txt b/Manifest.txt
index 264b848..3fe28db 100644
--- a/Manifest.txt
+++ b/Manifest.txt
@@ -57,6 +57,7 @@ lib/psych/stream.rb
lib/psych/streaming.rb
lib/psych/syntax_error.rb
lib/psych/tree_builder.rb
+lib/psych/versions.rb
lib/psych/visitors.rb
lib/psych/visitors/depth_first.rb
lib/psych/visitors/emitter.rb
@@ -65,6 +66,8 @@ lib/psych/visitors/to_ruby.rb
lib/psych/visitors/visitor.rb
lib/psych/visitors/yaml_tree.rb
lib/psych/y.rb
+lib/psych_jars.rb
+lib/psych.jar
test/psych/handlers/test_recorder.rb
test/psych/helper.rb
test/psych/json/test_stream.rb
diff --git a/Mavenfile b/Mavenfile
new file mode 100644
index 0000000..93d4348
--- /dev/null
+++ b/Mavenfile
@@ -0,0 +1,9 @@
+#-*- mode: ruby -*-
+
+pom 'org.jruby:jruby:9.0.0.0.pre1', :scope => :provided
+
+jar 'org.yaml:snakeyaml:${snakeyaml.version}'
+
+plugin :dependency, '2.8', :outputFile => 'pkg/classpath'
+
+# vim: syntax=Ruby
diff --git a/Rakefile b/Rakefile
index 3acf614..15c7b7c 100644
--- a/Rakefile
+++ b/Rakefile
@@ -34,25 +34,37 @@ $hoe = Hoe.spec 'psych' do
extra_dev_deps << ['minitest', '~> 4.0']
self.spec_extras = {
- :extensions => ["ext/psych/extconf.rb"],
:required_ruby_version => '>= 1.9.2'
}
if java?
+ require './lib/psych/versions.rb'
+ extra_deps << ['jar-dependencies', '>= 0.1.7']
+
+ # the jar declaration for jar-dependencies
+ self.spec_extras[ 'requirements' ] = "jar org.yaml:snakeyaml, #{Psych::DEFAULT_SNAKEYAML_VERSION}"
+ self.spec_extras[ 'platform' ] = 'java'
# TODO: clean this section up.
require "rake/javaextensiontask"
Rake::JavaExtensionTask.new("psych", spec) do |ext|
- jruby_home = RbConfig::CONFIG['prefix']
+ require 'maven/ruby/maven'
+ # tell maven via system properties the snakeyaml version
+ ENV_JAVA['snakeyaml.version'] = Psych::DEFAULT_SNAKEYAML_VERSION
+ # uses Mavenfile to write classpath into pkg/classpath
+ Maven::Ruby::Maven.new.exec( 'dependency:build-classpath')#, '--quiet' )
+ ext.source_version = '1.7'
+ ext.target_version = '1.7'
+ ext.classpath = File.read('pkg/classpath')
ext.ext_dir = 'ext/java'
- jars = ["#{jruby_home}/lib/jruby.jar"] + FileList['lib/*.jar']
- ext.classpath = jars.map { |x| File.expand_path x }.join ':'
end
else
+ self.spec_extras[:extensions] = ["ext/psych/extconf.rb"]
Rake::ExtensionTask.new "psych", spec do |ext|
ext.lib_dir = File.join(*['lib', ENV['FAT_DIR']].compact)
end
end
end
+$hoe.spec.files << 'lib/psych.jar'
Hoe.add_include_dirs('.:lib/psych')
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) {
diff --git a/lib/psych.rb b/lib/psych.rb
index efcb142..e4d2ebf 100644
--- a/lib/psych.rb
+++ b/lib/psych.rb
@@ -1,6 +1,6 @@
case RUBY_ENGINE
when 'jruby'
- require 'psych.jar'
+ require 'psych_jars'
org.jruby.ext.psych.PsychLibrary.new.load(JRuby.runtime, false)
else
require 'psych.so'
diff --git a/lib/psych/versions.rb b/lib/psych/versions.rb
new file mode 100644
index 0000000..530d310
--- /dev/null
+++ b/lib/psych/versions.rb
@@ -0,0 +1,3 @@
+module Psych
+ DEFAULT_SNAKEYAML_VERSION = '1.14'.freeze
+end
diff --git a/lib/psych_jars.rb b/lib/psych_jars.rb
new file mode 100644
index 0000000..795c7ea
--- /dev/null
+++ b/lib/psych_jars.rb
@@ -0,0 +1,5 @@
+require 'psych/versions'
+require 'psych.jar'
+
+require 'jar-dependencies'
+require_jar('org.yaml', 'snakeyaml', Psych::DEFAULT_SNAKEYAML_VERSION)
diff --git a/lib/snakeyaml-1.10.jar b/lib/snakeyaml-1.10.jar
deleted file mode 100644
index f3f0fd7..0000000
--- a/lib/snakeyaml-1.10.jar
+++ /dev/null
Binary files differ