danger-spotbugs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+ ROOT = Pathname.new(File.expand_path('..', __dir__))
5
+ $LOAD_PATH.unshift("#{ROOT}lib".to_s)
6
+ $LOAD_PATH.unshift("#{ROOT}spec".to_s)
7
+
8
+ require 'bundler/setup'
9
+ require 'pry'
10
+
11
+ require 'rspec'
12
+ require 'danger'
13
+
14
+ if `git remote -v` == ''
15
+ puts 'You cannot run tests without setting a local git remote on this repo'
16
+ puts "It's a weird side-effect of Danger's internals."
17
+ exit(0)
18
+ end
19
+
20
+ # Use coloured output, it's the best.
21
+ RSpec.configure do |config|
22
+ config.filter_gems_from_backtrace 'bundler'
23
+ config.color = true
24
+ config.tty = true
25
+ end
26
+
27
+ require 'danger_plugin'
28
+
29
+ # These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
30
+ # If you are expanding these files, see if it's already been done ^.
31
+
32
+ # A silent version of the user interface,
33
+ # it comes with an extra function `.string` which will
34
+ # strip all ANSI colours from the string.
35
+
36
+ # rubocop:disable Lint/NestedMethodDefinition
37
+ def testing_ui
38
+ @output = StringIO.new
39
+ def @output.winsize
40
+ [20, 9999]
41
+ end
42
+
43
+ cork = Cork::Board.new(out: @output)
44
+ def cork.string
45
+ out.string.gsub(/\e\[([;\d]+)?m/, '')
46
+ end
47
+ cork
48
+ end
49
+ # rubocop:enable Lint/NestedMethodDefinition
50
+
51
+ # Example environment (ENV) that would come from
52
+ # running a PR on TravisCI
53
+ def testing_env
54
+ {
55
+ 'HAS_JOSH_K_SEAL_OF_APPROVAL' => 'true',
56
+ 'TRAVIS_PULL_REQUEST' => '800',
57
+ 'TRAVIS_REPO_SLUG' => 'artsy/eigen',
58
+ 'TRAVIS_COMMIT_RANGE' => '759adcbd0d8f...13c4dc8bb61d',
59
+ 'DANGER_GITHUB_API_TOKEN' => '123sbdq54erfsd3422gdfio'
60
+ }
61
+ end
62
+
63
+ # A stubbed out Dangerfile for use in tests
64
+ def testing_dangerfile
65
+ env = Danger::EnvironmentManager.new(testing_env)
66
+ Danger::Dangerfile.new(env, testing_ui)
67
+ end
@@ -0,0 +1,174 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('spec_helper', __dir__)
4
+
5
+ module Danger
6
+ describe Danger::DangerSpotbugs do
7
+ it 'should be a plugin' do
8
+ expect(Danger::DangerSpotbugs.new(nil)).to be_a Danger::Plugin
9
+ end
10
+
11
+ describe 'with Dangerfile' do
12
+ before do
13
+ @dangerfile = testing_dangerfile
14
+ @spotbugs = @dangerfile.spotbugs
15
+ end
16
+
17
+ it 'Check default Gradle task' do
18
+ expect(@spotbugs.gradle_task).to eq('spotbugsRelease')
19
+ end
20
+
21
+ it 'Set custom Gradle task' do
22
+ @spotbugs.gradle_task = 'spotbugsDebug'
23
+ expect(@spotbugs.gradle_task).to eq('spotbugsDebug')
24
+ end
25
+
26
+ it 'Check default skip Gradle task' do
27
+ expect(@spotbugs.skip_gradle_task).to be_falsey
28
+ end
29
+
30
+ it 'Set custom skip Gradle task' do
31
+ @spotbugs.skip_gradle_task = true
32
+ expect(@spotbugs.skip_gradle_task).to be_truthy
33
+ end
34
+
35
+ it 'Check default root path' do
36
+ expect(@spotbugs.root_path).to eq(Dir.pwd)
37
+ end
38
+
39
+ it 'Set custom root path' do
40
+ @spotbugs.root_path = '/Users/developer/project'
41
+ expect(@spotbugs.root_path).to eq('/Users/developer/project')
42
+ end
43
+
44
+ it 'Report with report file' do
45
+ # noinspection RubyLiteralArrayInspection
46
+ target_files = [
47
+ 'app/src/main/java/com/github/sample/tools/Tools.java',
48
+ 'app/src/main/java/com/github/sample/MainActivity.java',
49
+ 'app/src/main/java/com/github/sample/model/Message.java',
50
+ 'app/src/main/java/com/github/sample/model/User.java',
51
+ 'app/src/main/java/com/github/sample/view/ConversationAdapter.java'
52
+ ]
53
+ allow_any_instance_of(Danger::DangerSpotbugs).to receive(:target_files).and_return(target_files)
54
+
55
+ @spotbugs.report_file = 'spec/fixtures/spotbugs_report.xml'
56
+ @spotbugs.root_path = '/Users/developer/project/sample/'
57
+ @spotbugs.skip_gradle_task = true
58
+
59
+ spotbugs_issues = @spotbugs.report
60
+ expect(spotbugs_issues).not_to be_nil
61
+ expect(spotbugs_issues.length).to be(7)
62
+
63
+ spotbugs_issue1 = spotbugs_issues[0]
64
+ expect(spotbugs_issue1.rank).to eq(6)
65
+ expect(spotbugs_issue1.line).to eq(29)
66
+ expect(spotbugs_issue1.type).to eq(:warn)
67
+ expect(spotbugs_issue1.absolute_path).to eq('/Users/developer/project/sample/app/src/main/java/com/github/sample/MainActivity.java')
68
+ expect(spotbugs_issue1.relative_path).to eq('app/src/main/java/com/github/sample/MainActivity.java')
69
+ expect(spotbugs_issue1.description).to eq('Possible null pointer dereference of MainActivity.conversationAdapter in com.github.sample.MainActivity.onCreate(Bundle)')
70
+
71
+ spotbugs_issue2 = spotbugs_issues[1]
72
+ expect(spotbugs_issue2.rank).to eq(6)
73
+ expect(spotbugs_issue2.line).to eq(31)
74
+ expect(spotbugs_issue2.type).to eq(:warn)
75
+ expect(spotbugs_issue2.absolute_path).to eq('/Users/developer/project/sample/app/src/main/java/com/github/sample/tools/Tools.java')
76
+ expect(spotbugs_issue2.relative_path).to eq('app/src/main/java/com/github/sample/tools/Tools.java')
77
+ expect(spotbugs_issue2.description).to eq('Possible null pointer dereference of Tools$Helper.string in com.github.sample.tools.Tools$Helper.setText(TextView)')
78
+
79
+ spotbugs_issue3 = spotbugs_issues[2]
80
+ expect(spotbugs_issue3.rank).to eq(8)
81
+ expect(spotbugs_issue3.line).to eq(32)
82
+ expect(spotbugs_issue3.type).to eq(:warn)
83
+ expect(spotbugs_issue3.absolute_path).to eq('/Users/developer/project/sample/app/src/main/java/com/github/sample/tools/Tools.java')
84
+ expect(spotbugs_issue3.relative_path).to eq('app/src/main/java/com/github/sample/tools/Tools.java')
85
+ expect(spotbugs_issue3.description).to eq('Read of unwritten field title in com.github.sample.tools.Tools$Helper.setText(TextView)')
86
+
87
+ spotbugs_issue4 = spotbugs_issues[3]
88
+ expect(spotbugs_issue4.rank).to eq(18)
89
+ expect(spotbugs_issue4.line).to eq(23)
90
+ expect(spotbugs_issue4.type).to eq(:warn)
91
+ expect(spotbugs_issue4.absolute_path).to eq('/Users/developer/project/sample/app/src/main/java/com/github/sample/tools/Tools.java')
92
+ expect(spotbugs_issue4.relative_path).to eq('app/src/main/java/com/github/sample/tools/Tools.java')
93
+ expect(spotbugs_issue4.description).to eq('Should com.github.sample.tools.Tools$Helper be a _static_ inner class?')
94
+
95
+ spotbugs_issue5 = spotbugs_issues[4]
96
+ expect(spotbugs_issue5.rank).to eq(12)
97
+ expect(spotbugs_issue5.line).to eq(32)
98
+ expect(spotbugs_issue5.type).to eq(:warn)
99
+ expect(spotbugs_issue5.absolute_path).to eq('/Users/developer/project/sample/app/src/main/java/com/github/sample/tools/Tools.java')
100
+ expect(spotbugs_issue5.relative_path).to eq('app/src/main/java/com/github/sample/tools/Tools.java')
101
+ expect(spotbugs_issue5.description).to eq('Unwritten field: com.github.sample.tools.Tools$Helper.title')
102
+
103
+ spotbugs_issue6 = spotbugs_issues[5]
104
+ expect(spotbugs_issue6.rank).to eq(18)
105
+ expect(spotbugs_issue6.line).to eq(15)
106
+ expect(spotbugs_issue6.type).to eq(:warn)
107
+ expect(spotbugs_issue6.absolute_path).to eq('/Users/developer/project/sample/app/src/main/java/com/github/sample/tools/Tools.java')
108
+ expect(spotbugs_issue6.relative_path).to eq('app/src/main/java/com/github/sample/tools/Tools.java')
109
+ expect(spotbugs_issue6.description).to eq('Should com.github.sample.tools.Tools$Other be a _static_ inner class?')
110
+
111
+ spotbugs_issue7 = spotbugs_issues[6]
112
+ expect(spotbugs_issue7.rank).to eq(5)
113
+ expect(spotbugs_issue7.line).to eq(32)
114
+ expect(spotbugs_issue7.type).to eq(:warn)
115
+ expect(spotbugs_issue7.absolute_path).to eq('/Users/developer/project/sample/app/src/main/java/com/github/sample/view/ConversationAdapter.java')
116
+ expect(spotbugs_issue7.relative_path).to eq('app/src/main/java/com/github/sample/view/ConversationAdapter.java')
117
+ expect(spotbugs_issue7.description).to eq('Bad comparison of nonnegative value with -1 in com.github.sample.view.ConversationAdapter.setConversations(ArrayList)')
118
+ end
119
+
120
+ it 'Report with report file not in target files' do
121
+ # noinspection RubyLiteralArrayInspection
122
+ target_files = [
123
+ 'app/src/main/java/com/github/sample/MainActivity.java',
124
+ 'app/src/main/java/com/github/sample/model/Message.java',
125
+ 'app/src/main/java/com/github/sample/model/User.java',
126
+ 'app/src/main/java/com/github/sample/view/ConversationAdapter.java'
127
+ ]
128
+ allow_any_instance_of(Danger::DangerSpotbugs).to receive(:target_files).and_return(target_files)
129
+
130
+ @spotbugs.report_file = 'spec/fixtures/spotbugs_report.xml'
131
+ @spotbugs.root_path = '/Users/developer/project/sample/'
132
+ @spotbugs.skip_gradle_task = true
133
+
134
+ spotbugs_issues = @spotbugs.report
135
+ expect(spotbugs_issues).not_to be_nil
136
+ expect(spotbugs_issues.length).to be(2)
137
+
138
+ spotbugs_issue1 = spotbugs_issues[0]
139
+ expect(spotbugs_issue1.rank).to eq(6)
140
+ expect(spotbugs_issue1.line).to eq(29)
141
+ expect(spotbugs_issue1.type).to eq(:warn)
142
+ expect(spotbugs_issue1.absolute_path).to eq('/Users/developer/project/sample/app/src/main/java/com/github/sample/MainActivity.java')
143
+ expect(spotbugs_issue1.relative_path).to eq('app/src/main/java/com/github/sample/MainActivity.java')
144
+ expect(spotbugs_issue1.description).to eq('Possible null pointer dereference of MainActivity.conversationAdapter in com.github.sample.MainActivity.onCreate(Bundle)')
145
+
146
+ spotbugs_issue2 = spotbugs_issues[1]
147
+ expect(spotbugs_issue2.rank).to eq(5)
148
+ expect(spotbugs_issue2.line).to eq(32)
149
+ expect(spotbugs_issue2.type).to eq(:warn)
150
+ expect(spotbugs_issue2.absolute_path).to eq('/Users/developer/project/sample/app/src/main/java/com/github/sample/view/ConversationAdapter.java')
151
+ expect(spotbugs_issue2.relative_path).to eq('app/src/main/java/com/github/sample/view/ConversationAdapter.java')
152
+ expect(spotbugs_issue2.description).to eq('Bad comparison of nonnegative value with -1 in com.github.sample.view.ConversationAdapter.setConversations(ArrayList)')
153
+ end
154
+
155
+ it 'Report without Gradle' do
156
+ allow_any_instance_of(Danger::DangerSpotbugs).to receive(:target_files).and_return([])
157
+
158
+ @spotbugs.report_file = 'spec/fixtures/spotbugs_report.xml'
159
+ @spotbugs.skip_gradle_task = false
160
+
161
+ expect { @spotbugs.report }.to raise_error('Could not find `gradlew` inside current directory')
162
+ end
163
+
164
+ it 'Report without existing report file' do
165
+ allow_any_instance_of(Danger::DangerSpotbugs).to receive(:target_files).and_return([])
166
+
167
+ @spotbugs.report_file = 'spec/fixtures/custom/spotbugs_report.xml'
168
+ @spotbugs.skip_gradle_task = true
169
+
170
+ expect { @spotbugs.report }.to raise_error('Could not find matching SpotBugs report files for ["spec/fixtures/custom/spotbugs_report.xml"] inside current directory')
171
+ end
172
+ end
173
+ end
174
+ end
metadata ADDED
@@ -0,0 +1,249 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: danger-spotbugs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mathieu Rul
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-03-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: danger-plugin-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: oga
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.15'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.15'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.2.14
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.2.14
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 10.5.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 10.5.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.10.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.10.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.11.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.11.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.5.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.5.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 2.2.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 2.2.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: yard
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.9.26
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.9.26
139
+ - !ruby/object:Gem::Dependency
140
+ name: guard
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 2.16.2
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 2.16.2
153
+ - !ruby/object:Gem::Dependency
154
+ name: guard-rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 4.7.3
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 4.7.3
167
+ - !ruby/object:Gem::Dependency
168
+ name: listen
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: 3.0.8
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: 3.0.8
181
+ - !ruby/object:Gem::Dependency
182
+ name: pry
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: 0.14.0
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: 0.14.0
195
+ description: A Danger plugin for SpotBugs.
196
+ email:
197
+ - mathroule@gmail.com
198
+ executables: []
199
+ extensions: []
200
+ extra_rdoc_files: []
201
+ files:
202
+ - ".github/workflows/publish.yml"
203
+ - ".github/workflows/test.yml"
204
+ - ".gitignore"
205
+ - ".rubocop.yml"
206
+ - Gemfile
207
+ - Gemfile.lock
208
+ - Guardfile
209
+ - LICENSE
210
+ - README.md
211
+ - Rakefile
212
+ - danger-spotbugs.gemspec
213
+ - lib/danger_plugin.rb
214
+ - lib/danger_spotbugs.rb
215
+ - lib/spotbugs/entity/bug_instance.rb
216
+ - lib/spotbugs/gem_version.rb
217
+ - lib/spotbugs/plugin.rb
218
+ - spec/entity/bug_instance_spec.rb
219
+ - spec/fixtures/spotbugs_report.xml
220
+ - spec/spec_helper.rb
221
+ - spec/spotbugs_spec.rb
222
+ homepage: https://github.com/mathroule/danger-spotbugs
223
+ licenses:
224
+ - MIT
225
+ metadata: {}
226
+ post_install_message:
227
+ rdoc_options: []
228
+ require_paths:
229
+ - lib
230
+ required_ruby_version: !ruby/object:Gem::Requirement
231
+ requirements:
232
+ - - ">="
233
+ - !ruby/object:Gem::Version
234
+ version: '0'
235
+ required_rubygems_version: !ruby/object:Gem::Requirement
236
+ requirements:
237
+ - - ">="
238
+ - !ruby/object:Gem::Version
239
+ version: '0'
240
+ requirements: []
241
+ rubygems_version: 3.2.3
242
+ signing_key:
243
+ specification_version: 4
244
+ summary: A Danger plugin for SpotBugs, see https://spotbugs.github.io.
245
+ test_files:
246
+ - spec/entity/bug_instance_spec.rb
247
+ - spec/fixtures/spotbugs_report.xml
248
+ - spec/spec_helper.rb
249
+ - spec/spotbugs_spec.rb