nokogiri 1.5.0.beta.4-java → 1.5.0-java

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of nokogiri might be problematic. Click here for more details.

Files changed (87) hide show
  1. data/.gemtest +0 -0
  2. data/CHANGELOG.ja.rdoc +34 -0
  3. data/CHANGELOG.rdoc +40 -1
  4. data/Manifest.txt +11 -2
  5. data/README.rdoc +1 -1
  6. data/Rakefile +96 -105
  7. data/bin/nokogiri +1 -2
  8. data/ext/java/nokogiri/HtmlDocument.java +1 -31
  9. data/ext/java/nokogiri/HtmlSaxParserContext.java +1 -1
  10. data/ext/java/nokogiri/NokogiriService.java +77 -22
  11. data/ext/java/nokogiri/XmlAttr.java +5 -16
  12. data/ext/java/nokogiri/XmlCdata.java +4 -11
  13. data/ext/java/nokogiri/XmlComment.java +5 -5
  14. data/ext/java/nokogiri/XmlDocument.java +49 -59
  15. data/ext/java/nokogiri/XmlDocumentFragment.java +14 -8
  16. data/ext/java/nokogiri/XmlDtd.java +45 -43
  17. data/ext/java/nokogiri/XmlElement.java +19 -46
  18. data/ext/java/nokogiri/XmlElementDecl.java +9 -5
  19. data/ext/java/nokogiri/XmlEntityReference.java +24 -2
  20. data/ext/java/nokogiri/XmlNamespace.java +89 -34
  21. data/ext/java/nokogiri/XmlNode.java +31 -52
  22. data/ext/java/nokogiri/XmlNodeSet.java +42 -86
  23. data/ext/java/nokogiri/XmlProcessingInstruction.java +15 -19
  24. data/ext/java/nokogiri/XmlReader.java +40 -43
  25. data/ext/java/nokogiri/XmlSaxParserContext.java +2 -2
  26. data/ext/java/nokogiri/XmlSchema.java +14 -9
  27. data/ext/java/nokogiri/XmlText.java +18 -35
  28. data/ext/java/nokogiri/XmlXpathContext.java +43 -23
  29. data/ext/java/nokogiri/XsltStylesheet.java +17 -3
  30. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +2 -4
  31. data/ext/java/nokogiri/internals/NokogiriHelpers.java +77 -20
  32. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +13 -17
  33. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +13 -1
  34. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +23 -8
  35. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +20 -3
  36. data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +67 -0
  37. data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +86 -0
  38. data/ext/java/nokogiri/internals/ParserContext.java +25 -27
  39. data/ext/java/nokogiri/internals/ReaderNode.java +58 -1
  40. data/ext/java/nokogiri/internals/SaveContextVisitor.java +567 -0
  41. data/ext/java/nokogiri/internals/XmlDomParser.java +1 -2
  42. data/ext/java/nokogiri/internals/XmlDomParserContext.java +6 -0
  43. data/ext/nokogiri/nokogiri.c +24 -1
  44. data/ext/nokogiri/xml_io.c +32 -7
  45. data/ext/nokogiri/xml_node.c +14 -13
  46. data/ext/nokogiri/xml_sax_parser.c +9 -4
  47. data/ext/nokogiri/xslt_stylesheet.c +7 -1
  48. data/lib/nokogiri.rb +3 -22
  49. data/lib/nokogiri/css.rb +4 -0
  50. data/lib/nokogiri/html/document.rb +10 -14
  51. data/lib/nokogiri/nokogiri.jar +0 -0
  52. data/lib/nokogiri/version.rb +76 -23
  53. data/lib/nokogiri/xml/builder.rb +7 -0
  54. data/lib/nokogiri/xml/document.rb +17 -1
  55. data/lib/nokogiri/xml/document_fragment.rb +14 -0
  56. data/lib/nokogiri/xml/node.rb +36 -28
  57. data/lib/nokogiri/xml/node/save_options.rb +17 -1
  58. data/lib/nokogiri/xml/node_set.rb +7 -0
  59. data/lib/nokogiri/xml/parse_options.rb +8 -0
  60. data/lib/nokogiri/xml/reader.rb +6 -6
  61. data/lib/nokogiri/xml/schema.rb +7 -1
  62. data/lib/xercesImpl.jar +0 -0
  63. data/nokogiri_help_responses.md +40 -0
  64. data/tasks/cross_compile.rb +134 -159
  65. data/tasks/nokogiri.org.rb +18 -0
  66. data/tasks/test.rb +1 -1
  67. data/test/files/encoding.html +82 -0
  68. data/test/files/encoding.xhtml +84 -0
  69. data/test/files/metacharset.html +10 -0
  70. data/test/files/noencoding.html +47 -0
  71. data/test/helper.rb +2 -0
  72. data/test/html/test_document.rb +15 -0
  73. data/test/html/test_document_encoding.rb +13 -0
  74. data/test/test_memory_leak.rb +20 -0
  75. data/test/test_reader.rb +22 -0
  76. data/test/test_xslt_transforms.rb +6 -2
  77. data/test/xml/node/test_save_options.rb +10 -2
  78. data/test/xml/test_builder.rb +17 -0
  79. data/test/xml/test_document.rb +22 -0
  80. data/test/xml/test_node.rb +19 -1
  81. data/test/xml/test_node_reparenting.rb +16 -3
  82. data/test/xml/test_node_set.rb +34 -0
  83. data/test/xml/test_schema.rb +5 -0
  84. data/test/xslt/test_exception_handling.rb +37 -0
  85. metadata +141 -107
  86. data/deps.rip +0 -5
  87. data/ext/java/nokogiri/internals/SaveContext.java +0 -288
