You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
175 lines
4.2 KiB
175 lines
4.2 KiB
#!/usr/bin/env ruby
|
|
# Purpose: run Debian package checks using lintian and report in JUnit format
|
|
################################################################################
|
|
# Notes:
|
|
# * for JUnit spec details see http://windyroad.org/dl/Open%20Source/JUnit.xsd
|
|
#
|
|
# Ideas:
|
|
# * integrate within Jenkins plugin (using jruby)
|
|
# * integrate in Violations plugin (for further reporting options)
|
|
# git://github.com/jenkinsci/violations-plugin.git
|
|
################################################################################
|
|
|
|
# make sure we're rewrite ", ', <, > and & accordingly
|
|
require "rexml/document"
|
|
|
|
### cmdline parsing {{{
|
|
require 'optparse'
|
|
options = {}
|
|
|
|
# default
|
|
lintian_file = "lintian.txt"
|
|
|
|
o = OptionParser.new do|opts|
|
|
opts.banner = "Usage: #{$0} [<options>] <debian_package_file(s)>"
|
|
|
|
options[:warnings] = false
|
|
opts.on( '-w', '--warnings', 'Output lintian errors *AND* warnings' ) do
|
|
options[:warnings] = true
|
|
end
|
|
|
|
options[:disablenotes] = false
|
|
opts.on('--disable-notes', 'Disable verbose lintian output' ) do
|
|
options[:disablenotes] = true
|
|
end
|
|
|
|
opts.on("--filename <filename>", String, "Write lintian output to <filename> (defaults to lintian.txt)") do |f|
|
|
lintian_file = f
|
|
end
|
|
|
|
options[:disableplaintext] = false
|
|
opts.on('--disable-plaintext', 'Disable recording lintian output in lintian.txt' ) do
|
|
options[:disableplaintext] = true
|
|
end
|
|
|
|
opts.on( '-h', '--help', 'Display this screen' ) do
|
|
puts opts
|
|
exit
|
|
end
|
|
end
|
|
|
|
begin o.parse! ARGV
|
|
rescue OptionParser::InvalidOption => e
|
|
puts e
|
|
puts o
|
|
exit(1)
|
|
end
|
|
|
|
# brrr!
|
|
def usage
|
|
$stderr.puts "Usage: #{$0} [<options>] <debian_package_file(s)>"
|
|
exit(1)
|
|
end
|
|
|
|
file = ARGV[0]
|
|
usage if file.nil?
|
|
### }}}
|
|
|
|
### make sure lintian is available {{{
|
|
if not system("which lintian >/dev/null 2>&1") then
|
|
$stderr.puts "Error: lintian not available."
|
|
exit(1)
|
|
end
|
|
# }}}
|
|
|
|
### run lintian {{{
|
|
start = Time.now.to_f
|
|
if options[:disablenotes] then
|
|
cmd = "lintian #{file}"
|
|
else
|
|
cmd = "lintian --info #{file}"
|
|
end
|
|
$output = `#{cmd}`
|
|
$duration = Time.now.to_f - start
|
|
|
|
if ! options[:disablenotes] then
|
|
File.open(lintian_file, 'w') {|f| f.write($output) }
|
|
end
|
|
|
|
# adjust encoding *after* storing output to plaintext file
|
|
$output = REXML::Text.new($output, false, nil, false, ['s']).to_s
|
|
### }}}
|
|
|
|
### helper functions {{{
|
|
def success_message
|
|
puts "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
|
<testsuite name=\"lintian\" tests=\"1\" time=\"#{$duration}\" failures=\"0\" errors=\"0\" skipped=\"0\" assertions=\"0\">
|
|
<testcase name=\"lintian\" time=\"#{$duration}\" assertions=\"0\">
|
|
</testcase>
|
|
<system-out>
|
|
#{$output} </system-out>
|
|
<system-err>
|
|
</system-err>
|
|
</testsuite>"
|
|
end
|
|
|
|
def error_header
|
|
puts "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
|
<testsuite name=\"lintian\" tests=\"#{$lintian_count}\" time=\"1\" failures=\"#{$lintian_count}\" errors=\"0\" skipped=\"0\" assertions=\"0\">"
|
|
end
|
|
|
|
def error_message(package, note)
|
|
puts " <testcase name=\"#{package}\" time=\"#{$duration}\" assertions=\"0\">
|
|
<failure type=\"#{note}\" message=\"#{note}\">
|
|
#{package}: #{note}
|
|
</failure>
|
|
</testcase>"
|
|
end
|
|
|
|
def error_footer
|
|
puts " <system-out>
|
|
#{$output} </system-out>
|
|
<system-err>
|
|
</system-err>
|
|
</testsuite>"
|
|
end
|
|
### }}}
|
|
|
|
### count lintian errors/warnings {{{
|
|
$lintian_count=0
|
|
|
|
$output.each_line do |line|
|
|
if /^E:.*/.match(line) then
|
|
$lintian_count += 1
|
|
end
|
|
if options[:warnings] then
|
|
if /^W:.*/.match(line) then
|
|
$lintian_count += 1
|
|
end
|
|
end
|
|
end
|
|
# }}}
|
|
|
|
### no output from lintian? good! :) {{{
|
|
if $lintian_count == 0 || $output.empty? then
|
|
success_message
|
|
exit(0)
|
|
end
|
|
# }}}
|
|
|
|
### write output {{{
|
|
error_header
|
|
|
|
$output.each_line do |line|
|
|
if /^E:\s([^:]*):\s(.*)/.match(line) then
|
|
package = Regexp.last_match(1)
|
|
note = Regexp.last_match(2)
|
|
error_message(package, note)
|
|
end
|
|
|
|
# enable warnings only if requested:
|
|
if options[:warnings] then
|
|
if /^W:\s([^:]*):\s(.*)/.match(line) then
|
|
package = Regexp.last_match(1)
|
|
note = Regexp.last_match(2)
|
|
error_message(package, note)
|
|
end
|
|
end
|
|
end
|
|
|
|
error_footer
|
|
### }}}
|
|
|
|
## END OF FILE #################################################################
|
|
# vim:foldmethod=marker ts=2 ft=sh ai expandtab tw=80 sw=2 ft=ruby
|