Skip to content

Instantly share code, notes, and snippets.

@bridiver
Created December 1, 2013 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bridiver/7735356 to your computer and use it in GitHub Desktop.
Save bridiver/7735356 to your computer and use it in GitHub Desktop.
Fix for various JRuby 1.7 jar loading issues
# @see JRUBY-6970.rb
# encoding: utf-8
# a 'require "openssl" has occurred.
class OpenSSL::SSL::SSLContext
alias_method :ca_path_JRUBY_6970=, :ca_path=
alias_method :ca_file_JRUBY_6970=, :ca_file=
def ca_file=(arg)
if arg =~ /^jar:file:\//
return ca_file_JRUBY_6970=(arg.gsub(/^jar:/, ""))
end
return ca_file_JRUBY_6970=(arg)
end
def ca_path=(arg)
if arg =~ /^jar:file:\//
return ca_path_JRUBY_6970=(arg.gsub(/^jar:/, ""))
end
return ca_path_JRUBY_6970=(arg)
end
end
# encoding: utf-8
# Monkeypatch for JRUBY-6970
#
# Should solve this error:
# Caused by: org.jruby.exceptions.RaiseException: (SSLError) jar:file:/mnt/storm/supervisor/stormdist/topology-name-1-1385830575/stormjar.jar!/gems/gems/aws-sdk-1.8.0/ca-bundle.crt
# at org.jruby.ext.openssl.SSLContext.setup(org/jruby/ext/openssl/SSLContext.java:230)
# at org.jruby.ext.openssl.SSLSocket.initialize(org/jruby/ext/openssl/SSLSocket.java:145)
module Kernel
alias_method :require_JRUBY_6970_hack, :require
def require(path)
if path =~ /^jar:file:.+!.+/
path = path.gsub(/^jar:/, "")
end
# JRUBY-7065
path = File.expand_path(path) if path.include?("/../")
rc = require_JRUBY_6970_hack(path)
# Only monkeypatch openssl after it's been loaded.
if path == "openssl"
require_relative "JRUBY-6970-openssl"
end
return rc
end
end
# Work around for a bug in File.expand_path that doesn't account for resources
# in jar paths.
#
# Should solve (Errno::ENOENT) errors with file: paths
class File
class << self
alias_method :expand_path_JRUBY_6970, :expand_path
def expand_path(path, dir=nil)
if path =~ /(jar:)?file:\/.*\.jar!/
jar, resource = path.split("!", 2)
if resource.nil? || resource == ""
# Nothing after the "!", nothing special to handle.
return expand_path_JRUBY_6970(path, dir)
else
resource = expand_path_JRUBY_6970(resource, dir)
return fix_jar_path(jar, resource)
end
elsif dir =~ /(jar:)?file:\/.*\.jar!/
jar, dir = dir.split("!", 2)
if dir.empty?
# sometimes the original dir is just 'file:/foo.jar!'
return File.join("#{jar}!", path)
end
dir = expand_path_JRUBY_6970(path, dir)
return fix_jar_path(jar, dir)
else
return expand_path_JRUBY_6970(path, dir)
end
end
end
protected
def self.fix_jar_path(jar, resource)
if RbConfig::CONFIG["host_os"] == "mswin32"
# 'expand_path' on "/" will return "C:/" on windows.
# So like.. we don't want that because technically this
# is the root of the jar, not of a disk.
return "#{jar}!#{resource.gsub(/^[A-Za-z]:/, "")}"
else
return "#{jar}!#{resource}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment