Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mathroule committed Mar 23, 2021
1 parent cec7001 commit 5a28787
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/pmd/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ class DangerPmd < Plugin
# Custom Gradle task to run.
# This is useful when your project has different flavors.
# Defaults to 'pmd'.
#
# @return [String]
attr_writer :gradle_task

# A getter for `gradle_task`, returning 'pmd' if value is nil.
#
# @return [String]
def gradle_task
@gradle_task ||= 'pmd'
Expand All @@ -54,10 +56,12 @@ def gradle_task
# Skip Gradle task.
# If you skip Gradle task, for example project does not manage Gradle.
# Defaults to `false`.
#
# @return [Boolean]
attr_writer :skip_gradle_task

# A getter for `skip_gradle_task`, returning false if value is nil.
#
# @return [Boolean]
def skip_gradle_task
@skip_gradle_task ||= false
Expand All @@ -66,10 +70,12 @@ def skip_gradle_task
# An absolute path to a root.
# To comment errors to VCS, this needs to know relative path of files from the root.
# Defaults to result of 'git rev-parse --show-toplevel'.
# @return [String] the root path of git repository by default.
#
# @return [String]
attr_writer :root_path

# A getter for `root_path`, returning result of `git rev-parse --show-toplevel` if value is nil.
#
# @return [String]
def root_path
@root_path ||= `git rev-parse --show-toplevel`.chomp
Expand All @@ -78,10 +84,12 @@ def root_path
# Location of report file.
# If your PMD task task outputs to a different location, you can specify it here.
# Defaults to 'app/build/reports/pmd/pmd.xml'.
#
# @return [String]
attr_writer :report_file

# A getter for `report_file`, returning 'app/build/reports/pmd/pmd.xml' if value is nil.
#
# @return [String]
def report_file
@report_file ||= 'app/build/reports/pmd/pmd.xml'
Expand All @@ -90,10 +98,12 @@ def report_file
# Location of report files.
# If your PMD task outputs to a different location, you can specify it here.
# Defaults to ['app/build/reports/pmd/pmd.xml'].
#
# @return [Array[String]]
attr_writer :report_files

# A getter for `report_files`, returning ['app/build/reports/pmd/pmd.xml'] if value is nil.
#
# @return [Array[String]]
def report_files
@report_files ||= [report_file]
Expand All @@ -103,6 +113,9 @@ def report_files
# 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.
#
# @param [Boolean] inline_mode Report as inline comment, defaults to [true].
#
# @return [Array[PmdFile]]
def report(inline_mode: true)
unless skip_gradle_task
Expand All @@ -120,25 +133,29 @@ def report(inline_mode: true)
private

# Check gradlew file exists in current directory.
#
# @return [Boolean]
def gradlew_exists?
!`ls gradlew`.strip.empty?
end

# Run Gradle task.
#
# @return [void]
def exec_gradle_task
system "./gradlew #{gradle_task}"
end

# A getter for `pmd_report`, returning PMD report.
#
# @return [Oga::XML::Document]
def pmd_report(report_file)
require 'oga'
Oga.parse_xml(File.open(report_file))
end

# A getter for PMD issues, returning PMD issues.
#
# @return [Array[PmdFile]]
def pmd_issues(report_file)
pmd_report(report_file).xpath('//file').map do |pmd_file|
Expand All @@ -147,12 +164,14 @@ def pmd_issues(report_file)
end

# A getter for current updated files.
#
# @return [Array[String]]
def target_files
@target_files ||= (git.modified_files - git.deleted_files) + git.added_files
end

# Generate report and send inline comment with Danger's warn or fail method.
#
# @return [Array[PmdFile]]
def do_comment(report_files, inline_mode)
pmd_issues = []
Expand Down

0 comments on commit 5a28787

Please sign in to comment.