license_finder 1.1.1-java → 1.2-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -2
  3. data/CHANGELOG.rdoc +10 -0
  4. data/Gemfile +1 -1
  5. data/README.md +363 -0
  6. data/Rakefile +30 -1
  7. data/TODO.md +28 -0
  8. data/bin/license_finder_pip.py +18 -0
  9. data/db/migrate/201410031451_rename_dependency_license_name.rb +6 -0
  10. data/features/multiple_licenses.feature +9 -0
  11. data/features/step_definitions/cli_steps.rb +9 -9
  12. data/features/step_definitions/cocoapod_steps.rb +1 -1
  13. data/features/step_definitions/configure_bundler_groups_steps.rb +3 -3
  14. data/features/step_definitions/configure_whitelist_steps.rb +4 -4
  15. data/features/step_definitions/gradle_steps.rb +1 -1
  16. data/features/step_definitions/manually_added_steps.rb +3 -3
  17. data/features/step_definitions/manually_approved_steps.rb +5 -5
  18. data/features/step_definitions/manually_assigned_license_steps.rb +4 -4
  19. data/features/step_definitions/maven_steps.rb +1 -1
  20. data/features/step_definitions/multiple_licenses_steps.rb +14 -0
  21. data/features/step_definitions/node_steps.rb +1 -1
  22. data/features/step_definitions/python_steps.rb +1 -1
  23. data/features/step_definitions/report_csv_steps.rb +3 -3
  24. data/features/step_definitions/report_html_steps.rb +5 -5
  25. data/features/step_definitions/shared_steps.rb +23 -6
  26. data/lib/license_finder.rb +3 -0
  27. data/lib/license_finder/cli.rb +13 -34
  28. data/lib/license_finder/configuration.rb +8 -4
  29. data/lib/license_finder/dependency_manager.rb +25 -15
  30. data/lib/license_finder/license.rb +8 -0
  31. data/lib/license_finder/logger.rb +59 -0
  32. data/lib/license_finder/package.rb +37 -30
  33. data/lib/license_finder/package_manager.rb +20 -0
  34. data/lib/license_finder/package_managers/bower.rb +4 -9
  35. data/lib/license_finder/package_managers/bower_package.rb +2 -1
  36. data/lib/license_finder/package_managers/bundler.rb +26 -41
  37. data/lib/license_finder/package_managers/bundler_package.rb +6 -3
  38. data/lib/license_finder/package_managers/cocoa_pods.rb +18 -10
  39. data/lib/license_finder/package_managers/cocoa_pods_package.rb +4 -3
  40. data/lib/license_finder/package_managers/gradle.rb +7 -11
  41. data/lib/license_finder/package_managers/gradle_package.rb +2 -7
  42. data/lib/license_finder/package_managers/maven.rb +5 -9
  43. data/lib/license_finder/package_managers/maven_package.rb +4 -8
  44. data/lib/license_finder/package_managers/npm.rb +6 -10
  45. data/lib/license_finder/package_managers/npm_package.rb +2 -1
  46. data/lib/license_finder/package_managers/pip.rb +11 -24
  47. data/lib/license_finder/package_managers/pip_package.rb +2 -1
  48. data/lib/license_finder/package_saver.rb +2 -2
  49. data/lib/license_finder/platform.rb +4 -0
  50. data/lib/license_finder/possible_license_file.rb +4 -0
  51. data/lib/license_finder/possible_license_files.rb +2 -1
  52. data/lib/license_finder/reports/detailed_text_report.rb +1 -1
  53. data/lib/license_finder/reports/formatted_report.rb +1 -1
  54. data/lib/license_finder/tables/dependency.rb +22 -12
  55. data/lib/license_finder/yml_to_sql.rb +1 -1
  56. data/lib/templates/html_report.erb +4 -4
  57. data/lib/templates/markdown_report.erb +4 -4
  58. data/lib/templates/text_report.erb +1 -1
  59. data/license_finder.gemspec +28 -12
  60. data/spec/lib/license_finder/cli_spec.rb +193 -185
  61. data/spec/lib/license_finder/configuration_spec.rb +46 -47
  62. data/spec/lib/license_finder/dependency_manager_spec.rb +48 -44
  63. data/spec/lib/license_finder/license/definitions_spec.rb +26 -26
  64. data/spec/lib/license_finder/license_spec.rb +25 -25
  65. data/spec/lib/license_finder/package_managers/bower_package_spec.rb +33 -17
  66. data/spec/lib/license_finder/package_managers/bower_spec.rb +35 -35
  67. data/spec/lib/license_finder/package_managers/bundler_package_spec.rb +20 -15
  68. data/spec/lib/license_finder/package_managers/bundler_spec.rb +12 -19
  69. data/spec/lib/license_finder/package_managers/cocoa_pods_package_spec.rb +8 -5
  70. data/spec/lib/license_finder/package_managers/cocoa_pods_spec.rb +20 -22
  71. data/spec/lib/license_finder/package_managers/gradle_package_spec.rb +8 -5
  72. data/spec/lib/license_finder/package_managers/gradle_spec.rb +20 -20
  73. data/spec/lib/license_finder/package_managers/maven_package_spec.rb +8 -5
  74. data/spec/lib/license_finder/package_managers/maven_spec.rb +18 -18
  75. data/spec/lib/license_finder/package_managers/npm_package_spec.rb +36 -17
  76. data/spec/lib/license_finder/package_managers/npm_spec.rb +17 -17
  77. data/spec/lib/license_finder/package_managers/pip_package_spec.rb +16 -10
  78. data/spec/lib/license_finder/package_managers/pip_spec.rb +21 -18
  79. data/spec/lib/license_finder/package_saver_spec.rb +15 -25
  80. data/spec/lib/license_finder/possible_license_file_spec.rb +5 -4
  81. data/spec/lib/license_finder/possible_license_files_spec.rb +11 -5
  82. data/spec/lib/license_finder/reports/detailed_text_report_spec.rb +3 -3
  83. data/spec/lib/license_finder/reports/html_report_spec.rb +23 -23
  84. data/spec/lib/license_finder/reports/markdown_report_spec.rb +12 -12
  85. data/spec/lib/license_finder/reports/reporter_spec.rb +11 -11
  86. data/spec/lib/license_finder/reports/text_report_spec.rb +3 -3
  87. data/spec/lib/license_finder/tables/dependency_spec.rb +59 -41
  88. data/spec/lib/license_finder/yml_to_sql_spec.rb +21 -21
  89. data/spec/lib/license_finder_spec.rb +1 -1
  90. data/spec/spec_helper.rb +0 -13
  91. data/spec/support/shared_examples_for_package.rb +46 -0
  92. data/spec/support/shared_examples_for_package_manager.rb +15 -0
  93. metadata +19 -100
  94. data/readme.md +0 -259
