license_finder 0.8.0-java → 0.8.1-java

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.
@@ -1,47 +0,0 @@
1
- Feature: License Finder command line executable
2
- So that I can report and manage my application's dependencies and licenses to my business
3
- As an application developer
4
- I want a command-line interface
5
-
6
- Scenario: Running without a configuration file
7
- Given I have an app with license finder
8
- And my app does not have a "config" directory
9
- When I run "license_finder -q"
10
- Then I should see a "config" directory
11
- And I should see the file "config/license_finder.yml" with the following content:
12
- """
13
- ---
14
- whitelist:
15
- #- MIT
16
- #- Apache 2.0
17
- ignore_groups:
18
- #- test
19
- #- development
20
- dependencies_file_dir: './doc/'
21
-
22
- """
23
-
24
- Scenario: Auditing an application with non-whitelisted licenses
25
- Given I have an app with license finder
26
- And my app depends on a gem "mit_licensed_gem" licensed with "MIT"
27
- When I run "license_finder -q"
28
- Then it should exit with status code 1
29
- And I should see "mit_licensed_gem" in its output
30
-
31
- Scenario: Auditing an application with whitelisted licenses
32
- Given I have an app with license finder
33
- And my app depends on a gem "mit_licensed_gem" licensed with "MIT"
34
- When I run "license_finder -q"
35
- Then I should see "mit_licensed_gem" in its output
36
- When I whitelist the following licenses: "MIT, other"
37
- And I run "license_finder -q"
38
- Then I should see "All gems are approved for use" in its output
39
- And it should exit with status code 0
40
-
41
- Scenario: Keep manually set license dependencies
42
- Given I have a project that depends on mime-types
43
- And I manually set the license type to Ruby
44
- And I run license_finder again
45
- Then the mime-types license is set to Ruby
46
- When I run license_finder again
47
- Then the mime-types license is set to Ruby
@@ -1,37 +0,0 @@
1
- Feature: License Finder rake task
2
- So that I can break my build suite if someone adds a dependency to the application with a non-whitelisted license
3
- As an application developer
4
- I want a rake task that exit's with a non-zero exit status if there are any action items
5
-
6
- Scenario: Running without a configuration file
7
- Given I have an app with rake and license finder
8
- And my app does not have a "config" directory
9
- When I run "rake license_finder"
10
- Then I should see a "config" directory
11
- And I should see the file "config/license_finder.yml" with the following content:
12
- """
13
- ---
14
- whitelist:
15
- #- MIT
16
- #- Apache 2.0
17
- ignore_groups:
18
- #- test
19
- #- development
20
- dependencies_file_dir: './doc/'
21
-
22
- """
23
-
24
- Scenario: Auditing an application with non-whitelisted licenses
25
- Given I have an app with rake and license finder
26
- And my app depends on a gem "mit_licensed_gem" licensed with "MIT"
27
- When I run "rake license_finder"
28
- Then it should exit with status code 1
29
- And I should see "mit_licensed_gem" in its output
30
-
31
- Scenario: Auditing an application with whitelisted licenses
32
- Given I have an app with rake and license finder
33
- And my app depends on a gem "mit_licensed_gem" licensed with "MIT"
34
- And I whitelist the following licenses: "MIT, other"
35
- When I run "rake license_finder"
36
- Then it should exit with status code 0
37
- And I should see "All gems are approved for use" in its output
@@ -1,25 +0,0 @@
1
- require 'license_finder'
2
- require 'fileutils'
3
- require 'pathname'
4
- require 'bundler'
5
- require 'capybara'
6
-
7
- Given /^I have a project that depends on mime\-types$/ do
8
- @user = ::DSL::User.new
9
- @user.create_rails_app
10
- @user.add_gem_dependency('mime-types')
11
- @user.bundle_app
12
- @user.execute_command "license_finder"
13
- end
14
-
15
- Given /^I manually set the license type to Ruby$/ do
16
- @output = @user.execute_command "license_finder -l Ruby mime-types"
17
- end
18
-
19
- When /^I run license_finder again$/ do
20
- @output = @user.execute_command "license_finder -q"
21
- end
22
-
23
- Then /^the mime\-types license is set to Ruby$/ do
24
- @output.should =~ /mime-types.*Ruby/
25
- end
@@ -1,376 +0,0 @@
1
- require 'fileutils'
2
- require 'pathname'
3
- require 'bundler'
4
- require 'capybara'
5
-
6
- Given /^I have a rails app(?:lication)? with license finder$/ do
7
- @user = ::DSL::User.new
8
- @user.create_rails_app
9
- end
10
-
11
- Given /^I have an app(?:lication)? with license finder$/ do
12
- @user = ::DSL::User.new
13
- @user.create_nonrails_app
14
- end
15
-
16
- Given /^I have an app(?:lication)? with rake and license finder$/ do
17
- @user = ::DSL::User.new
18
- @user.create_nonrails_app
19
- @user.add_license_finder_to_rakefile
20
- end
21
-
22
- Given /^my app(?:lication)? does not have a "([^"]+)" directory$/ do |name|
23
- path = @user.app_path(name)
24
-
25
- FileUtils.rm_rf(path)
26
- File.should_not be_exists(path)
27
- end
28
-
29
- Given /^my (?:rails )?app(?:lication)? depends on a gem "(.*?)" licensed with "(.*?)"$/ do |gem_name, license|
30
- @user.add_dependency_to_app gem_name, :license => license
31
- end
32
-
33
- Given /^my (?:rails )?app(?:lication)? depends on a gem "(.*?)" licensed with "(.*?)" in the "(.*?)" bundler groups$/ do |gem_name, license, bundler_groups|
34
- @user.add_dependency_to_app gem_name, :license => license, :bundler_groups => bundler_groups
35
- end
36
-
37
- Given /^I whitelist the "(.*?)" license$/ do |license|
38
- @user.configure_license_finder_whitelist [license]
39
- end
40
-
41
- Given /^I whitelist the following licenses: "([^"]*)"$/ do |licenses|
42
- @user.configure_license_finder_whitelist licenses.split(", ")
43
- end
44
-
45
- Given /^I have a legacy dependencies\.yml file with "(.*?)" approved with its "(.*?)" license$/ do |gem_name, license_name|
46
- @user.modifying_dependencies_file do |f|
47
- f.write <<-YAML
48
- - name: #{gem_name}
49
- version: 1.5.0
50
- license: #{license_name}
51
- approved: true
52
- notes: ''
53
- license_files:
54
- - path: /some/path/to/files/that/are/rad
55
- YAML
56
- end
57
- end
58
-
59
- And /^I have a legacy dependencies\.yml file with readme_files entry for gem "(.*?)"$/ do |gem_name|
60
- @user.modifying_dependencies_file do |f|
61
- f.write <<-YAML
62
- - name: #{gem_name}
63
- version: 1.5.0
64
- license: some_license
65
- approved: true
66
- notes: ''
67
- license_files:
68
- - path: /some/path/to/files/that/are/rad
69
- readme_files:
70
- - path: /some/path/to/files/that/are/rad/readme
71
- YAML
72
- end
73
- end
74
-
75
- Given /^I have a legacy dependencies\.yml file with a blank readme_files entry for gem "(.*?)"$/ do |gem_name|
76
- @user.modifying_dependencies_file do |f|
77
- f.write(<<-YAML)
78
- - name: #{gem_name}
79
- version: 1.5.0
80
- license: some_license
81
- approved: true
82
- notes: ''
83
- license_files:
84
- - path: /some/path/to/files/that/are/rad
85
- readme_files:
86
- YAML
87
- end
88
- end
89
-
90
- When /^I run "(.*?)"$/ do |command|
91
- @output = @user.execute_command command
92
- end
93
-
94
- When /^I update the settings for "([^"]*)" with the following content:$/ do |gem, text|
95
- @user.update_gem(gem, YAML.load(text))
96
- end
97
-
98
- When /^I add the following content to "([^"]*)":$/ do |filename, text|
99
- @user.append_to_file(filename, @content = text)
100
- end
101
-
102
- When /^my app(?:lication)? depends on a gem "([^"]*)" with:$/ do |gem_name, gem_info|
103
- info = gem_info.hashes.first
104
- @user.add_dependency_to_app(gem_name,
105
- :license => info["license"],
106
- :summary => info["summary"],
107
- :description => info["description"],
108
- :version => info["version"],
109
- :homepage => info["homepage"],
110
- :bundler_groups => info["bundler_groups"]
111
- )
112
- end
113
-
114
- When /^the text "([^"]*)" should link to "([^"]*)"$/ do |text, link|
115
- html = Capybara.string File.read(@user.dependencies_html_path)
116
- html.all(:xpath, "//a[@href='#{link}']").first.text.should == text
117
- end
118
-
119
- When /^"([^"]*)" is an alternative name for the "MIT" license$/ do |alternative_name|
120
- # this step is simply for readability
121
- end
122
-
123
- When /^I whitelist the "([^"]*)" bundler group$/ do |group|
124
- @user.configure_license_finder_bundler_whitelist(group)
125
- end
126
-
127
- Then(/^I should see other_license_gem set to MIT license$/) do
128
- @output.should =~ /other_license_gem.*MIT/
129
- end
130
-
131
- Then /^I should see a "([^"]+)" directory$/ do |name|
132
- File.should be_exists(@user.app_path(name))
133
- end
134
-
135
- Then /^I should see "(.*?)" in its output$/ do |gem_name|
136
- @output.should include gem_name
137
- end
138
-
139
- Then /^I should not see "(.*?)" in its output$/ do |gem_name|
140
- @output.should_not include gem_name
141
- end
142
-
143
- Then /^I should see the file "([^"]*)" with the following content:$/ do |filename, text|
144
- File.read(@user.app_path(filename)).should == text.gsub(/^\s+/, "")
145
- end
146
-
147
- Then /^I should see the file "([^"]*)" containing:$/ do |filename, text|
148
- File.read(@user.app_path(filename)).should include(text.gsub(/^\s+/, ""))
149
- end
150
-
151
- Then /^I should see exactly one entry for "(.*?)" in "(.*?)"$/ do |gem_name, filename|
152
- file_contents = File.read(@user.app_path(filename))
153
- file_contents.scan(/#{gem_name}/).size.should == 1
154
- end
155
-
156
- Then /^I should not see an entry "(.*?)" for gem "(.*?)" in my dependencies\.yml$/ do |entry_key, gem_name|
157
- settings = YAML.load(File.read(@user.dependencies_file_path))
158
- gem_settings = settings.detect { |gem| gem['name'] == gem_name }
159
- gem_settings.should_not have_key entry_key
160
- end
161
-
162
- Then /^it should exit with status code (\d)$/ do |status|
163
- $?.exitstatus.should == status.to_i
164
- end
165
-
166
- Then /^I should see the "([^"]*)" in the html flagged as "([^"]*)"$/ do |gem_name, css_class|
167
- html = File.read(@user.dependencies_html_path)
168
- page = Capybara.string(html)
169
- gpl_gem = page.find("##{gem_name}")
170
- gpl_gem[:class].should == css_class
171
- end
172
-
173
- Then /^I should see (?:the )?"([^"]*)" in the html with the following details:$/ do |gem_name, table|
174
- html = File.read(@user.dependencies_html_path)
175
- page = Capybara.string(html)
176
- section = page.find("##{gem_name}")
177
-
178
- table.hashes.first.each do |property_name, property_value|
179
- section.should have_content property_value
180
- end
181
- end
182
-
183
- Then /^I should see "([^"]*)" in the html$/ do |text|
184
- html = File.read(@user.dependencies_html_path)
185
- page = Capybara.string(html)
186
-
187
- page.should have_content text
188
- end
189
-
190
- module DSL
191
- class User
192
- def create_nonrails_app
193
- reset_projects!
194
-
195
- `cd #{projects_path} && bundle gem #{app_name}`
196
-
197
- add_gem_dependency('rake')
198
- add_gem_dependency('license_finder', :path => root_path)
199
-
200
- bundle_app
201
- end
202
-
203
- def create_rails_app
204
- reset_projects!
205
-
206
- `bundle exec rails new #{app_path} --skip-bundle`
207
-
208
- add_gem_dependency('license_finder', :path => root_path)
209
-
210
- bundle_app
211
- end
212
-
213
- def add_license_finder_to_rakefile
214
- add_to_rakefile <<-RUBY
215
- require 'bundler/setup'
216
- require 'license_finder'
217
- LicenseFinder.load_rake_tasks
218
- RUBY
219
- end
220
-
221
- def update_gem(name, attrs)
222
- file_contents = YAML.load(File.read(dependencies_file_path))
223
-
224
- index = file_contents.index { |gem| gem['name'] == name }
225
- file_contents[index].merge!(attrs)
226
-
227
- File.open(dependencies_file_path, "w") do |f|
228
- f.puts file_contents.to_yaml
229
- end
230
- end
231
-
232
- def append_to_file(filename, text)
233
- File.open(File.join(app_path, filename), "a") do |f|
234
- f.puts text
235
- end
236
- end
237
-
238
- def add_dependency_to_app(gem_name, options={})
239
- license = options.fetch(:license)
240
- summary = options.fetch(:summary, "")
241
- description = options.fetch(:description, "")
242
- bundler_groups = options.fetch(:bundler_groups, "").to_s.split(',').map(&:strip)
243
- version = options[:version] || "0.0.0"
244
- homepage = options[:homepage]
245
-
246
- gem_dir = File.join(projects_path, gem_name)
247
-
248
- FileUtils.mkdir(gem_dir)
249
- File.open(File.join(gem_dir, "#{gem_name}.gemspec"), 'w') do |file|
250
- file.write <<-GEMSPEC
251
- Gem::Specification.new do |s|
252
- s.name = "#{gem_name}"
253
- s.version = "#{version}"
254
- s.author = "Cucumber"
255
- s.summary = "#{summary}"
256
- s.license = "#{license}"
257
- s.description = "#{description}"
258
- s.homepage = "#{homepage}"
259
- end
260
- GEMSPEC
261
- end
262
-
263
- gem_options = {}
264
- gem_options[:path] = File.join(projects_path, gem_name)
265
- gem_options[:groups] = bundler_groups unless bundler_groups.empty?
266
-
267
- add_gem_dependency(gem_name, gem_options)
268
-
269
- bundle_app
270
- end
271
-
272
- def configure_license_finder_whitelist(whitelisted_licenses=[])
273
- FileUtils.mkdir_p(config_path)
274
- File.open(File.join(config_path, "license_finder.yml"), "w") do |f|
275
- f.write({'whitelist' => whitelisted_licenses}.to_yaml)
276
- end
277
- end
278
-
279
- def configure_license_finder_bundler_whitelist(whitelisted_groups=[])
280
- whitelisted_groups = Array whitelisted_groups
281
- FileUtils.mkdir_p(config_path)
282
- File.open(File.join(config_path, "license_finder.yml"), "w") do |f|
283
- f.write({'ignore_groups' => whitelisted_groups}.to_yaml)
284
- end
285
- end
286
-
287
- def execute_command(command)
288
- Bundler.with_clean_env do
289
- @output = `cd #{app_path} && bundle exec #{command}`
290
- end
291
-
292
- @output
293
- end
294
-
295
- def app_path(sub_directory = nil)
296
- path = app_path = Pathname.new(File.join(projects_path, app_name)).cleanpath.to_s
297
-
298
- if sub_directory
299
- path = Pathname.new(File.join(app_path, sub_directory)).cleanpath.to_s
300
-
301
- raise "#{name} is outside of the app" unless path =~ %r{^#{app_path}/}
302
- end
303
-
304
- path
305
- end
306
-
307
- def config_path
308
- File.join(app_path, 'config')
309
- end
310
-
311
- def doc_path
312
- File.join(app_path, 'doc')
313
- end
314
-
315
- def dependencies_file_path
316
- File.join(doc_path, 'dependencies.yml')
317
- end
318
-
319
- def dependencies_html_path
320
- File.join(doc_path, 'dependencies.html')
321
- end
322
-
323
- def add_gem_dependency(name, options = {})
324
- line = "gem #{name.inspect}"
325
- line << ", " + options.inspect unless options.empty?
326
-
327
- add_to_gemfile(line)
328
- end
329
-
330
- def bundle_app
331
- Bundler.with_clean_env do
332
- `bundle install --gemfile=#{File.join(app_path, "Gemfile")} --path=#{bundle_path}`
333
- end
334
- end
335
-
336
- def modifying_dependencies_file
337
- FileUtils.mkdir_p(File.dirname(dependencies_file_path))
338
- File.open(dependencies_file_path, 'w+') { |f| yield f }
339
- end
340
-
341
- private
342
-
343
- def add_to_gemfile(line)
344
- `echo #{line.inspect} >> #{File.join(app_path, "Gemfile")}`
345
- end
346
-
347
- def add_to_rakefile(line)
348
- `echo #{line.inspect} >> #{File.join(app_path, "Rakefile")}`
349
- end
350
-
351
- def app_name
352
- "my_app"
353
- end
354
-
355
- def sandbox_path
356
- File.join(root_path, "tmp")
357
- end
358
-
359
- def projects_path
360
- File.join(sandbox_path, "projects")
361
- end
362
-
363
- def bundle_path
364
- File.join(sandbox_path, "bundle")
365
- end
366
-
367
- def reset_projects!
368
- `rm -rf #{projects_path}`
369
- `mkdir -p #{projects_path}`
370
- end
371
-
372
- def root_path
373
- Pathname.new(File.join(File.dirname(__FILE__), "..", "..")).realpath.to_s
374
- end
375
- end
376
- end