From 286fadf1999b27248175e182eecc61c2abe01407 Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Fri, 1 Jul 2016 01:21:08 -0600 Subject: [PATCH] add support for JRuby When RUBY_ENGINE == 'jruby', do the following: - map popen4 function to Open.popen3 - map Yajl to MultiJson and set MultiJson engine to json_gem - update gemspec to build -java gem when running under JRuby - drop posix/spawn and yaml dependencies and add multi_json Additionally, add rake as a dev dependency so rake can be run via Bundler --- lib/pygments/popen.rb | 17 ++++++++++++++--- pygments.rb.gemspec | 11 ++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/pygments/popen.rb b/lib/pygments/popen.rb index 9598ebfc..4791a9ae 100644 --- a/lib/pygments/popen.rb +++ b/lib/pygments/popen.rb @@ -1,6 +1,17 @@ # coding: utf-8 -require 'posix/spawn' -require 'yajl' +if RUBY_ENGINE == 'jruby' + require 'open3' + def popen4(script) + streams = Open3.popen3(script) + streams.unshift(streams.pop[:pid]) + streams + end + require 'multi_json' + (Yajl = MultiJson).engine = 'json_gem' +else + require 'yajl' + require 'posix/spawn' +end require 'timeout' require 'logger' require 'time' @@ -13,7 +24,7 @@ class MentosError < IOError # Python process. module Pygments module Popen - include POSIX::Spawn + include POSIX::Spawn if defined?(::POSIX::Spawn) extend self # Get things started by opening a pipe to mentos (the freshmaker), a diff --git a/pygments.rb.gemspec b/pygments.rb.gemspec index 17d09711..26e9350e 100644 --- a/pygments.rb.gemspec +++ b/pygments.rb.gemspec @@ -14,9 +14,14 @@ Gem::Specification.new do |s| s.email = ['aman@tmm1.net'] s.license = 'MIT' - s.add_dependency 'yajl-ruby', '~> 1.2.0' - s.add_dependency 'posix-spawn', '~> 0.3.6' - s.add_development_dependency 'rake-compiler', '~> 0.7.6' + if RUBY_ENGINE == 'jruby' + s.platform = 'java' + s.add_dependency 'multi_json', '~> 1.12.1' + else + s.add_dependency 'yajl-ruby', '~> 1.2.0' + s.add_dependency 'posix-spawn', '~> 0.3.6' + end + s.add_development_dependency 'rake' # s.extensions = ['ext/extconf.rb'] s.require_paths = ['lib']