Class: Danger::DangerSpotbugs

Inherits:
Plugin
  • Object
show all
Defined in:
lib/spotbugs/plugin.rb

Overview

Checks on your Gradle project’s Java source files. This is done using [SpotBugs](spotbugs.github.io) Results are passed out as tables in markdown.

Examples:

Running SpotBugs with its basic configuration


spotbugs.report

Running SpotBugs with a specific Gradle task or report file (glob accepted)


spotbugs.gradle_task = 'module:spotbugsRelease' # default: 'spotbugsRelease'
spotbugs.report_file = 'module/build/reports/spotbugs/release.xml' # default: 'app/build/reports/spotbugs/release.xml'
spotbugs.report

Running SpotBugs with a specific root path


spotbugs.root_path = '/Users/developer/project' # default: result of `git rev-parse --show-toplevel`
spotbugs.report

Running SpotBugs with an array of report files (glob accepted)


spotbugs.report_files = ['modules/**/build/reports/spotbugs/release.xml', 'app/build/reports/spotbugs/release.xml']
spotbugs.report

Running SpotBugs without running a Gradle task


spotbugs.skip_gradle_task = true # default: false
spotbugs.report

Running SpotBugs without inline comment


spotbugs.report(inline_mode: false) # default: true

See Also:

  • mathroule/danger-spotbugs

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#gradle_taskString

A getter for ‘gradle_task`, returning ’spotbugsRelease’ if value is nil.

Returns:

  • (String)


53
54
55
# File 'lib/spotbugs/plugin.rb', line 53

def gradle_task
  @gradle_task ||= 'spotbugsRelease'
end

#report_fileString

A getter for ‘report_file`, returning ’app/build/reports/spotbugs/release.xml’ if value is nil.

Returns:

  • (String)


95
96
97
# File 'lib/spotbugs/plugin.rb', line 95

def report_file
  @report_file ||= 'app/build/reports/spotbugs/release.xml'
end

#report_filesArray[String]

A getter for ‘report_files`, returning [’app/build/reports/spotbugs/release.xml’] if value is nil.

Returns:

  • (Array[String])


109
110
111
# File 'lib/spotbugs/plugin.rb', line 109

def report_files
  @report_files ||= [report_file]
end

#root_pathString

A getter for ‘root_path`, returning result of `git rev-parse –show-toplevel` if value is nil.

Returns:

  • (String)


81
82
83
# File 'lib/spotbugs/plugin.rb', line 81

def root_path
  @root_path ||= `git rev-parse --show-toplevel`.chomp
end

#skip_gradle_taskBoolean

A getter for ‘skip_gradle_task`, returning false if value is nil.

Returns:

  • (Boolean)


67
68
69
# File 'lib/spotbugs/plugin.rb', line 67

def skip_gradle_task
  @skip_gradle_task ||= false
end

Instance Method Details

#report(inline_mode: true) ⇒ Array[PmdFile]

Calls SpotBugs task of your Gradle project. It fails if ‘gradlew` cannot be found inside current directory. It fails if `report_file` cannot be found inside current directory. It fails if `report_files` is empty.

Parameters:

  • inline_mode (Boolean) (defaults to: true)

    Report as inline comment, defaults to [true].

Returns:

  • (Array[PmdFile])


121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/spotbugs/plugin.rb', line 121

def report(inline_mode: true)
  unless skip_gradle_task
    raise('Could not find `gradlew` inside current directory') unless gradlew_exists?

    exec_gradle_task
  end

  report_files_expanded = Dir.glob(report_files).sort
  raise("Could not find matching SpotBugs report files for #{report_files} inside current directory") if report_files_expanded.empty?

  do_comment(report_files_expanded, inline_mode)
end