danger-pmd 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 25bc46f8d31771647e30e868e5c70414c8a09f5d020351b4442f998698f7f8a5
4
- data.tar.gz: 882f95e0c94495be3507a2f5be3af5e5eebcf26af3fe9f98fe3b37590719f22b
3
+ metadata.gz: 3dafff6ceb58505c4b23ec986c622262c7f86dc4cc700d6dcd22ebf26e588683
4
+ data.tar.gz: 7247d9dd0fa56d8c889118357a62b844f4c5a2390664f63382469726ee5d554a
5
5
  SHA512:
6
- metadata.gz: 9e86137b4137acdc557fa7c17ddfe8958c3d2f153adbe1a2ce8eabfef2d24421aaa641777cecf85088fe9ff7d7b1b8a9bd5b75d52b1c8a761f03e628ee1e0b6b
7
- data.tar.gz: 17a959da13097dab76c2eab0eee92357701a63f876a2b3743c2b57e4313175fe68a5e53f9d147f214b4c99bfeb72d1ab6131d3cd5f6af6619d03843ec78bef24
6
+ metadata.gz: fa586124b9ff281a55364ff172c3bcc7533817e02175a1a957a2bd573244b3d54a10df38e32bcd9fe04d16233dbe5ee771e291ad4ba20774c70f40e17cab1abd
7
+ data.tar.gz: a6666d735f488a85145653d64b501dde58250fc6d184255ce66799093559ea779064ae3d4cbefb9c353c09494f8b18fe04612849cacbb521ccf7925583912cd7
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Danger PMD
2
2
 
3
- Danger plugin for PMD report XML file. This plugin is inspired from https://github.com/kazy1991/danger-findbugs.
3
+ Danger plugin for PMD formatted xml file. This plugin is inspired from https://github.com/kazy1991/danger-findbugs.
4
4
 
5
5
  ## Installation
6
6
 
@@ -11,6 +11,54 @@ Danger plugin for PMD report XML file. This plugin is inspired from https://gith
11
11
  Methods and attributes from this plugin are available in
12
12
  your `Dangerfile` under the `pmd` namespace.
13
13
 
14
+ <blockquote>Running PMD with its basic configuration
15
+ <pre>
16
+ pmd.report
17
+ </pre>
18
+ </blockquote>
19
+
20
+ <blockquote>Running PMD with a specific Gradle task or report_file
21
+ <pre>
22
+ pmd.gradle_task = 'app:pmd' #defalut: pmd
23
+ pmd.report_file = "app/build/reports/pmd/pmd.xml"
24
+ pmd.report
25
+ </pre>
26
+ </blockquote>
27
+
28
+ #### Attributes
29
+
30
+ `gradle_module` - Custom Gradle module to run.
31
+ This is useful when your project has different flavors.
32
+ Defaults to "app".
33
+
34
+ `gradle_task` - Custom Gradle task to run.
35
+ This is useful when your project has different flavors.
36
+ Defaults to "pmd".
37
+
38
+ `report_file` - Location of report file
39
+ If your pmd task outputs to a different location, you can specify it here.
40
+ Defaults to "app/build/reports/pmd/pmd.xml".
41
+
42
+ #### Methods
43
+
44
+ `report` - Calls pmd task of your Gradle project.
45
+ It fails if `gradlew` cannot be found inside current directory.
46
+ It fails if `report_file` cannot be found inside current directory.
47
+
48
+ `target_files` - A getter for current updated files
49
+
50
+ `exec_gradle_task` - Run Gradle task
51
+
52
+ `gradlew_exists?` - Check gradlew file exists in current directory
53
+
54
+ `report_file_exist?` - Check report_file exists in current directory
55
+
56
+ `pmd_report` - A getter for `pmd_report`, returning PMD report.
57
+
58
+ `pmd_issues` - A getter for PMD issues, returning PMD issues.
59
+
60
+ `send_inline_comment` - Send inline comment with danger's warn or fail method
61
+
14
62
  ## Development
15
63
 
16
64
  1. Clone this repo
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pmd
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
data/lib/pmd/plugin.rb CHANGED
@@ -42,7 +42,7 @@ module Danger
42
42
  GRADLEW_NOT_FOUND = "Could not find `gradlew` inside current directory"
43
43
  REPORT_FILE_NOT_FOUND = "PMD report not found"
44
44
 
45
- # Calls pmd task of your gradle project.
45
+ # Calls PMD task of your Gradle project.
46
46
  # It fails if `gradlew` cannot be found inside current directory.
47
47
  # It fails if `report_file` cannot be found inside current directory.
48
48
  # @return [void]
@@ -81,7 +81,7 @@ module Danger
81
81
  @target_files ||= (git.modified_files - git.deleted_files) + git.added_files
82
82
  end
83
83
 
84
- # Run gradle task
84
+ # Run Gradle task
85
85
  # @return [void]
86
86
  def exec_gradle_task
87
87
  system "./gradlew #{gradle_task}"
@@ -99,26 +99,25 @@ module Danger
99
99
  File.exist?(report_file)
100
100
  end
101
101
 
102
- # A getter for `gradle_task`, returning "pmd" if value is nil.
102
+ # A getter for `pmd_report`, returning PMD report.
103
103
  # @return [Oga::XML::Document]
104
104
  def pmd_report
105
105
  require "oga"
106
106
  @pmd_report ||= Oga.parse_xml(File.open(report_file))
107
107
  end
108
108
 
109
- # A getter for PMD files.
109
+ # A getter for PMD issues, returning PMD issues.
110
110
  # @return [Array[PmdFile]]
111
- def pmd_files
112
- @pmd_files ||= pmd_report.xpath("//file").map do |pmd_file|
111
+ def pmd_issues
112
+ @pmd_issues ||= pmd_report.xpath("//file").map do |pmd_file|
113
113
  PmdFile.new(gradle_module, pmd_file)
114
114
  end
115
115
  end
116
116
 
117
117
  # Send inline comment with Danger's warn or fail method
118
- #
119
118
  # @return [void]
120
119
  def send_inline_comment
121
- pmd_files.each do |pmd_file|
120
+ pmd_issues.each do |pmd_file|
122
121
  next unless target_files.include? pmd_file.absolute_path
123
122
 
124
123
  pmd_file.violations.each do |pmd_violation|
data/spec/pmd_spec.rb CHANGED
@@ -47,51 +47,51 @@ module Danger
47
47
  it "Create files" do
48
48
  custom_report_path = "spec/fixtures/pmd_report.xml"
49
49
  @my_plugin.report_file = custom_report_path
50
- pmd_files = @my_plugin.pmd_files
51
- expect(pmd_files).not_to be_nil
50
+ pmd_issues = @my_plugin.pmd_issues
51
+ expect(pmd_issues).not_to be_nil
52
52
 
