danger-pmd 0.2.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/publish.yml +35 -0
- data/.github/workflows/test.yml +24 -0
- data/.rubocop.yml +4777 -99
- data/Gemfile.lock +83 -63
- data/LICENSE +21 -0
- data/README.md +34 -21
- data/danger-pmd.gemspec +24 -22
- data/lib/danger_plugin.rb +1 -1
- data/lib/danger_pmd.rb +1 -1
- data/lib/pmd/{pmd_file.rb → entity/pmd_file.rb} +10 -13
- data/lib/pmd/{pmd_violation.rb → entity/pmd_violation.rb} +5 -4
- data/lib/pmd/gem_version.rb +1 -1
- data/lib/pmd/plugin.rb +35 -32
- data/spec/entity/pmd_file_spec.rb +48 -0
- data/spec/pmd_spec.rb +58 -64
- data/spec/spec_helper.rb +18 -18
- metadata +62 -31
- data/.travis.yml +0 -10
- data/LICENSE.txt +0 -22
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Represent a PMD violation.
|
3
4
|
class PmdViolation
|
4
|
-
PRIORITY_ERROR_THRESHOLD =
|
5
|
+
PRIORITY_ERROR_THRESHOLD = 4
|
5
6
|
attr_accessor :violation
|
6
7
|
|
7
8
|
def initialize(violation)
|
@@ -9,7 +10,7 @@ class PmdViolation
|
|
9
10
|
end
|
10
11
|
|
11
12
|
def priority
|
12
|
-
@priority ||= violation.attribute(
|
13
|
+
@priority ||= violation.attribute('priority').value.to_i
|
13
14
|
end
|
14
15
|
|
15
16
|
def type
|
@@ -17,10 +18,10 @@ class PmdViolation
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def line
|
20
|
-
@line ||= violation.attribute(
|
21
|
+
@line ||= violation.attribute('beginline').value.to_i
|
21
22
|
end
|
22
23
|
|
23
24
|
def description
|
24
|
-
@description ||= violation.text.gsub("\n",
|
25
|
+
@description ||= violation.text.gsub("\n", '')
|
25
26
|
end
|
26
27
|
end
|
data/lib/pmd/gem_version.rb
CHANGED
data/lib/pmd/plugin.rb
CHANGED
@@ -11,18 +11,18 @@ module Danger
|
|
11
11
|
#
|
12
12
|
# @example Running PMD with a specific Gradle task or report file (glob accepted)
|
13
13
|
#
|
14
|
-
# pmd.gradle_task = 'app:pmd' #
|
15
|
-
# pmd.report_file =
|
14
|
+
# pmd.gradle_task = 'app:pmd' # default: pmd
|
15
|
+
# pmd.report_file = 'module/build/reports/pmd/pmd.xml' # default: app/build/reports/pmd/pmd.xml
|
16
16
|
# pmd.report
|
17
17
|
#
|
18
18
|
# @example Running PMD with a specific root path
|
19
19
|
#
|
20
|
-
# pmd.root_path = '/Users/developer/project
|
20
|
+
# pmd.root_path = '/Users/developer/project'
|
21
21
|
# pmd.report
|
22
22
|
#
|
23
23
|
# @example Running PMD with an array of report files (glob accepted)
|
24
24
|
#
|
25
|
-
# pmd.report_files = [
|
25
|
+
# pmd.report_files = ['modules/**/build/reports/pmd/pmd.xml', 'app/build/reports/pmd/pmd.xml']
|
26
26
|
# pmd.report
|
27
27
|
#
|
28
28
|
# @example Running PMD without running a Gradle task
|
@@ -32,20 +32,19 @@ module Danger
|
|
32
32
|
#
|
33
33
|
# @see mathroule/danger-pmd
|
34
34
|
# @tags java, android, pmd
|
35
|
-
|
36
35
|
class DangerPmd < Plugin
|
37
|
-
require_relative
|
36
|
+
require_relative './entity/pmd_file'
|
38
37
|
|
39
38
|
# Custom Gradle task to run.
|
40
39
|
# This is useful when your project has different flavors.
|
41
|
-
# Defaults to
|
40
|
+
# Defaults to 'pmd'.
|
42
41
|
# @return [String]
|
43
42
|
attr_writer :gradle_task
|
44
43
|
|
45
|
-
# A getter for `gradle_task`, returning
|
44
|
+
# A getter for `gradle_task`, returning 'pmd' if value is nil.
|
46
45
|
# @return [String]
|
47
46
|
def gradle_task
|
48
|
-
@gradle_task ||=
|
47
|
+
@gradle_task ||= 'pmd'
|
49
48
|
end
|
50
49
|
|
51
50
|
# Skip Gradle task.
|
@@ -62,11 +61,11 @@ module Danger
|
|
62
61
|
|
63
62
|
# An absolute path to a root.
|
64
63
|
# To comment errors to VCS, this needs to know relative path of files from the root.
|
65
|
-
# Defaults to result of
|
64
|
+
# Defaults to result of 'git rev-parse --show-toplevel'.
|
66
65
|
# @return [String] the root path of git repository by default.
|
67
66
|
attr_writer :root_path
|
68
67
|
|
69
|
-
# A getter for `root_path`, returning result of
|
68
|
+
# A getter for `root_path`, returning result of 'git rev-parse --show-toplevel' if value is nil.
|
70
69
|
# @return [String]
|
71
70
|
def root_path
|
72
71
|
@root_path ||= `git rev-parse --show-toplevel`.chomp
|
@@ -74,23 +73,23 @@ module Danger
|
|
74
73
|
|
75
74
|
# Location of report file.
|
76
75
|
# If your pmd task outputs to a different location, you can specify it here.
|
77
|
-
# Defaults to
|
76
|
+
# Defaults to 'app/build/reports/pmd/pmd.xml'.
|
78
77
|
# @return [String]
|
79
78
|
attr_writer :report_file
|
80
79
|
|
81
|
-
# A getter for `report_file`, returning
|
80
|
+
# A getter for `report_file`, returning 'app/build/reports/pmd/pmd.xml' if value is nil.
|
82
81
|
# @return [String]
|
83
82
|
def report_file
|
84
|
-
@report_file ||=
|
83
|
+
@report_file ||= 'app/build/reports/pmd/pmd.xml'
|
85
84
|
end
|
86
85
|
|
87
86
|
# Location of report files.
|
88
87
|
# If your pmd task outputs to a different location, you can specify it here.
|
89
|
-
# Defaults to [
|
88
|
+
# Defaults to ['app/build/reports/pmd/pmd.xml'].
|
90
89
|
# @return [Array[String]]
|
91
90
|
attr_writer :report_files
|
92
91
|
|
93
|
-
# A getter for `report_files`, returning [
|
92
|
+
# A getter for `report_files`, returning ['app/build/reports/pmd/pmd.xml'] if value is nil.
|
94
93
|
# @return [Array[String]]
|
95
94
|
def report_files
|
96
95
|
@report_files ||= [report_file]
|
@@ -101,17 +100,17 @@ module Danger
|
|
101
100
|
# It fails if `report_file` cannot be found inside current directory.
|
102
101
|
# It fails if `report_files` is empty.
|
103
102
|
# @return [Array[PmdFile]]
|
104
|
-
def report(
|
103
|
+
def report(inline_mode: true)
|
105
104
|
unless skip_gradle_task
|
106
|
-
|
105
|
+
raise('Could not find `gradlew` inside current directory') unless gradlew_exists?
|
107
106
|
|
108
107
|
exec_gradle_task
|
109
108
|
end
|
110
109
|
|
111
110
|
report_files_expanded = Dir.glob(report_files).sort
|
112
|
-
|
111
|
+
raise("Could not find matching PMD report files for #{report_files} inside current directory") if report_files_expanded.empty?
|
113
112
|
|
114
|
-
do_comment(report_files_expanded,
|
113
|
+
do_comment(report_files_expanded, inline_mode)
|
115
114
|
end
|
116
115
|
|
117
116
|
private
|
@@ -137,14 +136,14 @@ module Danger
|
|
137
136
|
# A getter for `pmd_report`, returning PMD report.
|
138
137
|
# @return [Oga::XML::Document]
|
139
138
|
def pmd_report(report_file)
|
140
|
-
require
|
139
|
+
require 'oga'
|
141
140
|
Oga.parse_xml(File.open(report_file))
|
142
141
|
end
|
143
142
|
|
144
143
|
# A getter for PMD issues, returning PMD issues.
|
145
144
|
# @return [Array[PmdFile]]
|
146
145
|
def pmd_issues(report_file)
|
147
|
-
pmd_report(report_file).xpath(
|
146
|
+
pmd_report(report_file).xpath('//file').map do |pmd_file|
|
148
147
|
PmdFile.new(root_path, pmd_file)
|
149
148
|
end
|
150
149
|
end
|
@@ -157,26 +156,30 @@ module Danger
|
|
157
156
|
|
158
157
|
# Generate report and send inline comment with Danger's warn or fail method.
|
159
158
|
# @return [Array[PmdFile]]
|
160
|
-
def do_comment(report_files,
|
159
|
+
def do_comment(report_files, inline_mode)
|
161
160
|
pmd_issues = []
|
162
161
|
|
163
162
|
report_files.each do |report_file|
|
164
163
|
pmd_issues(report_file).each do |pmd_file|
|
165
164
|
next unless target_files.include? pmd_file.relative_path
|
166
165
|
|
167
|
-
|
168
|
-
|
169
|
-
pmd_file.violations.each do |pmd_violation|
|
170
|
-
if inline_comment
|
171
|
-
send(pmd_violation.type, pmd_violation.description, file: pmd_file.relative_path, line: pmd_violation.line)
|
172
|
-
else
|
173
|
-
send(pmd_violation.type, "#{pmd_file.relative_path} : #{pmd_violation.description} at #{pmd_violation.line}")
|
174
|
-
end
|
175
|
-
end
|
166
|
+
parse_file(pmd_file, pmd_issues, inline_mode)
|
176
167
|
end
|
177
168
|
end
|
178
169
|
|
179
170
|
pmd_issues
|
180
171
|
end
|
172
|
+
|
173
|
+
def parse_file(pmd_file, pmd_issues, inline_mode)
|
174
|
+
pmd_issues.push(pmd_file)
|
175
|
+
|
176
|
+
pmd_file.violations.each do |pmd_violation|
|
177
|
+
if inline_mode
|
178
|
+
send(pmd_violation.type, pmd_violation.description, file: pmd_file.relative_path, line: pmd_violation.line)
|
179
|
+
else
|
180
|
+
send(pmd_violation.type, "#{pmd_file.relative_path} : #{pmd_violation.description} at #{pmd_violation.line}")
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
181
184
|
end
|
182
185
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../spec_helper"
|
4
|
+
|
5
|
+
module Pmd
|
6
|
+
require 'oga'
|
7
|
+
|
8
|
+
describe PmdFile do
|
9
|
+
it 'should initialize relative path ending with file separator' do
|
10
|
+
xml = Oga.parse_xml(File.open('spec/fixtures/pmd_report.xml'))
|
11
|
+
pmd_file = PmdFile.new('/Users/developer/sample/', xml.xpath('//file').first)
|
12
|
+
|
13
|
+
expect(pmd_file.absolute_path).to eq('/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java')
|
14
|
+
expect(pmd_file.relative_path).to eq('app/src/main/java/com/android/sample/Tools.java')
|
15
|
+
expect(pmd_file.violations).not_to be_nil
|
16
|
+
expect(pmd_file.violations.length).to eq(1)
|
17
|
+
expect(pmd_file.violations.first).not_to be_nil
|
18
|
+
expect(pmd_file.violations.first.line).to eq(5)
|
19
|
+
expect(pmd_file.violations.first.description).to eq("The utility class name 'Tools' doesn't match '[A-Z][a-zA-Z0-9]+(Utils?|Helper)'")
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should initialize relative path not ending with file separator' do
|
23
|
+
xml = Oga.parse_xml(File.open('spec/fixtures/pmd_report.xml'))
|
24
|
+
pmd_file = PmdFile.new('/Users/developer/sample', xml.xpath('//file').first)
|
25
|
+
|
26
|
+
expect(pmd_file.absolute_path).to eq('/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java')
|
27
|
+
expect(pmd_file.relative_path).to eq('app/src/main/java/com/android/sample/Tools.java')
|
28
|
+
expect(pmd_file.violations).not_to be_nil
|
29
|
+
expect(pmd_file.violations.length).to eq(1)
|
30
|
+
expect(pmd_file.violations.first).not_to be_nil
|
31
|
+
expect(pmd_file.violations.first.line).to eq(5)
|
32
|
+
expect(pmd_file.violations.first.description).to eq("The utility class name 'Tools' doesn't match '[A-Z][a-zA-Z0-9]+(Utils?|Helper)'")
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should initialize relative path not prefixed' do
|
36
|
+
xml = Oga.parse_xml(File.open('spec/fixtures/pmd_report.xml'))
|
37
|
+
pmd_file = PmdFile.new('/Users/developer/something', xml.xpath('//file').first)
|
38
|
+
|
39
|
+
expect(pmd_file.absolute_path).to eq('/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java')
|
40
|
+
expect(pmd_file.relative_path).to eq('/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java')
|
41
|
+
expect(pmd_file.violations).not_to be_nil
|
42
|
+
expect(pmd_file.violations.length).to eq(1)
|
43
|
+
expect(pmd_file.violations.first).not_to be_nil
|
44
|
+
expect(pmd_file.violations.first.line).to eq(5)
|
45
|
+
expect(pmd_file.violations.first.description).to eq("The utility class name 'Tools' doesn't match '[A-Z][a-zA-Z0-9]+(Utils?|Helper)'")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/spec/pmd_spec.rb
CHANGED
@@ -1,70 +1,70 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require File.expand_path(
|
3
|
+
require File.expand_path('spec_helper', __dir__)
|
4
4
|
|
5
5
|
module Danger
|
6
6
|
describe Danger::DangerPmd do
|
7
|
-
it
|
7
|
+
it 'should be a plugin' do
|
8
8
|
expect(Danger::DangerPmd.new(nil)).to be_a Danger::Plugin
|
9
9
|
end
|
10
10
|
|
11
|
-
describe
|
11
|
+
describe 'with Dangerfile' do
|
12
12
|
before do
|
13
13
|
@dangerfile = testing_dangerfile
|
14
14
|
@pmd = @dangerfile.pmd
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
18
|
-
expect(@pmd.gradle_task).to eq(
|
17
|
+
it 'Check default Gradle task' do
|
18
|
+
expect(@pmd.gradle_task).to eq('pmd')
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
22
|
-
custom_task =
|
21
|
+
it 'Set custom Gradle task' do
|
22
|
+
custom_task = 'pmdStagingDebug'
|
23
23
|
@pmd.gradle_task = custom_task
|
24
24
|
expect(@pmd.gradle_task).to eq(custom_task)
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
27
|
+
it 'Check default skip Gradle task' do
|
28
28
|
expect(@pmd.skip_gradle_task).to eq(false)
|
29
29
|
end
|
30
30
|
|
31
|
-
it
|
31
|
+
it 'Set custom skip Gradle task' do
|
32
32
|
skip_gradle_task = true
|
33
33
|
@pmd.skip_gradle_task = skip_gradle_task
|
34
34
|
expect(@pmd.skip_gradle_task).to eq(skip_gradle_task)
|
35
35
|
end
|
36
36
|
|
37
|
-
it
|
38
|
-
expect(@pmd.report_file).to eq(
|
37
|
+
it 'Check default report file path' do
|
38
|
+
expect(@pmd.report_file).to eq('app/build/reports/pmd/pmd.xml')
|
39
39
|
end
|
40
40
|
|
41
|
-
it
|
42
|
-
custom_report_path =
|
41
|
+
it 'Set custom report file path' do
|
42
|
+
custom_report_path = 'custom-path/pmd_sub_report.xml'
|
43
43
|
@pmd.report_file = custom_report_path
|
44
44
|
expect(@pmd.report_file).to eq(custom_report_path)
|
45
45
|
end
|
46
46
|
|
47
|
-
it
|
48
|
-
expect(@pmd.report_files).to eq([
|
47
|
+
it 'Check default report files paths' do
|
48
|
+
expect(@pmd.report_files).to eq(['app/build/reports/pmd/pmd.xml'])
|
49
49
|
end
|
50
50
|
|
51
|
-
it
|
52
|
-
custom_report_paths = [
|
51
|
+
it 'Set custom report files paths' do
|
52
|
+
custom_report_paths = %w[custom-path/pmd_report_1.xml custom-path/pmd_report_2.xml]
|
53
53
|
@pmd.report_files = custom_report_paths
|
54
54
|
expect(@pmd.report_files).to eq(custom_report_paths)
|
55
55
|
end
|
56
56
|
|
57
|
-
it
|
57
|
+
it 'Check default root path' do
|
58
58
|
expect(@pmd.root_path).to eq(Dir.pwd)
|
59
59
|
end
|
60
60
|
|
61
|
-
it
|
62
|
-
root_path =
|
61
|
+
it 'Set custom root path' do
|
62
|
+
root_path = '/Users/developer/sample/'
|
63
63
|
@pmd.root_path = root_path
|
64
64
|
expect(@pmd.root_path).to eq(root_path)
|
65
65
|
end
|
66
66
|
|
67
|
-
it
|
67
|
+
it 'Report with report file' do
|
68
68
|
target_files = [
|
69
69
|
"app/src/main/java/com/android/sample/MainActivity.java",
|
70
70
|
"app/src/main/java/com/android/sample/Tools.java",
|
@@ -73,8 +73,8 @@ module Danger
|
|
73
73
|
]
|
74
74
|
allow_any_instance_of(Danger::DangerPmd).to receive(:target_files).and_return(target_files)
|
75
75
|
|
76
|
-
@pmd.report_file =
|
77
|
-
@pmd.root_path =
|
76
|
+
@pmd.report_file = 'spec/fixtures/pmd_report.xml'
|
77
|
+
@pmd.root_path = '/Users/developer/sample/'
|
78
78
|
@pmd.skip_gradle_task = true
|
79
79
|
|
80
80
|
pmd_issues = @pmd.report
|
@@ -83,8 +83,8 @@ module Danger
|
|
83
83
|
|
84
84
|
pmd_issue1 = pmd_issues[0]
|
85
85
|
expect(pmd_issue1).not_to be_nil
|
86
|
-
expect(pmd_issue1.absolute_path).to eq(
|
87
|
-
expect(pmd_issue1.relative_path).to eq(
|
86
|
+
expect(pmd_issue1.absolute_path).to eq('/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java')
|
87
|
+
expect(pmd_issue1.relative_path).to eq('app/src/main/java/com/android/sample/Tools.java')
|
88
88
|
expect(pmd_issue1.violations).not_to be_nil
|
89
89
|
expect(pmd_issue1.violations.length).to eq(1)
|
90
90
|
expect(pmd_issue1.violations.first).not_to be_nil
|
@@ -93,8 +93,8 @@ module Danger
|
|
93
93
|
|
94
94
|
pmd_issue2 = pmd_issues[1]
|
95
95
|
expect(pmd_issue2).not_to be_nil
|
96
|
-
expect(pmd_issue2.absolute_path).to eq(
|
97
|
-
expect(pmd_issue2.relative_path).to eq(
|
96
|
+
expect(pmd_issue2.absolute_path).to eq('/Users/developer/sample/app/src/main/java/com/android/sample/MainActivity.java')
|
97
|
+
expect(pmd_issue2.relative_path).to eq('app/src/main/java/com/android/sample/MainActivity.java')
|
98
98
|
expect(pmd_issue2.violations).not_to be_nil
|
99
99
|
expect(pmd_issue2.violations.length).to eq(1)
|
100
100
|
expect(pmd_issue2.violations.first).not_to be_nil
|
@@ -103,8 +103,8 @@ module Danger
|
|
103
103
|
|
104
104
|
pmd_issue3 = pmd_issues[2]
|
105
105
|
expect(pmd_issue3).not_to be_nil
|
106
|
-
expect(pmd_issue3.absolute_path).to eq(
|
107
|
-
expect(pmd_issue3.relative_path).to eq(
|
106
|
+
expect(pmd_issue3.absolute_path).to eq('/Users/developer/sample/app/src/test/java/com/android/sample/ExampleUnitTest.java')
|
107
|
+
expect(pmd_issue3.relative_path).to eq('app/src/test/java/com/android/sample/ExampleUnitTest.java')
|
108
108
|
expect(pmd_issue3.violations).not_to be_nil
|
109
109
|
expect(pmd_issue3.violations.length).to eq(1)
|
110
110
|
expect(pmd_issue3.violations.first).not_to be_nil
|
@@ -113,8 +113,8 @@ module Danger
|
|
113
113
|
|
114
114
|
pmd_issue4 = pmd_issues[3]
|
115
115
|
expect(pmd_issue4).not_to be_nil
|
116
|
-
expect(pmd_issue4.absolute_path).to eq(
|
117
|
-
expect(pmd_issue4.relative_path).to eq(
|
116
|
+
expect(pmd_issue4.absolute_path).to eq('/Users/developer/sample/app/src/test/java/com/android/sample/ToolsTest.java')
|
117
|
+
expect(pmd_issue4.relative_path).to eq('app/src/test/java/com/android/sample/ToolsTest.java')
|
118
118
|
expect(pmd_issue4.violations).not_to be_nil
|
119
119
|
expect(pmd_issue4.violations.length).to eq(2)
|
120
120
|
expect(pmd_issue4.violations[0]).not_to be_nil
|
@@ -142,8 +142,8 @@ module Danger
|
|
142
142
|
|
143
143
|
pmd_issue1 = pmd_issues[0]
|
144
144
|
expect(pmd_issue1).not_to be_nil
|
145
|
-
expect(pmd_issue1.absolute_path).to eq(
|
146
|
-
expect(pmd_issue1.relative_path).to eq(
|
145
|
+
expect(pmd_issue1.absolute_path).to eq('/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java')
|
146
|
+
expect(pmd_issue1.relative_path).to eq('app/src/main/java/com/android/sample/Tools.java')
|
147
147
|
expect(pmd_issue1.violations).not_to be_nil
|
148
148
|
expect(pmd_issue1.violations.length).to eq(1)
|
149
149
|
expect(pmd_issue1.violations.first).not_to be_nil
|
@@ -152,8 +152,8 @@ module Danger
|
|
152
152
|
|
153
153
|
pmd_issue2 = pmd_issues[1]
|
154
154
|
expect(pmd_issue2).not_to be_nil
|
155
|
-
expect(pmd_issue2.absolute_path).to eq(
|
156
|
-
expect(pmd_issue2.relative_path).to eq(
|
155
|
+
expect(pmd_issue2.absolute_path).to eq('/Users/developer/sample/app/src/test/java/com/android/sample/ToolsTest.java')
|
156
|
+
expect(pmd_issue2.relative_path).to eq('app/src/test/java/com/android/sample/ToolsTest.java')
|
157
157
|
expect(pmd_issue2.violations).not_to be_nil
|
158
158
|
expect(pmd_issue2.violations.length).to eq(2)
|
159
159
|
expect(pmd_issue2.violations[0]).not_to be_nil
|
@@ -175,8 +175,8 @@ module Danger
|
|
175
175
|
]
|
176
176
|
allow_any_instance_of(Danger::DangerPmd).to receive(:target_files).and_return(target_files)
|
177
177
|
|
178
|
-
@pmd.report_files = [
|
179
|
-
@pmd.root_path =
|
178
|
+
@pmd.report_files = %w[spec/fixtures/pmd_report.xml spec/fixtures/**/pmd_sub_report.xml]
|
179
|
+
@pmd.root_path = '/Users/developer/sample/'
|
180
180
|
@pmd.skip_gradle_task = true
|
181
181
|
|
182
182
|
pmd_issues = @pmd.report
|
@@ -185,8 +185,8 @@ module Danger
|
|
185
185
|
|
186
186
|
pmd_issue1 = pmd_issues[0]
|
187
187
|
expect(pmd_issue1).not_to be_nil
|
188
|
-
expect(pmd_issue1.absolute_path).to eq(
|
189
|
-
expect(pmd_issue1.relative_path).to eq(
|
188
|
+
expect(pmd_issue1.absolute_path).to eq('/Users/developer/sample/app/src/main/java/com/android/sample/Tools.java')
|
189
|
+
expect(pmd_issue1.relative_path).to eq('app/src/main/java/com/android/sample/Tools.java')
|
190
190
|
expect(pmd_issue1.violations).not_to be_nil
|
191
191
|
expect(pmd_issue1.violations.length).to eq(1)
|
192
192
|
expect(pmd_issue1.violations.first).not_to be_nil
|
@@ -195,8 +195,8 @@ module Danger
|
|
195
195
|
|
196
196
|
pmd_issue2 = pmd_issues[1]
|
197
197
|
expect(pmd_issue2).not_to be_nil
|
198
|
-
expect(pmd_issue2.absolute_path).to eq(
|
199
|
-
expect(pmd_issue2.relative_path).to eq(
|
198
|
+
expect(pmd_issue2.absolute_path).to eq('/Users/developer/sample/app/src/main/java/com/android/sample/MainActivity.java')
|
199
|
+
expect(pmd_issue2.relative_path).to eq('app/src/main/java/com/android/sample/MainActivity.java')
|
200
200
|
expect(pmd_issue2.violations).not_to be_nil
|
201
201
|
expect(pmd_issue2.violations.length).to eq(1)
|
202
202
|
expect(pmd_issue2.violations.first).not_to be_nil
|
@@ -205,8 +205,8 @@ module Danger
|
|
205
205
|
|
206
206
|
pmd_issue3 = pmd_issues[2]
|
207
207
|
expect(pmd_issue3).not_to be_nil
|
208
|
-
expect(pmd_issue3.absolute_path).to eq(
|
209
|
-
expect(pmd_issue3.relative_path).to eq(
|
208
|
+
expect(pmd_issue3.absolute_path).to eq('/Users/developer/sample/app/src/test/java/com/android/sample/ExampleUnitTest.java')
|
209
|
+
expect(pmd_issue3.relative_path).to eq('app/src/test/java/com/android/sample/ExampleUnitTest.java')
|
210
210
|
expect(pmd_issue3.violations).not_to be_nil
|
211
211
|
expect(pmd_issue3.violations.length).to eq(1)
|
212
212
|
expect(pmd_issue3.violations.first).not_to be_nil
|
@@ -215,8 +215,8 @@ module Danger
|
|
215
215
|
|
216
216
|
pmd_issue4 = pmd_issues[3]
|
217
217
|
expect(pmd_issue4).not_to be_nil
|
218
|
-
expect(pmd_issue4.absolute_path).to eq(
|
219
|
-
expect(pmd_issue4.relative_path).to eq(
|
218
|
+
expect(pmd_issue4.absolute_path).to eq('/Users/developer/sample/app/src/test/java/com/android/sample/ToolsTest.java')
|
219
|
+
expect(pmd_issue4.relative_path).to eq('app/src/test/java/com/android/sample/ToolsTest.java')
|
220
220
|
expect(pmd_issue4.violations).not_to be_nil
|
221
221
|
expect(pmd_issue4.violations.length).to eq(2)
|
222
222
|
expect(pmd_issue4.violations[0]).not_to be_nil
|
@@ -228,50 +228,44 @@ module Danger
|
|
228
228
|
|
229
229
|
pmd_issue5 = pmd_issues[4]
|
230
230
|
expect(pmd_issue5).not_to be_nil
|
231
|
-
expect(pmd_issue5.absolute_path).to eq(
|
232
|
-
expect(pmd_issue5.relative_path).to eq(
|
231
|
+
expect(pmd_issue5.absolute_path).to eq('/Users/developer/sample/app/src/main/java/com/android/sample/Utils.java')
|
232
|
+
expect(pmd_issue5.relative_path).to eq('app/src/main/java/com/android/sample/Utils.java')
|
233
233
|
expect(pmd_issue5.violations).not_to be_nil
|
234
234
|
expect(pmd_issue5.violations.length).to eq(2)
|
235
235
|
expect(pmd_issue5.violations[0]).not_to be_nil
|
236
236
|
expect(pmd_issue5.violations[0].line).to eq(23)
|
237
|
-
expect(pmd_issue5.violations[0].description).to eq(
|
237
|
+
expect(pmd_issue5.violations[0].description).to eq('These nested if statements could be combined')
|
238
238
|
expect(pmd_issue5.violations[1]).not_to be_nil
|
239
239
|
expect(pmd_issue5.violations[1].line).to eq(45)
|
240
|
-
expect(pmd_issue5.violations[1].description).to eq(
|
240
|
+
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')
|
241
241
|
|
242
242
|
pmd_issue6 = pmd_issues[5]
|
243
243
|
expect(pmd_issue6).not_to be_nil
|
244
|
-
expect(pmd_issue6.absolute_path).to eq(
|
245
|
-
expect(pmd_issue6.relative_path).to eq(
|
244
|
+
expect(pmd_issue6.absolute_path).to eq('/Users/developer/sample/app/src/main/java/com/android/sample/Application.java')
|
245
|
+
expect(pmd_issue6.relative_path).to eq('app/src/main/java/com/android/sample/Application.java')
|
246
246
|
expect(pmd_issue6.violations).not_to be_nil
|
247
247
|
expect(pmd_issue6.violations.length).to eq(1)
|
248
248
|
expect(pmd_issue6.violations[0]).not_to be_nil
|
249
249
|
expect(pmd_issue6.violations[0].line).to eq(135)
|
250
|
-
expect(pmd_issue6.violations[0].description).to eq(
|
250
|
+
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')
|
251
251
|
end
|
252
252
|
|
253
|
-
it
|
253
|
+
it 'Report without Gradle' do
|
254
254
|
allow_any_instance_of(Danger::DangerPmd).to receive(:target_files).and_return([])
|
255
255
|
|
256
|
-
@pmd.report_file =
|
256
|
+
@pmd.report_file = 'spec/fixtures/pmd_report.xml'
|
257
257
|
@pmd.skip_gradle_task = false
|
258
258
|
|
259
|
-
|
260
|
-
expect(pmd_issues).not_to be_nil
|
261
|
-
expect(pmd_issues.length).to be(1)
|
262
|
-
expect(pmd_issues[0]).to be("Could not find `gradlew` inside current directory")
|
259
|
+
expect { @pmd.report }.to raise_error('Could not find `gradlew` inside current directory')
|
263
260
|
end
|
264
261
|
|
265
|
-
it
|
262
|
+
it 'Report without existing report file' do
|
266
263
|
allow_any_instance_of(Danger::DangerPmd).to receive(:target_files).and_return([])
|
267
264
|
|
268
|
-
@pmd.report_file =
|
265
|
+
@pmd.report_file = 'spec/fixtures/custom/pmd_report.xml'
|
269
266
|
@pmd.skip_gradle_task = true
|
270
267
|
|
271
|
-
|
272
|
-
expect(pmd_issues).not_to be_nil
|
273
|
-
expect(pmd_issues.length).to be(1)
|
274
|
-
expect(pmd_issues[0]).to eq("Could not find matching PMD report files for [\"spec/fixtures/custom/pmd_report.xml\"] inside current directory")
|
268
|
+
expect { @pmd.report }.to raise_error('Could not find matching PMD report files for ["spec/fixtures/custom/pmd_report.xml"] inside current directory')
|
275
269
|
end
|
276
270
|
end
|
277
271
|
end
|