@@ -71,7 +71,6 @@ public class XmlDomParser extends DOMParser {
71
71
  if (doc == null)
72
72
  throw new RuntimeException("null document");
73
73
 
74
- doc.setUserData(XmlDocument.DTD_RAW_DOCUMENT, dtd.getDocument(),
75
- null);
74
+ doc.setUserData(XmlDocument.DTD_RAW_DOCUMENT, dtd.getDocument(), null);
76
75
  }
77
76
  }
@@ -42,6 +42,7 @@ import java.util.List;
42
42
 
43
43
  import nokogiri.NokogiriService;
44
44
  import nokogiri.XmlDocument;
45
+ import nokogiri.XmlDtd;
45
46
  import nokogiri.XmlSyntaxError;
46
47
 
47
48
  import org.apache.xerces.parsers.DOMParser;
@@ -189,6 +190,11 @@ public class XmlDomParserContext extends ParserContext {
189
190
  XmlDocument xmlDocument = (XmlDocument) NokogiriService.XML_DOCUMENT_ALLOCATOR.allocate(context.getRuntime(), klazz);
190
191
  xmlDocument.setNode(context, doc);
191
192
  xmlDocument.setEncoding(ruby_encoding);
193
+
194
+ if (options.dtdLoad) {
195
+ XmlDtd xmlDtd = (XmlDtd) XmlDtd.newFromExternalSubset(context.getRuntime(), doc);
196
+ doc.setUserData(XmlDocument.DTD_EXTERNAL_SUBSET, xmlDtd, null);
197
+ }
192
198
  return xmlDocument;
193
199
  }
194
200
 
@@ -23,6 +23,29 @@ int vasprintf (char **strp, const char *fmt, va_list ap)
23
23
  }
24
24
  #endif
25
25
 
26
+ #ifdef USING_SYSTEM_ALLOCATOR_LIBRARY /* Ruby Enterprise Edition with tcmalloc */
27
+ void vasprintf_free (void *p)
28
+ {
29
+ system_free(p);
30
+ }
31
+ #else
32
+ void vasprintf_free (void *p)
33
+ {
34
+ free(p);
35
+ }
36
+ #endif
37
+
38
+ #ifndef __MACRUBY__
39
+ /* Allocate strdupped strings with the same memory allocator Ruby uses. */
40
+ static char *ruby_strdup(const char *s)
41
+ {
42
+ size_t len = strlen(s);
43
+ char *result = ruby_xmalloc((ssize_t) (len + 1));
44
+ memcpy(result, s, len + 1);
45
+ return result;
46
+ }
47
+ #endif
48
+
26
49
  void Init_nokogiri()