data/TODO.md ADDED
@@ -0,0 +1,28 @@
1
+
2
+ # immediate
3
+
4
+ - gradle and maven are broken
5
+ - [x] let's refactor `PossibleLicenseFiles` to accept a nil install_path
6
+ - [x] then remove `#licenses_from_files` from `{maven,gradle}_package.rb`
7
+ - [x] update docs in package.rb to reflect what our expectations are.
8
+ - [x] commit the rest of the WIP
9
+
10
+
11
+ # architecture
12
+
13
+ - [x] package managers should use instance methods so we can inject things like loggers
14
+ - [ ] are we sprinkling database logic around too much? see 23f4cae for related work.
15
+
16
+
17
+ # renamings, etc.
18
+
19
+ - [x] retitle the shared example "it conforms to interface required by PackageSaver"
20
+ - [x] shared specs should go into a separate file(s)
21
+ - [ ] classes under `package_managers` should be in a PackageManagers module
22
+ - [ ] `license_names_from_standard_spec` should be the default instance method
23
+ - [ ] #groups in some Packages, #included_groups etc. in others
24
+
25
+
26
+ # docs
27
+
28
+ - [ ] specify gradle version >= 1.8
@@ -0,0 +1,18 @@
1
+ #! /usr/bin/env python
2
+
3
+ import json
4
+ from pip.util import get_installed_distributions
5
+
6
+ packages = []
7
+
8
+ for dist in get_installed_distributions():
9
+ packages.append(
10
+ {
11
+ "name": dist.project_name,
12
+ "version": dist.version,
13
+ "location": dist.location,
14
+ "dependencies": map(lambda dependency: dependency.project_name, dist.requires())
15
+ }
16
+ )
17
+
18
+ print json.dumps(packages)
@@ -0,0 +1,6 @@
1
+ Sequel.migration do
2
+ up do
3
+ rename_column :dependencies, :license_name, :license_names
4
+ run %Q{UPDATE dependencies SET license_names='["' || license_names || '"]'}
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ Feature: Dependencies with multiple licenses
2
+ As a developer
3
+ I want multi-licensed dependencies to be approved if one license is whitelisted
4
+ So that any dependencies with those licenses do not show up as action items
5
+
6
+ Scenario: Depending on whitelisted licenses
7
+ Given I have an app that depends on BSD and GPL-2 licenses
8
+ When I whitelist the GPL-2 license
9
+ Then I should not see a BSD and GPL-2 licensed gem unapproved
@@ -3,7 +3,7 @@ Given(/^I have an app that has no config directory$/) do
3
3
  @user.create_ruby_app
