license_finder 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,9 @@
1
+ Given(/^I have an app with license finder that depends on a gem with license and version details$/) do
2
+ @user = ::DSL::User.new
3
+ @user.create_nonrails_app
4
+ @user.add_dependency_to_app('info_gem', license: 'MIT', version: '1.1.1')
5
+ end
6
+
7
+ Then(/^I should see those version and license details in the dependencies\.txt file$/) do
8
+ File.read(@user.app_path("doc/dependencies.txt")).should include "info_gem, 1.1.1, MIT"
9
+ end
@@ -0,0 +1,14 @@
1
+ Given(/^I have an app with license finder that depends on an MIT license$/) do
2
+ @user = ::DSL::User.new
3
+ @user.create_nonrails_app
4
+ @user.add_dependency_to_app 'mit_gem', :license => 'MIT'
5
+ end
6
+
7
+ When(/^I whitelist the Expat license$/) do
8
+ @user.configure_license_finder_whitelist ["Expat"]
9
+ @output = @user.execute_command 'license_finder -q'
10
+ end
11
+
12
+ Then(/^I should not see a MIT licensed gem unapproved$/) do
13
+ @output.should_not include 'mit_gem'
14
+ end
@@ -4,24 +4,6 @@ Feature: Text Report
4
4
  I want license finder to generate an easy-to-understand text report
5
5
 
6
6
  Scenario: Viewing dependencies
7
- Given I have an app with license finder
8
- And my application depends on a gem "descriptive_gem" with:
9
- | license | version |
10
- | MIT | 1.1.1 |
11
- When I run "license_finder"
12
- Then I should see the file "doc/dependencies.txt" containing:
13
- """
14
- descriptive_gem, 1.1.1, MIT
15
- """
16
-
17
- Scenario: Viewing dependencies after multiple runs
18
- Given I have an app with license finder
19
- And my application depends on a gem "descriptive_gem" with:
20
- | license | version |
21
- | MIT | 1.1.1 |
22
- When I run "license_finder"
23
- And I run "license_finder"
24
- Then I should see the file "doc/dependencies.txt" containing:
25
- """
26
- descriptive_gem, 1.1.1, MIT
27
- """
7
+ Given I have an app with license finder that depends on a gem with license and version details
8
+ When I run license_finder
9
+ Then I should see those version and license details in the dependencies.txt file
@@ -3,22 +3,7 @@ Feature: Whitelist licenses
3
3
  I want to whitelist certain OSS licenses that my business has pre-approved
4
4
  So that any dependencies with those licenses do not show up as action items
5
5
 
6
- Scenario: Auditing an application with whitelisted licenses
7
- Given I have an app with license finder
8
- And my app depends on a gem "mit_licensed_gem" licensed with "MIT"
9
- When I run "license_finder"
10
- Then I should see "mit_licensed_gem" in its output
11
- When I whitelist the following licenses: "MIT, other"
12
- And I run "license_finder"
13
- Then I should see "All gems are approved for use" in its output
14
- And it should exit with status code 0
15
-
16
6
  Scenario: Whitelist with MIT License alternative name "Expat" should whitelist "MIT" licenses
17
- Given I have an app with license finder
18
- And "Expat" is an alternative name for the "MIT" license
19
- And my app depends on a gem "mit_licensed_gem" licensed with "MIT"
20
- When I run "license_finder"
21
- Then I should see "mit_licensed_gem" in its output
22
- When I whitelist the "Expat" license
23
- And I run "license_finder"
24
- Then I should not see "mit_licensed_gem" in its output
7
+ Given I have an app with license finder that depends on an MIT license
8
+ When I whitelist the Expat license
9
+ Then I should not see a MIT licensed gem unapproved
@@ -2,7 +2,7 @@ require './lib/license_finder/platform'
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "license_finder"
5
- s.version = "0.8.0"
5
+ s.version = "0.8.1"
6
6
  s.authors = ["Jacob Maine", "Matthew Kane Parker", "Ian Lesperance", "David Edwards", "Paul Meskers", "Brent Wheeldon", "David Tengdin"]