27
50
  {
28
51
  #ifndef __MACRUBY__
@@ -30,7 +53,7 @@ void Init_nokogiri()
30
53
  (xmlFreeFunc)ruby_xfree,
31
54
  (xmlMallocFunc)ruby_xmalloc,
32
55
  (xmlReallocFunc)ruby_xrealloc,
33
- strdup
56
+ ruby_strdup
34
57
  );
35
58
  #endif
36
59
 
@@ -2,22 +2,47 @@
2
2
 
3
3
  static ID id_read, id_write;
4
4
 
5
+ VALUE read_check(VALUE *args) {
6
+ return rb_funcall(args[0], id_read, 1, args[1]);
7
+ }
8
+
9
+ VALUE read_failed(void) {
10
+ return Qnil;
11
+ }
12
+
5
13
  int io_read_callback(void * ctx, char * buffer, int len) {
6
- VALUE io = (VALUE)ctx;
7
- VALUE string = rb_funcall(io, id_read, 1, INT2NUM(len));
14
+ VALUE string, args[2];
15
+ size_t str_len, safe_len;
16
+
17
+ args[0] = (VALUE)ctx;
18
+ args[1] = INT2NUM(len);
19
+
20
+ string = rb_rescue(read_check, (VALUE)args, read_failed, 0);
8
21
 
9
22
  if(NIL_P(string)) return 0;
10
23
 
11
- memcpy(buffer, StringValuePtr(string), (size_t)RSTRING_LEN(string));
24
+ str_len = (size_t)RSTRING_LEN(string);
25
+ safe_len = str_len > (size_t)len ? (size_t)len : str_len;
26
+ memcpy(buffer, StringValuePtr(string), safe_len);
12
27
 
13
- return (int)RSTRING_LEN(string);
28
+ return safe_len;
29
+ }
30
+
31
+ VALUE write_check(VALUE *args) {
32
+ return rb_funcall(args[0], id_write, 1, args[1]);
33
+ }
34
+
35
+ VALUE write_failed(void) {
36
+ return Qnil;
14
37
  }
15
38
 
16
39
  int io_write_callback(void * ctx, char * buffer, int len) {
17
- VALUE io = (VALUE)ctx;
18
- VALUE string = rb_str_new(buffer, (long)len);
40
+ VALUE args[2];
41
+
42
+ args[0] = (VALUE)ctx;
43
+ args[1] = rb_str_new(buffer, (long)len);
19
44
 
20
- rb_funcall(io, id_write, 1, string);
45
+ rb_rescue(write_check, (VALUE)args, write_failed, 0);
21
46
  return len;
22
47
  }
23
48
 
@@ -14,10 +14,7 @@ static void debug_node_dealloc(xmlNodePtr x)
14
14
 
15
15
  static void mark(xmlNodePtr node)
16
16
  {
17
- /* it's OK if the document isn't fully realized (as in XML::Reader). */
18
- /* see http://github.com/tenderlove/nokogiri/issues/closed/#issue/95 */
19
- if (DOC_RUBY_OBJECT_TEST(node->doc) && DOC_RUBY_OBJECT(node->doc))
20
- rb_gc_mark(DOC_RUBY_OBJECT(node->doc));
17
+ rb_gc_mark(DOC_RUBY_OBJECT(node->doc));
21
18
  }
22
19
 
23
20
  /* :nodoc: */
@@ -1235,6 +1232,8 @@ VALUE Nokogiri_wrap_xml_node(VALUE klass, xmlNodePtr node)
1235
1232
  VALUE document = Qnil ;
1236
1233
  VALUE node_cache = Qnil ;
1237
1234
  VALUE rb_node = Qnil ;
1235
+ int node_has_a_document = 0 ;
1236
+ void (*mark_method)(xmlNodePtr) = NULL ;
1238
1237
 
1239
1238
  assert(node);
1240
1239
 
@@ -1243,11 +1242,9 @@ VALUE Nokogiri_wrap_xml_node(VALUE klass, xmlNodePtr node)
1243
1242
 
1244
1243
  if(NULL != node->_private) return (VALUE)node->_private;
