Skip to content

Commit

Permalink
Merge pull request tonsky#38 from bundler/build-against-jruby
Browse files Browse the repository at this point in the history
Build against JRuby
  • Loading branch information
smellsblue committed Nov 3, 2015
2 parents 4c7911e + ebec3f0 commit 190f352
Show file tree
Hide file tree
Showing 17 changed files with 126 additions and 26 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ rvm:
- 2.1
- 2.2
- ruby-head
- jruby-9.0.3.0
bundler_args: "--binstubs --jobs=3 --retry=3"
before_install: gem install bundler -v 1.10.6
cache: bundler
Expand Down
8 changes: 7 additions & 1 deletion gemstash.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Gem::Specification.new do |spec|
spec.version = Gemstash::VERSION
spec.authors = ["Andre Arko"]
spec.email = ["andre@arko.net"]
spec.platform = "java" if RUBY_PLATFORM == "java"

spec.summary = "A place to stash gems you'll need"
spec.description = "Gemstash acts as a local RubyGems server, caching \
Expand All @@ -28,11 +29,16 @@ you push your own private gems as well."
spec.add_runtime_dependency "puma", "~> 2.14"
spec.add_runtime_dependency "sequel", "~> 4.26"
spec.add_runtime_dependency "sinatra", "~> 1.4"
spec.add_runtime_dependency "sqlite3", "~> 1.3"
spec.add_runtime_dependency "thor", "~> 0.19"
spec.add_runtime_dependency "faraday", "~> 0.9"
spec.add_runtime_dependency "faraday_middleware", "~> 0.10"

if RUBY_PLATFORM == "java"
spec.add_runtime_dependency "jdbc-sqlite3", "~> 3.8"
else
spec.add_runtime_dependency "sqlite3", "~> 1.3"
end

spec.add_development_dependency "bundler", "~> 1.10"
spec.add_development_dependency "rack-test", "~> 0.6"
spec.add_development_dependency "rake", "~> 10.0"
Expand Down
11 changes: 9 additions & 2 deletions lib/gemstash/cli/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,15 @@ def ask_database

def ask_postgres_details
say_current_config(:db_url, "Current database url")
url = @cli.ask "Where is the database? [postgres:///gemstash]"
url = "postgres:///gemstash" if url.empty?

if RUBY_PLATFORM == "java"
default_value = "jdbc:postgres:///gemstash"
else
default_value = "postgres:///gemstash"
end

url = @cli.ask "Where is the database? [#{default_value}]"
url = default_value if url.empty?
@config[:db_url] = url
end

Expand Down
4 changes: 2 additions & 2 deletions lib/gemstash/db/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def reindex
def self.find_by_spec(gem_id, spec)
self[rubygem_id: gem_id,
number: spec.version.to_s,
platform: spec.platform]
platform: spec.platform.to_s]
end

def self.find_by_full_name(full_name)
Expand All @@ -29,7 +29,7 @@ def self.insert_by_spec(gem_id, spec)
gem_name = Gemstash::DB::Rubygem[gem_id].name
new(rubygem_id: gem_id,
number: spec.version.to_s,
platform: spec.platform,
platform: spec.platform.to_s,
full_name: "#{gem_name}-#{spec.version}-#{spec.platform}",
storage_id: spec.full_name,
indexed: true).tap(&:save).id
Expand Down
7 changes: 6 additions & 1 deletion lib/gemstash/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ def db
case config[:db_adapter]
when "sqlite3"
db_path = base_file("gemstash.db")
db = Sequel.connect("sqlite://#{db_path}")

if RUBY_PLATFORM == "java"
db = Sequel.connect("jdbc:sqlite:#{db_path}")
else
db = Sequel.connect("sqlite://#{db_path}")
end
when "postgres"
db = Sequel.connect(config[:db_url])
else
Expand Down
1 change: 1 addition & 0 deletions spec/data/gems/example/example.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Gem::Specification.new do |spec|
spec.version = Example::VERSION
spec.authors = ["Mike Virata-Stone"]
spec.email = ["mike@virata-stone.com"]
spec.platform = ENV["SPEC_PLATFORM"] unless ENV["SPEC_PLATFORM"].to_s.empty?

