Skip to content

Commit

Permalink
Merge pull request #2545 from sparklemotion/flavorjones-better-jruby-…
Browse files Browse the repository at this point in the history
…dep-version-info

feat: better jruby dependency listings in VersionInfo

---

**What problem is this PR intended to solve?**

After moving to maven-managed dependencies, the output from `nokogiri -v` looked like:

```
# Nokogiri (1.14.0.dev)
    ---
    warnings: []
    nokogiri:
      version: 1.14.0.dev
    ruby:
      version: 2.6.8
      platform: java
      gem_platform: universal-java-11
      description: jruby 9.3.2.0 (2.6.8) 2021-12-01 0b8223f905 OpenJDK 64-Bit Server VM
        11.0.15+10-Ubuntu-0ubuntu0.20.04.1 on 11.0.15+10-Ubuntu-0ubuntu0.20.04.1 [linux-x86_64]
      engine: jruby
      jruby: 9.3.2.0
    other_libraries:
      isorelax: isorelax:isorelax:20030108
      Saxon-HE: net.sf.saxon:Saxon-HE:9.6.0-4
      neko-htmlunit: net.sourceforge.htmlunit:neko-htmlunit:2.61.0
      jing: nu.validator:jing:20200702VNU
      nekodtd: org.nokogiri:nekodtd:0.1.11.noko1
      serializer: xalan:serializer:2.7.2
      xalan: xalan:xalan:2.7.2
      xercesImpl: xerces:xercesImpl:2.12.2
      xml-apis: xml-apis:xml-apis:1.4.01
```

after this PR it looks like:

```
# Nokogiri (1.14.0.dev)
    ---
    warnings: []
    nokogiri:
      version: 1.14.0.dev
    ruby:
      version: 2.6.8
      platform: java
      gem_platform: universal-java-11
      description: jruby 9.3.2.0 (2.6.8) 2021-12-01 0b8223f905 OpenJDK 64-Bit Server VM
        11.0.15+10-Ubuntu-0ubuntu0.20.04.1 on 11.0.15+10-Ubuntu-0ubuntu0.20.04.1 [linux-x86_64]
      engine: jruby
      jruby: 9.3.2.0
    other_libraries:
      isorelax:isorelax: '20030108'
      net.sf.saxon:Saxon-HE: 9.6.0-4
      net.sourceforge.htmlunit:neko-htmlunit: 2.61.0
      nu.validator:jing: 20200702VNU
      org.nokogiri:nekodtd: 0.1.11.noko1
      xalan:serializer: 2.7.2
      xalan:xalan: 2.7.2
      xerces:xercesImpl: 2.12.2
      xml-apis:xml-apis: 1.4.01
```

(note the change to `other_libraries`).

See #2432 for the changeset that introduced the previous format.


**Have you included adequate test coverage?**

Existing coverage should suffice.


**Does this change affect the behavior of either the C or the Java implementations?**

Only the JRuby VERSION_INFO has changed.
  • Loading branch information
flavorjones authored May 12, 2022
2 parents 64c62e3 + 7cec00e commit 7661464
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
6 changes: 3 additions & 3 deletions lib/nokogiri/jruby/nokogiri_jars.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

