license_finder 0.4.5 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/README.markdown +43 -11
  2. data/bin/license_finder +2 -5
  3. data/features/executables/license_finder.feature +19 -0
  4. data/features/rake_tasks/action_items.feature +18 -4
  5. data/features/rake_tasks/action_items_ok.feature +10 -7
  6. data/features/rake_tasks/generate_dependencies.feature +43 -12
  7. data/features/rake_tasks/init.feature +8 -1
  8. data/features/rake_tasks/regressions.feature +18 -0
  9. data/features/step_definitions/steps.rb +163 -43
  10. data/lib/license_finder.rb +9 -4
  11. data/lib/license_finder/{gem_spec_details.rb → bundled_gem.rb} +12 -41
  12. data/lib/license_finder/bundler_dependency_query.rb +51 -0
  13. data/lib/license_finder/cli.rb +16 -0
  14. data/lib/license_finder/dependency.rb +80 -28
  15. data/lib/license_finder/dependency_list.rb +20 -35
  16. data/lib/license_finder/finder.rb +2 -2
  17. data/lib/license_finder/license.rb +74 -0
  18. data/lib/license_finder/license/apache.rb +5 -0
  19. data/lib/license_finder/license/bsd.rb +2 -0
  20. data/lib/license_finder/license/gplv2.rb +2 -0
  21. data/lib/license_finder/license/isc.rb +2 -0
  22. data/lib/license_finder/license/lgpl.rb +2 -0
  23. data/lib/license_finder/license/mit.rb +20 -0
  24. data/lib/license_finder/license/new_bsd.rb +5 -0
  25. data/lib/license_finder/license/ruby.rb +11 -0
  26. data/lib/license_finder/license/simplified_bsd.rb +5 -0
  27. data/lib/license_finder/{file_parser.rb → possible_license_file.rb} +9 -17
  28. data/lib/tasks/license_finder.rake +8 -8
  29. data/lib/templates/{Apache-2.0-body → Apache.txt} +0 -0
  30. data/lib/templates/BSD.txt +24 -0
  31. data/lib/templates/{GPL-2.0-body → GPLv2.txt} +0 -0
  32. data/lib/templates/{ISC-body → ISC.txt} +0 -0
  33. data/lib/templates/{LGPL-body → LGPL.txt} +0 -0
  34. data/lib/templates/{MIT-body → MIT.txt} +0 -0
  35. data/lib/templates/NewBSD.txt +21 -0
  36. data/lib/templates/Ruby.txt +52 -0
  37. data/lib/templates/SimplifiedBSD.txt +23 -0
  38. data/license_finder.gemspec +4 -3
  39. data/spec/fixtures/{no_license/.gitkeep → license_names/Licence.rdoc} +0 -0
  40. data/spec/lib/license_finder/bundled_gem_spec.rb +148 -0
  41. data/spec/lib/license_finder/dependency_list_spec.rb +133 -144
  42. data/spec/lib/license_finder/dependency_spec.rb +189 -5
  43. data/spec/lib/license_finder/license/apache_spec.rb +7 -0
  44. data/spec/lib/license_finder/license/bsd_spec.rb +41 -0
  45. data/spec/lib/license_finder/license/gplv2_spec.rb +7 -0
  46. data/spec/lib/license_finder/license/isc_spec.rb +7 -0
  47. data/spec/lib/license_finder/license/lgpl_spec.rb +7 -0
  48. data/spec/lib/license_finder/license/mit_spec.rb +33 -0
  49. data/spec/lib/license_finder/license/new_bsd_spec.rb +35 -0
  50. data/spec/lib/license_finder/license/ruby_spec.rb +19 -0
  51. data/spec/lib/license_finder/license/simplified_bsd_spec.rb +7 -0
  52. data/spec/lib/license_finder/possible_license_file_spec.rb +42 -0
  53. data/spec/spec_helper.rb +6 -0
  54. data/spec/support/license_examples.rb +24 -0
  55. metadata +89 -33
  56. data/lib/license_finder/license_file.rb +0 -98
  57. data/spec/fixtures/apache_licensed_gem/LICENSE +0 -191
  58. data/spec/fixtures/gplv2_licensed_gem/LICENSE +0 -339
  59. data/spec/fixtures/isc_licensed_gem/LICENSE +0 -10
  60. data/spec/fixtures/lgpl_licensed_gem/LICENSE +0 -165
  61. data/spec/fixtures/mit_licensed_gem_in_README/README.rdoc +0 -222
  62. data/spec/fixtures/mit_licensed_gem_via_url/README +0 -210
  63. data/spec/fixtures/mit_licensed_with_hashes/MIT-LICENSE +0 -20
  64. data/spec/lib/license_finder/file_parser_spec.rb +0 -16
  65. data/spec/lib/license_finder/gem_spec_details_spec.rb +0 -229
  66. data/spec/lib/license_finder/license_file_spec.rb +0 -155
