class AdLint::Postfilter::AnalysisCommand

Public Class Methods

for(command_line, config_fpath, src_vpath = nil) click to toggle source
# File lib/adlint/postfilter/command.rb, line 45
def self.for(command_line, config_fpath, src_vpath = nil)
  case name = command_line.split.first
  when "adlint"
    ADLINT.new(command_line, config_fpath, src_vpath)
  when "adlint_sma"
    ADLINT_SMA.new(command_line, config_fpath, src_vpath)
  when "adlint_cma"
    ADLINT_CMA.new(command_line, config_fpath, src_vpath)
  when "adlint_chk"
    ADLINT_CHK.new(command_line, config_fpath, src_vpath)
  else
    raise "unknown command `#{name}'"
  end
end
new(command_line, config_fpath, src_vpath = nil) click to toggle source
# File lib/adlint/postfilter/command.rb, line 60
def initialize(command_line, config_fpath, src_vpath = nil)
  @command_line = command_line
  @config_fpath = config_fpath
  @src_vpath = src_vpath

  @traits_fpath, @strip_num, @output_dpath, @src_fpaths =
    parse_adlint_command_line(@command_line, @src_vpath)
end

Public Instance Methods

execute() click to toggle source
# File lib/adlint/postfilter/command.rb, line 69
def execute
  status, stderr_content = exec_adlint_command(@command_line)
  filter_results(create_filters, stderr_content)
  status
end

Private Instance Methods

create_cma_config() click to toggle source
# File lib/adlint/postfilter/command.rb, line 150
def create_cma_config
  CmaConfig.new(@config_fpath, @traits_fpath, @strip_num, @output_dpath,
                create_sma_configs)
end
create_cma_filter() click to toggle source
# File lib/adlint/postfilter/command.rb, line 139
def create_cma_filter
  MessageFilter.new(create_cma_config)
end
create_filters() click to toggle source
# File lib/adlint/postfilter/command.rb, line 88
def create_filters
  subclass_responsibility
end
create_sma_configs() click to toggle source
# File lib/adlint/postfilter/command.rb, line 143
def create_sma_configs
  @src_fpaths.map do |src_fpath|
    SmaConfig.new(@config_fpath, @traits_fpath, src_fpath, @strip_num,
                  @output_dpath)
  end
end
create_sma_filters() click to toggle source
# File lib/adlint/postfilter/command.rb, line 135
def create_sma_filters
  create_sma_configs.map { |sma_config| MessageFilter.new(sma_config) }
end
exec_adlint_command(command_line) click to toggle source
# File lib/adlint/postfilter/command.rb, line 76
def exec_adlint_command(command_line)
  system("#{command_line} 2>#{stderr_fpath}")
  return $?, StderrContent.new(File.read(stderr_fpath))
ensure
  FileUtils.rm_f(stderr_fpath)
end
filter_results(filters, stderr_content) click to toggle source
# File lib/adlint/postfilter/command.rb, line 83
def filter_results(filters, stderr_content)
  filters.each { |filter| filter.execute(stderr_content) }
  stderr_content.overwrite!
end
parse_adlint_command_line(command_line, src_vpath = nil) click to toggle source
# File lib/adlint/postfilter/command.rb, line 92
def parse_adlint_command_line(command_line, src_vpath = nil)
  parser = GetoptLong.new(
    ["--traits", "-t", GetoptLong::REQUIRED_ARGUMENT],
    ["--list-file", "-l", GetoptLong::REQUIRED_ARGUMENT],
    ["--output-dir", "-o", GetoptLong::REQUIRED_ARGUMENT],
    ["--strip", "-p", GetoptLong::REQUIRED_ARGUMENT],
    ["--verbose", "-v", GetoptLong::NO_ARGUMENT])
  parser.quiet = true

  begin
    traits_fpath = nil
    output_dpath = nil
    strip_num = src_vpath ? src_vpath.components.size : 0

    ARGV.replace(command_line.split).shift

    parser.each_option do |optname, optarg|
      case optname
      when "--traits"
        traits_fpath = Pathname.new(optarg)
      when "--output-dir"
        output_dpath = Pathname.new(optarg)
      when "--strip"
        strip_num = optarg.to_i
      end
    end
  rescue
    # NOTE: If the AdLint's command line is invalid, child analysis command
    #       will encounter the same problem and will notice it.
    #       So, nothing to be done.
  end

  src_fpaths = ARGV.map { |str|
    if str.end_with?(".c.met.csv")
      @src_vpath.join(Pathname.new(str.sub(/.met.csv\z/, "")))
    else
      Pathname.new(str)
    end
  }

  return traits_fpath, strip_num, output_dpath, src_fpaths
end
stderr_fpath() click to toggle source
# File lib/adlint/postfilter/command.rb, line 155
def stderr_fpath
  Pathname.new("./adlint_postfilter.#{$$}.stderr")
end