Skip to content

Commit

Permalink
dep(jruby): include jar versions in VERSION_INFO
Browse files Browse the repository at this point in the history
  • Loading branch information
flavorjones committed Jan 19, 2022
1 parent 0998d24 commit 4ea9ccd
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 8 deletions.
1 change: 0 additions & 1 deletion ext/java/nokogiri/NokogiriService.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ public class NokogiriService implements BasicLibraryService
private void
createJavaLibraryVersionConstants(Ruby ruby, RubyModule nokogiri)
{
nokogiri.defineConstant("XERCES_VERSION", ruby.newString(org.apache.xerces.impl.Version.getVersion()));
nokogiri.defineConstant("NEKO_VERSION", ruby.newString(org.cyberneko.html.Version.getVersion()));
}

Expand Down
6 changes: 6 additions & 0 deletions lib/nokogiri/jruby/nokogiri_jars.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@
require_jar 'xerces', 'xercesImpl', '2.12.1'
require_jar 'isorelax', 'isorelax', '20030108'
end

# generated by the :vendor_jars rake task
module Nokogiri
JAR_DEPENDENCIES = {"isorelax"=>"isorelax:isorelax:20030108", "jing"=>"nu.validator:jing:20200702VNU", "serializer"=>"xalan:serializer:2.7.2", "xalan"=>"xalan:xalan:2.7.2", "xercesImpl"=>"xerces:xercesImpl:2.12.1", "xml-apis"=>"xml-apis:xml-apis:1.4.01"}.freeze
XERCES_VERSION = JAR_DEPENDENCIES["xercesImpl"]
end
4 changes: 3 additions & 1 deletion lib/nokogiri/version/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,10 @@ def to_hash
vi["other_libraries"] = Hash[*Nokogiri::OTHER_LIBRARY_VERSIONS.split(/[,:]/)]
elsif jruby?
vi["other_libraries"] = {}.tap do |ol|
ol["xerces"] = Nokogiri::XERCES_VERSION
ol["nekohtml"] = Nokogiri::NEKO_VERSION
Nokogiri::JAR_DEPENDENCIES.each do |k, v|
ol[k] = v
end
end
end
end
Expand Down
13 changes: 13 additions & 0 deletions rakelib/extensions.rake
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,19 @@ if java?
require "jars/installer"
FileUtils.rm(FileList["lib/nokogiri/jruby/*/**/*.jar"], verbose: true)
Jars::Installer.vendor_jars!("lib/nokogiri/jruby")
jar_dependencies = Jars::GemspecArtifacts.new(NOKOGIRI_SPEC).artifacts.each_with_object({}) do |a, d|
d[a.artifact_id] = a.to_gacv
end.to_s
File.open("lib/nokogiri/jruby/nokogiri_jars.rb", "a") do |f|
f.puts
f.puts <<~EOF
# generated by the :vendor_jars rake task
module Nokogiri
JAR_DEPENDENCIES = #{jar_dependencies}.freeze
XERCES_VERSION = JAR_DEPENDENCIES["xercesImpl"]
end
EOF
end
end
else
require "rake/extensiontask"
Expand Down
15 changes: 10 additions & 5 deletions scripts/test-gem-file-contents
Original file line number Diff line number Diff line change
Expand Up @@ -266,20 +266,25 @@ describe File.basename(gemfile) do
end

it "contains the java jar files" do
assert_includes(gemfile_contents, "lib/nokogiri/nokogiri.jar")
assert_includes(gemfile_contents, "lib/nokogiri/jruby/nekodtd.jar")
assert_includes(gemfile_contents, "lib/nokogiri/jruby/nekohtml.jar")

actual_jars = gemfile_contents.grep(/.*\.jar$/)
expected_jars = [
"isorelax",
"jing",
"nekodtd",
"nekohtml",
"nokogiri",
"serializer",
"xalan",
"xercesImpl",
"xml-apis",
]
expected_jars.each do |jar|
assert_equal(1, actual_jars.grep(%r{/#{jar}\.jar$}).length, "expected to contain #{jar}.jar")
expected_jars.each do |name|
assert_equal(
1,
actual_jars.select { |j| File.fnmatch?("lib/nokogiri/jruby/**/#{name}-*.jar", j) }.length,
"expected to contain '#{name}-*.jar'"
)
end
end
end if gemspec.platform == Gem::Platform.new("java")
Expand Down
8 changes: 7 additions & 1 deletion test/test_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ def test_version_info_basics

def test_version_info_for_xerces_and_nekohtml
skip_unless_jruby("xerces/nekohtml is only used for JRuby")
assert_equal(Nokogiri::XERCES_VERSION, version_info["other_libraries"]["xerces"])
assert_equal(Nokogiri::XERCES_VERSION, version_info["other_libraries"]["xercesImpl"])
assert_equal(Nokogiri::NEKO_VERSION, version_info["other_libraries"]["nekohtml"])
refute_nil(version_info["other_libraries"]["isorelax"])
refute_nil(version_info["other_libraries"]["jing"])
refute_nil(version_info["other_libraries"]["serializer"])
refute_nil(version_info["other_libraries"]["xalan"])
refute_nil(version_info["other_libraries"]["xercesImpl"])
refute_nil(version_info["other_libraries"]["xml-apis"])
assert_empty(Nokogiri.libxml2_patches)
end

Expand Down

0 comments on commit 4ea9ccd

Please sign in to comment.