53
- pmd_file1 = pmd_files[0]
54
- expect(pmd_file1).not_to be_nil
55
- expect(pmd_file1.source_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java")
56
- expect(pmd_file1.absolute_path).to eq("app/src/main/java/com/android/sample/Tools.java")
57
- expect(pmd_file1.violations).not_to be_nil
58
- expect(pmd_file1.violations.length).to eq(1)
59
- expect(pmd_file1.violations.first).not_to be_nil
60
- expect(pmd_file1.violations.first.line).to eq(5)
61
- expect(pmd_file1.violations.first.description).to eq("The utility class name 'Tools' doesn't match '[A-Z][a-zA-Z0-9]+(Utils?|Helper)'")
53
+ pmd_issue1 = pmd_issues[0]
54
+ expect(pmd_issue1).not_to be_nil
55
+ expect(pmd_issue1.source_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java")
56
+ expect(pmd_issue1.absolute_path).to eq("app/src/main/java/com/android/sample/Tools.java")
57
+ expect(pmd_issue1.violations).not_to be_nil
58
+ expect(pmd_issue1.violations.length).to eq(1)
59
+ expect(pmd_issue1.violations.first).not_to be_nil
60
+ expect(pmd_issue1.violations.first.line).to eq(5)
61
+ expect(pmd_issue1.violations.first.description).to eq("The utility class name 'Tools' doesn't match '[A-Z][a-zA-Z0-9]+(Utils?|Helper)'")
62
62
 
63
- pmd_file2 = pmd_files[1]
64
- expect(pmd_file2).not_to be_nil
65
- expect(pmd_file2.source_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/MainActivity.java")
66
- expect(pmd_file2.absolute_path).to eq("app/src/main/java/com/android/sample/MainActivity.java")
67
- expect(pmd_file2.violations).not_to be_nil
68
- expect(pmd_file2.violations.length).to eq(1)
69
- expect(pmd_file2.violations.first).not_to be_nil
70
- expect(pmd_file2.violations.first.line).to eq(39)
71
- expect(pmd_file2.violations.first.description).to eq("Use equals() to compare strings instead of '==' or '!='")
63
+ pmd_issue2 = pmd_issues[1]
64
+ expect(pmd_issue2).not_to be_nil
65
+ expect(pmd_issue2.source_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/MainActivity.java")
66
+ expect(pmd_issue2.absolute_path).to eq("app/src/main/java/com/android/sample/MainActivity.java")
67
+ expect(pmd_issue2.violations).not_to be_nil
68
+ expect(pmd_issue2.violations.length).to eq(1)
69
+ expect(pmd_issue2.violations.first).not_to be_nil
70
+ expect(pmd_issue2.violations.first.line).to eq(39)
71
+ expect(pmd_issue2.violations.first.description).to eq("Use equals() to compare strings instead of '==' or '!='")
72
72
 
73
- pmd_file3 = pmd_files[2]
74
- expect(pmd_file3).not_to be_nil
75
- expect(pmd_file3.source_path).to eq("/Users/developer/sample/app/src/test/java/com/android/sample/ExampleUnitTest.java")
76
- expect(pmd_file3.absolute_path).to eq("app/src/test/java/com/android/sample/ExampleUnitTest.java")
77
- expect(pmd_file3.violations).not_to be_nil
78
- expect(pmd_file3.violations.length).to eq(1)
79
- expect(pmd_file3.violations.first).not_to be_nil
80
- expect(pmd_file3.violations.first.line).to eq(15)
81
- expect(pmd_file3.violations.first.description).to eq("The JUnit 4 test method name 'addition_isCorrect' doesn't match '[a-z][a-zA-Z0-9]*'")
73
+ pmd_issue3 = pmd_issues[2]
74
+ expect(pmd_issue3).not_to be_nil
75
+ expect(pmd_issue3.source_path).to eq("/Users/developer/sample/app/src/test/java/com/android/sample/ExampleUnitTest.java")
76
+ expect(pmd_issue3.absolute_path).to eq("app/src/test/java/com/android/sample/ExampleUnitTest.java")
77
+ expect(pmd_issue3.violations).not_to be_nil
78
+ expect(pmd_issue3.violations.length).to eq(1)
79
+ expect(pmd_issue3.violations.first).not_to be_nil
80
+ expect(pmd_issue3.violations.first.line).to eq(15)
81
+ expect(pmd_issue3.violations.first.description).to eq("The JUnit 4 test method name 'addition_isCorrect' doesn't match '[a-z][a-zA-Z0-9]*'")
82
82
 
83
- pmd_file4 = pmd_files[3]
84
- expect(pmd_file4).not_to be_nil
85
- expect(pmd_file4.source_path).to eq("/Users/developer/sample/app/src/test/java/com/android/sample/ToolsTest.java")
86
- expect(pmd_file4.absolute_path).to eq("app/src/test/java/com/android/sample/ToolsTest.java")
87
- expect(pmd_file4.violations).not_to be_nil
88
- expect(pmd_file4.violations.length).to eq(2)
89
- expect(pmd_file4.violations[0]).not_to be_nil
90
- expect(pmd_file4.violations[0].line).to eq(12)
91
- expect(pmd_file4.violations[0].description).to eq("The JUnit 4 test method name 'getLabel_1' doesn't match '[a-z][a-zA-Z0-9]*'")
92
- expect(pmd_file4.violations[1]).not_to be_nil
93
- expect(pmd_file4.violations[1].line).to eq(18)
94
- expect(pmd_file4.violations[1].description).to eq("The JUnit 4 test method name 'getLabel_2' doesn't match '[a-z][a-zA-Z0-9]*'")
83
+ pmd_issue4 = pmd_issues[3]
84
+ expect(pmd_issue4).not_to be_nil
85
+ expect(pmd_issue4.source_path).to eq("/Users/developer/sample/app/src/test/java/com/android/sample/ToolsTest.java")
86
+ expect(pmd_issue4.absolute_path).to eq("app/src/test/java/com/android/sample/ToolsTest.java")
87
+ expect(pmd_issue4.violations).not_to be_nil
88
+ expect(pmd_issue4.violations.length).to eq(2)
89
+ expect(pmd_issue4.violations[0]).not_to be_nil
90
+ expect(pmd_issue4.violations[0].line).to eq(12)
91
+ expect(pmd_issue4.violations[0].description).to eq("The JUnit 4 test method name 'getLabel_1' doesn't match '[a-z][a-zA-Z0-9]*'")
92
+ expect(pmd_issue4.violations[1]).not_to be_nil
93
+ expect(pmd_issue4.violations[1].line).to eq(18)
94
+ expect(pmd_issue4.violations[1].description).to eq("The JUnit 4 test method name 'getLabel_2' doesn't match '[a-z][a-zA-Z0-9]*'")
95
95
  end
96
96
 
97
97
  it "Send inline comments" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-pmd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathieu Rul