Sha256: 480d0c43fdc17516c9cbbfab0c3fc346e5369a9c28ce5466f6aba592dd8025a0

Contents?: true

Size: 1.68 KB

Versions: 2

Compression:

Stored size: 1.68 KB

Contents

#!/usr/bin/env jruby
$LOAD_PATH.unshift(File.expand_path('./lib'), File.dirname(__FILE__))
require 'schematronium'

raise "Not enough arguments" if ARGV.length < 2

Saxon::Processor.default.config[:line_numbering] = true

stron = Schematronium.new(ARGV.shift)

@fnames = []

if ARGV.empty?
  @fnames = @fnames + Dir[File.join('.', "*.xml")]
else
  ARGV.each do |arg|
    # Because absolute_path doesn't work right? Investigate
    arg = arg.sub(/~/, Dir.home)

    @fnames += case File.absolute_path(arg)
               when File.method(:directory?).to_proc
                 Dir[File.join(File.absolute_path(arg), "*.xml")]
               when File.method(:file?).to_proc
                 [File.absolute_path(arg)]
               else
                 []
               end
  end
end

puts '<?xml version="1.0" encoding="UTF-8"?><files>'
@fnames.each do |f|
  $stderr.write "Processing '#{f}'..."
  s_xml = Saxon.XML(File.open(f))
  xml = stron.check(s_xml)
  xml.remove_namespaces!

  xml = xml.xpath("//*[self::failed-assert or self::successful-report]")
  xml.each do |el|
    el["line-number"] = s_xml.xpath(el.attr("location")).get_line_number
  end
  output = Nokogiri::XML::DocumentFragment.new(Nokogiri::XML::Document.new)

  file = output.add_child("<file id='#{f}' total_errors='#{xml.count}'/>").first
  counts = xml.group_by {|el| el.children.map(&:text).join.strip.gsub(/\s+/, ' ')}.reduce({}) {|res, (k,v)| res[k] = v.count; res}
  err_count = file.add_child("<error_counts />").first
  counts.each do |k,v|
    err_count.add_child("<message count='#{v}'>#{k}</message>")
  end
  errs = file.add_child("<errors />").first
  errs.children = xml

  puts output

  $stderr.write " Finished\n"
end

puts '</files>'

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
schematronium-0.1.0-java bin/schematronium
schematronium-0.0.0-java bin/schematronium