danger-pmd 0.0.5 → 0.1.0

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: 53cc82c8c415625b6288cbe5723362dc833f633d2fbe9ccb0b51e410aa83d989
4
- data.tar.gz: bb9a5b9e8658e72cc8092b0623cd0aa645f6d8fb634e0312b8c113b0f7057234
3
+ metadata.gz: 9a2697bcfe2820d4c84823070dffd3ea0062a1aa743c55d1265613eb78865508
4
+ data.tar.gz: 61412ff7cae4072811742d730ab19667b0c23584bee3a92cd5ad5241700db2b3
5
5
  SHA512:
6
- metadata.gz: 1de03c38720bb5f06dfca0ff63c3589d95e6237596e6ce80bd09f87050ef34f4281bda05367f272c1dbf5dae23fbc3c4084b55938c52559e0e97c29967a7fa48
7
- data.tar.gz: f18e9d01bf1b6c5c4210226f571637a735575d089b6da85cb37742277e7651ca787f22bc782d498f96cc9605a27343f1058aaa49c04aaadd8022211d4ce4717a
6
+ metadata.gz: a34d67327b69424a7ac177fd80358881c01159592711d79b62ffc45c3293144692b3549e394c71e287a7471c61a5e58c989259a952f79d51a4181a59a4d73d35
7
+ data.tar.gz: 916683f3ed4821208a84f0af44a6d2b33fb13c2769a03b3655d35e6a7ef8d5fd11ef6f913f3a0e4f3ee261be01be08d2a13cf8f8ea4058aa45afe2f2dd997360
data/.rubocop.yml CHANGED
@@ -23,10 +23,10 @@ Lint/UselessAssignment:
23
23
  - '**/spec/**/*'
24
24
 
25
25
  # We could potentially enable the 2 below:
26
- Layout/IndentFirstHashElement:
26
+ Layout/FirstHashElementIndentation:
27
27
  Enabled: false
28
28
 
29
- Layout/AlignHash:
29
+ Layout/HashAlignment:
30
30
  Enabled: false
31
31
 
32
32
  # HoundCI doesn't like this rule
@@ -124,13 +124,18 @@ Metrics/BlockLength:
124
124
  Exclude:
125
125
  - "**/*_spec.rb"
126
126
 
127
+ Metrics/ModuleLength:
128
+ Max: 100
129
+ Exclude:
130
+ - "**/*_spec.rb"
131
+
127
132
  Style/MixinGrouping:
128
133
  Enabled: false
129
134
 
130
135
  Style/FileName:
131
136
  Enabled: false
132
137
 
133
- Layout/IndentHeredoc:
138
+ Layout/HeredocIndentation:
134
139
  Enabled: false
135
140
 
136
141
  Style/SpecialGlobalVars:
data/.travis.yml CHANGED
@@ -4,7 +4,7 @@ cache:
4
4
  - bundle
5
5
 
6
6
  rvm:
7
- - 2.3.1
7
+ - 2.3.8
8
8
 
9
9
  script:
10
- - bundle exec rake spec
10
+ - bundle exec rake spec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danger-pmd (0.0.4)
4
+ danger-pmd (0.1.0)
5
5
  danger-plugin-api (~> 1.0)
6
6
  oga (~> 2.10)
7
7
 
@@ -37,14 +37,14 @@ GEM
37
37
  danger-plugin-api (1.0.0)
38
38
  danger (> 2.0)
39
39
  diff-lcs (1.3)
40
- faraday (0.16.2)
40
+ faraday (0.17.1)
41
41
  multipart-post (>= 1.2, < 3)
42
42
  faraday-http-cache (2.0.0)
43
43
  faraday (~> 0.8)
44
- ffi (1.11.1)
44
+ ffi (1.11.3)
45
45
  formatador (0.2.5)
46
46
  git (1.5.0)
47
- guard (2.15.1)
47
+ guard (2.16.1)
48
48
  formatador (>= 0.2.4)
49
49
  listen (>= 2.7, < 4.0)
50
50
  lumberjack (>= 1.0.12, < 2.0)
@@ -58,7 +58,7 @@ GEM
58
58
  guard (~> 2.1)
59
59
  guard-compat (~> 1.1)
60
60
  rspec (>= 2.99.0, < 4.0)
61
- jaro_winkler (1.5.3)
61
+ jaro_winkler (1.5.4)
62
62
  kramdown (2.1.0)
63
63
  kramdown-parser-gfm (1.1.0)
64
64
  kramdown (~> 2.0)
@@ -80,7 +80,7 @@ GEM
80
80
  ast
81
81
  ruby-ll (~> 2.1)
82
82
  open4 (1.3.4)
83
- parallel (1.17.0)
83
+ parallel (1.19.1)
84
84
  parser (2.6.5.0)
85
85
  ast (~> 2.4.0)
86
86
  pry (0.12.2)
@@ -90,22 +90,22 @@ GEM
90
90
  rainbow (3.0.0)
91
91
  rake (10.5.0)
92
92
  rb-fsevent (0.10.3)
93
- rb-inotify (0.10.0)
93
+ rb-inotify (0.10.1)
94
94
  ffi (~> 1.0)
