Skip to content

Commit

Permalink
Provide workaround for JRuby with native API access disabled. Prepare…
Browse files Browse the repository at this point in the history
… release.
  • Loading branch information
emboss committed Jun 22, 2014
1 parent b300a96 commit 39c6d3a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -14,7 +14,7 @@ gem 'ffi'

group :development do
gem 'rake'
gem 'rspec'
gem 'rspec', '~> 2.99.0'
gem 'jruby-openssl', :platforms => :jruby
end

Expand Down
4 changes: 2 additions & 2 deletions krypt.gemspec
@@ -1,5 +1,5 @@
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
$:.unshift File.expand_path('../lib', __FILE__)

require 'krypt/version'

Gem::Specification.new do |s|
Expand Down
22 changes: 20 additions & 2 deletions lib/krypt/provider.rb
@@ -1,8 +1,26 @@
require_relative 'provider/provider'

##
# If JRuby is configured with native API access disabled, requiring the FFI
# provider will result in a LoadError. The FFI provider is not required at
# runtime as there is always a default (Java-based) provider.
#

def java?
!! (RUBY_PLATFORM =~ /java/)
end

def native_disabled?
require 'jruby'
!JRuby.runtime.instance_config.native_enabled
end

begin
require_relative 'provider/ffi'
rescue LoadError => e
# cf. https://github.com/krypt/krypt/issues/47
warn "FFI provider could not be loaded. Error message: #{e}"
if java? && native_disabled?
# Do not use the FFI provider with JRuby and native API access disabled
else
raise e
end
end
2 changes: 1 addition & 1 deletion lib/krypt/version.rb
@@ -1,3 +1,3 @@
module Krypt
VERSION = "0.0.2.rc1"
VERSION = "0.0.2"
end

0 comments on commit 39c6d3a

Please sign in to comment.