1245
1244
 
1246
- if(RTEST(klass))
1247
- rb_node = Data_Wrap_Struct(klass, mark, debug_node_dealloc, node) ;
1248
-
1249
- else switch(node->type)
1250
- {
1245
+ if(!RTEST(klass)) {
1246
+ switch(node->type)
1247
+ {
1251
1248
  case XML_ELEMENT_NODE:
1252
1249
  klass = cNokogiriXmlElement;
1253
1250
  break;
@@ -1286,15 +1283,19 @@ VALUE Nokogiri_wrap_xml_node(VALUE klass, xmlNodePtr node)
1286
1283
  break;
1287
1284
  default:
1288
1285
  klass = cNokogiriXmlNode;
1286
+ }
1289
1287
  }
1290
1288
 
1291
- rb_node = Data_Wrap_Struct(klass, mark, debug_node_dealloc, node) ;
1289
+ /* It's OK if the node doesn't have a fully-realized document (as in XML::Reader). */
1290
+ /* see https://github.com/tenderlove/nokogiri/issues/95 */
1291
+ /* and https://github.com/tenderlove/nokogiri/issues/439 */
1292
+ node_has_a_document = (DOC_RUBY_OBJECT_TEST(node->doc) && DOC_RUBY_OBJECT(node->doc)) ? 1 : 0 ;
1293
+ mark_method = node_has_a_document ? mark : NULL ;
1292
1294
 
1295
+ rb_node = Data_Wrap_Struct(klass, mark_method, debug_node_dealloc, node) ;
1293
1296
  node->_private = (void *)rb_node;
1294
1297
 
1295
- if (DOC_RUBY_OBJECT_TEST(node->doc) && DOC_RUBY_OBJECT(node->doc)) {
1296
- /* it's OK if the document isn't fully realized (as in XML::Reader). */
1297
- /* see http://github.com/tenderlove/nokogiri/issues/closed/#issue/95 */
1298
+ if (node_has_a_document) {
1298
1299
  document = DOC_RUBY_OBJECT(node->doc);
1299
1300
  node_cache = DOC_NODE_CACHE(node->doc);
1300
1301
  rb_ary_push(node_cache, rb_node);
@@ -1,6 +1,7 @@
1
1
  #include <xml_sax_parser.h>
2
2
 
3
3
  int vasprintf (char **strp, const char *fmt, va_list ap);
4
+ void vasprintf_free (void *p);
4
5
 
5
6
  static ID id_start_document, id_end_document, id_start_element, id_end_element;
6
7
  static ID id_start_element_namespace, id_end_element_namespace;
@@ -198,14 +199,16 @@ static void warning_func(void * ctx, const char *msg, ...)
198
199
  VALUE self = NOKOGIRI_SAX_SELF(ctx);
199
200
  VALUE doc = rb_iv_get(self, "@document");
200
201
  char * message;
202
+ VALUE ruby_message;
201
203
 
202
204
  va_list args;
203
205
  va_start(args, msg);
204
206
  vasprintf(&message, msg, args);
205
207
  va_end(args);
206
208
 
207
- rb_funcall(doc, id_warning, 1, NOKOGIRI_STR_NEW2(message));
208
- free(message);
209
+ ruby_message = NOKOGIRI_STR_NEW2(message);
210
+ vasprintf_free(message);
211
+ rb_funcall(doc, id_warning, 1, ruby_message);
209
212
  }
210
213
 
211
214
  static void error_func(void * ctx, const char *msg, ...)
@@ -213,14 +216,16 @@ static void error_func(void * ctx, const char *msg, ...)
213
216
  VALUE self = NOKOGIRI_SAX_SELF(ctx);
214
217
  VALUE doc = rb_iv_get(self, "@document");
215
218
  char * message;
219
+ VALUE ruby_message;
216
220
 
217
221
  va_list args;
218
222
  va_start(args, msg);
219
223
  vasprintf(&message, msg, args);
220
224
  va_end(args);
221
225
 
222
- rb_funcall(doc, id_error, 1, NOKOGIRI_STR_NEW2(message));
223
- free(message);
226
+ ruby_message = NOKOGIRI_STR_NEW2(message);
227
+ vasprintf_free(message);
228
+ rb_funcall(doc, id_error, 1, ruby_message);
224
229
  }
225
230
 
226
231
  static void cdata_block(void * ctx, const xmlChar * value, int len)
@@ -8,6 +8,7 @@
8
8
  VALUE xslt;
9
9
 
10
10
  int vasprintf (char **strp, const char *fmt, va_list ap);
11
+ void vasprintf_free (void *p);
11
12
 
12
13
  static void dealloc(xsltStylesheetPtr doc)
13
14
  {
@@ -20,13 +21,16 @@ NORETURN(static void xslt_generic_error_handler(void * ctx, const char *msg, ...
20
21
  static void xslt_generic_error_handler(void * ctx, const char *msg, ...)
21
22
  {
22
23
  char * message;
24
+ VALUE exception;
23
25
 
24
26
  va_list args;
25
27
  va_start(args, msg);
26
28
  vasprintf(&message, msg, args);
27
29
  va_end(args);
28
30
 
29
- rb_exc_raise(rb_exc_new2(rb_eRuntimeError, message));
31
+ exception = rb_exc_new2(rb_eRuntimeError, message);
32
+ vasprintf_free(message);
33
+ rb_exc_raise(exception);
30
34
  }
31
35
 
32
36
  /*
@@ -100,6 +104,8 @@ static VALUE transform(int argc, VALUE* argv, VALUE self)
100
104
 
101
105
  rb_scan_args(argc, argv, "11", &xmldoc, &paramobj);
102
106
  if (NIL_P(paramobj)) { paramobj = rb_ary_new2(0L) ; }
107
+ if (!rb_obj_is_kind_of(xmldoc, cNokogiriXmlDocument))
108
+ rb_raise(rb_eArgError, "argument must be a Nokogiri::XML::Document");
103
109
 
104
110
  /* handle hashes as arguments. */
105
111
  if(T_HASH == TYPE(paramobj)) {
@@ -22,28 +22,9 @@ if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
22
22
  require 'nekodtd.jar'
23
23
  require 'xercesImpl.jar'
24
24
  end
25
- require 'nokogiri/nokogiri'
26
- else
27
- require 'nokogiri/nokogiri'
28
25
  end
29
26
 
30
- warn(<<-eowarn) if '1.8.6' == RUBY_VERSION && $VERBOSE
31
- !!! DEPRECATION WARNING !!!
32
- Hey Champ! I see you're using Ruby 1.8.6! While I applaud you for sticking to
33
- your guns and using The One True Ruby, I have to let you know that we're going
34
- to stop supporting 1.8.6. I know, it's sad. But, we just don't have time to
35
- support every version of Ruby out there. Whether we like it or not, time moves
36
- forward and so does our software.
37
-
38
- On August 1, 2010, we will no longer support Ruby 1.8.6. If nokogiri happens to
39
- work on 1.8.6 after that date, then great! We will hownever, no longer test,
40
- use, or endorse 1.8.6 as a supported platform.
41
-
42
- Thanks,
43
-
44
- Team Nokogiri
45
- eowarn
46
-
27
+ require 'nokogiri/nokogiri'
47
28
  require 'nokogiri/version'
48
29
  require 'nokogiri/syntax_error'
49
30
  require 'nokogiri/xml'
@@ -86,13 +67,13 @@ module Nokogiri
86
67
  doc =
87
68
  if string.respond_to?(:read) ||
88
69
  string =~ /^\s*<[^Hh>]*html/i # Probably html
89
- Nokogiri::HTML(
70
+ Nokogiri.HTML(
90
71
  string,
91
72
  url,
92
73
  encoding, options || XML::ParseOptions::DEFAULT_HTML
93
74
  )
94
75
  else
95
- Nokogiri::XML(string, url, encoding,
76
+ Nokogiri.XML(string, url, encoding,
96
77
  options || XML::ParseOptions::DEFAULT_XML)
97
78
  end
98
79
  yield doc if block_given?
@@ -1,6 +1,10 @@
1
1
  require 'nokogiri/css/node'
2
2
  require 'nokogiri/css/xpath_visitor'
3
+ x = $-w
4
+ $-w = false
3
5
  require 'nokogiri/css/parser'
6
+ $-w = x
7
+
4
8
  require 'nokogiri/css/tokenizer'
5
9
  require 'nokogiri/css/syntax_error'
6
10
 
@@ -58,10 +58,7 @@ module Nokogiri
58
58
  # end
59
59
  #
60
60
  def serialize options = {}
61
- options[:save_with] ||= XML::Node::SaveOptions::FORMAT |
62
- XML::Node::SaveOptions::AS_HTML |
63
- XML::Node::SaveOptions::NO_DECLARATION |
64
- XML::Node::SaveOptions::NO_EMPTY_TAGS
61
+ options[:save_with] ||= XML::Node::SaveOptions::DEFAULT_HTML
65
62
  super
66
63
  end
67
64
 
@@ -73,7 +70,7 @@ module Nokogiri
73
70
 
74
71
  class << self
75
72
  ###
76
- # Parse HTML. +thing+ may be a String, or any object that
73
+ # Parse HTML. +string_or_io+ may be a String, or any object that
77
74
  # responds to _read_ and _close_ such as an IO, or StringIO.
78
75
  # +url+ is resource where this document is located. +encoding+ is the
79
76
  # encoding that should be used when processing the document. +options+
@@ -95,7 +92,7 @@ module Nokogiri
95
92
  if string_or_io.respond_to?(:read)
96
93
  url ||= string_or_io.respond_to?(:path) ? string_or_io.path : nil
97
94
  if !encoding
98
- # Perform further encoding detection that libxml2 does
95
+ # Perform advanced encoding detection that libxml2 does
99
96
  # not do.
100
97
  string_or_io = EncodingReader.new(string_or_io)
101
98
  begin
@@ -150,6 +147,8 @@ module Nokogiri
150
147
  not_found
151
148
  when 'meta'
152
149
  attr = Hash[attrs]
150
+ charset = attr['charset'] and
151
+ found charset
153
152
  http_equiv = attr['http-equiv'] and
154
153
  http_equiv.match(/\AContent-Type\z/i) and
155
154
  content = attr['content'] and
@@ -174,7 +173,7 @@ module Nokogiri
174
173
  parser.parse(chunk)
175
174
  }
176
175
  handler.encoding
177
- rescue => e
176
+ rescue
178
177
  nil
179
178
  end
180
179
 
@@ -189,16 +188,13 @@ module Nokogiri
189
188
  if !@firstchunk
190
189
  @firstchunk = @io.read(len) or return nil
191
190
 
192
- # This implementation expects and assumes that the first
193
- # call from htmlReadIO() is made with a length long enough
194
- # (~1KB) to achieve further encoding detection that
195
- # libxml2 does not do.
191
+ # This implementation expects that the first call from
192
+ # htmlReadIO() is made with a length long enough (~1KB) to
193
+ # achieve advanced encoding detection.
196
194
  if encoding = EncodingReader.detect_encoding(@firstchunk)
195
+ # The first chunk is stored for the next read in retry.
197
196
  raise EncodingFoundException, encoding
198
197
  end
199
-
200
- # This chunk is stored for the next read in retry.
201
- return @firstchunk
202
198
  end
203
199
 
204
200
  ret = @firstchunk.slice!(0, len)
Binary file
@@ -1,35 +1,88 @@
1
1
  module Nokogiri
2
2
  # The version of Nokogiri you are using
3
- VERSION = '1.5.0.beta.4'
3
+ VERSION = '1.5.0'
4
4
 
5
- # More complete version information about libxml
6
- VERSION_INFO = {}
7
- VERSION_INFO['warnings'] = []
8
- VERSION_INFO['nokogiri'] = Nokogiri::VERSION
9
- VERSION_INFO['ruby'] = {}
10
- VERSION_INFO['ruby']['version'] = ::RUBY_VERSION
11
- VERSION_INFO['ruby']['platform'] = ::RUBY_PLATFORM
12
- VERSION_INFO['ruby']['engine'] = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'mri'
13
-
14
- VERSION_INFO['ruby']['jruby'] = ::JRUBY_VERSION if RUBY_PLATFORM == "java"
15
- if defined?(LIBXML_VERSION)
16
- VERSION_INFO['libxml'] = {}
17
- VERSION_INFO['libxml']['binding'] = 'extension'
18
- VERSION_INFO['libxml']['compiled'] = LIBXML_VERSION
19
- VERSION_INFO['libxml']['loaded'] = LIBXML_PARSER_VERSION.scan(/^(.*)(..)(..)$/).first.collect{|j|j.to_i}.join(".")
20
-
21
- if VERSION_INFO['libxml']['compiled'] != VERSION_INFO['libxml']['loaded']
22
- warning = "Nokogiri was built against LibXML version #{VERSION_INFO['libxml']['compiled']}, but has dynamically loaded #{VERSION_INFO['libxml']['loaded']}"
23
- VERSION_INFO['warnings'] << warning
5
+ class VersionInfo # :nodoc:
6
+ def jruby?
7
+ ::JRUBY_VERSION if RUBY_PLATFORM == "java"
8
+ end
9
+
10
+ def engine
11
+ defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'mri'
12
+ end
13
+
14
+ def loaded_parser_version
15
+ LIBXML_PARSER_VERSION.scan(/^(.*)(..)(..)$/).first.collect{ |j|
16
+ j.to_i
17
+ }.join(".")
18
+ end
19
+
20
+ def compiled_parser_version
21
+ LIBXML_VERSION
22
+ end
23
+
24
+ def libxml2?
25
+ defined?(LIBXML_VERSION)
26
+ end
27
+
28
+ def warnings
29
+ return [] unless libxml2?
30
+
31
+ if compiled_parser_version != loaded_parser_version
32
+ ["Nokogiri was built against LibXML version #{compiled_parser_version}, but has dynamically loaded #{loaded_parser_version}"]
33
+ else
34
+ []
35
+ end
36
+ end
37
+
38
+ def to_hash
39
+ hash_info = {}
40
+ hash_info['warnings'] = []
41
+ hash_info['nokogiri'] = Nokogiri::VERSION
42
+ hash_info['ruby'] = {}
43
+ hash_info['ruby']['version'] = ::RUBY_VERSION
44
+ hash_info['ruby']['platform'] = ::RUBY_PLATFORM
45
+ hash_info['ruby']['description'] = ::RUBY_DESCRIPTION
46
+ hash_info['ruby']['engine'] = engine
47
+ hash_info['ruby']['jruby'] = jruby? if jruby?
48
+
49
+ if libxml2?
50
+ hash_info['libxml'] = {}
51
+ hash_info['libxml']['binding'] = 'extension'
52
+ hash_info['libxml']['compiled'] = compiled_parser_version
53
+ hash_info['libxml']['loaded'] = loaded_parser_version
54
+ hash_info['warnings'] = warnings
55
+ end
56
+
57
+ hash_info
58
+ end
59
+
60
+ def to_markdown
61
+ begin
62
+ require 'psych'
63
+ rescue LoadError
64
+ end
65
+ require 'yaml'
66
+ "# Nokogiri (#{Nokogiri::VERSION})\n" +
67
+ YAML.dump(to_hash).each_line.map { |line| " #{line}" }.join
68
+ end
69
+
70
+ # FIXME: maybe switch to singleton?
71
+ @@instance = new
72
+ @@instance.warnings.each do |warning|
24
73
  warn "WARNING: #{warning}"
25
74
  end
75
+ def self.instance; @@instance; end
26
76
  end
27
77
 
78
+ # More complete version information about libxml
79
+ VERSION_INFO = VersionInfo.instance.to_hash
80
+
28
81
  def self.uses_libxml? # :nodoc:
29
- !Nokogiri::VERSION_INFO['libxml'].nil?
82
+ VersionInfo.instance.libxml2?
30
83
  end
31
84
 
32
- def self.jruby?
33
- !Nokogiri::VERSION_INFO['ruby']['jruby'].nil?
85
+ def self.jruby? # :nodoc:
86
+ VersionInfo.instance.jruby?
34
87
  end
35
88
  end