diff --git a/bundler/lib/bundler/stub_specification.rb b/bundler/lib/bundler/stub_specification.rb index 026f753d411f..00e5cae04275 100644 --- a/bundler/lib/bundler/stub_specification.rb +++ b/bundler/lib/bundler/stub_specification.rb @@ -38,7 +38,11 @@ def ignored? @ignored = missing_extensions? return false unless @ignored - warn "Source #{source} is ignoring #{self} because it is missing extensions" + # If we share GEM_HOME for all of Ruby platform, the platform specific gem always warn that specification. + # ex `jruby-launcher` and CRuby + if (platform == Gem::Platform::RUBY || Gem::Platform.local === platform) && RUBY_ENGINE != "jruby" + warn "Source #{source} is ignoring #{self} because it is missing extensions" + end true end diff --git a/bundler/spec/bundler/stub_specification_spec.rb b/bundler/spec/bundler/stub_specification_spec.rb index beb966b3ce8b..8efe460d05be 100644 --- a/bundler/spec/bundler/stub_specification_spec.rb +++ b/bundler/spec/bundler/stub_specification_spec.rb @@ -12,6 +12,17 @@ described_class.from_stub(gemspec) end + let(:with_java_gem_stub_spec) do + gemspec = Gem::Specification.new do |s| + s.name = "gemname" + s.version = "1.0.0" + s.loaded_from = __FILE__ + s.platform = "java" + end + + described_class.from_stub(gemspec) + end + describe "#from_stub" do it "returns the same stub if already a Bundler::StubSpecification" do stub = described_class.from_stub(with_bundler_stub_spec) @@ -43,6 +54,17 @@ end end + describe "#ignored?" do + skip "This example is only for without JRuby" if RUBY_ENGINE == "jruby" + + it "returns true if the gem is for different platform" do + stub = described_class.from_stub(with_java_gem_stub_spec) + allow(stub).to receive(:missing_extensions?).and_return(true) + expect(stub).to_not receive(:warn) + expect(stub.ignored?).to be true + end + end + describe "#missing_extensions?" do it "returns false if manually_installed?" do stub = described_class.from_stub(with_bundler_stub_spec) diff --git a/lib/rubygems/basic_specification.rb b/lib/rubygems/basic_specification.rb index a0b552f63ceb..619bbd7ed474 100644 --- a/lib/rubygems/basic_specification.rb +++ b/lib/rubygems/basic_specification.rb @@ -73,8 +73,12 @@ def base_dir def contains_requirable_file?(file) if ignored? if platform == Gem::Platform::RUBY || Gem::Platform.local === platform - warn "Ignoring #{full_name} because its extensions are not built. " \ - "Try: gem pristine #{name} --version #{version}" + # RubyGems warns gem specification of C extensions. But JRuby couldn't + # rebuild with `gem pristine` command. So, we skip the warning. + if RUBY_ENGINE != "jruby" + warn "Ignoring #{full_name} because its extensions are not built. " \ + "Try: gem pristine #{name} --version #{version}" + end end return false diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index cdc3479e3739..c48cfc2ec8da 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -1308,8 +1308,12 @@ def test_self_try_activate_missing_extensions refute Gem.try_activate "nonexistent" end - expected = "Ignoring ext-1 because its extensions are not built. " \ + expected = if RUBY_ENGINE == "jruby" + "" + else + "Ignoring ext-1 because its extensions are not built. " \ "Try: gem pristine ext --version 1\n" + end assert_equal expected, err end diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index af351f4d2e1f..c7e114118682 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -1557,8 +1557,12 @@ def test_contains_requirable_file_eh_extension refute @ext.contains_requirable_file? "nonexistent" end - expected = "Ignoring ext-1 because its extensions are not built. " \ + expected = if RUBY_ENGINE == "jruby" + "" + else + "Ignoring ext-1 because its extensions are not built. " \ "Try: gem pristine ext --version 1\n" + end assert_equal expected, err end diff --git a/test/rubygems/test_gem_stub_specification.rb b/test/rubygems/test_gem_stub_specification.rb index 4b2d4c570a13..de91896f85b3 100644 --- a/test/rubygems/test_gem_stub_specification.rb +++ b/test/rubygems/test_gem_stub_specification.rb @@ -71,8 +71,12 @@ def test_contains_requirable_file_eh_extension refute stub.contains_requirable_file? "nonexistent" end - expected = "Ignoring stub_e-2 because its extensions are not built. " \ + expected = if RUBY_ENGINE == "jruby" + "" + else + "Ignoring stub_e-2 because its extensions are not built. " \ "Try: gem pristine stub_e --version 2\n" + end assert_equal expected, err end