spec.summary = "A gem that isn't real."
spec.description = "This is an example gem for testing purposes."
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions spec/data/gems/speaker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib/speaker/platform.rb
29 changes: 29 additions & 0 deletions spec/data/gems/speaker/Rakefile
Original file line number Diff line number Diff line change
@@ -1 +1,30 @@
task :build do
platform_rb = File.expand_path("../lib/speaker/platform.rb", __FILE__)
puts "Generating #{platform_rb}"

if RUBY_PLATFORM == "java"
File.write(platform_rb, <<-EOF)
module Speaker
#:nodoc:
module Platform
def self.name
"Java"
end
end
end
EOF
else
File.write(platform_rb, <<-EOF)
module Speaker
#:nodoc:
module Platform
def self.name
"Ruby"
end
end
end
EOF
end
end

require "bundler/gem_tasks"
5 changes: 3 additions & 2 deletions spec/data/gems/speaker/lib/speaker.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "speaker/version"
require "speaker/platform"

#:nodoc:
module Speaker
Expand All @@ -11,9 +12,9 @@ def self.say(argv)
usage if argv.size != 1

if argv.first == "hi"
puts "Hello world"
puts "Hello world, #{Speaker::Platform.name}"
elsif argv.first == "bye"
puts "Goodbye moon"
puts "Goodbye moon, #{Speaker::Platform.name}"
else
usage
end
Expand Down
Binary file not shown.
Binary file modified spec/data/gems/speaker/pkg/speaker-0.1.0.gem
Binary file not shown.
1 change: 1 addition & 0 deletions spec/data/gems/speaker/speaker.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Gem::Specification.new do |spec|
spec.version = Speaker::VERSION
spec.authors = ["Mike Virata-Stone"]
spec.email = ["mike@virata-stone.com"]
spec.platform = "java" if RUBY_PLATFORM == "java"

spec.summary = "A gem that isn't real."
spec.description = "This is an example gem for testing purposes."
Expand Down
6 changes: 3 additions & 3 deletions spec/gemstash/gem_pusher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
end

context "with a non-ruby platform" do
# TODO: I think this will fail without some changes
# TODO: Also, should 'example-0.1.0-ruby' work from storage?
xit "saves the dependency info and stores the gem" do
let(:gem_contents) { read_gem("example", "0.1.0-java") }