7
7
  s.email = ["licensefinder@pivotalabs.com"]
8
8
  s.homepage = "https://github.com/pivotal/LicenseFinder"
@@ -22,10 +22,11 @@ Gem::Specification.new do |s|
22
22
  s.add_dependency "sequel"
23
23
  s.add_dependency LicenseFinder::Platform.sqlite_gem
24
24
 
25
- %w(rspec rake xpath capybara cucumber database_cleaner).each do |gem|
25
+ %w(rspec rake xpath cucumber database_cleaner).each do |gem|
26
26
  s.add_development_dependency gem
27
27
  end
28
28
 
29
+ s.add_development_dependency "capybara", "~> 2.0.0"
29
30
  s.add_development_dependency "rails", "~> 3.2.0"
30
31
 
31
32
  s.files = `git ls-files`.split("\n")
data/readme.md CHANGED
@@ -93,6 +93,16 @@ $ license_finder -a awesome_gpl_gem
93
93
 
94
94
  If you rerun `license_finder`, you should no longer see `awesome_gpl_gem` in the output.
95
95
 
96
+ ## Upgrade for pre 0.8.0 users
97
+
98
+ If you wish to cleanup your root directory you can run:
99
+
100
+ ```sh
101
+ $ license_finder -m
102
+ ```
103
+
104
+ This will move your dependencies.* files to the /doc directory and update the config.
105
+
96
106
  ## Compatibility
97
107
 
98
108
  license_finder is compatible with ruby 1.9, and ruby 2.0. There is also experimental support for jruby.
@@ -0,0 +1,17 @@
1
+ ## Tips on releasing
2
+
3
+ Build the gem for both ruby and jruby (use a later version of each ruby, if desired)
4
+
5
+ ```sh
6
+ $ rvm use jruby-1.7.3-d19
7
+ $ rake build
8
+ $ rvm use ruby-1.9.3-p392
9
+ $ rake build
10
+ ```
11
+
12
+ Push both versions of the gem
13
+
14
+ ```sh
15
+ $ rake release # will push default MRI build of gem, and importantly, tag the gem
16
+ $ gem push pkg/license_finder-LATEST_VERSION_HERE-java.gem
17
+ ```
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: license_finder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -15,7 +15,7 @@ authors:
15
15
  autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
- date: 2013-04-09 00:00:00.000000000 Z
18
+ date: 2013-04-14 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: bundler
@@ -114,7 +114,7 @@ dependencies:
114
114
  - !ruby/object:Gem::Version
115
115
  version: '0'
116
116
  - !ruby/object:Gem::Dependency
117
- name: capybara
117
+ name: cucumber
118
118
  requirement: !ruby/object:Gem::Requirement
119
119
  none: false
120
120
  requirements:
@@ -130,7 +130,7 @@ dependencies:
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  - !ruby/object:Gem::Dependency
133
- name: cucumber
133
+ name: database_cleaner
134
134
  requirement: !ruby/object:Gem::Requirement
135
135
  none: false
136
136
  requirements:
@@ -146,21 +146,21 @@ dependencies:
146
146
  - !ruby/object:Gem::Version
147
147
  version: '0'
148
148
  - !ruby/object:Gem::Dependency
149
- name: database_cleaner
149
+ name: capybara
150
150
  requirement: !ruby/object:Gem::Requirement
151
151
  none: false
152
152
  requirements:
153
- - - ! '>='
153
+ - - ~>
154
154
  - !ruby/object:Gem::Version
155
- version: '0'
155
+ version: 2.0.0
156
156
  type: :development
157
157
  prerelease: false
158
158
  version_requirements: !ruby/object:Gem::Requirement
159
159
  none: false
160
160
  requirements:
161
- - - ! '>='
161
+ - - ~>
162
162
  - !ruby/object:Gem::Version
163
- version: '0'
163
+ version: 2.0.0
164
164
  - !ruby/object:Gem::Dependency