95
- rspec (3.8.0)
96
- rspec-core (~> 3.8.0)
97
- rspec-expectations (~> 3.8.0)
98
- rspec-mocks (~> 3.8.0)
99
- rspec-core (3.8.2)
100
- rspec-support (~> 3.8.0)
101
- rspec-expectations (3.8.5)
95
+ rspec (3.9.0)
96
+ rspec-core (~> 3.9.0)
97
+ rspec-expectations (~> 3.9.0)
98
+ rspec-mocks (~> 3.9.0)
99
+ rspec-core (3.9.0)
100
+ rspec-support (~> 3.9.0)
101
+ rspec-expectations (3.9.0)
102
102
  diff-lcs (>= 1.2.0, < 2.0)
103
- rspec-support (~> 3.8.0)
104
- rspec-mocks (3.8.2)
103
+ rspec-support (~> 3.9.0)
104
+ rspec-mocks (3.9.0)
105
105
  diff-lcs (>= 1.2.0, < 2.0)
106
- rspec-support (~> 3.8.0)
107
- rspec-support (3.8.3)
108
- rubocop (0.75.0)
106
+ rspec-support (~> 3.9.0)
107
+ rspec-support (3.9.0)
108
+ rubocop (0.78.0)
109
109
  jaro_winkler (~> 1.5.1)
110
110
  parallel (~> 1.10)
111
111
  parser (>= 2.6)
@@ -122,7 +122,7 @@ GEM
122
122
  shellany (0.0.1)
123
123
  terminal-table (1.8.0)
124
124
  unicode-display_width (~> 1.1, >= 1.1.1)
125
- thor (0.20.3)
125
+ thor (1.0.1)
126
126
  unicode-display_width (1.6.0)
127
127
  yard (0.9.20)
128
128
 
@@ -142,4 +142,4 @@ DEPENDENCIES
142
142
  yard (~> 0.9.20)
143
143
 
144
144
  BUNDLED WITH
145
- 1.17.2
145
+ 1.17.3
data/README.md CHANGED
@@ -25,44 +25,50 @@ pmd.report
25
25
  </pre>
26
26
  </blockquote>
27
27
 
28
- #### Attributes
28
+ <blockquote>Running PMD with an array of report files
29
+ <pre>
30
+ pmd.report_files = ["modules/**/build/reports/pmd/pmd.xml", "app/build/reports/pmd/pmd.xml"]
31
+ pmd.report
32
+ </pre>
33
+ </blockquote>
29
34
 
30
- `gradle_module` - Custom Gradle module to run.
31
- This is useful when your project has different flavors.
32
- Defaults to "app".
35
+ <blockquote>Running PMD without running a Gradle task
36
+ <pre>
37
+ pmd.skip_gradle_task = true
38
+ pmd.report
39
+ </pre>
40
+ </blockquote>
41
+
42
+ #### Attributes
33
43
 
34
44
  `gradle_task` - Custom Gradle task to run.
35
45
  This is useful when your project has different flavors.
36
46
  Defaults to "pmd".
37
47
 
48
+ `skip_gradle_task` - Skip Gradle task.
49
+ If you skip Gradle task, for example project does not manage Gradle.
50
+
38
51
  `report_file` - Location of report file
39
52
  If your pmd task outputs to a different location, you can specify it here.
40
53
  Defaults to "app/build/reports/pmd/pmd.xml".
41
54
 