data/README.markdown CHANGED
@@ -24,30 +24,62 @@ This is where you should add licenses which are allowed on the project, so they
24
24
 
25
25
  ## Usage
26
26
 
27
- Once you've whitelisted licenses, you can then tell license finder to analyze your Gemfile:
27
+ Once you've whitelisted licenses, you can then tell license finder to analyze your Gemfile and generate a list of
28
+ dependencies that have non-whitelisted licenses:
28
29
 
29
30
  ```sh
30
- $ bundle exec rake license:generate_dependencies
31
+ $ bundle exec rake license:action_items
31
32
  ```
32
33
 
33
- This will write out a dependencies.yml and dependencies.txt file in the root of your project.
34
+ This will write out a dependencies.yml and dependencies.txt file in the root of your project, as well as
35
+ output a list of unapproved dependencies to the console. It will also return a non-zero exit status if there
36
+ unapproved dependencies. You could use this in a CI build, for example, to alert you whenever someone adds an
37
+ unapproved dependency to the project.
34
38
 
35
39
  It will also merge in an existing dependencies.yml file, if one exists (i.e., you've previously run this command
36
40
  and then edited the resulting file).
37
41
 
38
- ### Action Items
42
+ ### Manually approving dependencies
39
43
 
40
- Once you've generated a `dependencies.yml` file via the `rake license:generate_dependencies` file, you can tell
41
- License Finder to output a list of dependencies that have non-whitelisted licenses:
44
+ Whenever you have a dependency that falls outside of your whitelist, `rake license:action_items` will tell you.
45
+ If your business decides that this is an acceptable risk, you can manually approve the dependency by finding its
46
+ section in the `dependencies.yml` file and setting its `approved` attribute to true. For example, lets assume you've only
47
+ whitelisted the "MIT" license in your `config/license_finder.yml`. You then add the 'awesome_gpl_gem' to your Gemfile,
48
+ which we'll assume is licensed with the `GPL` license. You then run `rake license_finder:action_items` and see
49
+ the gem listed in the output:
42
50
 
43
- ```sh
44
- $ bundle exec rake license:action_items
51
+ ```txt
52
+ awesome_gpl_gem 1.0.0, GPL
53
+ ```
54
+
55
+ Your business tells you that in this case, it's acceptable to use this gem. You should now update your `dependencies.yml`
56
+ file, setting the `approved` attribute to `true` for the `awesome_gpl_gem` section:
57
+
58
+ ```yaml
59
+ - name: awesome_gpl_gem
60
+ version: 1.0.0
61
+ license: GPL
62
+ approved: true
45
63
  ```
46
64
 
47
- This will output a list of unapproved dependencies to the console.
65
+ If you rerun `rake license:action_items`, you should no longer see `awesome_gpl_gem` in the output.
66
+
67
+
68
+ ## Manually managing Javascript Dependencies
69
+
70
+ License Finder currently has no method for automatically detecting third-party javascript libraries in your application
71
+ and alerting you to license violations. However, you can manually add javascript dependencies to your `dependencies.yml`
72
+ file:
73
+
74
+ ```yaml
75
+ - name: "my_javascript_library"
76
+ version: "0.0.0"
77
+ license: "GPL"
78
+ approved: false
79
+ ```
48
80
 
49
- Similarly, `bundle exec rake license:action_items:ok` will return a non-zero exit status if there unapproved dependencies.
50
- You could use this in a CI build, for example, to alert you whenever someone adds an unapproved dependency to the project.
81
+ You could then update the "approved" attribute to true once you have signoff from your business. License Finder will
82
+ remember any manually added licenses between successive runs.
51
83
 
52
84
 
53
85
  ## Usage outside Rails
data/bin/license_finder CHANGED
@@ -1,7 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'pathname'
4
- $LOAD_PATH.unshift Pathname.new(__FILE__).dirname + ".." + "lib"
5
- require "license_finder"
6
-
7
- LicenseFinder::Finder.new.from_bundler.each { |lf| puts lf.to_s(ARGV.first == "--with-licenses") }
3
+ require 'license_finder'
4
+ LicenseFinder::CLI.new.check_for_action_items
@@ -0,0 +1,19 @@
1
+ Feature: License Finder command line executable
2
+
3
+ Scenario: I want to check if any of my dependencies are not approved
4
+ Given I have an application setup with rake and license finder
5
+ And my app depends on a gem "gpl_licensed_gem" licensed with "GPL"
6
+ And my app depends on a gem "mit_licensed_gem" licensed with "MIT"
7
+ And I whitelist the "MIT" license
8
+ When I run "license_finder"
9
+ Then I should see "gpl_licensed_gem" in its output
10
+ And I should not see "mit_licensed_gem" in its output
11
+ And it should exit with status code 1
12
+
13
+ Scenario: I want my build to pass when all dependencies are approved
14
+ Given I have an application setup with rake and license finder
15
+ And my app depends on a gem "mit_licensed_gem" licensed with "MIT"
16
+ And I whitelist the following licenses: "MIT, other"
17
+ When I run "license_finder"
18
+ Then it should exit with status code 0
19
+ And I should see "All gems are approved for use" in its output
@@ -3,11 +3,25 @@ Feature: rake license:action_items
3
3
  I want a rake task "license:action_items" that lists any dependencies with licenses that fall outside of my whitelist
4
4
  So that I know the limitations of distributing my application
5
5
 
6
+ Background:
7
+ Given I have an application setup with rake and license finder
8
+
6
9
  Scenario: Application with non-free dependency
7
- Given I have a rails application with license finder
8
- And my rails app depends on a gem "gpl_licensed_gem" licensed with "GPL"
9
- And my rails app depends on a gem "mit_licensed_gem" licensed with "MIT"
10
+ Given my app depends on a gem "gpl_licensed_gem" licensed with "GPL"
11
+ And my app depends on a gem "mit_licensed_gem" licensed with "MIT"
10
12
  And I whitelist the "MIT" license
11
- When I run "bundle exec rake license:action_items"
13
+ When I run "rake license:action_items"
12
14
  Then I should see "gpl_licensed_gem" in its output
13
15
  And I should not see "mit_licensed_gem" in its output
16
+
17
+ Scenario: Application with action items
18
+ Given my app depends on a gem "gpl_licensed_gem" licensed with "GPL"
19
+ And I whitelist the "MIT" license
20
+ When I run "rake license:action_items"
21
+ Then it should exit with status code 1
22
+
23
+ Scenario: Application with no action items
24
+ Given I whitelist the "MIT" license
25
+ When I run "rake license:action_items"
26
+ Then I should see "All gems are approved for use" in its output
27
+ And it should exit with status code 0
@@ -4,17 +4,20 @@ Feature: rake license:action_items:ok
4
4
  So that I can create a CI build that fails if there are any action items
5
5
 
6
6
  Background:
7
- Given I have a rails application with license finder
7
+ Given I have an application setup with rake and license finder
8
8
 
9
9
  Scenario: Application with action items
10
- Given my rails app depends on a gem "gpl_licensed_gem" licensed with "GPL"
10
+ Given my app depends on a gem "gpl_licensed_gem" licensed with "GPL"
11
11
  And I whitelist the "MIT" license
12
- When I run "bundle exec rake license:action_items:ok"
13
- Then I should see "Dependencies that need approval" in its output
14
- And it should exit with status code 1
12
+ When I run "rake license:action_items:ok"
13
+ Then it should exit with status code 1
15
14
 
16
15
  Scenario: Application with no action items
17
- Given I whitelist the following licenses: "MIT, other"
18
- When I run "bundle exec rake license:action_items:ok"
16
+ Given I whitelist the following licenses: "MIT"
17
+ When I run "rake license:action_items:ok"
19
18
  Then I should see "All gems are approved for use" in its output
20
19
  And it should exit with status code 0
20
+
21
+ Scenario: Deprecation for version 1.0
22
+ When I run "rake license:action_items:ok"
23
+ Then I should see "rake license:action_items:ok is deprecated and will be removed in version 1.0. Use rake license:action_items instead." in its output
@@ -4,28 +4,59 @@ Feature: rake license:generate_dependencies
4
4
  So that I can manually approve a dependency with a non-whitelisted license
5
5
 
6
6
  Scenario: Manually approve non-whitelisted dependency
7
- Given I have a rails application with license finder
8
- And my rails app depends on a gem "gpl_gem" licensed with "GPL"
7
+ Given I have an application setup with rake and license finder
8
+ And my app depends on a gem "gpl_gem" licensed with "GPL"
9
9
  And I whitelist the "MIT" license
10
10
 
11
- When I run "bundle exec rake license:generate_dependencies"
11
+ When I run "rake license:generate_dependencies"
12
+ Then I should see the following settings for "gpl_gem":
13
+ """
14
+ version: "0.0.0"
15
+ license: "GPL"
16
+ approved: false
17
+ """
12
18
 
13
- Then license finder should generate a file "dependencies.yml" that includes the following content:
19
+ When I update the settings for "gpl_gem" with the following content:
14
20
  """
15
- - name: "gpl_gem"
21
+ approved: true
22
+ """
23
+ And I run "rake license:action_items"
24
+ Then I should not see "gpl_gem" in its output
25
+
26
+ Scenario: Manually adding a javascript dependency to dependencies.yml
27
+ Given I have an application setup with rake and license finder
28
+ When I run "rake license:generate_dependencies"
29
+ And I add the following content to "dependencies.yml":
30
+ """
31
+ - name: "my_javascript_library"
16
32
  version: "0.0.0"
17
33
  license: "GPL"
18
34
  approved: false
19
35
  """
36
+ And I run "rake license:action_items"
37
+ Then I should see "my_javascript_library" in its output
20
38
 
21
- When I replace that content with the following content in "dependencies.yml":
39
+ When I update the settings for "my_javascript_library" with the following content:
22
40
  """
23
- - name: "gpl_gem"
24
- version: "0.0.0"
25
- license: "GPL"
26
- approved: true
41
+ approved: true
27
42
  """
43
+ And I run "rake license:action_items"
44
+ Then I should not see "my_javascript_library" in its output
28
45
 
29
- And I run "bundle exec rake license:action_items"
46
+ Scenario: I want to see the group that my dependencies belong to in the dependencies.txt
47
+ Given I have an application setup with rake and license finder
48
+ And my app depends on a gem "mit_gem" licensed with "MIT" in the "production" bundler groups
49
+ When I run "rake license:generate_dependencies"
50
+ Then license finder should generate a file "dependencies.txt" containing:
51
+ """
52
+ mit_gem 0.0.0, MIT, production
53
+ """
30
54
 
31
- Then I should not see "gpl_gem" in its output
55
+ Scenario: I have specified multiple groups for my gem
56
+ Given I have an application setup with rake and license finder
57
+ And my app depends on a gem "mit_gem" licensed with "MIT" in the "production, demo, staging" bundler groups
58
+ When I run "rake license:generate_dependencies"
59
+ Then license finder should generate a file "dependencies.txt" containing:
60
+ """
61
+ mit_gem 0.0.0, MIT, production, demo, staging
62
+ """
@@ -5,7 +5,7 @@ Feature: rake license:init
5
5
 
6
6
  Scenario: No license finder configuration
7
7
  Given I have a rails application with license finder
8
- When I run "bundle exec rake license:init"
8
+ When I run "rake license:init"
9
9
  Then license finder should generate a file "config/license_finder.yml" with the following content:
10
10
  """
11
11
  ---
@@ -17,3 +17,10 @@ Feature: rake license:init
17
17
  #- development
18
18
  dependencies_file_dir: './'
19
19
  """
20
+
21
+ Scenario: The project including LicenseFinder does not already have a config directory
22
+ Given I have an application with license finder
23
+ And my application's rake file requires license finder
24
+ And my application does not have a config directory
25
+ When I run "rake license:init"
26
+ Then the config directory should exist
@@ -0,0 +1,18 @@
1
+ Feature: Catch Regressions!
2
+
3
+ Scenario Outline: Generating dependencies multiple times should not lose information
4
+ Given I have an application setup with rake and license finder
5
+ And my application depends on a gem "descriptive_gem" with:
6
+ | license | summary | description |
7
+ | MIT | summary | description |
8
+ When I run "<command>"
9
+ And I run "<command>"
10
+ Then license finder should generate a file "dependencies.txt" containing:
11
+ """
12
+ descriptive_gem 0.0.0, MIT, summary, description, default
13
+ """
14
+
15
+ Examples:
16
+ | command |
17
+ | rake license:generate_dependencies |
18
+ | rake license:action_items |
@@ -1,10 +1,42 @@
1
+ require 'fileutils'
2
+
1
3
  Given /^I have a rails application with license finder$/ do
2
4
  @user = DSL::User.new
3
5
  @user.create_rails_app
4
6
  end
5
7
 
6
- Given /^my rails app depends on a gem "(.*?)" licensed with "(.*?)"$/ do |gem_name, license|
7
- @user.add_dependency_to_app gem_name, license
8
+ Given /^I have an application with license finder$/ do
9
+ @user = DSL::User.new
10
+ @user.create_nonrails_app
11
+ end
12
+
13
+
14
+ Given /^I have an application setup with rake and license finder$/ do
15
+ @user = DSL::User.new
16
+ @user.create_nonrails_app
17
+ @user.add_license_finder_to_rakefile
18
+ @user.execute_command "rake license:init"
19
+ end
20
+
21
+ Given /^my application does not have a config directory$/ do
22
+ FileUtils.rm_rf(@user.config_path)
23
+ File.exists?(@user.config_path).should be_false
24
+ end
25
+
26
+ Then /^the config directory should exist$/ do
27
+ File.exists?(@user.config_path).should be_true
28
+ end
29
+
30
+ Given /^my application's rake file requires license finder$/ do
31
+ @user.add_license_finder_to_rakefile
32
+ end
33
+
34
+ Given /^my (?:rails )?app depends on a gem "(.*?)" licensed with "(.*?)"$/ do |gem_name, license|
35
+ @user.add_dependency_to_app gem_name, :license => license
36
+ end
37
+
38
+ Given /^my (?:rails )?app depends on a gem "(.*?)" licensed with "(.*?)" in the "(.*?)" bundler groups$/ do |gem_name, license, bundler_groups|
39
+ @user.add_dependency_to_app gem_name, :license => license, :bundler_groups => bundler_groups
8
40
  end
9
41
 
10
42
  Given /^I whitelist the "(.*?)" license$/ do |license|
@@ -19,8 +51,21 @@ When /^I run "(.*?)"$/ do |command|
19
51
  @output = @user.execute_command command
20
52
  end
21
53
 
22
- When /^I replace that content with the following content in "([^"]*)":$/ do |filename, text|
23
- @user.edit_file(filename, replace_this: @content, with: text)
54
+ When /^I update the settings for "([^"]*)" with the following content:$/ do |gem, text|
55
+ @user.update_gem(gem, YAML.load(text))
56
+ end
57
+
58
+ When /^I add the following content to "([^"]*)":$/ do |filename, text|
59
+ @user.append_to_file(filename, @content = text)
60
+ end
61
+
62
+ When /^my application depends on a gem "([^"]*)" with:$/ do |gem_name, gem_info|
63
+ info = gem_info.hashes.first
64
+ @user.add_dependency_to_app(gem_name,
65
+ :license => info["license"],
66
+ :summary => info["summary"],
67
+ :description => info["description"]
68
+ )
24
69
  end
25
70
 
26
71
  Then /^I should see "(.*?)" in its output$/ do |gem_name|
@@ -32,13 +77,19 @@ Then /^I should not see "(.*?)" in its output$/ do |gem_name|
32
77
  end
33
78
 
34
79
  Then /^license finder should generate a file "([^"]*)" with the following content:$/ do |filename, text|
35
- File.read(File.join(@user.app_location, filename)).should == text.gsub(/^\s+/, "")
80
+ File.read(File.join(@user.app_path, filename)).should == text.gsub(/^\s+/, "")
36
81
  end
37
82
 
38
- Then /^license finder should generate a file "([^"]*)" that includes the following content:$/ do |filename, text|
39
- @content = text
40
- file = File.read(File.join(@user.app_location, filename))
41
- file.should include @content
83
+ Then /^license finder should generate a file "([^"]*)" containing:$/ do |filename, text|
84
+ File.read(File.join(@user.app_path, filename)).should include(text.gsub(/^\s+/, ""))
85
+ end
86
+
87
+ Then /^I should see the following settings for "([^"]*)":$/ do |name, yaml|
88
+ expected_settings = YAML.load(yaml)
89
+ all_settings = YAML.load(File.read(@user.dependencies_file_path))
90
+ actual_settings = all_settings.detect { |gem| gem['name'] == name }
91
+
92
+ actual_settings.should include expected_settings
42
93
  end
43
94
 
44
95
  Then /^it should exit with status code (\d)$/ do |status|
@@ -46,86 +97,155 @@ Then /^it should exit with status code (\d)$/ do |status|
46
97
  end
47
98
 
48
99
 
49
-
50
100
  module DSL
51
101
  class User
102
+ def create_nonrails_app
103
+ reset_projects!
104
+
105
+ `cd #{projects_path} && bundle gem #{app_name}`
106
+
107
+ add_gem_dependency('rake')
108
+ add_gem_dependency('license_finder', :path => root_path)
109
+ end
110
+
52
111
  def create_rails_app