it "saves the dependency info and stores the gem" do
results = [{
:name => "example",
:number => "0.1.0",
Expand Down
52 changes: 38 additions & 14 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@

describe "gemstash integration tests" do
before(:all) do
speaker_deps = {
:name => "speaker",
:number => "0.1.0",
:platform => "ruby",
:dependencies => []
}
speaker_deps = [
{
:name => "speaker",
:number => "0.1.0",
:platform => "ruby",
:dependencies => []
}, {
:name => "speaker",
:number => "0.1.0",
:platform => "java",
:dependencies => []
}
]

@rubygems_server = SimpleServer.new("127.0.0.1", port: 9043)
@rubygems_server.mount_gem_deps("speaker", [speaker_deps])
@rubygems_server.mount_gem_deps("speaker", speaker_deps)
@rubygems_server.mount_gem("speaker", "0.1.0")
@rubygems_server.mount_gem("speaker", "0.1.0-java")
@rubygems_server.start
@empty_server = SimpleServer.new("127.0.0.1", port: 9044)
@empty_server.mount_gem_deps
Expand Down Expand Up @@ -118,6 +126,14 @@
describe "bundle install against gemstash" do
let(:dir) { bundle_path(bundle) }

let(:platform_message) do
if RUBY_PLATFORM == "java"
"Java"
else
"Ruby"
end
end

after do
clean_bundle bundle
end
Expand All @@ -127,7 +143,8 @@

it "successfully bundles" do
expect(execute("bundle", dir: dir)).to exit_success
expect(execute("bundle exec speaker hi", dir: dir)).to exit_success.and_output("Hello world\n")
expect(execute("bundle exec speaker hi", dir: dir)).
to exit_success.and_output("Hello world, #{platform_message}\n")
end
end

Expand All @@ -137,7 +154,8 @@
# This should stay skipped until bundler sends the X-Gemfile-Source header
xit "successfully bundles" do
expect(execute("bundle", dir: dir)).to exit_success
expect(execute("bundle exec speaker hi", dir: dir)).to exit_success.and_output("Hello world\n")
expect(execute("bundle exec speaker hi", dir: dir)).
to exit_success.and_output("Hello world, #{platform_message}\n")
end
end

Expand All @@ -146,17 +164,20 @@

it "successfully bundles" do
expect(execute("bundle", dir: dir)).to exit_success
expect(execute("bundle exec speaker hi", dir: dir)).to exit_success.and_output("Hello world\n")
expect(execute("bundle exec speaker hi", dir: dir)).
to exit_success.and_output("Hello world, #{platform_message}\n")
end

it "can successfully bundle twice" do
expect(execute("bundle", dir: dir)).to exit_success
expect(execute("bundle exec speaker hi", dir: dir)).to exit_success.and_output("Hello world\n")
expect(execute("bundle exec speaker hi", dir: dir)).
to exit_success.and_output("Hello world, #{platform_message}\n")

clean_bundle bundle

expect(execute("bundle", dir: dir)).to exit_success
expect(execute("bundle exec speaker hi", dir: dir)).to exit_success.and_output("Hello world\n")
expect(execute("bundle exec speaker hi", dir: dir)).
to exit_success.and_output("Hello world, #{platform_message}\n")
end
end

Expand All @@ -165,22 +186,25 @@

it "successfully bundles" do
expect(execute("bundle", dir: dir)).to exit_success
expect(execute("bundle exec speaker hi", dir: dir)).to exit_success.and_output("Hello world\n")
expect(execute("bundle exec speaker hi", dir: dir)).
to exit_success.and_output("Hello world, #{platform_message}\n")
end
end

context "with private gems", :db_transaction => false do
before do
Gemstash::Authorization.authorize("test-key", "all")
Gemstash::GemPusher.new("test-key", read_gem("speaker", "0.1.0")).push
Gemstash::GemPusher.new("test-key", read_gem("speaker", "0.1.0-java")).push
@gemstash.env.cache.flush
end

let(:bundle) { "integration_spec/private_gems" }

it "successfully bundles" do
expect(execute("bundle", dir: dir)).to exit_success
expect(execute("bundle exec speaker hi", dir: dir)).to exit_success.and_output("Hello world\n")
expect(execute("bundle exec speaker hi", dir: dir)).
to exit_success.and_output("Hello world, #{platform_message}\n")
end
end
end
Expand Down
24 changes: 23 additions & 1 deletion spec/support/exec_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@
# Helpers for executing commands and asserting the results.
module ExecHelpers
def execute(command, dir: nil, env: {})
bundle_gemfile = nil

if dir
gemfile_path = File.join(dir, "Gemfile")
bundle_gemfile = gemfile_path if File.exist?(gemfile_path)
end

env = {
"BUNDLE_GEMFILE" => nil,
"BUNDLE_GEMFILE" => bundle_gemfile,
"RUBYLIB" => nil,
"RUBYOPT" => nil,
"GEM_PATH" => ENV["_ORIGINAL_GEM_PATH"]
Expand All @@ -21,6 +28,7 @@ def initialize(env, command, dir)
@command = command
@dir = dir
@output, @status = Open3.capture2e(env, command, chdir: dir)
fix_jruby_output
end

def successful?
Expand All @@ -31,6 +39,20 @@ def matches_output?(expected)
return true unless expected
@output == expected
end

private

def fix_jruby_output
return unless RUBY_PLATFORM == "java"
# Travis builds or runs JRuby in a way that outputs the following warning for some reason
@output.gsub!(/^.*warning: unknown property jruby.cext.enabled\n/, "")

if Gem::Requirement.new(">= 1.11.0").satisfied_by?(Gem::Version.new(Bundler::VERSION))
raise "Please remove ExecHelpers#fix_jruby_output if the warning doesn't occur anymore"
end

@output.gsub!(/^.*warning: unsupported exec option: close_others\n/, "")
end
end
end

Expand Down
2 changes: 2 additions & 0 deletions spec/support/server_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def wait
def server_online?
Socket.tcp("127.0.0.1", @port, nil, nil, connect_timeout: 1).close
true
rescue Errno::EBADF
false
rescue Errno::ECONNREFUSED
false
rescue Errno::ETIMEDOUT
Expand Down

0 comments on commit 190f352

Please sign in to comment.