class Glue::PMD

Public Class Methods

new(trigger, tracker) click to toggle source
Calls superclass method Glue::BaseTask::new
# File lib/glue/tasks/pmd.rb, line 11
def initialize(trigger, tracker)
  super(trigger, tracker)
  @name = "PMD"
  @description = "PMD Source Code Analyzer"
  @stage = :code
  @labels << "code"
end

Public Instance Methods

analyze() click to toggle source
# File lib/glue/tasks/pmd.rb, line 26
def analyze
  begin
    @results.each do |result|
      attributes = result.at_xpath('violation').attributes
      description = result.children.children.to_s.strip
      detail = "Ruleset: #{attributes['ruleset']}"
      source = {:scanner => @name, :file => result.attributes['name'].to_s.split(Pathname.new(@trigger.path).cleanpath.to_s)[1][1..-1], :line => attributes['beginline'].to_s, :code => "package: #{attributes['package'].to_s}\nclass: #{attributes['class'].to_s}\nmethod: #{attributes['method'].to_s}" }
      case attributes['priority'].value.to_i
      when 3
        sev = 1
      when 2
        sev = 2
      when 1
        sev = 3
      else
        sev = 0
      end
      fprint = fingerprint("#{description}#{detail}#{source}#{sev}")

      report description, detail, source, sev, fprint
    end
  rescue Exception => e
    Glue.warn e.message
    Glue.warn e.backtrace
  end
end
run() click to toggle source
# File lib/glue/tasks/pmd.rb, line 19
def run
  @tracker.options[:pmd_checks] ||= "java-basic,java-sunsecure"
  Dir.chdir @tracker.options[:pmd_path] do
    @results = Nokogiri::XML(runsystem(true,'bin/run.sh', 'pmd', '-d', "#{@trigger.path}", '-f', 'xml', '-R', "#{@tracker.options[:pmd_checks]}")).xpath('//file')
  end
end
supported?() click to toggle source
# File lib/glue/tasks/pmd.rb, line 53
def supported?
  unless @tracker.options.has_key?(:pmd_path) and File.exist?("#{@tracker.options[:pmd_path]}/bin/run.sh")
    Glue.notify "#{@tracker.options[:pmd_path]}"
    Glue.notify "Install PMD from: https://pmd.github.io/"
    return false
  else
    return true
  end
end