53
- reset_sandbox!
112
+ reset_projects!
54
113
 
55
- `bundle exec rails new #{app_location} --skip-bundle`
114
+ `bundle exec rails new #{app_path} --skip-bundle`
56
115
 
57
- Bundler.with_clean_env do
58
- `cd #{app_location} && echo \"gem 'license_finder', path: '../../'\" >> Gemfile`
59
- end
116
+ add_gem_dependency('license_finder', :path => root_path)
117
+
118
+ bundle_app
60
119
  end
61
120
 
62
- def edit_file(filename, options={})
63
- replace_this = options.fetch :replace_this
64
- with = options.fetch :with
121
+ def add_license_finder_to_rakefile
122
+ add_to_rakefile <<-RUBY
123
+ require 'bundler/setup'
124
+ require 'license_finder'
125
+ LicenseFinder.load_rake_tasks
126
+ RUBY
127
+ end
128
+
129
+ def update_gem(name, attrs)
130
+ file_contents = YAML.load(File.read(dependencies_file_path))
65
131
 
66
- file_contents = File.read(File.join(app_location, filename))
132
+ index = file_contents.index { |gem| gem['name'] == name }
133
+ file_contents[index].merge!(attrs)
67
134
 
68
- file_contents[replace_this] = with
135
+ File.open(dependencies_file_path, "w") do |f|
136
+ f.puts file_contents.to_yaml
137
+ end
138
+ end
69
139
 