165
165
  name: rails
166
166
  requirement: !ruby/object:Gem::Requirement
@@ -193,6 +193,7 @@ files:
193
193
  - .gitignore
194
194
  - .rspec
195
195
  - .travis.yml
196
+ - CHANGELOG.rdoc
196
197
  - Gemfile
197
198
  - LICENSE
198
199
  - Rakefile
@@ -207,14 +208,20 @@ files:
207
208
  - db/migrate/201304011027_allow_null_dependency_version.rb
208
209
  - db/migrate/201304020947_change_table_name_licenses_to_license_aliases.rb
209
210
  - features/approve_dependencies.feature
211
+ - features/cli.feature
210
212
  - features/html_report.feature
211
213
  - features/ignore_bundle_groups.feature
212
- - features/license_finder.feature
213
- - features/license_finder_rake_task.feature
214
214
  - features/rails_rake.feature
215
215
  - features/set_license.feature
216
- - features/step_definitions/license_finder_steps.rb
217
- - features/step_definitions/steps.rb
216
+ - features/step_definitions/approve_dependencies_steps.rb
217
+ - features/step_definitions/cli_steps.rb
218
+ - features/step_definitions/html_report_steps.rb
219
+ - features/step_definitions/ignore_bundle_groups_steps.rb
220
+ - features/step_definitions/rails_rake_steps.rb
221
+ - features/step_definitions/set_license_steps.rb
222
+ - features/step_definitions/shared_steps.rb
223
+ - features/step_definitions/text_report_steps.rb
224
+ - features/step_definitions/whitelist_steps.rb
218
225
  - features/text_report.feature
219
226
  - features/whitelist.feature
220
227
  - files/license_finder.yml
@@ -264,6 +271,7 @@ files:
264
271
  - lib/templates/text_report.erb
265
272
  - license_finder.gemspec
266
273
  - readme.md
274
+ - release.md
267
275
  - spec/fixtures/APACHE-2-LICENSE
268
276
  - spec/fixtures/GPLv2
269
277
  - spec/fixtures/ISC-LICENSE
@@ -332,7 +340,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
332
340
  version: '0'
333
341
  segments:
334
342
  - 0
335
- hash: -1906227057992874758
343
+ hash: 3257953094972143579
336
344
  required_rubygems_version: !ruby/object:Gem::Requirement
337
345
  none: false
338
346
  requirements:
@@ -341,7 +349,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
341
349
  version: '0'
342
350
  segments:
343
351
  - 0
344
- hash: -1906227057992874758
352
+ hash: 3257953094972143579
345
353
  requirements: []
346
354
  rubyforge_project:
347
355
  rubygems_version: 1.8.25
@@ -350,14 +358,20 @@ specification_version: 3
350
358
  summary: Audit the OSS licenses of your application's dependencies.
351
359
  test_files:
352
360
  - features/approve_dependencies.feature
361
+ - features/cli.feature
353
362
  - features/html_report.feature
354
363
  - features/ignore_bundle_groups.feature
355
- - features/license_finder.feature
356
- - features/license_finder_rake_task.feature
357
364
  - features/rails_rake.feature
358
365
  - features/set_license.feature
359
- - features/step_definitions/license_finder_steps.rb
360
- - features/step_definitions/steps.rb
366
+ - features/step_definitions/approve_dependencies_steps.rb
367
+ - features/step_definitions/cli_steps.rb
368
+ - features/step_definitions/html_report_steps.rb
369
+ - features/step_definitions/ignore_bundle_groups_steps.rb
370
+ - features/step_definitions/rails_rake_steps.rb
371
+ - features/step_definitions/set_license_steps.rb
372
+ - features/step_definitions/shared_steps.rb
373
+ - features/step_definitions/text_report_steps.rb
374
+ - features/step_definitions/whitelist_steps.rb
361
375
  - features/text_report.feature
362
376
  - features/whitelist.feature
363
377
  - spec/fixtures/APACHE-2-LICENSE
@@ -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