4
4
  path = @user.config_path
5
5
  path.rmtree if path.exist?
6
- path.should_not be_exist
6
+ expect(path).to_not be_exist
7
7
  end
8
8
 
9
9
  Given(/^I have an app with an unapproved dependency$/) do
@@ -21,31 +21,31 @@ When(/^I run license_finder help$/) do
21
21
  end
22
22
 
23
23
  Then(/^it creates a config directory with the license_finder config$/) do
24
- @user.config_path.should be_exist
24
+ expect(@user.config_path).to be_exist
25
25
  text = %|---\nwhitelist:\n#- MIT\n#- Apache 2.0\nignore_groups:\n#- test\n#- development\nignore_dependencies:\n#- bundler\ndependencies_file_dir: './doc/'\nproject_name: # project name\ngradle_command: # only meaningful if used with a Java/gradle project. Defaults to "gradle".\n|
26
- @user.config_file.read.should == text.gsub(/^\s+/, "")
26
+ expect(@user.config_file.read).to eq(text.gsub(/^\s+/, ""))
27
27
  end
28
28
 
29
29
  Then /^it should exit with status code (\d)$/ do |status|
30
- $?.exitstatus.should == status.to_i
30
+ expect($last_command_exit_status.exitstatus).to eq(status.to_i)
31
31
  end
32
32
 
33
33
  Then(/^should list my unapproved dependency in the output$/) do
34
- @user.should be_seeing 'unapproved_gem'
34
+ expect(@user).to be_seeing 'unapproved_gem'
35
35
  end
36
36
 
37
37
  Then(/^I should see all dependencies approved for use$/) do
38
- @user.should be_seeing 'All dependencies are approved for use'
38
+ expect(@user).to be_seeing 'All dependencies are approved for use'
39
39
  end
40
40
 
41
41
  Then(/^I should see the correct subcommand usage instructions$/) do
42
- @user.should be_seeing 'license_finder ignored_bundler_groups add GROUP'
42
+ expect(@user).to be_seeing 'license_finder ignored_bundler_groups add GROUP'
43
43
  end
44
44
 
45
45
  Then(/^I should see the default usage instructions$/) do
46
- @user.should be_seeing 'license_finder help [COMMAND]'
46
+ expect(@user).to be_seeing 'license_finder help [COMMAND]'
47
47
  end
48
48
 
49
49
  Then(/^I should see License Finder has the MIT license$/) do
50
- @user.should be_seeing_something_like /license_finder.*MIT/
50
+ expect(@user).to be_seeing_something_like /license_finder.*MIT/
51
51
  end
@@ -4,5 +4,5 @@ Given(/^A Podfile with dependencies$/) do
4
4
  end
5
5
 
6
6
  Then(/^I should see a CocoaPods dependency with a license$/) do
7
- @user.should be_seeing_line "ABTest, 0.0.5, MIT"
7
+ expect(@user).to be_seeing_line "ABTest, 0.0.5, MIT"
8
8
  end
@@ -18,13 +18,13 @@ When(/^I get the ignored groups$/) do
18
18
  end
19
19
 
20
20
  Then(/^I should not see the test gem in the output$/) do
21
- @user.should_not be_seeing 'gpl_gem'
21
+ expect(@user).to_not be_seeing 'gpl_gem'
22
22
  end
23
23
 
24
24
  Then(/^I should see the test group in the output$/) do
25
- @user.should be_seeing 'test'
25
+ expect(@user).to be_seeing 'test'
26
26
  end
27
27
 
28
28
  Then(/^I should not see the test group in the output$/) do