70
- File.open(File.join(app_location, filename), "w") do |f|
71
- f.puts file_contents
140
+ def append_to_file(filename, text)
141
+ File.open(File.join(app_path, filename), "a") do |f|
142
+ f.puts text
72
143
  end
73
144
  end
74
145
 
75
- def add_dependency_to_app(gem_name, license)
76
- `mkdir #{sandbox_location}/#{gem_name}`
146
+ def add_dependency_to_app(gem_name, options={})
147
+ license = options.fetch(:license)
148
+ summary = options.fetch(:summary, "")
149
+ description = options.fetch(:description, "")
150
+ bundler_groups = options.fetch(:bundler_groups, "").split(',').map(&:strip)
77
151
 
78
- File.open("#{sandbox_location}/#{gem_name}/#{gem_name}.gemspec", 'w') do |file|
152
+ gem_dir = File.join(projects_path, gem_name)
153
+
154
+ FileUtils.mkdir(gem_dir)
155
+ File.open(File.join(gem_dir, "#{gem_name}.gemspec"), 'w') do |file|
79
156
  file.write <<-GEMSPEC
80
157
  Gem::Specification.new do |s|
81
158
  s.name = "#{gem_name}"
82
159
  s.version = "0.0.0"
83
160
  s.author = "Cucumber"
