Class: Pipeline::PMD

Inherits:
BaseTask show all
Includes:
Util
Defined in:
lib/pipeline/tasks/pmd.rb

Instance Attribute Summary

Attributes inherited from BaseTask

#appname, #description, #findings, #labels, #name, #stage, #trigger, #warnings

Instance Method Summary collapse

Methods included from Util

#fingerprint, #relative_path, #runsystem, #strip_archive_path

Methods inherited from BaseTask

#directories_with?, #report, #severity, #warn

Constructor Details

#initialize(trigger, tracker) ⇒ PMD

Returns a new instance of PMD.



11
12
13
14
15
16
17
# File 'lib/pipeline/tasks/pmd.rb', line 11

def initialize(trigger, tracker)
  super(trigger, tracker)
  @name = "PMD"
  @description = "PMD Source Code Analyzer"
  @stage = :code
  @labels << "code"
end

Instance Method Details

#analyzeObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/pipeline/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
    Pipeline.warn e.message
    Pipeline.warn e.backtrace
  end
end

#runObject



19
20
21
22
23
24
# File 'lib/pipeline/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?Boolean

Returns:

  • (Boolean)


53
54
55
56
57
58
59
60
61
# File 'lib/pipeline/tasks/pmd.rb', line 53

def supported?
  unless @tracker.options.has_key?(:pmd_path) and File.exist?("#{@tracker.options[:pmd_path]}/bin/run.sh")
    Pipeline.notify "#{@tracker.options[:pmd_path]}"
    Pipeline.notify "Install PMD from: https://pmd.github.io/"
    return false
  else
    return true
  end
end