42
- `skip_gradle_task` - Skip Gradle task.
43
- If you skip Gradle task, for example project does not manage Gradle.
55
+ `report_files` - Location of report files
56
+ If your pmd task outputs to a different location, you can specify it here.
57
+ Defaults to ["app/build/reports/pmd/pmd.xml]".
44
58
 
45
59
  #### Methods
46
60
 
47
- `report` - Calls pmd task of your Gradle project.
61
+ `report` - Calls PMD task of your Gradle project, send comment and return PMD issues.
48
62
  It fails if `gradlew` cannot be found inside current directory.
49
- It fails if `report_file` cannot be found inside current directory.
63
+ It fails if `report_file` or `report_files` cannot be found inside current directory.
50
64
 
51
- `target_files` - A getter for current updated files.
65
+ `gradle_task` - A getter for `gradle_task`, returning Gradle task report.
52
66
 
53
- `exec_gradle_task` - Run Gradle task.
67
+ `skip_gradle_task` - A getter for `skip_gradle_task`.
54
68
 
55
- `gradlew_exists?` - Check gradlew file exists in current directory.
69
+ `report_file` - A getter for `report_file`.
56
70
 
57
- `report_file_exist?` - Check report_file exists in current directory.
58
-
59
- `pmd_report` - A getter for `pmd_report`, returning PMD report.
60
-
61
- `pmd_issues` - A getter for PMD issues, returning PMD issues.
62
-
63
- `send_inline_comment` - Send inline comment with danger's warn or fail method.
64
-
65
- `skip_gradle_task` - Skip Gradle task.
71
+ `report_files` - A getter for `report_files`.
66
72
 
67
73
  ## Development
68
74
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pmd
4
- VERSION = "0.0.5"
4
+ VERSION = "0.1.0"
5
5
  end
data/lib/pmd/plugin.rb CHANGED
@@ -15,6 +15,11 @@ module Danger
15
15
  # pmd.report_file = "app/build/reports/pmd/pmd.xml"
16
16
  # pmd.report
17
17
  #
18
+ # @example Running PMD with an array of report files
19
+ #
20
+ # pmd.report_files = ["modules/**/build/reports/pmd/pmd.xml", "app/build/reports/pmd/pmd.xml"]
21
+ # pmd.report
22
+ #
18
23
  # @example Running PMD without running a Gradle task
19
24
  #
20
25
  # pmd.skip_gradle_task = true
@@ -26,123 +31,139 @@ module Danger
26
31
  class DangerPmd < Plugin
27
32
  require_relative "./pmd_file"
28
33
 
29
- # Custom Gradle module to run.
30
- # This is useful when your project has different flavors.
31
- # Defaults to "app".
32
- # @return [String]
33
- attr_writer :gradle_module
34
-
35
34
  # Custom Gradle task to run.
36
35
  # This is useful when your project has different flavors.
37
36
  # Defaults to "pmd".
38
37
  # @return [String]
39
38
  attr_writer :gradle_task
40
39
 
41
- # Location of report file
42
- # If your pmd task outputs to a different location, you can specify it here.
43
- # Defaults to "build/reports/pmd/pmd.xml".
40
+ # A getter for `gradle_task`, returning "pmd" if value is nil.
44
41
  # @return [String]
45
- attr_writer :report_file
42
+ def gradle_task
43
+ @gradle_task ||= "pmd"
44
+ end
46
45
 
47
- # Skip Gradle task
46
+ # Skip Gradle task.
48
47
  # If you skip Gradle task, for example project does not manage Gradle.
48
+ # Defaults to `false`.
49
49
  # @return [Bool]
50
50
  attr_writer :skip_gradle_task
51
51
 
52
- GRADLEW_NOT_FOUND = "Could not find `gradlew` inside current directory"
53
- REPORT_FILE_NOT_FOUND = "PMD report not found"
52
+ # A getter for `skip_gradle_task`, returning false if value is nil.
53
+ # @return [Boolean]
54
+ def skip_gradle_task
55
+ @skip_gradle_task ||= false
56
+ end
57
+
58
+ # Location of report file.
59
+ # If your pmd task outputs to a different location, you can specify it here.
60
+ # Defaults to "app/build/reports/pmd/pmd.xml".
61
+ # @return [String]
62
+ attr_writer :report_file
63
+
64
+ # A getter for `report_file`, returning "app/build/reports/pmd/pmd.xml" if value is nil.
65
+ # @return [String]
66
+ def report_file
67
+ @report_file ||= "app/build/reports/pmd/pmd.xml"
68
+ end
69
+
70
+ # Location of report files.
71
+ # If your pmd task outputs to a different location, you can specify it here.
72
+ # Defaults to "app/build/reports/pmd/pmd.xml".
73
+ # @return [Array[String]]
74
+ attr_writer :report_files
75
+
76
+ # A getter for `report_files`, returning ["app/build/reports/pmd/pmd.xml"] if value is nil.
77
+ # @return [Array[String]]
78
+ def report_files
79
+ @report_files ||= [report_file]
80
+ end
54
81
 
55
82
  # Calls PMD task of your Gradle project.
56
83
  # It fails if `gradlew` cannot be found inside current directory.
57
84
  # It fails if `report_file` cannot be found inside current directory.
58
- # @return [void]
85
+ # It fails if `report_files` is empty.
86
+ # @return [Array[PmdFile]]
59
87
  def report(inline_mode = true)
60
88
  unless skip_gradle_task
61
- return fail(GRADLEW_NOT_FOUND) unless gradlew_exists?
89
+ return fail("Could not find `gradlew` inside current directory") unless gradlew_exists?
62
90
 
63
91
  exec_gradle_task
64
92
  end
65
93
 
66
- return fail(REPORT_FILE_NOT_FOUND) unless report_file_exist?
94
+ report_files_flatten = []
95
+ report_files.each do |report_file|
96
+ Dir.glob(report_file).sort.each do |report_file_glob|
97
+ return fail("PMD report file not found #{report_file_glob}") unless report_file_exist?(report_file_glob)
67
98
 
68
- if inline_mode
69
- send_inline_comment
99
+ report_files_flatten.push(report_file_glob)
100
+ end
70
101
  end
71
- end
72
102
 
73
- # A getter for `gradle_module`, returning "app" if value is nil.
74
- # @return [String]
75
- def gradle_module
76
- @gradle_module ||= "app"
103
+ report_and_send_inline_comment(report_files_flatten, inline_mode)
77
104
  end
78
105
 
79
- # A getter for `gradle_task`, returning "pmd" if value is nil.
80
- # @return [String]
81
- def gradle_task
82
- @gradle_task ||= "pmd"
83
- end
84
-
85
- # A getter for `skip_gradle_task`, returning false if value is nil.
86
- # @return [Boolean]
87
- def skip_gradle_task
88
- @skip_gradle_task ||= false
89
- end
106
+ private
90
107
 
91
- # A getter for `report_file`, returning "app/build/reports/pmd/pmd.xml" if value is nil.
92
- # @return [String]
93
- def report_file
94
- @report_file ||= "app/build/reports/pmd/pmd.xml"
95
- end
96
-
97
- # A getter for current updated files
98
- # @return [Array[String]]
99
- def target_files
100
- @target_files ||= (git.modified_files - git.deleted_files) + git.added_files
108
+ # Check gradlew file exists in current directory.
109
+ # @return [Bool]
110
+ def gradlew_exists?
111
+ !`ls gradlew`.strip.empty?
101
112
  end
102
113
 
103
- # Run Gradle task
114
+ # Run Gradle task.
104
115
  # @return [void]
105
116
  def exec_gradle_task
106
117
  system "./gradlew #{gradle_task}"
107
118
  end
108
119
 
109
- # Check gradlew file exists in current directory
110
- # @return [Bool]
111
- def gradlew_exists?
112
- !`ls gradlew`.strip.empty?
113
- end
114
-
115
- # Check report_file exists in current directory
120
+ # Check report_file exists in current directory.
116
121
  # @return [Bool]
117
- def report_file_exist?
122
+ def report_file_exist?(report_file)
118
123
  File.exist?(report_file)
119
124
  end
120
125
 
121
126
  # A getter for `pmd_report`, returning PMD report.
122
127
  # @return [Oga::XML::Document]
123
- def pmd_report
128
+ def pmd_report(report_file)
124
129
  require "oga"
125
- @pmd_report ||= Oga.parse_xml(File.open(report_file))
130
+ Oga.parse_xml(File.open(report_file))
126
131
  end
127
132
 
128
133
  # A getter for PMD issues, returning PMD issues.
129
134
  # @return [Array[PmdFile]]
130
- def pmd_issues
131
- @pmd_issues ||= pmd_report.xpath("//file").map do |pmd_file|
132
- PmdFile.new(gradle_module, pmd_file)
135
+ def pmd_issues(report_file)
136
+ pmd_report(report_file).xpath("//file").map do |pmd_file|
137
+ PmdFile.new(pmd_file)
133
138
  end
134
139
  end
135
140
 
136
- # Send inline comment with Danger's warn or fail method
137
- # @return [void]
138
- def send_inline_comment
139
- pmd_issues.each do |pmd_file|
140
- next unless target_files.include? pmd_file.absolute_path
141
+ # A getter for current updated files.
142
+ # @return [Array[String]]
143
+ def target_files
144
+ @target_files ||= (git.modified_files - git.deleted_files) + git.added_files
145
+ end
146
+
147
+ # Generate report and send inline comment with Danger's warn or fail method.
148
+ # @return [Array[PmdFile]]
149
+ def report_and_send_inline_comment(report_files, inline_mode = true)
150
+ pmd_issues = []
141
151
 
142
- pmd_file.violations.each do |pmd_violation|
143
- send(pmd_violation.type, pmd_violation.description, file: pmd_file.absolute_path, line: pmd_violation.line)
152
+ report_files.each do |report_file|
153
+ pmd_issues(report_file).each do |pmd_file|
154
+ next unless target_files.include? pmd_file.absolute_path
155
+
156
+ pmd_issues.push(pmd_file)
157
+
158
+ next if inline_mode
159
+
160
+ pmd_file.violations.each do |pmd_violation|
161
+ send(pmd_violation.type, pmd_violation.description, file: pmd_file.absolute_path, line: pmd_violation.line)
162
+ end
144
163
  end
145
164
  end
165
+
166
+ pmd_issues
146
167
  end
147
168
  end
148
169
  end
data/lib/pmd/pmd_file.rb CHANGED
@@ -2,11 +2,9 @@
2
2
 
3
3
  class PmdFile
4
4
  require_relative "./pmd_violation"
5
- attr_accessor :module_name
6
5
  attr_accessor :file
7
6
 
8
- def initialize(module_name, file)
9
- @module_name = module_name
7
+ def initialize(file)
10
8
  @file = file
11
9
  end
12
10
 
@@ -15,12 +13,19 @@ class PmdFile
15
13
  end
16
14
 
17
15
  def absolute_path
18
- @absolute_path ||= Pathname.new(source_path[source_path.index(module_name), source_path.length]).to_s
16
+ dirname = File.basename(Dir.getwd)
17
+ if source_path.index(dirname)
18
+ index_start = source_path.index(dirname) + dirname.length + 1
19
+ else
20
+ index_start = 0
21
+ end
22
+ index_end = source_path.length
23
+ @absolute_path ||= Pathname.new(source_path[index_start, index_end]).to_s
19
24
  end
20
25
 
21
26
  def violations
22
27
  @violations ||= file.xpath("violation").map do |pmd_violation|
23
- PmdViolation.new(module_name, pmd_violation)
28
+ PmdViolation.new(pmd_violation)
24
29
  end
25
30
  end
26
31
  end
@@ -2,11 +2,9 @@
2
2
 
3
3
  class PmdViolation
4
4
  PRIORITY_ERROR_THRESHOLD = 2
5
- attr_accessor :module_name
6
5
  attr_accessor :violation
7
6
 
8
- def initialize(module_name, violation)
9
- @module_name = module_name
7
+ def initialize(violation)
10
8
  @violation = violation
11
9
  end
12
10
 
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <pmd xmlns="http://pmd.sourceforge.net/report/2.0.0"
3
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+ xsi:schemaLocation="http://pmd.sourceforge.net/report/2.0.0 http://pmd.sourceforge.net/report_2_0_0.xsd"
5
+ version="6.8.0" timestamp="2019-10-03T20:34:18.074">
6
+ <file name="/Users/developer/sample/app/src/main/java/com/android/sample/Utils.java">
7
+ <violation beginline="23" endline="23" begincolumn="21" endcolumn="21" rule="CollapsibleIfStatements" ruleset="Design" package="com.android.sample" class="Utils" method="doSomething" externalInfoUrl="https://pmd.github.io/pmd-6.15.0/pmd_rules_java_design.html#collapsibleifstatements" priority="3">
8
+ These nested if statements could be combined
9
+ </violation>
10
+ <violation beginline="45" endline="45" begincolumn="23" endcolumn="30" rule="AvoidDuplicateLiterals" ruleset="Error Prone" package="com.android.sample" class="Utils" externalInfoUrl="https://pmd.github.io/pmd-6.15.0/pmd_rules_java_errorprone.html#avoidduplicateliterals" priority="3">
11
+ The String literal &quot;unused&quot; appears 4 times in this file; the first occurrence is on line 45
12
+ </violation>
13
+ </file>
14
+ </pmd>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <pmd xmlns="http://pmd.sourceforge.net/report/2.0.0"
3
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+ xsi:schemaLocation="http://pmd.sourceforge.net/report/2.0.0 http://pmd.sourceforge.net/report_2_0_0.xsd"
5
+ version="6.8.0" timestamp="2019-10-03T20:34:18.074">
6
+ <file name="/Users/developer/sample/app/src/main/java/com/android/sample/Application.java">
7
+ <violation beginline="135" endline="135" begincolumn="27" endcolumn="33" rule="AvoidDuplicateLiterals" ruleset="Error Prone" package="com.android.sample" class="Application" method="start" externalInfoUrl="https://pmd.github.io/pmd-6.15.0/pmd_rules_java_errorprone.html#avoidduplicateliterals" priority="3">
8
+ The String literal &quot;label&quot; appears 5 times in this file; the first occurrence is on line 135
9
+ </violation>
10
+ </file>
11
+ </pmd>
data/spec/pmd_spec.rb CHANGED
@@ -11,59 +11,69 @@ module Danger
11
11
  describe "with Dangerfile" do
12
12
  before do
13
13
  @dangerfile = testing_dangerfile
14
- @my_plugin = @dangerfile.pmd
14
+ @pmd = @dangerfile.pmd
15
15
  end
16
16
 
17
17
  it "Check default report file path" do
18
- expect(@my_plugin.report_file).to eq("app/build/reports/pmd/pmd.xml")
18
+ expect(@pmd.report_file).to eq("app/build/reports/pmd/pmd.xml")
19
19
  end
20
20
 
21
21
  it "Set custom report file path" do
22
- custom_report_path = "custom/pmd_report.xml"
23
- @my_plugin.report_file = custom_report_path
24
- expect(@my_plugin.report_file).to eq(custom_report_path)
22
+ custom_report_path = "custom-path/pmd_sub_report.xml"
23
+ @pmd.report_file = custom_report_path
24
+ expect(@pmd.report_file).to eq(custom_report_path)
25
25
  end
26
26
 
27
- it "Check default Gradle module" do
28
- expect(@my_plugin.gradle_module).to eq("app")
27
+ it "Check default report files paths" do
28
+ expect(@pmd.report_files).to eq(["app/build/reports/pmd/pmd.xml"])
29
29
  end
30
30
 
31
- it "Set custom Gradle module" do
32
- my_module = "custom_module"
33
- @my_plugin.gradle_module = my_module
34
- expect(@my_plugin.gradle_module).to eq(my_module)
31
+ it "Set custom report files paths" do
32
+ custom_report_paths = %w(custom-path/pmd_report_1.xml custom-path/pmd_report_2.xml)
33
+ @pmd.report_files = custom_report_paths
34
+ expect(@pmd.report_files).to eq(custom_report_paths)
35
35
  end
36
36
 
37
37
  it "Check default Gradle task" do
38
- expect(@my_plugin.gradle_task).to eq("pmd")
38
+ expect(@pmd.gradle_task).to eq("pmd")
39
39
  end
40
40
 
41
41
  it "Set custom Gradle task" do
42
42
  custom_task = "pmdStagingDebug"
43
- @my_plugin.gradle_task = custom_task
44
- expect(@my_plugin.gradle_task).to eq(custom_task)
43
+ @pmd.gradle_task = custom_task
44
+ expect(@pmd.gradle_task).to eq(custom_task)
45
45
  end
46
46
 
47
47
  it "Skip Gradle task" do
48
48
  skip_gradle_task = true
49
- @my_plugin.skip_gradle_task = skip_gradle_task
50
- expect(@my_plugin.skip_gradle_task).to eq(skip_gradle_task)
49
+ @pmd.skip_gradle_task = skip_gradle_task
50
+ expect(@pmd.skip_gradle_task).to eq(skip_gradle_task)
51
51
  end
52
52
 
53
53
  it "Check default skip Gradle task" do
54
- expect(@my_plugin.skip_gradle_task).to eq(false)
54
+ expect(@pmd.skip_gradle_task).to eq(false)
55
55
  end
56
56
 
57
- it "Create files" do
58
- custom_report_path = "spec/fixtures/pmd_report.xml"
59
- @my_plugin.report_file = custom_report_path
60
- pmd_issues = @my_plugin.pmd_issues
57
+ it "Report with report file" do
58
+ target_files = [
59
+ "/Users/developer/sample/app/src/main/java/com/android/sample/MainActivity.java",
60
+ "/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java",
61
+ "/Users/developer/sample/app/src/test/java/com/android/sample/ExampleUnitTest.java",
62
+ "/Users/developer/sample/app/src/test/java/com/android/sample/ToolsTest.java"
63
+ ]
64
+ allow_any_instance_of(Danger::DangerPmd).to receive(:target_files).and_return(target_files)
65
+
66
+ @pmd.report_file = "spec/fixtures/pmd_report.xml"
67
+ @pmd.skip_gradle_task = true
68
+
69
+ pmd_issues = @pmd.report
61
70
  expect(pmd_issues).not_to be_nil
71
+ expect(pmd_issues.length).to be(4)
62
72
 
63
73
  pmd_issue1 = pmd_issues[0]
64
74
  expect(pmd_issue1).not_to be_nil
65
75
  expect(pmd_issue1.source_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java")
66
- expect(pmd_issue1.absolute_path).to eq("app/src/main/java/com/android/sample/Tools.java")
76
+ expect(pmd_issue1.absolute_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java")
67
77
  expect(pmd_issue1.violations).not_to be_nil
68
78
  expect(pmd_issue1.violations.length).to eq(1)
69
79
  expect(pmd_issue1.violations.first).not_to be_nil
@@ -73,7 +83,7 @@ module Danger
73
83
  pmd_issue2 = pmd_issues[1]
74
84
  expect(pmd_issue2).not_to be_nil
75
85
  expect(pmd_issue2.source_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/MainActivity.java")
76
- expect(pmd_issue2.absolute_path).to eq("app/src/main/java/com/android/sample/MainActivity.java")
86
+ expect(pmd_issue2.absolute_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/MainActivity.java")
77
87
  expect(pmd_issue2.violations).not_to be_nil
78
88
  expect(pmd_issue2.violations.length).to eq(1)
79
89
  expect(pmd_issue2.violations.first).not_to be_nil
@@ -83,7 +93,7 @@ module Danger
83
93
  pmd_issue3 = pmd_issues[2]
84
94
  expect(pmd_issue3).not_to be_nil
85
95
  expect(pmd_issue3.source_path).to eq("/Users/developer/sample/app/src/test/java/com/android/sample/ExampleUnitTest.java")
86
- expect(pmd_issue3.absolute_path).to eq("app/src/test/java/com/android/sample/ExampleUnitTest.java")
96
+ expect(pmd_issue3.absolute_path).to eq("/Users/developer/sample/app/src/test/java/com/android/sample/ExampleUnitTest.java")
87
97
  expect(pmd_issue3.violations).not_to be_nil
88
98
  expect(pmd_issue3.violations.length).to eq(1)
89
99
  expect(pmd_issue3.violations.first).not_to be_nil
@@ -93,7 +103,7 @@ module Danger
93
103
  pmd_issue4 = pmd_issues[3]
94
104
  expect(pmd_issue4).not_to be_nil
95
105
  expect(pmd_issue4.source_path).to eq("/Users/developer/sample/app/src/test/java/com/android/sample/ToolsTest.java")
96
- expect(pmd_issue4.absolute_path).to eq("app/src/test/java/com/android/sample/ToolsTest.java")
106
+ expect(pmd_issue4.absolute_path).to eq("/Users/developer/sample/app/src/test/java/com/android/sample/ToolsTest.java")
97
107
  expect(pmd_issue4.violations).not_to be_nil
98
108
  expect(pmd_issue4.violations.length).to eq(2)
99
109
  expect(pmd_issue4.violations[0]).not_to be_nil
@@ -104,11 +114,150 @@ module Danger
104
114
  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]*'")
105
115
  end
106
116
 
107
- it "Send inline comments" do
117
+ it "Report with report file not in target files" do
118
+ target_files = [
119
+ "/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java",
120
+ "/Users/developer/sample/app/src/test/java/com/android/sample/ToolsTest.java"
121
+ ]
122
+ allow_any_instance_of(Danger::DangerPmd).to receive(:target_files).and_return(target_files)
123
+
124
+ @pmd.report_file = "spec/fixtures/pmd_report.xml"
125
+ @pmd.skip_gradle_task = true
126
+
127
+ pmd_issues = @pmd.report
128
+ expect(pmd_issues).not_to be_nil
129
+ expect(pmd_issues.length).to be(2)
130
+
131
+ pmd_issue1 = pmd_issues[0]
132
+ expect(pmd_issue1).not_to be_nil
133
+ expect(pmd_issue1.source_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java")
134
+ expect(pmd_issue1.absolute_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java")
135
+ expect(pmd_issue1.violations).not_to be_nil
136
+ expect(pmd_issue1.violations.length).to eq(1)
137
+ expect(pmd_issue1.violations.first).not_to be_nil
138
+ expect(pmd_issue1.violations.first.line).to eq(5)
139
+ expect(pmd_issue1.violations.first.description).to eq("The utility class name 'Tools' doesn't match '[A-Z][a-zA-Z0-9]+(Utils?|Helper)'")
140
+
141
+ pmd_issue2 = pmd_issues[1]
142
+ expect(pmd_issue2).not_to be_nil
143
+ expect(pmd_issue2.source_path).to eq("/Users/developer/sample/app/src/test/java/com/android/sample/ToolsTest.java")
144
+ expect(pmd_issue2.absolute_path).to eq("/Users/developer/sample/app/src/test/java/com/android/sample/ToolsTest.java")
145
+ expect(pmd_issue2.violations).not_to be_nil
146
+ expect(pmd_issue2.violations.length).to eq(2)
147
+ expect(pmd_issue2.violations[0]).not_to be_nil
148
+ expect(pmd_issue2.violations[0].line).to eq(12)
149
+ expect(pmd_issue2.violations[0].description).to eq("The JUnit 4 test method name 'getLabel_1' doesn't match '[a-z][a-zA-Z0-9]*'")
150
+ expect(pmd_issue2.violations[1]).not_to be_nil
151
+ expect(pmd_issue2.violations[1].line).to eq(18)
152
+ expect(pmd_issue2.violations[1].description).to eq("The JUnit 4 test method name 'getLabel_2' doesn't match '[a-z][a-zA-Z0-9]*'")
153
+ end
154
+
155
+ it "Report with report files" do
156
+ target_files = [
157
+ "/Users/developer/sample/app/src/main/java/com/android/sample/Application.java",
158
+ "/Users/developer/sample/app/src/main/java/com/android/sample/MainActivity.java",
159
+ "/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java",
160
+ "/Users/developer/sample/app/src/main/java/com/android/sample/Utils.java",
161
+ "/Users/developer/sample/app/src/test/java/com/android/sample/ExampleUnitTest.java",
162
+ "/Users/developer/sample/app/src/test/java/com/android/sample/ToolsTest.java"
163
+ ]
164
+ allow_any_instance_of(Danger::DangerPmd).to receive(:target_files).and_return(target_files)
165
+
166
+ @pmd.report_files = %w(spec/fixtures/pmd_report.xml spec/fixtures/**/pmd_sub_report.xml)
167
+ @pmd.skip_gradle_task = true
168
+
169
+ pmd_issues = @pmd.report
170
+ expect(pmd_issues).not_to be_nil
171
+ expect(pmd_issues.length).to be(6)
172
+
173
+ pmd_issue1 = pmd_issues[0]
174
+ expect(pmd_issue1).not_to be_nil
175
+ expect(pmd_issue1.source_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java")
176
+ expect(pmd_issue1.absolute_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java")
177
+ expect(pmd_issue1.violations).not_to be_nil
178
+ expect(pmd_issue1.violations.length).to eq(1)
179
+ expect(pmd_issue1.violations.first).not_to be_nil
180
+ expect(pmd_issue1.violations.first.line).to eq(5)
181
+ expect(pmd_issue1.violations.first.description).to eq("The utility class name 'Tools' doesn't match '[A-Z][a-zA-Z0-9]+(Utils?|Helper)'")
182
+
183
+ pmd_issue2 = pmd_issues[1]
184
+ expect(pmd_issue2).not_to be_nil
185
+ expect(pmd_issue2.source_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/MainActivity.java")
186
+ expect(pmd_issue2.absolute_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/MainActivity.java")
187
+ expect(pmd_issue2.violations).not_to be_nil
188
+ expect(pmd_issue2.violations.length).to eq(1)
189
+ expect(pmd_issue2.violations.first).not_to be_nil
190
+ expect(pmd_issue2.violations.first.line).to eq(39)
191
+ expect(pmd_issue2.violations.first.description).to eq("Use equals() to compare strings instead of '==' or '!='")
192
+
193
+ pmd_issue3 = pmd_issues[2]
194
+ expect(pmd_issue3).not_to be_nil
195
+ expect(pmd_issue3.source_path).to eq("/Users/developer/sample/app/src/test/java/com/android/sample/ExampleUnitTest.java")
196
+ expect(pmd_issue3.absolute_path).to eq("/Users/developer/sample/app/src/test/java/com/android/sample/ExampleUnitTest.java")
197
+ expect(pmd_issue3.violations).not_to be_nil
198
+ expect(pmd_issue3.violations.length).to eq(1)
199
+ expect(pmd_issue3.violations.first).not_to be_nil
200
+ expect(pmd_issue3.violations.first.line).to eq(15)
201
+ 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]*'")
202
+
203
+ pmd_issue4 = pmd_issues[3]
204
+ expect(pmd_issue4).not_to be_nil
205
+ expect(pmd_issue4.source_path).to eq("/Users/developer/sample/app/src/test/java/com/android/sample/ToolsTest.java")
206
+ expect(pmd_issue4.absolute_path).to eq("/Users/developer/sample/app/src/test/java/com/android/sample/ToolsTest.java")
207
+ expect(pmd_issue4.violations).not_to be_nil
208
+ expect(pmd_issue4.violations.length).to eq(2)
209
+ expect(pmd_issue4.violations[0]).not_to be_nil
210
+ expect(pmd_issue4.violations[0].line).to eq(12)
211
+ 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]*'")
212
+ expect(pmd_issue4.violations[1]).not_to be_nil
213
+ expect(pmd_issue4.violations[1].line).to eq(18)
214
+ 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]*'")
215
+
216
+ pmd_issue5 = pmd_issues[4]
217
+ expect(pmd_issue5).not_to be_nil
218
+ expect(pmd_issue5.source_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/Utils.java")
219
+ expect(pmd_issue5.absolute_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/Utils.java")
220
+ expect(pmd_issue5.violations).not_to be_nil
221
+ expect(pmd_issue5.violations.length).to eq(2)
222
+ expect(pmd_issue5.violations[0]).not_to be_nil
223
+ expect(pmd_issue5.violations[0].line).to eq(23)
224
+ expect(pmd_issue5.violations[0].description).to eq("These nested if statements could be combined")
225
+ expect(pmd_issue5.violations[1]).not_to be_nil
226
+ expect(pmd_issue5.violations[1].line).to eq(45)
227
+ expect(pmd_issue5.violations[1].description).to eq("The String literal \"unused\" appears 4 times in this file; the first occurrence is on line 45")
228
+
229
+ pmd_issue6 = pmd_issues[5]
230
+ expect(pmd_issue6).not_to be_nil
231
+ expect(pmd_issue6.source_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/Application.java")
232
+ expect(pmd_issue6.absolute_path).to eq("/Users/developer/sample/app/src/main/java/com/android/sample/Application.java")
233
+ expect(pmd_issue6.violations).not_to be_nil
234
+ expect(pmd_issue6.violations.length).to eq(1)
235
+ expect(pmd_issue6.violations[0]).not_to be_nil
236
+ expect(pmd_issue6.violations[0].line).to eq(135)
237
+ expect(pmd_issue6.violations[0].description).to eq("The String literal \"label\" appears 5 times in this file; the first occurrence is on line 135")
238
+ end
239
+
240
+ it "Report without Gradle" do
108
241
  allow_any_instance_of(Danger::DangerPmd).to receive(:target_files).and_return([])
109
- custom_report_path = "spec/fixtures/pmd_report.xml"
110
- @my_plugin.report_file = custom_report_path
111
- expect(@my_plugin.send_inline_comment).not_to be_nil
242
+
243
+ @pmd.report_file = "spec/fixtures/pmd_report.xml"
244
+ @pmd.skip_gradle_task = false
245
+
246
+ pmd_issues = @pmd.report
247
+ expect(pmd_issues).not_to be_nil
248
+ expect(pmd_issues.length).to be(1)
249
+ expect(pmd_issues[0]).to be("Could not find `gradlew` inside current directory")
250
+ end
251
+
252
+ it "Report without existing report file" do
253
+ allow_any_instance_of(Danger::DangerPmd).to receive(:target_files).and_return([])
254
+
255
+ @pmd.report_file = "spec/fixtures/custom/pmd_report.xml"
256
+ @pmd.skip_gradle_task = true
257
+
258
+ pmd_issues = @pmd.report
259
+ expect(pmd_issues).not_to be_nil
260
+ expect(pmd_issues.length).to be(0)
112
261
  end
113
262
  end
114
263
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-pmd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathieu Rul
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-05 00:00:00.000000000 Z
11
+ date: 2019-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-plugin-api
@@ -188,6 +188,8 @@ files:
188
188
  - lib/pmd/pmd_file.rb
189
189
  - lib/pmd/pmd_violation.rb
190
190
  - spec/fixtures/pmd_report.xml
191
+ - spec/fixtures/report_1/pmd_sub_report.xml
192
+ - spec/fixtures/report_2/pmd_sub_report.xml
191
193
  - spec/pmd_spec.rb
192
194
  - spec/spec_helper.rb
193
195
  homepage: https://github.com/mathroule/danger-pmd
@@ -209,11 +211,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
209
211
  - !ruby/object:Gem::Version
210
212
  version: '0'
211
213
  requirements: []
212
- rubygems_version: 3.0.3
214
+ rubygems_version: 3.0.6
213
215
  signing_key:
214
216
  specification_version: 4
215
217
  summary: A Danger plugin for PMD (Programming Mistake Detector), see https://pmd.github.io.
216
218
  test_files:
217
219
  - spec/fixtures/pmd_report.xml
220
+ - spec/fixtures/report_1/pmd_sub_report.xml
221
+ - spec/fixtures/report_2/pmd_sub_report.xml
218
222
  - spec/pmd_spec.rb
219
223
  - spec/spec_helper.rb