84
- s.summary = "Gem for testing License Finder"
161
+ s.summary = "#{summary}"
85
162
  s.license = "#{license}"
163
+ s.description = "#{description}"
86
164
  end
87
165
  GEMSPEC
88
166
  end
89
167
 
90
- Bundler.with_clean_env do
91
- `cd #{app_location} && echo \"gem '#{gem_name}', path: '../#{gem_name}'\" >> Gemfile && bundle`
92
- end
168
+ gem_options = {}
169
+ gem_options[:path] = File.join(projects_path, gem_name)
170
+ gem_options[:groups] = bundler_groups unless bundler_groups.empty?
171
+
172
+ add_gem_dependency(gem_name, gem_options)
173
+
174
+ bundle_app
93
175
  end
94
176
 
95
177
  def configure_license_finder_whitelist(whitelisted_licenses=[])
96
- File.open("tmp/my_app/config/license_finder.yml", "w") do |f|
97
- f.write <<-YML
98
- ---
99
- whitelist:
100
- #{whitelisted_licenses.map {|l| "- #{l}"}.join("\n")}
101
- YML
178
+ File.open(File.join(config_path, "license_finder.yml"), "w") do |f|
179
+ f.write({'whitelist' => whitelisted_licenses}.to_yaml)
102
180
  end
