danger-pmd 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +49 -1
- data/lib/pmd/gem_version.rb +1 -1
- data/lib/pmd/plugin.rb +7 -8
- data/spec/pmd_spec.rb +41 -41
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dafff6ceb58505c4b23ec986c622262c7f86dc4cc700d6dcd22ebf26e588683
|
4
|
+
data.tar.gz: 7247d9dd0fa56d8c889118357a62b844f4c5a2390664f63382469726ee5d554a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
data/lib/pmd/gem_version.rb
CHANGED
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
|
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
|
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 `
|
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
|
109
|
+
# A getter for PMD issues, returning PMD issues.
|
110
110
|
# @return [Array[PmdFile]]
|
111
|
-
def
|
112
|
-
@
|
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
|
-
|
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
|
-
|
51
|
-
expect(
|
50
|
+
pmd_issues = @my_plugin.pmd_issues
|
51
|
+
expect(pmd_issues).not_to be_nil
|
52
52
|
|
53
|
-
|
54
|
-
expect(
|
55
|
-
expect(
|
56
|
-
expect(
|
57
|
-
expect(
|
58
|
-
expect(
|
59
|
-
expect(
|
60
|
-
expect(
|
61
|
-
expect(
|
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
|
-
|
64
|
-
expect(
|
65
|
-
expect(
|
66
|
-
expect(
|
67
|
-
expect(
|
68
|
-
expect(
|
69
|
-
expect(
|
70
|
-
expect(
|
71
|
-
expect(
|
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
|
-
|
74
|
-
expect(
|
75
|
-
expect(
|
76
|
-
expect(
|
77
|
-
expect(
|
78
|
-
expect(
|
79
|
-
expect(
|
80
|
-
expect(
|
81
|
-
expect(
|
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
|
-
|
84
|
-
expect(
|
85
|
-
expect(
|
86
|
-
expect(
|
87
|
-
expect(
|
88
|
-
expect(
|
89
|
-
expect(
|
90
|
-
expect(
|
91
|
-
expect(
|
92
|
-
expect(
|
93
|
-
expect(
|
94
|
-
expect(
|
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
|