lib/pmd/plugin.rb in danger-pmd-0.0.4 vs lib/pmd/plugin.rb in danger-pmd-0.0.5

- old
+ new

@@ -13,10 +13,15 @@ # # pmd.gradle_task = 'app:pmd' #defalut: pmd # pmd.report_file = "app/build/reports/pmd/pmd.xml" # pmd.report # + # @example Running PMD without running a Gradle task + # + # pmd.skip_gradle_task = true + # pmd.report + # # @see mathroule/danger-pmd # @tags java, android, pmd class DangerPmd < Plugin require_relative "./pmd_file" @@ -37,21 +42,29 @@ # If your pmd task outputs to a different location, you can specify it here. # Defaults to "build/reports/pmd/pmd.xml". # @return [String] attr_writer :report_file + # Skip Gradle task + # If you skip Gradle task, for example project does not manage Gradle. + # @return [Bool] + attr_writer :skip_gradle_task + GRADLEW_NOT_FOUND = "Could not find `gradlew` inside current directory" REPORT_FILE_NOT_FOUND = "PMD report not found" # Calls PMD 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. # @return [void] def report(inline_mode = true) - return fail(GRADLEW_NOT_FOUND) unless gradlew_exists? + unless skip_gradle_task + return fail(GRADLEW_NOT_FOUND) unless gradlew_exists? - exec_gradle_task + exec_gradle_task + end + return fail(REPORT_FILE_NOT_FOUND) unless report_file_exist? if inline_mode send_inline_comment end @@ -65,9 +78,15 @@ # A getter for `gradle_task`, returning "pmd" if value is nil. # @return [String] def gradle_task @gradle_task ||= "pmd" + end + + # A getter for `skip_gradle_task`, returning false if value is nil. + # @return [Boolean] + def skip_gradle_task + @skip_gradle_task ||= false end # A getter for `report_file`, returning "app/build/reports/pmd/pmd.xml" if value is nil. # @return [String] def report_file