29
- @user.should_not be_seeing 'test'
29
+ expect(@user).to_not be_seeing 'test'
30
30
  end
@@ -28,18 +28,18 @@ end
28
28
 
29
29
  Then(/^I should not see a MIT licensed gem unapproved$/) do
30
30
  @user.execute_command 'license_finder --quiet'
31
- @user.should_not be_seeing 'mit_gem'
31
+ expect(@user).to_not be_seeing 'mit_gem'
32
32
  end
33
33
 
34
34
  Then(/^I should see Expat in the output$/) do
35
- @user.should be_seeing 'Expat'
35
+ expect(@user).to be_seeing 'Expat'
36
36
  end
37
37
 
38
38
  Then(/^I should not see Expat in the output$/) do
39
- @user.should_not be_seeing 'Expat'
39
+ expect(@user).to_not be_seeing 'Expat'
40
40
  end
41
41
 
42
42
  Then(/^I should not see a BSD licensed gem unapproved$/) do
43
43
  @user.execute_command 'license_finder --quiet'
44
- @user.should_not be_seeing 'bsd_gem'
44
+ expect(@user).to_not be_seeing 'bsd_gem'
45
45
  end
@@ -4,5 +4,5 @@ Given(/^A build.gradle file with dependencies$/) do
4
4
  end
5
5
 
6
6
  Then(/^I should see a Gradle dependency with a license$/) do
7
- @user.should be_seeing_line "junit, 4.11, Common Public License Version 1.0"
7
+ expect(@user).to be_seeing_line "junit, 4.11, Common Public License Version 1.0"
8
8
  end
@@ -10,7 +10,7 @@ end
10
10
 
11
11
  When(/^I add my JS dependency with an approval flag$/) do
12
12
  @user.execute_command 'license_finder dependencies add --approve MIT my_js_dep 1.2.3'
13
- @user.should be_seeing "The my_js_dep dependency has been added and approved"
13
+ expect(@user).to be_seeing "The my_js_dep dependency has been added and approved"
14
14
  end
15
15
 
16
16
  When(/^I remove my JS dependency$/) do
@@ -19,10 +19,10 @@ end
19
19
 
20
20
  Then(/^I should see the JS dependency in the console output$/) do
21
21
  @user.execute_command 'license_finder --quiet'
22
- @user.should be_seeing 'my_js_dep, 1.2.3, MIT'
22
+ expect(@user).to be_seeing 'my_js_dep, 1.2.3, MIT'
23
23
  end
24
24
 
25
25
  Then(/^I should not see the JS dependency in the console output$/) do
26
26
  @user.execute_command 'license_finder --quiet'
27
- @user.should_not be_seeing 'my_js_dep, 1.2.3, MIT'
27
+ expect(@user).to_not be_seeing 'my_js_dep, 1.2.3, MIT'
28
28
  end
@@ -6,19 +6,19 @@ end
6
6
 
7
7
  When(/^I approve that gem$/) do
8
8
  @user.execute_command "license_finder"
9
- @user.should be_seeing "gpl_gem"
9
+ expect(@user).to be_seeing "gpl_gem"
10
10
  @user.execute_command "license_finder approve gpl_gem --approver 'Julian' --message 'We really need this'"
11
11
  @user.execute_command "license_finder --quiet"
12
12
  end
13
13
 
14
14
  Then(/^I should not see that gem in the console output$/) do
15
- @user.should_not be_seeing "gpl_gem"
15
+ expect(@user).to_not be_seeing "gpl_gem"
16
16
  end
17
17
 
18
18
  Then(/^I should see that gem approved in dependencies\.html$/) do
19
19
  @user.in_gem_html("gpl_gem") do |gpl_gem|
20
- gpl_gem[:class].split(' ').should include "approved"
21
- gpl_gem.should have_content "Julian"
22
- gpl_gem.should have_content "We really need this"
20
+ expect(gpl_gem[:class].split(' ')).to include "approved"
21
+ expect(gpl_gem).to have_content "Julian"
22
+ expect(gpl_gem).to have_content "We really need this"
23
23
  end
24
24
  end