103
181
  end
104
182
 
105
183
  def execute_command(command)
106
184
  Bundler.with_clean_env do
107
- @output = `cd #{app_location} && bundle exec #{command}`
185
+ @output = `cd #{app_path} && bundle exec #{command}`
108
186
  end
109
187
 
110
188
  @output
111
189
  end
112
190
 
113
- def app_location
114
- File.join(sandbox_location, app_name)
191
+ def app_path
192
+ File.join(projects_path, app_name)
193
+ end
194
+
195
+ def config_path
196
+ File.join(app_path, 'config')
197
+ end
198
+
199
+ def dependencies_file_path
200
+ File.join(app_path, 'dependencies.yml')
115
201
  end
116
202
 
117
203
  private
204
+
205
+ def bundle_app
206
+ Bundler.with_clean_env do
207
+ `bundle install --gemfile=#{File.join(app_path, "Gemfile")} --path=#{bundle_path}`
208
+ end
209
+ end
210
+
211
+ def add_gem_dependency(name, options = {})
212
+ line = "gem #{name.inspect}"
213
+ line << ", " + options.inspect unless options.empty?
214
+
215
+ add_to_gemfile(line)
216
+ end
217
+
218
+ def add_to_gemfile(line)
219
+ `echo #{line.inspect} >> #{File.join(app_path, "Gemfile")}`
220
+ end
221
+
222
+ def add_to_rakefile(line)
223
+ `echo #{line.inspect} >> #{File.join(app_path, "Rakefile")}`
224
+ end
225
+
118
226
  def app_name
119
227
  "my_app"
120
228
  end
121
229
 
122
- def sandbox_location
123
- "tmp"
230
+ def sandbox_path
231
+ File.join(root_path, "tmp")
232
+ end
233
+
234
+ def projects_path
235
+ File.join(sandbox_path, "projects")
236
+ end
237
+
238
+ def bundle_path
239
+ File.join(sandbox_path, "bundle")
240
+ end
241
+
242
+ def reset_projects!
243
+ `rm -rf #{projects_path}`
244
+ `mkdir -p #{projects_path}`
124
245
  end
125
246
 
126
- def reset_sandbox!
127
- `rm -rf #{sandbox_location}`
128
- `mkdir #{sandbox_location}`
247
+ def root_path
248
+ File.realpath(File.join(File.dirname(__FILE__), "..", ".."))
129
249
  end
130
250
  end
131
251
  end