module Buildr::Spotbugs

Provides the spotbugs:html and spotbugs:xml tasks. Require explicitly using require "buildr/spotbugs".

Public Class Methods

dependencies() click to toggle source

The specs for requirements

# File addon/buildr/spotbugs.rb, line 24
def dependencies
  %w(
    com.github.spotbugs:spotbugs:jar:4.2.1
    com.github.spotbugs:spotbugs-annotations:jar:4.2.1
    com.google.code.findbugs:jsr305:jar:3.0.2
    net.jcip:jcip-annotations:jar:1.0
    org.apache.bcel:bcel:jar:6.5.0
    org.apache.commons:commons-lang3:jar:3.11
    org.apache.commons:commons-text:jar:1.9
    org.dom4j:dom4j:jar:2.1.3
    org.json:json:jar:20201115
    org.ow2.asm:asm:jar:9.0
    org.ow2.asm:asm-analysis:jar:9.0
    org.ow2.asm:asm-tree:jar:9.0
    org.ow2.asm:asm-commons:jar:9.0
    org.ow2.asm:asm-util:jar:9.0
    org.slf4j:slf4j-api:jar:1.7.30
    org.slf4j:slf4j-jdk14:jar:1.7.30
    jaxen:jaxen:jar:1.2.0
    net.sf.saxon:Saxon-HE:jar:10.3
  )
end
fb_contrib_dependencies() click to toggle source
# File addon/buildr/spotbugs.rb, line 47
def fb_contrib_dependencies
  %w(com.mebigfatguy.fb-contrib:fb-contrib:jar:7.4.2.sb)
end
spotbugs(output_file, source_paths, analyze_paths, options = {}) click to toggle source
# File addon/buildr/spotbugs.rb, line 51
def spotbugs(output_file, source_paths, analyze_paths, options = {})
  plugins = self.fb_contrib_dependencies
  Buildr.artifacts(self.dependencies).each { |a| a.invoke if a.respond_to?(:invoke) }

  args = []
  args << '-textui'
  packages_to_analyze = options[:packages_to_analyze] || []
  if packages_to_analyze.size > 0
    args << '-onlyAnalyze' << (packages_to_analyze.collect{|p| "#{p}.-"}.join(',') + ':')
  end
  args << '-effort:max'
  args << '-medium'
  args << ('html' == options[:output] ? '-html' : '-xml:withMessages')
  args << '-output' << output_file
  args << '-sourcepath' << source_paths.map(&:to_s).join(File::PATH_SEPARATOR)
  args << '-pluginList' << Buildr.artifacts(plugins).map(&:to_s).join(File::PATH_SEPARATOR)

  extra_dependencies = (options[:extra_dependencies] || []) + plugins
  if 0 != extra_dependencies.size
    args << '-auxclasspath' << Buildr.artifacts(extra_dependencies).each { |a| a.invoke if a.respond_to?(:invoke) }.map(&:to_s).join(File::PATH_SEPARATOR)
  end
  if options[:exclude_filter]
    args << '-exclude' << options[:exclude_filter]
  end

  analyze_paths.each do |dep|
    a = dep.is_a?(String) ? file(dep) : dep
    a.invoke
    args << a.to_s
  end

  mkdir_p File.dirname(output_file)

  begin
    Java::Commands.java 'edu.umd.cs.findbugs.LaunchAppropriateUI', *(args + [{:classpath => Buildr.artifacts(dependencies), :properties => options[:properties], :java_args => options[:java_args]}])
  rescue Exception => e
    puts e
    raise e if options[:fail_on_error]
  end
end