@@ -12,11 +12,11 @@ When(/^I set one gem's license to MIT from the command line$/) do
12
12
  end
13
13
 
14
14
  Then(/^I should see that gem's license set to MIT$/) do
15
- @user.should be_seeing 'other_gem, 1.0, MIT'
15
+ expect(@user).to be_seeing 'other_gem, 1.0, MIT'
16
16
  end
17
17
 
18
18
  Then(/^I should see other gems have not changed their licenses$/) do
19
- @user.should be_seeing 'control_gem, 1.0, other'
19
+ expect(@user).to be_seeing 'control_gem, 1.0, other'
20
20
  end
21
21
 
22
22
  Given(/^I have an app that depends on a manually licensed gem$/) do
@@ -25,10 +25,10 @@ Given(/^I have an app that depends on a manually licensed gem$/) do
25
25
  @user.create_and_depend_on_gem 'changed_gem', license: 'MIT'
26
26
  @user.execute_command "license_finder --quiet"
27
27
  @user.execute_command "license_finder license Ruby changed_gem"
28
- @user.should be_seeing_something_like /changed_gem.*Ruby/
28
+ expect(@user).to be_seeing_something_like /changed_gem.*Ruby/
29
29
  end
30
30
 
31
31
  Then(/^the gem should keep its manually assigned license$/) do
32
- @user.should be_seeing_something_like /changed_gem.*ruby/
32
+ expect(@user).to be_seeing_something_like /changed_gem.*ruby/
33
33
  end
34
34
 
@@ -4,5 +4,5 @@ Given(/^A pom file with dependencies$/) do
4
4
  end
5
5
 
6
6
  Then(/^I should see a Maven dependency with a license$/) do
7
- @user.should be_seeing_line "junit, 4.11, Common Public License Version 1.0"
7
+ expect(@user).to be_seeing_line "junit, 4.11, Common Public License Version 1.0"
8
8
  end
@@ -0,0 +1,14 @@
1
+ Given(/^I have an app that depends on BSD and GPL-2 licenses$/) do
2
+ @user = ::DSL::User.new
3
+ @user.create_ruby_app
4
+ @user.create_and_depend_on_gem 'bsd_and_gpl2_gem', licenses: %w(BSD GPL-2)
5
+ end
6
+
7
+ When(/^I whitelist the GPL-2 license$/) do
8
+ @user.execute_command 'license_finder whitelist add GPL-2'
9
+ end
10
+
11
+ Then(/^I should not see a BSD and GPL-2 licensed gem unapproved$/) do
12
+ @user.execute_command 'license_finder --quiet'
13
+ expect(@user).to_not be_seeing 'bsd_and_gpl2_gem'
14
+ end
@@ -4,5 +4,5 @@ Given(/^A package file with dependencies$/) do
4
4
  end
5
5
 
6
6
  Then(/^I should see a Node dependency with a license$/) do
7
- @user.should be_seeing_line "http-server, 0.6.1, MIT"
7
+ expect(@user).to be_seeing_line "http-server, 0.6.1, MIT"
8
8
  end
@@ -4,5 +4,5 @@ Given(/^A requirements file with dependencies$/) do
4
4
  end
5
5
 
6
6
  Then(/^I should see a Python dependency with a license$/) do
7
- @user.should be_seeing_line "argparse, 1.2.1, Python Software Foundation License"
7
+ expect(@user).to be_seeing_line "argparse, 1.2.1, Python Software Foundation License"
8
8
  end
@@ -11,10 +11,10 @@ Given(/^I have a dependencies\.txt file$/) do
11
11
  end
12
12
 
13
13
  Then(/^I should see those version and license details in the dependencies\.csv file$/) do
14
- @user.app_path("doc/dependencies.csv").read.should include "info_gem, 1.1.1, MIT"
14
+ expect(@user.app_path("doc/dependencies.csv").read).to include "info_gem, 1.1.1, MIT"
15
15
  end
16
16
 
17
17
  Then(/^I should see dependencies\.txt replaced by dependencies\.csv$/) do
18
- @user.app_path("doc/dependencies.txt").should_not be_exist
19
- @user.app_path("doc/dependencies.csv").should be_exist
18
+ expect(@user.app_path("doc/dependencies.txt")).to_not be_exist
19
+ expect(@user.app_path("doc/dependencies.csv")).to be_exist
20
20
  end
@@ -30,9 +30,9 @@ end
30
30
 
31
31
  Then(/^I should see my specific gem details listed in the html$/) do
32
32
  @user.in_gem_html(@gem_name) do |section|
33
- section.find("a[href='#{@gem_homepage}']", text: @gem_name).should be
33
+ expect(section.find("a[href='#{@gem_homepage}']", text: @gem_name)).to be
34
34
  @table.values.each do |property_value|
35
- section.should have_content property_value
35
+ expect(section).to have_content property_value
36
36
  end
37
37
  end
38
38
  end
@@ -47,14 +47,14 @@ end
47
47
 
48
48
  Then(/^I should see only see GPL liceneses as unapproved in the html$/) do
49
49
  @user.in_html do |page|
50
- page.should have_content '1 GPL'
50
+ expect(page).to have_content '1 GPL'
51
51
  action_items = page.find('.action-items')
52
- action_items.should have_content '(GPL)'
52
+ expect(action_items).to have_content '(GPL)'
53
53
  end
54
54
  end
55
55
 
56
56
  def is_html_status?(gem, approval)
57
57
  @user.in_gem_html(gem) do |gpl_gem|
58
- gpl_gem[:class].split(' ').should include approval
58
+ expect(gpl_gem[:class].split(' ')).to include approval
59
59
  end
60
60
  end
@@ -2,6 +2,7 @@ require 'fileutils'
2
2
  require 'pathname'
3
3
  require 'bundler'
4
4
  require 'capybara'
5
+ require 'open3'
5
6
 
6
7
  ########## COMMON STEPS ##########
7
8
 
@@ -23,7 +24,7 @@ Then(/^I should see the project name (\w+) in the html$/) do |project_name|
23
24
  @user.in_html do |page|
24
25
  title = page.find("h1")
25
26
 
26
- title.should have_content project_name
27
+ expect(title).to have_content project_name
27
28
  end
28
29
  end
29
30
 
@@ -171,7 +172,12 @@ module DSL
171
172
  private
172
173
 
173
174
  def gemspec_string(gem_name, options)
174
- license = options.fetch(:license)
175
+ if options.has_key?(:license) && options.has_key?(:licenses)
176
+ raise "Can't specify both `license` and `licenses`"
177
+ end
178
+
179
+ license_key = ([:license, :licenses] & options.keys).first
180
+ license_value = options.fetch(license_key)
175
181
  summary = options.fetch(:summary, "")
176
182
  description = options.fetch(:description, "")
177
183
  version = options[:version] || "0.0.0"
@@ -183,7 +189,7 @@ module DSL
183
189
  s.version = "#{version}"
184
190
  s.author = "Cucumber"
185
191
  s.summary = "#{summary}"
186
- s.license = "#{license}"
192
+ s.#{license_key} = #{license_value.inspect}
187
193
  s.description = "#{description}"
188
194
  s.homepage = "#{homepage}"
189
195
  end
@@ -224,7 +230,7 @@ module DSL
224
230
 
225
231
  def bundle_install
226
232
  ::Bundler.with_clean_env do
227
- shell_out("bundle install --gemfile=#{app_path.join("Gemfile")} --path=#{sandbox_path.join("bundle")}")
233
+ shell_out("cd #{app_path} && bundle check || bundle install")
228
234
  end
229
235
  end
230
236
 
@@ -282,8 +288,19 @@ module DSL
282
288
  end
283
289
 
284
290
  def shell_out(command, allow_failures = false)
285
- output = `#{command}`
286
- raise RuntimeError.new("command failed #{command}") unless $?.success? || allow_failures
291
+ output = `#{command} 2>&1`
292
+ status = $?
293
+ unless status.success? || allow_failures
294
+ message_format = <<EOM
295
+ Command failed: `%s`
296
+ output: %s
297
+ exit: %d
298
+ EOM
299
+ message = sprintf message_format, command, output.chomp, status.exitstatus
300
+ raise RuntimeError.new(message)
301
+ end
302
+
303
+ $last_command_exit_status = status
287
304
  output
288
305
  end
289
306
  end
@@ -4,10 +4,13 @@ require 'erb'
4
4
 
5
5
  module LicenseFinder
6
6
  ROOT_PATH = Pathname.new(__FILE__).dirname
7
+ BIN_PATH = ROOT_PATH.join("../bin")
7
8
 
8
9
  Error = Class.new(StandardError)
9
10
 
11
+ autoload :Logger, 'license_finder/logger'
10
12
  autoload :CLI, 'license_finder/cli'
13
+ autoload :PackageManager, 'license_finder/package_manager'
11
14
  autoload :DependencyManager, 'license_finder/dependency_manager'
12
15
  autoload :PackageSaver, 'license_finder/package_saver'
13
16
  autoload :License, 'license_finder/license'
@@ -11,11 +11,10 @@ module LicenseFinder
11
11
 
12
12
  private
13
13
 
14
- def sync_with_spinner
14
+ def sync_with_package_managers options={}
15
15
  die_on_error {
16
- spinner {
17
- DependencyManager.sync_with_package_managers
18
- }
16
+ logger = LicenseFinder::Logger.new options
17
+ DependencyManager.new(logger: logger).sync_with_package_managers
19
18
  }
20
19
  end
21
20
 
@@ -25,29 +24,6 @@ module LicenseFinder
25
24
  say e.message, :red
26
25
  exit 1
27
26
  end
28
-
29
- def spinner
30
- if options[:quiet]
31
- yield
32
- else
33
- begin
34
- thread = Thread.new {
35
- wheel = '\|/-'
36
- i = 0
37
- while true do
38
- print "\r ---------- #{wheel[i]} ----------"
39
- i = (i + 1) % 4
40
- end
41
- }
42
- yield
43
- ensure
44
- if thread
45
- thread.kill
46
- puts "\r" + " "*24
47
- end
48
- end
49
- end
50
- end
51
27
  end
52
28
 
53
29
  # Thor fix for `license_finder <subcommand> help <action>`
@@ -76,8 +52,10 @@ module LicenseFinder
76
52
  desc "add LICENSE DEPENDENCY_NAME [VERSION] [--approve] [--approver APPROVER_NAME] [--message APPROVAL_MESSAGE]", "Add a dependency that is not managed by a package manager, optionally storing who approved the dependency and why"
77
53
  def add(license, name, version = nil)
78
54
  die_on_error {
79
- DependencyManager.manually_add(license, name, version)
80
- DependencyManager.approve!(name, options[:approver], options[:message]) if options[:approve]
55
+ DependencyManager.new.tap do |dependency_manager|
56
+ dependency_manager.manually_add(license, name, version)
57
+ dependency_manager.approve!(name, options[:approver], options[:message]) if options[:approve]
58
+ end
81
59
  }
82
60
  if options[:approve]
83
61
  say "The #{name} dependency has been added and approved!", :green
@@ -89,7 +67,7 @@ module LicenseFinder
89
67
  desc "remove DEPENDENCY_NAME", "Remove a dependency that is not managed by a package manager"
90
68
  def remove(name)
91
69
  die_on_error {
92
- DependencyManager.manually_remove(name)
70
+ DependencyManager.new.manually_remove(name)
93
71
  }
94
72
 
95
73
  say "The #{name} dependency has been removed.", :green
@@ -104,7 +82,7 @@ module LicenseFinder
104
82
  yield
105
83
 
106
84
  LicenseFinder.config.save
107
- sync_with_spinner
85
+ sync_with_package_managers
108
86
  }
109
87
  end
110
88
  end
@@ -215,9 +193,10 @@ module LicenseFinder
215
193
 
216
194
  class Main < Base
217
195
  method_option :quiet, type: :boolean, desc: "silences loading output"
196
+ method_option :debug, type: :boolean, desc: "emit detailed info about what LicenseFinder is doing"
218
197
  desc "rescan", "Find new dependencies. (Default action)"
219
198
  def rescan
220
- sync_with_spinner
199
+ sync_with_package_managers options
221
200
  show_results
222
201
  end
223
202
 
@@ -235,7 +214,7 @@ module LicenseFinder
235
214
  def approve(name, *other_names)
236
215
  names = other_names.unshift name
237
216
  die_on_error {
238
- names.each { |name| DependencyManager.approve!(name, options[:approver], options[:message]) }
217
+ names.each { |name| DependencyManager.new.approve!(name, options[:approver], options[:message]) }
239
218
  }
240
219
 
241
220
  say "The #{names.join(", ")} dependency has been approved!", :green
@@ -244,7 +223,7 @@ module LicenseFinder
244
223
  desc "license LICENSE DEPENDENCY_NAME", "Update a dependency's license"
245
224
  def license(license, name)
246
225
  die_on_error {
247
- DependencyManager.license!(name, license)
226
+ DependencyManager.new.license!(name, license)
248
227
  }
249
228
 
250
229
  say "The #{name} dependency has been marked as using #{license} license!", :green