# generated by the :vendor_jars rake task
module Nokogiri
JAR_DEPENDENCIES = {"isorelax"=>"isorelax:isorelax:20030108", "Saxon-HE"=>"net.sf.saxon:Saxon-HE:9.6.0-4", "neko-htmlunit"=>"net.sourceforge.htmlunit:neko-htmlunit:2.61.0", "jing"=>"nu.validator:jing:20200702VNU", "nekodtd"=>"org.nokogiri:nekodtd:0.1.11.noko1", "serializer"=>"xalan:serializer:2.7.2", "xalan"=>"xalan:xalan:2.7.2", "xercesImpl"=>"xerces:xercesImpl:2.12.2", "xml-apis"=>"xml-apis:xml-apis:1.4.01"}.freeze
XERCES_VERSION = JAR_DEPENDENCIES["xercesImpl"]
NEKO_VERSION = JAR_DEPENDENCIES["neko-htmlunit"]
JAR_DEPENDENCIES = {"isorelax:isorelax"=>"20030108", "net.sf.saxon:Saxon-HE"=>"9.6.0-4", "net.sourceforge.htmlunit:neko-htmlunit"=>"2.61.0", "nu.validator:jing"=>"20200702VNU", "org.nokogiri:nekodtd"=>"0.1.11.noko1", "xalan:serializer"=>"2.7.2", "xalan:xalan"=>"2.7.2", "xerces:xercesImpl"=>"2.12.2", "xml-apis:xml-apis"=>"1.4.01"}.freeze
XERCES_VERSION = JAR_DEPENDENCIES["xerces:xercesImpl"]
NEKO_VERSION = JAR_DEPENDENCIES["net.sourceforge.htmlunit:neko-htmlunit"]
end
9 changes: 5 additions & 4 deletions rakelib/extensions.rake
Original file line number Diff line number Diff line change
Expand Up @@ -387,17 +387,18 @@ if java?
FileUtils.rm(FileList["lib/nokogiri/jruby/*/**/*.jar"], verbose: true)
jars = Jars::Installer.vendor_jars!("lib/nokogiri/jruby")
jar_dependencies = jars.sort_by(&:gav).each_with_object({}) do |a, d|
artifact_id = a.coord.split(":")[1]
d[artifact_id] = a.gav
g, a, v = a.gav.split(":")
name = [g, a].join(":")
d[name] = v
end
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"]
NEKO_VERSION = JAR_DEPENDENCIES["neko-htmlunit"]
XERCES_VERSION = JAR_DEPENDENCIES["xerces:xercesImpl"]
NEKO_VERSION = JAR_DEPENDENCIES["net.sourceforge.htmlunit:neko-htmlunit"]
end
EOF
end
Expand Down
16 changes: 8 additions & 8 deletions test/test_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +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"]["xercesImpl"])
assert_equal(Nokogiri::NEKO_VERSION, version_info["other_libraries"]["neko-htmlunit"])
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_equal(Nokogiri::XERCES_VERSION, version_info["other_libraries"]["xerces:xercesImpl"])
assert_equal(Nokogiri::NEKO_VERSION, version_info["other_libraries"]["net.sourceforge.htmlunit:neko-htmlunit"])
refute_nil(version_info["other_libraries"]["isorelax:isorelax"])
refute_nil(version_info["other_libraries"]["nu.validator:jing"])
refute_nil(version_info["other_libraries"]["xalan:serializer"])
refute_nil(version_info["other_libraries"]["xalan:xalan"])
refute_nil(version_info["other_libraries"]["xerces:xercesImpl"])
refute_nil(version_info["other_libraries"]["xml-apis:xml-apis"])
assert_empty(Nokogiri.libxml2_patches)
end

Expand Down
11 changes: 8 additions & 3 deletions test/xml/test_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ class TestNode < Nokogiri::TestCase
describe Nokogiri::XML::Node do
let(:xml) { Nokogiri::XML(File.read(XML_FILE), XML_FILE) }

def pending_if_neko_htmlunit_is_not_patched_with_21286e4(&block)
# see https://github.com/sparklemotion/nekohtml/commit/21286e4de6c05d40c2ebdda11805082fde36188b
pending_if("nekohtml 21286e4 should be applied to neko-htmlunit", Nokogiri::VERSION_INFO["other_libraries"]["net.sourceforge.htmlunit:neko-htmlunit"], &block)
end

def test_first_element_child
node = xml.root.first_element_child
assert_equal("employee", node.name)
Expand Down Expand Up @@ -95,7 +100,7 @@ def test_node_context_parsing_of_malformed_html_fragment
context_node = doc.at_css("div")
nodeset = context_node.parse("<div </div>")

pending_if("nekohtml commit 21286e4 not applied to neko-htmlunit", Nokogiri::VERSION_INFO["other_libraries"]["neko-htmlunit"]) do
pending_if_neko_htmlunit_is_not_patched_with_21286e4 do
assert_equal(1, doc.errors.length)
end
assert_equal(1, nodeset.length)
Expand All @@ -109,7 +114,7 @@ def test_node_context_parsing_of_malformed_html_fragment_with_recover_is_correct
context_node = doc.at_css("div")
nodeset = context_node.parse("<div </div>", &:recover)

pending_if("nekohtml commit 21286e4 not applied to neko-htmlunit", Nokogiri::VERSION_INFO["other_libraries"]["neko-htmlunit"]) do
pending_if_neko_htmlunit_is_not_patched_with_21286e4 do
assert_equal(1, doc.errors.length)
end
assert_equal(1, nodeset.length)
Expand All @@ -121,7 +126,7 @@ def test_node_context_parsing_of_malformed_html_fragment_with_recover_is_correct
def test_node_context_parsing_of_malformed_html_fragment_without_recover_is_not_corrected
doc = HTML4.parse("<html><body><div></div></body></html>")
context_node = doc.at_css("div")
pending_if("nekohtml commit 21286e4 not applied to neko-htmlunit", Nokogiri::VERSION_INFO["other_libraries"]["neko-htmlunit"]) do
pending_if_neko_htmlunit_is_not_patched_with_21286e4 do
assert_raises(Nokogiri::XML::SyntaxError) do
context_node.parse("<div </div>", &:strict)
end
Expand Down

0 comments on commit 7661464

Please sign in to comment.