Skip to content

Commit

Permalink
add support for JRuby
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mojavelinux committed Jul 1, 2016
1 parent a21567d commit 286fadf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
17 changes: 14 additions & 3 deletions lib/pygments/popen.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Expand Down
11 changes: 8 additions & 3 deletions pygments.rb.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ Gem::Specification.new do |s|
s.email = ['[email protected]']
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']
Expand Down

0 comments on commit 286fadf

Please sign in to comment.